mi-task/test/cy-mark/marker_client.py

34 lines
1.0 KiB
Python
Raw Normal View History

2025-05-14 23:13:28 +08:00
#!/usr/bin/env python3
import rclpy
from rclpy.node import Node
from cyberdog_marker.srv import PlaceMarker
class MarkerClient(Node):
def __init__(self):
super().__init__('marker_client')
self.client = self.create_client(PlaceMarker, 'place_marker')
while not self.client.wait_for_service(timeout_sec=1.0):
self.get_logger().info('服务不可用,等待...')
self.req = PlaceMarker.Request()
def send_request(self, x, y, z, color):
self.req.x = x
self.req.y = y
self.req.z = z
self.req.color = color
self.future = self.client.call_async(self.req)
rclpy.spin_until_future_complete(self, self.future)
return self.future.result()
def main(args=None):
rclpy.init(args=args)
client = MarkerClient()
response = client.send_request(1.0, 1.0, 0.0, 'blue')
2025-05-14 23:13:28 +08:00
client.get_logger().info(
f'结果: {response.success}, 消息: {response.message}')
client.destroy_node()
rclpy.shutdown()
if __name__ == '__main__':
main()