-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use timeout instead of heartbeats (#18)
* WIP tcp server * Add EtherCATMaster and driver to server * Test client-server communication * Formatting * Integrate changes from main * Use AsyncIO to run ethercat and 0MQ concurrently * Variable naming * Stop server message * Use threading for server, since it's I/O bound, so GIL is not an issue * Fix formatting * Fix formatting * Fix formatting * Change log level to trace, otherwise we can't read logs properly * Change log level to trace, otherwise we can't read logs properly * Start expecting heartbeat messages after first request * Use property * Move logging call about sleep above sleep statement * Multithreading improvements, including daemon threads * Client update * use timeout instead of heartbeat * fix issues in implementation * print message when velocity timeout reached * fix typo in client test * rename Client to KELORobile * docstrings in google format * join thread instead of empty while loop --------- Co-authored-by: Mathieu De Coster <[email protected]>
- Loading branch information
1 parent
449fd2a
commit 8c2c7a5
Showing
6 changed files
with
137 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import zmq | ||
from airo_tulip.server.messages import ( | ||
RequestMessage, | ||
ResponseMessage, | ||
SetPlatformVelocityTargetMessage, | ||
StopServerMessage, | ||
) | ||
from loguru import logger | ||
|
||
|
||
class KELORobile: | ||
def __init__(self, robot_ip: str, robot_port: int): | ||
address = f"tcp://{robot_ip}:{robot_port}" | ||
logger.info(f"Connecting to {address}...") | ||
self._zmq_ctx = zmq.Context() | ||
self._zmq_socket = self._zmq_ctx.socket(zmq.REQ) | ||
self._zmq_socket.connect(address) | ||
logger.info(f"Connected to {address}.") | ||
|
||
def set_platform_velocity_target( | ||
self, vel_x: float, vel_y: float, vel_a: float, timeout: float = 1.0 | ||
) -> ResponseMessage: | ||
"""Set the x, y and angular velocity of the complete mobile platform. | ||
Args: | ||
vel_x: Linear velocity of platform in x (forward) direction in m/s. | ||
vel_y: Linear velocity of platform in y (left) direction in m/s. | ||
vel_a: Linear velocity of platform in angular direction in rad/s. | ||
timeout: Duration in seconds after which the movement is automatically stopped (default 1.0). | ||
Returns: | ||
A ResponseMessage object indicating the response status of the request. | ||
""" | ||
msg = SetPlatformVelocityTargetMessage(vel_x, vel_y, vel_a, timeout) | ||
return self._transceive_message(msg) | ||
|
||
def stop_server(self) -> ResponseMessage: | ||
"""Stops the remote server. | ||
Returns: | ||
A ResponseMessage object indicating the response status of the request. | ||
""" | ||
msg = StopServerMessage() | ||
return self._transceive_message(msg) | ||
|
||
def _transceive_message(self, req: RequestMessage) -> ResponseMessage: | ||
self._zmq_socket.send_pyobj(req) | ||
return self._zmq_socket.recv_pyobj() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import math | ||
import time | ||
|
||
from airo_tulip.server.kelo_robile import KELORobile | ||
|
||
|
||
def test(): | ||
mobi = KELORobile("localhost", 49789) | ||
|
||
mobi.set_platform_velocity_target(0.5, 0.0, 0.0) | ||
time.sleep(3) # movement should timeout | ||
|
||
mobi.set_platform_velocity_target(0.0, 0.0, math.pi / 8, timeout=2.0) | ||
time.sleep(2) | ||
|
||
mobi.set_platform_velocity_target(0.2, 0.0, 0.0) | ||
time.sleep(1) | ||
|
||
mobi.set_platform_velocity_target(0.0, 0.2, 0.0) | ||
time.sleep(1) | ||
|
||
mobi.set_platform_velocity_target(-0.2, 0.0, 0.0) | ||
time.sleep(1) | ||
|
||
mobi.set_platform_velocity_target(0.0, -0.2, 0.0) | ||
time.sleep(1) | ||
|
||
mobi.set_platform_velocity_target(0.0, 0.0, -math.pi / 8, timeout=2.0) | ||
time.sleep(2) | ||
|
||
mobi.set_platform_velocity_target(-0.5, 0.0, 0.0) | ||
time.sleep(3) # movement should timeout | ||
|
||
mobi.set_platform_velocity_target(0.0, 0.0, 0.0) | ||
time.sleep(0.5) | ||
|
||
mobi.stop_server() | ||
time.sleep(0.5) | ||
|
||
|
||
if __name__ == "__main__": | ||
test() |