parent
3c02dcde54
commit
fcd2b1095e
@ -0,0 +1,64 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from cyber.python.cyber_py3 import cyber
|
||||
from cyber.python.cyber_py3 import cyber_time
|
||||
from modules.common_msgs.external_command_msgs import lane_follow_command_pb2
|
||||
from modules.common_msgs.external_command_msgs import command_status_pb2
|
||||
import time
|
||||
import random
|
||||
|
||||
def parse_coordinate(coord_str):
|
||||
cleaned = coord_str.strip().strip('()')
|
||||
parts = cleaned.split(',')
|
||||
if len(parts) != 2:
|
||||
raise ValueError(f"Invalid coordinate format: {coord_str}")
|
||||
x = float(parts[0].strip())
|
||||
y = float(parts[1].strip())
|
||||
return x, y
|
||||
|
||||
def main():
|
||||
cyber.init()
|
||||
node = cyber.Node("lane_follow_requester")
|
||||
|
||||
cmd = lane_follow_command_pb2.LaneFollowCommand()
|
||||
cmd.header.timestamp_sec = cyber_time.Time.now().to_sec()
|
||||
cmd.header.module_name = "manual_command"
|
||||
cmd.header.sequence_num = 1
|
||||
cmd.command_id = random.randint(1, 2**31 - 1)
|
||||
cmd.is_start_pose_set = True
|
||||
|
||||
# 使用解析函数设置起点和终点坐标
|
||||
start_x, start_y = parse_coordinate("(587107.2299980448,4141578.018806449)")
|
||||
end_x, end_y = parse_coordinate("(587010.5463351277,4141603.8543796046)")
|
||||
|
||||
start_pose = cmd.way_point.add()
|
||||
start_pose.x = start_x
|
||||
start_pose.y = start_y
|
||||
|
||||
cmd.end_pose.x = end_x
|
||||
cmd.end_pose.y = end_y
|
||||
|
||||
client = node.create_client(
|
||||
'/apollo/external_command/lane_follow',
|
||||
lane_follow_command_pb2.LaneFollowCommand,
|
||||
command_status_pb2.CommandStatus
|
||||
)
|
||||
|
||||
time.sleep(1.0)
|
||||
print("Sending LaneFollowCommand:")
|
||||
print(cmd)
|
||||
|
||||
response = client.send_request(cmd)
|
||||
if response is not None:
|
||||
print("Response status:")
|
||||
print(f" - command_id: {response.command_id}")
|
||||
print(f" - status: {response.status}")
|
||||
print(f" - message: {response.message}")
|
||||
else:
|
||||
print("No response received. Make sure external_command_processor is running.")
|
||||
|
||||
cyber.shutdown()
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
Loading…
Reference in new issue