cat /mnt/topicfs/swiftpro/position/latest
{"x":226.6,"y":-2.8,"z":19.9}
echo '{"j1":90,"j2":45,"j3":45,"speed":5000,"wait":false}' \
> /mnt/topicfs/swiftpro/set_servo_angles/command
cat /mnt/topicfs/swiftpro/set_servo_angles/response
{"success":true}
echo '{}' > /mnt/topicfs/swiftpro/reset/command
cat /mnt/topicfs/swiftpro/reset/response
{"success":true}
what you need on the host
- any language that can open a file
- zero ROS2 packages installed
- zero compiled message libraries
- zero knowledge of DDS or topic types
- one running container (TopicFS)
import rclpy
from rclpy.node import Node
from geometry_msgs.msg import Point
from std_msgs.msg import Bool
from swiftpro_resources.srv import SetServoAngles, Reset
class ArmController(Node):
def __init__(self):
super().__init__('arm_controller')
self.position = None
self.create_subscription(
Point, '/swiftpro/position',
lambda msg: setattr(self, 'position', msg),
10
)
self.move_cli = self.create_client(
SetServoAngles, '/swiftpro/set_servo_angles'
)
while not self.move_cli.wait_for_service(
timeout_sec=1.0):
self.get_logger().info('waiting for move...')
self.reset_cli = self.create_client(
Reset, '/swiftpro/reset'
)
while not self.reset_cli.wait_for_service(
timeout_sec=1.0):
self.get_logger().info('waiting for reset...')
def get_position(self):
while self.position is None:
rclpy.spin_once(self, timeout_sec=0.1)
return self.position # Point(x,y,z)
def move(self, j1, j2, j3):
req = SetServoAngles.Request()
req.j1, req.j2, req.j3 = j1, j2, j3
req.speed = 5000; req.wait = False
future = self.move_cli.call_async(req)
rclpy.spin_until_future_complete(self, future)
return future.result().success # bool
def reset(self):
req = Reset.Request()
future = self.reset_cli.call_async(req)
rclpy.spin_until_future_complete(self, future)
return future.result().success # bool
rclpy.init()
node = ArmController()
pos = node.get_position() # 1. position
ok = node.move(90,45,45) # 2. move
print(ok) # 3. response
ok = node.reset() # 4. reset
print(ok)
what you need on the host
- ROS2 Jazzy fully installed + sourced
- swiftpro_resources package built
- compiled message typesupport .so files
- colcon build system
- understanding of DDS, QoS, spin loops
- Python rclpy bindings
- service client lifecycle management