Skip to content

Commit cfaca26

Browse files
committed
backlash implementation
1 parent f1180c3 commit cfaca26

2 files changed

Lines changed: 20 additions & 8 deletions

File tree

yaqd_pololu/_pololu_ticcmd.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ def __init__(self, name, config, config_filepath):
1515
self.cmd = ["ticcmd"]
1616
if config["serial"]:
1717
self.cmd += ["-d", config["serial"]]
18+
self._awaiting_backlash = False
19+
self.backlash = self._config["backlash"]
1820

1921
def ticcmd(self, *args):
2022
try:
@@ -32,7 +34,7 @@ async def update_state(self):
3234
status = self._get_status()
3335
self._state["position"] = int(status["Current position"])
3436
self._state["destination"] = int(status["Acting target position"])
35-
while self._state["position"] != self._state["destination"]:
37+
while (self._state["position"] != self._state["destination"]) and not self._awaiting_backlash:
3638
await asyncio.sleep(0.2)
3739
self.ticcmd("--reset-command-timeout")
3840
status = self._get_status()
@@ -49,9 +51,23 @@ def _transformed_to_relative(self, transformed_position):
4951
# units to steps
5052
return transformed_position * self._config["steps_per_unit"]
5153

52-
def _set_position(self, position):
54+
def _set_position(self, destination):
5355
self.ticcmd("--resume")
54-
self.ticcmd("--exit-safe-start", "-p", str(int(position)))
56+
if ((destination - self.state["position"]) * self.backlash > 0):
57+
destination += self.backlash
58+
self._awaiting_backlash = True
59+
asyncio.get_running_loop.create_task(self._correct_backlash())
60+
self.ticcmd("--exit-safe-start", "-p", str(int(destination)))
61+
62+
async def _correct_backlash(self):
63+
"""if backlash was applied, correct the backlash after movement"""
64+
await self._not_busy_sig.wait()
65+
self.ticcmd(
66+
"--exit-safe-start",
67+
"-p",
68+
str(int(self._state["destination"] - self.backlash))
69+
)
70+
self._awaiting_backlash = False
5571

5672
def home(self):
5773
if not self._config["is_homeable"]:

yaqd_pololu/pololu-ticcmd.toml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,9 @@ unit.default = "step"
3232
unit.doc = "unit of motion"
3333

3434
backlash.type = "float"
35-
backlash.doc = "units to travel for backlash correction"
35+
backlash.doc = "direction and distance (in steps) to travel for backlash correction. use negative value for backlash in the reverse direction."
3636
backlash.default = 0.0
3737

38-
backlash_dir.type = "dir"
39-
backlash_dir.doc = "The travel direction to which backlash is applied. e.g. if forward, destinations in the forward direction will overstep the destination by 'backlash' steps before walking back."
40-
backlash_dir.default = "fwd"
41-
4238
[state]
4339

4440
[messages]

0 commit comments

Comments
 (0)