1
0
mirror of https://github.com/undera/pylgbst.git synced 2020-11-18 19:37:26 -08:00

Some more examples

This commit is contained in:
Andrey Pohilko 2017-12-21 17:02:36 +03:00
parent 0496bb6dbd
commit af05877fde
2 changed files with 56 additions and 9 deletions

View File

@ -24,15 +24,15 @@ class Plotter(MoveHub):
self.is_tool_down = False
def _reset_caret(self):
self.motor_A.timed(0.2, self.base_speed)
self.motor_A.timed(0.5, 0.4)
self.color_distance_sensor.subscribe(self._on_distance, mode=ColorDistanceSensor.COLOR_DISTANCE_FLOAT,
granularity=5)
granularity=1)
try:
self.motor_A.constant(-self.base_speed)
self.motor_A.constant(-0.4)
count = 0
max_tries = 50
while not self._marker_color and count < max_tries:
time.sleep(5.0 / self.base_speed / max_tries)
while self._marker_color != COLOR_RED and count < max_tries:
time.sleep(7.0 / max_tries)
count += 1
logging.info("Centering tries: %s, color #%s", count,
COLORS[self._marker_color] if self._marker_color else None)
@ -42,7 +42,7 @@ class Plotter(MoveHub):
self.motor_A.stop()
self.color_distance_sensor.unsubscribe(self._on_distance)
self.motor_A.timed(self.field_width, self.base_speed)
self.motor_A.timed(0.925 / 0.4, 0.5)
def _on_distance(self, color, distance):
self._marker_color = None
@ -94,7 +94,7 @@ class Plotter(MoveHub):
length, speed_a, speed_b = self._calc_motor(movx, movy)
self.motor_AB.timed(length * 4.0, -speed_a * self.base_speed / 4.0, -speed_b * self.base_speed / 4.0)
self.motor_AB.timed(length, -speed_a * self.base_speed, -speed_b * self.base_speed)
# time.sleep(0.5)
@ -165,3 +165,20 @@ class Plotter(MoveHub):
self.motor_AB.constant(spa, spb)
logging.info("Motor speeds: %.3f / %.3f", spa, spb)
time.sleep(dur)
def rectangle(self, width, height, solid=False):
self.line(width, 0)
self.line(0, height)
self.line(-width, 0)
self.line(0, -height)
if solid:
max_step = 0.1
rounds = int(math.ceil(height / max_step))
step = height / rounds
flip = 1
self.line(0, step) # luft
for r in range(1, rounds + 3):
self.line(0, step)
self.line(width * flip, 0)
flip = -flip

View File

@ -125,6 +125,33 @@ def lego():
plotter.line(0, -t)
def square_spiral():
rounds = 7
step = FIELD_WIDTH / 4.0 / rounds
for r in range(1, rounds):
plotter.line(step * r * 4, 0)
plotter.line(0, step * (r * 4 + 1))
plotter.line(-step * (r * 4 + 2), 0)
plotter.line(0, -step * (r * 4 + 3))
def christmas_tree():
t = FIELD_WIDTH / 5
plotter.line(t, t)
plotter.line(-t * 0.5, 0)
plotter.line(t, t)
plotter.line(-t * 0.5, 0)
plotter.line(t, t)
plotter.line(-t * 3.5, 0)
plotter.line(t, -t)
plotter.line(-t * 0.5, 0)
plotter.line(t, -t)
plotter.line(-t * 0.5, 0)
plotter.line(t, -t)
if __name__ == '__main__':
logging.basicConfig(level=logging.INFO)
@ -134,7 +161,7 @@ if __name__ == '__main__':
logging.warning("Failed to use debug server: %s", traceback.format_exc())
conn = BLEConnection().connect()
plotter = LaserPlotter(conn, 0.4)
plotter = LaserPlotter(conn, 0.15)
FIELD_WIDTH = plotter.field_width
try:
@ -149,7 +176,10 @@ if __name__ == '__main__':
# romb()
# circles()
# plotter.spiral(4, 0.02)
lego()
# plotter.rectangle(FIELD_WIDTH / 5.0, FIELD_WIDTH / 5.0, solid=True)
# lego()
# square_spiral()
christmas_tree()
pass
finally:
plotter.finalize()