前言
下面这些主要是一些通讯中经常用到的一些命令,大家需要跟着下面的指示操作一遍,有个大致的了解即可。
1.学习目的
机器人系统中启动的节点少则几个,多则十几个、几十个,不同的节点名称各异,通信时使用话题、服务、消息、参数等等都各不相同,一个显而易见的问题是: 当需要自定义节点和其他某个已经存在的节点通信时,如何获取对方的话题、以及消息载体的格式呢。和之前介绍的文件系统操作命令比较,文件操作命令是静态的,操作的是磁盘上的文件,而上述命令是动态的,在ROS程序启动后,可以动态的获取运行中的节点或参数的相关信息
2.常用命令
1.rosnode获取节点信息命令
2.rostopic获取话题信息命令
3.rosserice获取服务信息命令
4.rosmsg获取msg消息信息命令
5.rossrv获取srv消息信息命令
6.rosparam获取参数信息命令
2.1 rosnode
终端输入rosnode自动获取rosnode的所有命令。
首先请先运行之前话题通讯的例子。
1.rosnode list 列出所有活跃的节点
2. rosnode ping 测试某个节点的连接状态
测试其中的一个活跃节点
3. rosnode info列出关于当前节点的信息
输出信息如下:
--------------------------------------------------------------------------------
Node [/banZhuren]
Publications:
* /liaoTian [plumbing_pub_sub/Person]
* /rosout [rosgraph_msgs/Log]
Subscriptions: None
Services:
* /banZhuren/get_loggers
* /banZhuren/set_logger_level
contacting node http://lvl-Legion-Y7000P-IRX9:46189/ ...
Pid: 7753
Connections:
* topic: /rosout
* to: /rosout
* direction: outbound (37749 - 127.0.0.1:54764) [11]
* transport: TCPROS
* topic: /liaoTian
* to: /jiaZhang
* direction: outbound (37749 - 127.0.0.1:53896) [12]
* transport: TCPROS
4. rosnode machine 多台设备协同运行时获取指定设备的节点信息
先利用指令获取设备名称再利用指令加设备名称获取指定设备的节点信息。
5.rosnode kill 杀死某个正在运行的节点
此时发布节点抛出异常
同时订阅节点也停止输出
6.rosnode cleanup 杀死僵尸进程
运行之前的小海龟案例
roscore
rosrun turtlesim turtlesim_node
rosrun turtlesim turtle_teleop_key
运行小海龟,可以看到此时有三个活跃节点
结束小海龟的进程,此时按道理应该是两个活跃节点,但是调用命令还是显示三个节点,此时存在僵尸节点。
利用cleanup命令删除僵尸节点,此时只有两个节点了。
2.2 rostopic
rostopic包含rostopic命令行工具,用于显示有关ROS 主题的调试信息,包括发布者,订阅者,发布频率和ROS消息。它还包含一个实验性Python库,用于动态获取有关主题的信息并与之交互。
终端输入rostopic自动获取rostopic的所有命令。
同理先运行话题通讯实例
1.rostopic list 列出所有话题列表
2.rostopic echo 打印某个话题下发布的信息
若是自定义的信息,应在工作空间下刷新环境变量(打印之前记得source)
非自定义消息,直接使用即可
3.rostopic pub 用命令行发布数据
做测试用。扮演发布者输入发布的信息
首先结束发布者的进程
输入命令
输入命令时可以利用Tab键进行补齐,信息可以进行更改再用Enter键确认。
rostopic pub liaoTian plumbing_pub_sub/Person "name: ''
age: 0
height: 0.0"
注意不要更改它的格式
4.rostopic info 显示话题的具体信息
5.rostopic hz 显示话题发布频率
2.3 rosservice
以服务通讯为例(demo01_ws)输入命令时确保你的实例正在运行。
同理终端输入rosservice得到相关的所有指令。
1.rosservice list 当前的ros服务中已经启动的服务
2.rosservice call 扮演客户端的角色向服务器发送请求
输入如下命令可用Tab补齐
rosservice call addInts "num1: 1
num2: 2"
数字区域可以进行修改。
3.rosservice info 服务相关的信息
2.4 rosmsg
rosmsg是用于显示有关 ROS消息类型的 信息的命令行工具。主要用于发布订阅模型中。
输入命令前请先运行带有自定义msg的话题通信模型。
输入rsomsg得到相关的命令。
1.rosmsg list列出所有的消息类型
内容有点多
actionlib/TestAction
actionlib/TestActionFeedback
actionlib/TestActionGoal
actionlib/TestActionResult
actionlib/TestFeedback
actionlib/TestGoal
actionlib/TestRequestAction
actionlib/TestRequestActionFeedback
actionlib/TestRequestActionGoal
actionlib/TestRequestActionResult
actionlib/TestRequestFeedback
actionlib/TestRequestGoal
actionlib/TestRequestResult
actionlib/TestResult
actionlib/TwoIntsAction
actionlib/TwoIntsActionFeedback
actionlib/TwoIntsActionGoal
actionlib/TwoIntsActionResult
actionlib/TwoIntsFeedback
actionlib/TwoIntsGoal
actionlib/TwoIntsResult
actionlib_msgs/GoalID
actionlib_msgs/GoalStatus
actionlib_msgs/GoalStatusArray
actionlib_tutorials/AveragingAction
actionlib_tutorials/AveragingActionFeedback
actionlib_tutorials/AveragingActionGoal
actionlib_tutorials/AveragingActionResult
actionlib_tutorials/AveragingFeedback
actionlib_tutorials/AveragingGoal
actionlib_tutorials/AveragingResult
actionlib_tutorials/FibonacciAction
actionlib_tutorials/FibonacciActionFeedback
actionlib_tutorials/FibonacciActionGoal
actionlib_tutorials/FibonacciActionResult
actionlib_tutorials/FibonacciFeedback
actionlib_tutorials/FibonacciGoal
actionlib_tutorials/FibonacciResult
bond/Constants
bond/Status
control_msgs/FollowJointTrajectoryAction
control_msgs/FollowJointTrajectoryActionFeedback
control_msgs/FollowJointTrajectoryActionGoal
control_msgs/FollowJointTrajectoryActionResult
control_msgs/FollowJointTrajectoryFeedback
control_msgs/FollowJointTrajectoryGoal
control_msgs/FollowJointTrajectoryResult
control_msgs/GripperCommand
control_msgs/GripperCommandAction
control_msgs/GripperCommandActionFeedback
control_msgs/GripperCommandActionGoal
control_msgs/GripperCommandActionResult
control_msgs/GripperCommandFeedback
control_msgs/GripperCommandGoal
control_msgs/GripperCommandResult
control_msgs/JointControllerState
control_msgs/JointJog
control_msgs/JointTolerance
control_msgs/JointTrajectoryAction
control_msgs/JointTrajectoryActionFeedback
control_msgs/JointTrajectoryActionGoal
control_msgs/JointTrajectoryActionResult
control_msgs/JointTrajectoryControllerState
control_msgs/JointTrajectoryFeedback
control_msgs/JointTrajectoryGoal
control_msgs/JointTrajectoryResult
control_msgs/PidState
control_msgs/PointHeadAction
control_msgs/PointHeadActionFeedback
control_msgs/PointHeadActionGoal
control_msgs/PointHeadActionResult
control_msgs/PointHeadFeedback
control_msgs/PointHeadGoal
control_msgs/PointHeadResult
control_msgs/SingleJointPositionAction
control_msgs/SingleJointPositionActionFeedback
control_msgs/SingleJointPositionActionGoal
control_msgs/SingleJointPositionActionResult
control_msgs/SingleJointPositionFeedback
control_msgs/SingleJointPositionGoal
control_msgs/SingleJointPositionResult
controller_manager_msgs/ControllerState
controller_manager_msgs/ControllerStatistics
controller_manager_msgs/ControllersStatistics
controller_manager_msgs/HardwareInterfaceResources
diagnostic_msgs/DiagnosticArray
diagnostic_msgs/DiagnosticStatus
diagnostic_msgs/KeyValue
dynamic_reconfigure/BoolParameter
dynamic_reconfigure/Config
dynamic_reconfigure/ConfigDescription
dynamic_reconfigure/DoubleParameter
dynamic_reconfigure/Group
dynamic_reconfigure/GroupState
dynamic_reconfigure/IntParameter
dynamic_reconfigure/ParamDescription
dynamic_reconfigure/SensorLevels
dynamic_reconfigure/StrParameter
gazebo_msgs/ContactState
gazebo_msgs/ContactsState
gazebo_msgs/LinkState
gazebo_msgs/LinkStates
gazebo_msgs/ModelState
gazebo_msgs/ModelStates
gazebo_msgs/ODEJointProperties
gazebo_msgs/ODEPhysics
gazebo_msgs/PerformanceMetrics
gazebo_msgs/SensorPerformanceMetric
gazebo_msgs/WorldState
geometry_msgs/Accel
geometry_msgs/AccelStamped
geometry_msgs/AccelWithCovariance
geometry_msgs/AccelWithCovarianceStamped
geometry_msgs/Inertia
geometry_msgs/InertiaStamped
geometry_msgs/Point
geometry_msgs/Point32
geometry_msgs/PointStamped
geometry_msgs/Polygon
geometry_msgs/PolygonStamped
geometry_msgs/Pose
geometry_msgs/Pose2D
geometry_msgs/PoseArray
geometry_msgs/PoseStamped
geometry_msgs/PoseWithCovariance
geometry_msgs/PoseWithCovarianceStamped
geometry_msgs/Quaternion
geometry_msgs/QuaternionStamped
geometry_msgs/Transform
geometry_msgs/TransformStamped
geometry_msgs/Twist
geometry_msgs/TwistStamped
geometry_msgs/TwistWithCovariance
geometry_msgs/TwistWithCovarianceStamped
geometry_msgs/Vector3
geometry_msgs/Vector3Stamped
geometry_msgs/Wrench
geometry_msgs/WrenchStamped
map_msgs/OccupancyGridUpdate
map_msgs/PointCloud2Update
map_msgs/ProjectedMap
map_msgs/ProjectedMapInfo
nav_msgs/GetMapAction
nav_msgs/GetMapActionFeedback
nav_msgs/GetMapActionGoal
nav_msgs/GetMapActionResult
nav_msgs/GetMapFeedback
nav_msgs/GetMapGoal
nav_msgs/GetMapResult
nav_msgs/GridCells
nav_msgs/MapMetaData
nav_msgs/OccupancyGrid
nav_msgs/Odometry
nav_msgs/Path
pcl_msgs/ModelCoefficients
pcl_msgs/PointIndices
pcl_msgs/PolygonMesh
pcl_msgs/Vertices
roscpp/Logger
rosgraph_msgs/Clock
rosgraph_msgs/Log
rosgraph_msgs/TopicStatistics
rospy_tutorials/Floats
rospy_tutorials/HeaderString
sensor_msgs/BatteryState
sensor_msgs/CameraInfo
sensor_msgs/ChannelFloat32
sensor_msgs/CompressedImage
sensor_msgs/FluidPressure
sensor_msgs/Illuminance
sensor_msgs/Image
sensor_msgs/Imu
sensor_msgs/JointState
sensor_msgs/Joy
sensor_msgs/JoyFeedback
sensor_msgs/JoyFeedbackArray
sensor_msgs/LaserEcho
sensor_msgs/LaserScan
sensor_msgs/MagneticField
sensor_msgs/MultiDOFJointState
sensor_msgs/MultiEchoLaserScan
sensor_msgs/NavSatFix
sensor_msgs/NavSatStatus
sensor_msgs/PointCloud
sensor_msgs/PointCloud2
sensor_msgs/PointField
sensor_msgs/Range
sensor_msgs/RegionOfInterest
sensor_msgs/RelativeHumidity
sensor_msgs/Temperature
sensor_msgs/TimeReference
shape_msgs/Mesh
shape_msgs/MeshTriangle
shape_msgs/Plane
shape_msgs/SolidPrimitive
smach_msgs/SmachContainerInitialStatusCmd
smach_msgs/SmachContainerStatus
smach_msgs/SmachContainerStructure
std_msgs/Bool
std_msgs/Byte
std_msgs/ByteMultiArray
std_msgs/Char
std_msgs/ColorRGBA
std_msgs/Duration
std_msgs/Empty
std_msgs/Float32
std_msgs/Float32MultiArray
std_msgs/Float64
std_msgs/Float64MultiArray
std_msgs/Header
std_msgs/Int16
std_msgs/Int16MultiArray
std_msgs/Int32
std_msgs/Int32MultiArray
std_msgs/Int64
std_msgs/Int64MultiArray
std_msgs/Int8
std_msgs/Int8MultiArray
std_msgs/MultiArrayDimension
std_msgs/MultiArrayLayout
std_msgs/String
std_msgs/Time
std_msgs/UInt16
std_msgs/UInt16MultiArray
std_msgs/UInt32
std_msgs/UInt32MultiArray
std_msgs/UInt64
std_msgs/UInt64MultiArray
std_msgs/UInt8
std_msgs/UInt8MultiArray
stereo_msgs/DisparityImage
tf/tfMessage
tf2_msgs/LookupTransformAction
tf2_msgs/LookupTransformActionFeedback
tf2_msgs/LookupTransformActionGoal
tf2_msgs/LookupTransformActionResult
tf2_msgs/LookupTransformFeedback
tf2_msgs/LookupTransformGoal
tf2_msgs/LookupTransformResult
tf2_msgs/TF2Error
tf2_msgs/TFMessage
theora_image_transport/Packet
trajectory_msgs/JointTrajectory
trajectory_msgs/JointTrajectoryPoint
trajectory_msgs/MultiDOFJointTrajectory
trajectory_msgs/MultiDOFJointTrajectoryPoint
turtle_actionlib/ShapeAction
turtle_actionlib/ShapeActionFeedback
turtle_actionlib/ShapeActionGoal
turtle_actionlib/ShapeActionResult
turtle_actionlib/ShapeFeedback
turtle_actionlib/ShapeGoal
turtle_actionlib/ShapeResult
turtle_actionlib/Velocity
turtlesim/Color
turtlesim/Pose
visualization_msgs/ImageMarker
visualization_msgs/InteractiveMarker
visualization_msgs/InteractiveMarkerControl
visualization_msgs/InteractiveMarkerFeedback
visualization_msgs/InteractiveMarkerInit
visualization_msgs/InteractiveMarkerPose
visualization_msgs/InteractiveMarkerUpdate
visualization_msgs/Marker
visualization_msgs/MarkerArray
visualization_msgs/MenuEntry
2.rosmsg info/show 列出消息内容信息
2.5 rossrv
rossrv是用于显示有关 ROS消息类型的 信息的命令行工具。主要用于服务通信中.
操作同rosmsg不做过多演示。
2.6 rsoparam
rosparam包含rosparam命令行工具,用于使用YAML编码文件在参数服务器上获取和设置ROS参数。是ROS参数服务器的命令。
同理输入rosparam得到相关的指令,并且在输入下面命令时确保参数服务器实例已经运行。
1.rosparam list 列出参数服务器里面的一些数据
/radius
/radius_param
/rosdistro
/roslaunch/uris/host_lvl_legion_y7000p_irx9__42515
/rosversion
/run_id
/type
/type_param
2.rosparam set 向参数服务器设置数据
lvl@lvl-Legion-Y7000P-IRX9:~/demo02_ws$ rosparam set name lvl
lvl@lvl-Legion-Y7000P-IRX9:~/demo02_ws$ rosparam list
/name
/radius
/radius_param
/rosdistro
/roslaunch/uris/host_lvl_legion_y7000p_irx9__42515
/rosversion
/run_id
/type
/type_param
3.rosparam get 获取键名所对应的值
vl@lvl-Legion-Y7000P-IRX9:~/demo02_ws$ source devel/setup.bash
lvl@lvl-Legion-Y7000P-IRX9:~/demo02_ws$ rosparam get name
lvl
4.rosparam delete 删除参数服务器里的键值对
vl@lvl-Legion-Y7000P-IRX9:~/demo02_ws$ source devel/setup.bash
lvl@lvl-Legion-Y7000P-IRX9:~/demo02_ws$ rosparam list
/name
/radius
/radius_param
/rosdistro
/roslaunch/uris/host_lvl_legion_y7000p_irx9__42515
/rosversion
/run_id
/type
/type_param
lvl@lvl-Legion-Y7000P-IRX9:~/demo02_ws$ rosparam delete name
lvl@lvl-Legion-Y7000P-IRX9:~/demo02_ws$ rosparam list
/radius
/radius_param
/rosdistro
/roslaunch/uris/host_lvl_legion_y7000p_irx9__42515
/rosversion
/run_id
/type
/type_param
5.rosparam dump 文件名.yaml 将参数写入磁盘文件(这个过程也叫做序列化)
6.rosparam load 文件名.yaml 反序列化
把文件中的参数加载到参数服务器中。
lvl@lvl-Legion-Y7000P-IRX9:~/demo02_ws$ source devel/setup.bash
lvl@lvl-Legion-Y7000P-IRX9:~/demo02_ws$ rosparam list
/name
/rosdistro
/roslaunch/uris/host_lvl_legion_y7000p_irx9__46169
/rosversion
/run_id
lvl@lvl-Legion-Y7000P-IRX9:~/demo02_ws$ rosparam delete name
lvl@lvl-Legion-Y7000P-IRX9:~/demo02_ws$ rosparam list
/rosdistro
/roslaunch/uris/host_lvl_legion_y7000p_irx9__46169
/rosversion
/run_id
lvl@lvl-Legion-Y7000P-IRX9:~/demo02_ws$ rosparam load param.yaml
lvl@lvl-Legion-Y7000P-IRX9:~/demo02_ws$ rosparam list
/name
/rosdistro
/roslaunch/uris/host_lvl_legion_y7000p_irx9__46169
/rosversion
/run_id
结束语
以上就是我学习到的内容,如果对您有帮助请多多支持我,如果哪里有问题欢迎大家在评论区积极讨论,我看到会及时回复。