天天看點

ROS2進階:基本指令與RVIZ2介紹

基于windows的ROS2。

在學習ROS的時候,你很可能已經習慣了這個

rosrun rviz rviz

而在ROS2,你隻需要直接輸入

rviz2

就可以了。

一些基本指令

你可以通過ros2 --help查詢所有的的指令,

D:\>ros2 --help
usage: ros2 [-h] Call `ros2 <command> -h` for more detailed usage. ...

ros2 is an extensible command-line tool for ROS 2.

optional arguments:
  -h, --help            show this help message and exit

Commands:
  action     Various action related sub-commands
  bag        Various rosbag related sub-commands
  component  Various component related sub-commands
  daemon     Various daemon related sub-commands
  doctor     Check ROS setup and other potential issues
  interface  Show information about ROS interfaces
  launch     Run a launch file
  lifecycle  Various lifecycle related sub-commands
  multicast  Various multicast related sub-commands
  node       Various node related sub-commands
  param      Various param related sub-commands
  pkg        Various package related sub-commands
  run        Run a package specific executable
  security   Various security related sub-commands
  service    Various service related sub-commands
  test       Run a ROS2 launch test
  topic      Various topic related sub-commands
  trace      Trace ROS nodes to get information on their execution
  wtf        Use `wtf` as alias to `doctor`

  Call `ros2 <command> -h` for more detailed usage.      
ros2 node list
ros2 node info /turtlesim
ros2 node info /teleop_turtle

ros2 topic list
ros2 topic echo <topic_name>
ros2 topic echo /turtle1/cmd_vel
ros2 topic echo /turtle1/pose
ros2 topic hz /turtle1/pose   #注:hz表示頻率
ros2 topic info /turtle1/cmd_vel
ros2 interface show geometry_msgs/msg/Twist
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}}"
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
ros2 service type /clear
ros2 service list -t
ros2 service find <type_name>
ros2 service find std_srvs/srv/Empty
ros2 interface show std_srvs/srv/Empty
ros2 interface show turtlesim/srv/Spawn
ros2 service call <service_name> <service_type> <arguments>
ros2 service call /clear std_srvs/srv/Empty
ros2 service call /spawn turtlesim/srv/Spawn "{x: 2, y: 2, theta: 0.2, name: ''}"

ros2 param list
ros2 param get <node_name> <parameter_name>
ros2 param get /turtlesim background_g
ros2 param set <node_name> <parameter_name> <value>
ros2 param set /turtlesim background_r 150
ros2 param dump <node_name>
ros2 param dump /turtlesim  #這在目前目錄下會生成一個叫turtlesim.yaml的檔案
ros2 param load <node_name> <parameter_file>
ros2 param load /turtlesim ./turtlesim.yaml
ros2 run turtlesim turtlesim_node --ros-args --params-file ./turtlesim.yaml

ros2 action list
ros2 action list -t #注:-t 表示type
ros2 action info /turtle1/rotate_absolute
ros2 interface show turtlesim/action/RotateAbsolute
ros2 action send_goal <action_name> <action_type> <values>
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      

RVIZ2