ROS2 - tutorials

1010阅读 0评论2020-06-17 iibull
分类:其他平台

1. 环境 
 点击(此处)折叠或打开

  1. source /opt/ros/<distro>/setup.bash ## 最好加入到 .bashrc
  2. printenv | grep -i ROS
  3. 应该出现
  4. ROS_VERSION=2
  5. ROS_PYTHON_VERSION=3
  6. ROS_DISTRO=foxy
当环境中有多个ROS2在跑时, 需要区别 通过 ROS_DOMAIN_ID [0-232].

点击(此处)折叠或打开

  1. echo "export ROS_DOMAIN_ID=" >> ~/.bashrc
 
----------------------------------------------------------------------------- 
学习 turtlesim 和 rqt 工具.
sudo apt install ~nros--rqt*
然后可执行 rqt
-----------------------------------------------------------------------------
ROS2 graph 是 ROS 2 的网络体系.
remapping 机制允许你重新指派节点的默认属性, 包括node_name, topic_name, 
service_name 等等
 
例如 ros2 run turtlesim turtlesim_node --ros-args --remap __node:=my_turtle 
即把名称有默认的 turtle1/2/3 改成 my_turtle

ros2 topic hz / list -t / echo / info 
 
ros2 interface show geometry_msgs/msg/Twist #查看消息类型的定义
ros2 topic pub   ''
 
单次 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}}"
1Hz ros2 topic pub --rate 1 /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 service list / type  / list -t / find 
 
ros2 interface show std_srvs/srv/Empty.srv # 查看 srv 的内容.
ros2 service call   
例如 ros2 service call /spawn turtlesim/srv/Spawn "{x: 2, y: 2, theta: 0.2, name: ''}"

-----------------------------------------------------------------------------
ros2 param list | get   
  | set    
            | dump  被存储在 node_name.yaml 文件. 
运行时加载参数文件
 
ros2 run   --ros-args --params-file 
竟然没了 load 指令, 惊讶.
-----------------------------------------------------------------------------
 
ros2 node info /teleop_turtle  会列出发布的话题,订阅的话题, services, action servers 和 action clients.
ros2 action list -t
ros2 action info action_name # 列出action的服务端 和 客户端.
 
ros2 interface show turtlesim/action/RotateAbsolute.action
ros2 action send_goal     values应该是yaml的格式.
例如
ros2 action send_goal /turtle1/rotate_absolute turtlesim/action/RotateAbsolute "{theta: 1.57}"-----------------------------------------------------------------------------
-----------------------------------------------------------------------------
 
 
rqt_console 是个GUI工具. 在此你可看到日志信息,可过滤检索手机等等
ros2 run rqt_console rqt_console
日志级别: Fatal / Error / Warn / Info 默认 / Debug
设置默认日志级别.
 
ros2 run turtlesim turtlesim_node --ros-args --log-level WARN
-----------------------------------------------------------------------------
建立launch 文件.
1. touch launch目录/turtlesim_mimic_launch.py
内容

点击(此处)折叠或打开

  1. from launch import LaunchDescription
  2. from launch_ros.actions import Node
  3. def generate_launch_description():
  4.     return LaunchDescription([
  5.         Node(
  6.             package='turtlesim',
  7.             namespace='turtlesim1',
  8.             executable='turtlesim_node',
  9.             name='sim'
  10.         ),
  11.         Node(
  12.             package='turtlesim',
  13.             namespace='turtlesim2',
  14.             executable='turtlesim_node',
  15.             name='sim'
  16.         ),
  17.         Node(
  18.             package='turtlesim',
  19.             executable='mimic',
  20.             name='mimic',
  21.             remappings=[ //相当于让 turtlesim2 模拟 turtlesim 1 的动作.
  22.                 ('/input/pose', '/turtlesim1/turtle1/pose'), 相当于订阅/turtlesim1/turtle1/pose
  23.                 ('/output/cmd_vel', '/turtlesim2/turtle1/cmd_vel'), 发布到/turtlesim2/turtle1/cmd_vel
  24.             ]
  25.         )
  26.     ])
 
ros2 launch  
ros2 launch turtlesim_mimic_launch.py 如果launch文件在当前目录下的情况
-----------------------------------------------------------------------------
sudo apt-get install ros--ros2bag ros--rosbag2*
ros2 bag record  产生一个 rosbag2-时间点 的文件.
ros2 bag record -o 录音名称 /topic1 /topic2
ros2 bag info 
ros2 bag play 
-----------------------------------------------------------------------------


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

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

上一篇:ROS2 ubuntu20.04安装
下一篇:ROS2 just do it