使用机器人操作系统ROS 2和仿真软件Gazebo 9命令遥控可视化教程(二)

网友投稿 17349 2022-05-29

上一篇,已经在Gazebo 9中放入了一个支持ROS 2的仿真机器人,具体参考:

使用机器人操作系统ROS 2和仿真软件Gazebo 9搭建机器人教程(一)

本篇,通过此案例学习并熟练掌握ROS2的如下内容:

ROS2常用命令回顾

遥控机器人在环境中运动

rqt和rviz2

摄像头图像显示和激光数据可视化

ROS2入门介绍参考:https://zhuanlan.zhihu.com/p/96940278

$ ros2 launch mobot world.launch.py

具体流程参考下图,配置不同会有路径和目录的差异:

节点

$ ros2 node

usage: ros2 node [-h]

Call `ros2 node -h` for more detailed usage. ...

Various node related sub-commands

optional arguments:

-h, --help            show this help message and exit

Commands:

info  Output information about a node

list  Output a list of available nodes

Call `ros2 node -h` for more detailed usage.

使用其中list:

$ ros2 node list

/launch_ros

/gazebo

/mobot/camera_controller

/mobot/gazebo_ros_head_hokuyo_controller

/mobot/skid_steer_drive_controller

第一个为ros接口,第二个为gazebo,第三到五个,为Gazebo插件的控制器对应摄像头、激光测距和运动驱动。

如果需要查看更具体的节点信息,如camera:

$ ros2 node info /mobot/camera_controller

/mobot/camera_controller

Subscribers:

/clock: rosgraph_msgs/msg/Clock

/mobot/parameter_events: rcl_interfaces/msg/ParameterEvent

Publishers:

/mobot/camera/image: sensor_msgs/msg/Image

/mobot/camera/image/camera_info: sensor_msgs/msg/CameraInfo

/mobot/parameter_events: rcl_interfaces/msg/ParameterEvent

/mobot/rosout: rcl_interfaces/msg/Log

Services:

/mobot/camera_controller/describe_parameters: rcl_interfaces/srv/DescribeParameters

/mobot/camera_controller/get_parameter_types: rcl_interfaces/srv/GetParameterTypes

/mobot/camera_controller/get_parameters: rcl_interfaces/srv/GetParameters

/mobot/camera_controller/list_parameters: rcl_interfaces/srv/ListParameters

/mobot/camera_controller/set_parameters: rcl_interfaces/srv/SetParameters

/mobot/camera_controller/set_parameters_atomically: rcl_interfaces/srv/SetParametersAtomically

/mobot/set_camera_info: sensor_msgs/srv/SetCameraInfo

此处需要注意,Dashing和Eloquent信息有一些的差异哦!

如果使用是Eloquent,如下:

$ ros2 node info /mobot/camera_controller

/mobot/camera_controller

Subscribers:

/clock: rosgraph_msgs/msg/Clock

/mobot/parameter_events: rcl_interfaces/msg/ParameterEvent

Publishers:

/mobot/camera/image: sensor_msgs/msg/Image

/mobot/camera/image/camera_info: sensor_msgs/msg/CameraInfo

/mobot/parameter_events: rcl_interfaces/msg/ParameterEvent

/mobot/rosout: rcl_interfaces/msg/Log

Service Servers:

/mobot/camera_controller/describe_parameters: rcl_interfaces/srv/DescribeParameters

/mobot/camera_controller/get_parameter_types: rcl_interfaces/srv/GetParameterTypes

/mobot/camera_controller/get_parameters: rcl_interfaces/srv/GetParameters

/mobot/camera_controller/list_parameters: rcl_interfaces/srv/ListParameters

/mobot/camera_controller/set_parameters: rcl_interfaces/srv/SetParameters

/mobot/camera_controller/set_parameters_atomically: rcl_interfaces/srv/SetParametersAtomically

/mobot/set_camera_info: sensor_msgs/srv/SetCameraInfo

Service Clients:

Action Servers:

Action Clients:

如上所见,该节点正在发布、订阅和由该节点提供的服务以及该节点充当客户端的服务的所有主题都会列出。

主题

$ ros2 topic

usage: ros2 topic [-h] [--include-hidden-topics]

Call `ros2 topic -h` for more detailed usage. ...

Various topic related sub-commands

optional arguments:

