Skip to content

Commit

Permalink
[xs_modules] Spin timing futures until complete
Browse files Browse the repository at this point in the history
Solves #55. Fixes a race condition in timing registers which would
cause the arm to move unexpectedly fast.
  • Loading branch information
lukeschmitt-tr committed Oct 31, 2023
1 parent 0b35403 commit f8ea9e8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -299,10 +299,7 @@ def set_trajectory_time(
value=int(moving_time * 1000),
)
)
self.core.executor.spin_once_until_future_complete(
future=future_moving_time,
timeout_sec=0.1
)
self.core.robot_spin_until_future_complete(future_moving_time)

if accel_time is not None and accel_time != self.accel_time:
self.accel_time = accel_time
Expand All @@ -314,10 +311,7 @@ def set_trajectory_time(
value=int(accel_time * 1000),
)
)
self.core.executor.spin_once_until_future_complete(
future=future_accel_time,
timeout_sec=0.1
)
self.core.robot_spin_until_future_complete(future_accel_time)

def _check_joint_limits(self, positions: List[float]) -> bool:
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@

"""Contains the `InterbotixRobotXSCore` class that interfaces with the interbotix_xs_sdk."""

from asyncio import Future
import copy
import sys
from threading import Lock
Expand All @@ -52,6 +51,7 @@
from rclpy.duration import Duration
from rclpy.logging import LoggingSeverity, set_logger_level
from rclpy.node import Node
from rclpy.task import Future
from sensor_msgs.msg import JointState
from trajectory_msgs.msg import JointTrajectory, JointTrajectoryPoint

Expand Down Expand Up @@ -456,9 +456,21 @@ def robot_spin_once_until_future_complete(
timeout_sec: float = 0.1
) -> None:
"""
Spin the core's executor until the given future is complete within the timeout.
Spin the core's executor once until the given future is complete within the timeout.
:param future: future to complete
:timeout_sec: seconds to wait. defaults to 0.1 seconds
"""
self.executor.spin_once_until_future_complete(future=future, timeout_sec=timeout_sec)

def robot_spin_until_future_complete(
self, future: Future,
timeout_sec: float = None
) -> None:
"""
Spin the core's executor until the given future is complete within the timeout.
:param future: future to complete
:timeout_sec: seconds to wait. defaults to None (no timeout)
"""
self.executor.spin_until_future_complete(future=future, timeout_sec=timeout_sec)

0 comments on commit f8ea9e8

Please sign in to comment.