小鱼 ROS 2 新书上线!点击链接查看, 新书配套视频点击链接查看。
提问前必看的发帖注意事项—— 提问前必看!不符合要求的问题拒绝回答!!
社区使用指南—如何添加标签修改密码
launch 执行cmd时有{}怎么处理
-
launch代码如下
import launch
import launch_ros
import os
from ament_index_python.packages import get_package_share_directory
angle='180'
servo='1'
str='"{a: '+angle+',b: '+servo+'}"'
def generate_launch_description():
action_six_dof_angle=launch.actions.ExecuteProcess(
cmd=['ros2' ,'service' ,'call' ,'/add_two_ints' ,'example_interfaces/srv/AddTwoInts','"{a: ',angle,',b: ',servo,'}"'
],output='both'
)
return launch.LaunchDescription([
action_six_dof_angle
])
终端报错
[DEBUG] [launch.launch_context]: emitting event synchronously: 'launch.events.IncludeLaunchDescription'
[INFO] [launch]: All log files can be found below /home/lyt/.ros/log/2024-12-01-07-48-13-941812-lyt-virtual-machine-6118
[INFO] [launch]: Default logging verbosity is set to DEBUG
[DEBUG] [launch]: processing event: '<launch.events.include_launch_description.IncludeLaunchDescription object at 0x7f66905f87f0>'
[DEBUG] [launch]: processing event: '<launch.events.include_launch_description.IncludeLaunchDescription object at 0x7f66905f87f0>' ✓ '<launch.event_handlers.on_include_launch_description.OnIncludeLaunchDescription object at 0x7f66905fb940>'
[INFO] [ros2-1]: process started with pid [6119]
[DEBUG] [launch.launch_context]: emitting event: 'launch.events.process.ProcessStarted'
[DEBUG] [launch]: processing event: '<launch.events.process.process_started.ProcessStarted object at 0x7f668f77ea10>'
[DEBUG] [launch.launch_context]: emitting event synchronously: 'launch.events.process.ProcessStderr'
[DEBUG] [launch]: processing event: '<launch.events.process.process_stderr.ProcessStderr object at 0x7f66905fb790>'
[DEBUG] [launch]: processing event: '<launch.events.process.process_stderr.ProcessStderr object at 0x7f66905fb790>' ✓ '<launch.event_handlers.on_process_io.OnProcessIO object at 0x7f668ec48d60>'
[ros2-1] usage: ros2 [-h] [--use-python-default-buffering]
[ros2-1] Callros2 <command> -h
for more detailed usage. ...
[DEBUG] [launch.launch_context]: emitting event synchronously: 'launch.events.process.ProcessStderr'
[DEBUG] [launch]: processing event: '<launch.events.process.process_stderr.ProcessStderr object at 0x7f66905fb790>'
[DEBUG] [launch]: processing event: '<launch.events.process.process_stderr.ProcessStderr object at 0x7f66905fb790>' ✓ '<launch.event_handlers.on_process_io.OnProcessIO object at 0x7f668ec48d60>'
[ros2-1] ros2: error: unrecognized arguments: 180 ,b: 1 }"
[ERROR] [ros2-1]: process has died [pid 6119, exit code 2, cmd 'ros2 service call /add_two_ints example_interfaces/srv/AddTwoInts "{a: 180 ,b: 1 }"'].
[DEBUG] [launch.launch_context]: emitting event: 'launch.events.process.ProcessExited'
[DEBUG] [launch]: processing event: '<launch.events.process.process_exited.ProcessExited object at 0x7f66905fb790>'
[DEBUG] [launch]: processing event: '<launch.events.process.process_exited.ProcessExited object at 0x7f66905fb790>' ✓ '<launch.event_handlers.on_process_exit.OnProcessExit object at 0x7f668ec48f40>'
[DEBUG] [launch]: processing event: '<launch.events.process.process_exited.ProcessExited object at 0x7f66905fb790>' ✓ '<launch.event_handlers.on_process_exit.OnProcessExit object at 0x7f668ec48e50>'
[DEBUG] [launch.launch_context]: emitting event: 'launch.events.Shutdown'
[DEBUG] [launch]: processing event: '<launch.events.shutdown.Shutdown object at 0x7f66905fb790>'
[DEBUG] [launch]: processing event: '<launch.events.shutdown.Shutdown object at 0x7f66905fb790>' ✓ '<launch.event_handlers.on_shutdown.OnShutdown object at 0x7f668ec48d90>'
[DEBUG] [launch]: processing event: '<launch.events.shutdown.Shutdown object at 0x7f66905fb790>' ✓ '<launch.event_handlers.on_shutdown.OnShutdown object at 0x7f66905f8c70>'