网站制作公司 恶意,公司文化墙图片大全,程序开发教程,微客通达推广引流目录 环境变量turtlesim和rqt以初始状态打开rqt node启动节点查看节点列表查看节点更多信息命令行参数 --ros-args topic话题列表话题类型话题列表#xff0c;附加话题类型根据类型查找话题名查看话题发布的数据查看话题的详细信息查看类型的详细信息给话题发布消息#xff0… 目录 环境变量turtlesim和rqt以初始状态打开rqt node启动节点查看节点列表查看节点更多信息命令行参数 --ros-args topic话题列表话题类型话题列表附加话题类型根据类型查找话题名查看话题发布的数据查看话题的详细信息查看类型的详细信息给话题发布消息在命令行带有时间戳的消息查看话题发布的频率Hz service服务列表服务类型服务列表附加服务类型根据类型查找服务名服务类型结构调用服务 parameters参数列表获取参数值设置参数值获取节点所有参数为节点加载参数启动时指定节点参数 action通信方式动作列表动作列表附加类型动作更多信息动作类型结构发送动作目标发送动作目标要求有稳定的反馈 topicserviceaction的区别使用 rqt_console 查看特定日志消息启动过滤某些级别的消息 启动节点(Launching nodes)记录和播放数据记录单个topic记录多个topic查看记录信息记录回放 环境变量
启动前要检查环境变量ROS_DOMAIN_ID 和 ROS_LOCALHOST_ONLY。如果通信时PIN不同应该首先考虑是不是环境变量设置错误。 Configuring environment
记得source一下ros2。
echo source /opt/ros/humble/setup.bash ~/.bashrcturtlesim和rqt
Turtlesim 是一款用于学习 ROS2 的轻量级模拟器。 它说明了 ROS 2 在最基本的层面上做了什么让您了解以后将如何处理真实机器人或机器人模拟。 ros2 工具是用户管理、内省和与 ROS 系统交互的方式。 它支持针对系统及其操作的不同方面的多个命令。 人们可能会使用它来启动节点、设置参数、收听话题等等。 ros2工具是核心 ROS2 安装的一部分。 rqt 是 ROS2 的图形用户界面 (GUI)工具。 在 rqt 中完成的所有操作都可以在命令行上完成但 rqt 提供了一种更用户友好的方式来操作 ROS2 元素。
以初始状态打开rqt
rqt每次启动都会以上次关闭时的状态打开如果rqt界面出现了什么异常卡顿比如某个页面无法点击或者无法滑动可以通过下面命令像第一次打开rqt一样。
rqt --clear-confignode
启动节点
ros2 run package_name executable_name查看节点列表
ros2 node list查看节点更多信息
可以看到节点的话题信息(subscribers and publishers)服务信息(services), 动作信息(action servers and action clients)。
ros2 node info node_name 一般是/node_name命令行参数 --ros-args
ROS的命令行参数
--remap
ros2 run some_package some_ros_executable --ros-args --remap foo:bar
ros2 run some_package some_ros_executable --ros-args -r foo:bar
ros2 run some_package some_ros_executable --ros-args -r some_node:foo:bar--param
ros2 run some_package some_ros_executable --ros-args --param string_param:test
ros2 run some_package some_ros_executable --ros-args -p string_param:test
ros2 run some_package some_ros_executable --ros-args -p some_node:string_param:test--params-file
ros2 run some_package some_ros_executable --ros-args --params-file params_file.yamlparams_file.yaml
node0_name:ros__parameters:param0_name: param0_value...paramN_name: paramN_value
...
nodeM_name:ros__parameters:...* 匹配由斜线划分的单个令牌。** 匹配由斜线划分的零或更多令牌。不允许部分匹配例如foo*。 例如
/**:ros__parameters:string_param: foo
将在所有节点上设置参数string_param./**/some_node:ros__parameters:string_param: foo
将在任何名称空间中的some_node上设置parameter string_param./foo/*:ros__parameters:string_param: foo
将在名称空间 /foo下的任何节点上设置参数string_param(例如只匹配到foo/foo1 而不会匹配到foo/foo1/foo11).topic
话题可以理解为是ROS中节点交换消息的总线。
在图中查看节点和话题之间的结构
rqt_graph圆的是节点方的是话题。
话题列表
ros2 topic list话题类型
ros2 topic type topic_name话题列表附加话题类型
类型其实就是消息结构消息属于哪个类。
ros2 topic list -t根据类型查找话题名
ros2 topic find type_name查看话题发布的数据
ros2 topic echo topic_name注意数据只有在发布时终端才可以看到。 此命令会发布一个新话题话题名字类似于/_ros2cli_26646在rqt_graph中取消选中Debug即可看见。
查看话题的详细信息
可以查看话题的消息类型以及其被多少个节点发布消息和被多少个节点订阅。
ros2 topic info topic_name查看类型的详细信息
这里的类型不只是话题的类型可以被查看其他类型也可以使用此方法看到具体的结构信息。
ros2 interface show msg type查看所有类型的列表
ros2 interface list以ros2 interface show geometry_msgs/msg/Twist为例显示的类型如下
# This expresses velocity in free space broken into its linear and angular parts.
Vector3 linearfloat64 xfloat64 yfloat64 z
Vector3 angularfloat64 xfloat64 yfloat64 z其中linear和angular可以理解为一个变量Vector3 是变量的类型x,y,z是linear/angular的成员也是变量。
给话题发布消息在命令行
args参数需要以yaml语法作为输入。
ros2 topic pub topic_name msg_type argsargs使用单引号和双引号是等价的都可以使用。 例如ros2 topic pub --once /turtle1/cmd_vel geometry_msgs/msg/Twist {linear: {x: 2.0, y: 0.0, z: 0.0}, angular: {x: 0.0, y: 0.0, z: 1.8}}格式和echo显示的结果是一样的
--once是一个可选的参数意为“发布一条消息然后退出”。--rate 1 以1Hz的频率持续发布消息(为默认参数设置)。args是yaml格式的,每一个冒号后面的空格都不可以省略。
在rqt-graph中显示如下
带有时间戳的消息
如果消息的header为完整的标题类型std_msgs/msg/Header(有没有可以通过interface show 查看)设置为auto会自动填充为当前时间。
ros2 topic pub /pose geometry_msgs/msg/PoseStamped {header: auto, pose: {position: {x: 1.0, y: 2.0, z: 3.0}}}如果消息中的类型为builtin_interfaces/msg/Time可以设置now
ros2 topic pub /reference sensor_msgs/msg/TimeReference {header: auto, time_ref: now, source: dumy}sensor_msgs/msg/TimeReference 结构如下
查看话题发布的频率Hz
ros2 topic hz topic_nameservice
服务是节点的另一种通信方法基于呼叫和响应(call-and-response)模型话题是publisher-subscriber模型。服务只有在客户端专门调用时才提供数据。
服务列表
ros2 service list服务类型
服务类型的定义与话题类型类似但是服务类型有两个部分一条是请求的消息另一条是响应的消息。
ros2 service type service_name服务列表附加服务类型
ros2 service list -t根据类型查找服务名
ros2 service find type_name服务类型结构
查看方法
ros2 interface show type_name结构
request structure
---
response structure---是request structure 和 response structure 的分隔符。
调用服务
ros2 service call service_name service_type arguments例如ros2 service call /spawn turtlesim/srv/Spawn {x: 2, y: 2, theta: 0.2, name: } 会返回
requester: making request: turtlesim.srv.Spawn_Request(x2.0, y2.0, theta0.2, name)response:
turtlesim.srv.Spawn_Response(nameturtle2)parameters
参数是节点(node)的配置值每个节点都维护自己的参数也有共享参数和C很像有私有成员也有静态成员。
参数列表
ros2 param list获取参数值
ros2 param get node_name parameter_name设置参数值
ros2 param set node_name parameter_name value获取节点所有参数
ros2 param dump node_name如果想将参数存入到文件中可以使用linux中的运算符
ros2 param dump /turtlesim turtlesim.yaml 导出为yaml结构以后使用时可以直接导入。
为节点加载参数
ros2 param load node_name parameter_file例如ros2 param load /turtlesim turtlesim.yaml 需要注意的是只读的参数只能在启动时进行修改所以那些参数将不会被修改。
启动时指定节点参数
ros2 run package_name executable_name --ros-args --params-file file_name例如ros2 run turtlesim turtlesim_node --ros-args --params-file turtlesim.yaml 这将使得所有参数根据给定的文件更新具体细节见ROS的命令行参数。 action
action基于topic和service。它的功能类似于service。但是action的特点是动作不仅可以被取消还提供了稳定的反馈(service只能返回一个单独的回复response)。 action由三个部分组成目标反馈和结果。 操作使用client-server模型类似于Publisher-Subscriber模型。 “action client”节点将目标发送到“action server”节点该节点确认目标并返回反馈和结果。
当调用 ros2 run turtlesim turtle_teleop_key终端会显示
Reading from keyboard
---------------------------
Use arrow keys to move the turtle.
Use G|B|V|C|D|E|R|T keys to rotate to absolute orientations. F to cancel a rotation.Q to quit.Use arrow keys to move the turtle.对应topic Use G|B|V|C|D|E|R|T keys to rotate to absolute orientations. ‘F’ to cancel a rotation. ‘Q’ to quit.对应action。 每次按下这些按键时都会将目标发送到/turtlesim节点的action服务器上。一旦乌龟旋转完成乌龟节点会返回一个信息比如[INFO] [turtlesim]: Rotation goal completed successfully 实际上不同的动作对应不同的反馈信息和结果。
对于动作而言client可以取消目标(按下F)server也可以取消目标(连续按下D G,server会自动放弃第一个目标但不是所有的server都是这样处理)。
通信方式
执行ros2 node info /turtlesim可以看到最下方关于action的信息 Action Servers:/turtle1/rotate_absolute: turtlesim/action/RotateAbsoluteAction Clients:这说明/turtlesim节点会接受/turtle1/rotate_absolute提供的目标并且给它提供反馈。
执行ros2 node info /teleop_turtle可以看到最下方关于action的信息 Action Servers:Action Clients:/turtle1/rotate_absolute: turtlesim/action/RotateAbsolute这说明/teleop_turtle节点会发送目标给/turtle1/rotate_absolute。
动作列表
ros2 action list动作列表附加类型
ros2 action list -t动作更多信息
会返回动作的客户端和服务端节点。
ros2 action info /turtle1/rotate_absolute动作类型结构
以turtlesim/action/RotateAbsolute类型为例
ros2 interface show turtlesim/action/RotateAbsolute返回
# The desired heading in radians
float32 theta
---
# The angular displacement in radians to the starting position
float32 delta
---
# The remaining rotation in radians
float32 remaining分成了三部分其中---是分隔符第一部分是目标第二部分是结果第三部分是反馈信息。
发送动作目标
ros2 action send_goal action_name action_type valuesvalues需要采用YAML格式。 例如ros2 action send_goal /turtle1/rotate_absolute turtlesim/action/RotateAbsolute {theta: 1.57}
发送动作目标要求有稳定的反馈
ros2 action send_goal /turtle1/rotate_absolute turtlesim/action/RotateAbsolute {theta: -1.57} --feedback会返回
Sending goal:theta: -1.57Goal accepted with ID: e6092c831f994afda92f0086f220da27Feedback:remaining: -3.1268222332000732Feedback:remaining: -3.1108222007751465…Result:delta: 3.1200008392333984Goal finished with status: SUCCEEDED其中Feedback会持续提供反馈信息直到目标达到。
topicserviceaction的区别
通信机制描述使用场景Topic一种异步消息队列分为publisher(发送信息)和subscriber(接受消息)处理连续数据流多对多的形式Service一种同步请求/响应交互模式(发送一次反馈/响应一次)一部分定义请求部分一部分定义回应部分Action一种异步请求/响应交互模式带有反馈机制(发送一个目标执行过程中连续反馈直到达到目标)需要反馈/状态跟踪需要花费大量时间可以被中断
使用 rqt_console 查看特定日志消息
启动
ros2 run rqt_console rqt_console过滤某些级别的消息
只查看级别大于等于WARN的日志消息。
ros2 run turtlesim turtlesim_node --ros-args --log-level WARN #大小写都可以ROS2的日志级别按严重性排序
Fatal
Error
Warn
Info
Debug默认级别是Info因此看不到级别为Debug的消息。 如果设置显示的消息级别是Warn那么Info和Debug级别的消息都会被显示。
启动节点(Launching nodes)
使用命令行工具一次启动多个节点。
ros2 launch turtlesim multisim.launch.py这会启动两个turtlesim node使用ros2 topic list可以看到两个node分别为turtlesim1和turtlesim2
/parameter_events
/rosout
/turtlesim1/turtle1/cmd_vel
/turtlesim1/turtle1/color_sensor
/turtlesim1/turtle1/pose
/turtlesim2/turtle1/cmd_vel
/turtlesim2/turtle1/color_sensor
/turtlesim2/turtle1/pose因此我们可以开两个终端来分别控制两个节点
ros2 topic pub /turtlesim1/turtle1/cmd_vel geometry_msgs/msg/Twist {linear: {x: 2.0, y: 0.0, z: 0.0}, angular: {x: 0.0, y: 0.0, z: 1.8}}ros2 topic pub /turtlesim2/turtle1/cmd_vel geometry_msgs/msg/Twist {linear: {x: 2.0, y: 0.0, z: 0.0}, angular: {x: 0.0, y: 0.0, z: -1.8}}
注意: 也可以使用XML和YAML来创建启动文件。 具体细节可以查看Using Python, XML, and YAML for ROS 2 Launch Files
对于launch的更多信息可以查看ROS2 launch tutorials
记录和播放数据
记录有关topic的数据因此可以随时重播和检查。
记录单个topic
ros2 bag record topic_name例如ros2 bag record /turtle1/cmd_vel 这会根据时间戳来创建bag文件的名称想要指定文件名称可以用-o来指定。
记录多个topic
记录多个topic时直接输入多个topic名称用空格隔开。
ros2 bag record -o subset topic1_name topic2_name -o选项允许为bag文件选择一个唯一的名称。这里的subset就是要创建的文件目录名称。 例如ros2 bag record -o subset /turtle1/cmd_vel /turtle1/pose
查看记录信息
ros2 bag info bag_file_name例如ros2 bag info subset
记录回放
ros2 bag play bag_file_name有关ros bag更详细的信息在这里找到https://github.com/ros2/rosbag2。