Don't try to start already-running threads#26
Don't try to start already-running threads#26michaelosthege wants to merge 2 commits intoCommonplaceRobotics:masterfrom
Conversation
|
@cpr-bar I didn't get around to do other changes yet, but this prevented me from connecting reliably.. |
|
Hi @michaelosthege, You seemed to have hit a case in which the connection was terminaed but But there is also the case that the connection was terminated and the thread functions returned. In this case it is not possible to just call I think the best to do is to always create a new Thread object when connecting instead of in |
|
I went into the I pushed another commit that makes it better, but it's still not great, because the socket and the threads may or may not be alive when If Related: The current implementation does not explicitly handle disconnects. Slightly related, coming back to the context manager idea, the following API might be quite useful: client = CRIClient(ip, port)
assert not hasattr(client, "move_joints") # client has no control methods
# for short-lived use:
async with client: # connect, wait for first status update
# TODO: read status
assert client.connected is True
print(client.robot_state)
# context exit: disconnect & dispose socket/threads
# for long-lived use
await client.connect()
# dome something
await client.disconnect() # also disposes socket/threadsFor active control: # for long-lived use
await client.connect()
await with client.active_control() as controller: # enable, reset, set_active_control, wait_for_kinematics_ready
assert isinstance(controller, CRIController)
assert isinstance(controller, CRIClient)
await controller.move_joints(...)
# disable, set_active_control(False)
await client.disconnect() # also disposes socket/threadsIf I'm not mistaken, this could nicely handle the lifecycle for the three connection levels: disconnected, observing, controlling. |
When the first connection attempt does not succeed, the receive/jog threads must either be terminated, or they can not be started again when trying to (re)connect.