Skip to content

Commit ae49a66

Browse files
Workaround, see Issue #12
1 parent 9cc739b commit ae49a66

File tree

2 files changed

+13
-18
lines changed

2 files changed

+13
-18
lines changed

examples/test_moto.py

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -119,20 +119,14 @@
119119
m.motion.send_joint_trajectory_point(p0) # Current position at time t=0.0
120120
m.motion.send_joint_trajectory_point(p1) # Desired position at time t=5.0
121121

122-
print("Waiting for robot to complete the trajectory...", end=' ')
123-
124-
time.sleep(1)
125-
# TODO: This isn't a reliable way to know if the trajectory is complete.
126-
while m.state.robot_status().in_motion:
127-
time.sleep(0.1)
128-
129-
print("Trajectory complete.")
130-
print("Disabling trajectory mode.")
131-
122+
input("Press enter when robot has stopped.")
123+
124+
print("Disabling trajectory mode, and turning off servos.")
132125
m.motion.stop_trajectory_mode()
133126
m.motion.stop_servos()
134127

135-
print("hold")
128+
print("Done.")
129+
136130
else:
137131
print("Aborting... Good bye.")
138132

moto/state_connection.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
from typing import List, Callable, Float
15+
from typing import List, Callable
1616
from copy import deepcopy
1717
from threading import Thread, Lock, Event
1818

@@ -41,6 +41,7 @@ def __init__(self, ip_address: str):
4141
self._joint_feedback_ex: JointFeedbackEx = None
4242
self._robot_status: RobotStatus = None
4343
self._initial_response: Event = Event()
44+
self._stop: Event = Event()
4445
self._lock: Lock = Lock()
4546

4647
self._joint_feedback_callbacks: List[Callable] = []
@@ -67,10 +68,11 @@ def add_joint_feedback_msg_callback(self, callback: Callable):
6768
def add_joint_feedback_ex_msg_callback(self, callback: Callable):
6869
self._joint_feedback_ex_callbacks.append(callback)
6970

70-
def start(self, timeout: Float = 5.0) -> None:
71+
def start(self, timeout: float = 5.0) -> None:
7172
self._tcp_client.connect()
7273
self._worker_thread.start()
7374
if not self._initial_response.wait(timeout):
75+
self._stop.set()
7476
raise TimeoutError(
7577
"Did not receive at least one of each message before timeout"
7678
" occured. Try increasing the timeout period. "
@@ -81,7 +83,7 @@ def stop(self) -> None:
8183
pass
8284

8385
def _worker(self) -> None:
84-
while True:
86+
while True and not self._stop.is_set():
8587
msg: SimpleMessage = self.recv()
8688
if msg.header.msg_type == MsgType.JOINT_FEEDBACK:
8789
with self._lock:
@@ -100,9 +102,8 @@ def _worker(self) -> None:
100102
self._robot_status = deepcopy(msg.body)
101103

102104
if not self._initial_response.is_set() and (
103-
self.robot_status is not None
104-
and self._joint_feedback is not None
105-
and self.joint_feedback_ex is not None
105+
isinstance(self.robot_status(), RobotStatus)
106+
and any(isinstance(elem, JointFeedback) for elem in self._joint_feedback)
107+
and isinstance(self.joint_feedback_ex(), JointFeedbackEx)
106108
):
107-
print("At least one message of every time has been received.")
108109
self._initial_response.set()

0 commit comments

Comments
 (0)