-h, --help            show this help message and exit

--include-hidden-topics

Consider hidden topics as well

Commands:

bw     Display bandwidth used by topic

delay  Display delay of topic from timestamp in header

echo   Output messages from a topic

使用机器人操作系统ROS 2和仿真软件Gazebo 9命令遥控可视化教程(二)

find   Output a list of available topics of a given type

hz     Print the average publishing rate to screen

info   Print information about a topic

list   Output a list of available topics

pub    Publish a message to a topic

type   Print a topic's type

Call `ros2 topic -h` for more detailed usage.

例如list:

$ ros2 topic list

/clock

/mobot/camera/image

/mobot/camera/image/camera_info

/mobot/cmd_vel

/mobot/odom

/mobot/parameter_events

/mobot/rosout

/mobot/scan

/parameter_events

/rosout

/tf

来看看图像数据和激光数据需要的带宽吧?

$ ros2 topic bw /mobot/camera/image

Subscribed to [/mobot/camera/image]

average: 27.89MB/s

mean: 1.92MB/s min: 1.92MB/s max: 1.92MB/s window: 12

average: 28.39MB/s

mean: 1.92MB/s min: 1.92MB/s max: 1.92MB/s window: 27

average: 25.82MB/s

mean: 1.92MB/s min: 1.92MB/s max: 1.92MB/s window: 38

average: 26.60MB/s

mean: 1.92MB/s min: 1.92MB/s max: 1.92MB/s window: 53

ros2 topic bw /mobot/scan

Subscribed to [/mobot/scan]

average: 169.85KB/s

mean: 5.83KB/s min: 5.83KB/s max: 5.83KB/s window: 29

average: 163.58KB/s

mean: 5.83KB/s min: 5.83KB/s max: 5.83KB/s window: 56

average: 163.45KB/s

mean: 5.83KB/s min: 5.83KB/s max: 5.83KB/s window: 84

average: 164.86KB/s

mean: 5.83KB/s min: 5.83KB/s max: 5.83KB/s window: 100

再比如:

$ ros2 topic info /mobot/cmd_vel

Type: geometry_msgs/msg/Twist

Publisher count: 0

Subscriber count: 1

如果发布消息告知机器人运动呢?

/mobot/skid_steer_drive_controller订阅/mobot/cmd_vel

目前,没有消息发布,使用teleop_twist_keyboard。

服务

此部分教程不涉及,后续补充^_^

基础知识参考:https://blog.csdn.net/zhangrelay/article/details/103493612

参数

默认节点通过修改参数可提高通用性!

Dashing:

sudo apt install ros-dashing-teleop-twist-keyboard

Eloquent:

sudo apt install ros-eloquent-teleop-twist-keyboard

命令:

$ ros2 run teleop_twist_keyboard teleop_twist_keyboard --ros-args -r __ns:=/mobot

This node takes keypresses from the keyboard and publishes them

as Twist messages. It works best with a US keyboard layout.

---------------------------

Moving around:

u    i    o

j    k    l

m    ,    .

For Holonomic mode (strafing), hold down the shift key:

---------------------------

U    I    O

J    K    L

M    <    >

t : up (+z)

b : down (-z)

anything else : stop

q/z : increase/decrease max speeds by 10%

w/x : increase/decrease only linear speed by 10%

e/c : increase/decrease only angular speed by 10%

CTRL-C to quit

currently:    speed 0.5    turn 1.0

这部分和工具同步给出示例。

使用键盘可以控制机器人在环境中运动,观察rqt和rviz2的变化。

遥控靠近白色球体,转到工具章节。

行动

此部分教程不涉及,后续补充^_^

基础知识参考:https://blog.csdn.net/zhangrelay/article/details/103496999

启动

此部分教程不涉及,后续补充^_^

基础知识参考:https://blog.csdn.net/ZhangRelay/article/details/103498784

工具

rqt和rviz2。

节点图

摄像头图像(Gazebo时间2:31:57)

激光数据可视化(Gazebo时间2:31:57)

摄像头图像(Gazebo时间2:46:31)

激光数据可视化(Gazebo时间2:46:31)

接下来,将会继续介绍使用C++节点编写程序处理激光和图像信息,自主驱动mobot。

机器人

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:ROS 2行动-actions-
下一篇:mysql进阶(二十七)数据库索引原理
相关文章