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

Playing with laser

This commit is contained in:
Andrey Pohilko 2017-12-20 18:41:05 +03:00
parent b3dc409e33
commit 6d691b988f
2 changed files with 24 additions and 13 deletions

View File

@ -4,8 +4,8 @@ import time
from pylgbst import MoveHub, ColorDistanceSensor, COLORS, COLOR_RED, COLOR_CYAN
BASE_SPEED = 0.75
FIELD_WIDTH = 1.2
BASE_SPEED = 0.4
FIELD_WIDTH = 0.925 / BASE_SPEED
MOTOR_RATIO = 1.15
@ -32,9 +32,10 @@ class Plotter(MoveHub):
count = 0
max_tries = 50
while not self._marker_color and count < max_tries:
time.sleep(5.0 / max_tries)
time.sleep(5.0 / BASE_SPEED / max_tries)
count += 1
logging.debug("Centering tries: %s", count)
logging.info("Centering tries: %s, color #%s", count,
COLORS[self._marker_color] if self._marker_color else None)
if count >= max_tries:
raise RuntimeError("Failed to center caret")
finally:
@ -57,11 +58,11 @@ class Plotter(MoveHub):
self._tool_up()
def _tool_down(self):
self.motor_external.angled(270, 1)
self.motor_external.angled(-270, 1)
self.is_tool_down = True
def _tool_up(self):
self.motor_external.angled(-270, 1)
self.motor_external.angled(270, 1)
self.is_tool_down = False
def move(self, movx, movy):
@ -142,7 +143,7 @@ class Plotter(MoveHub):
self._tool_down()
dur = 0.00
parts = 12
parts = 16
speeds = []
for r in range(0, rounds):
logging.info("Round: %s", r)

View File

@ -1,6 +1,8 @@
import logging
import traceback
import time
from examples.plotter import Plotter, FIELD_WIDTH
from pylgbst.comms import DebugServerConnection, BLEConnection
@ -50,6 +52,13 @@ def circles():
plotter.circle(FIELD_WIDTH)
class LaserPlotter(Plotter):
def _tool_down(self):
super(LaserPlotter, self)._tool_down()
time.sleep(1)
if __name__ == '__main__':
logging.basicConfig(level=logging.INFO)
@ -59,19 +68,20 @@ if __name__ == '__main__':
logging.warning("Failed to use debug server: %s", traceback.format_exc())
conn = BLEConnection().connect()
plotter = Plotter(conn)
plotter = LaserPlotter(conn)
try:
# plotter._tool_down()
# plotter._tool_up()
plotter.initialize()
# moves()
# triangle()
# square()
# cross()
#triangle()
#square()
#cross()
# romb()
# circles()
plotter.spiral(4, 0.01)
#circles()
plotter.spiral(4, 0.02)
pass
finally:
plotter.finalize()