ROS2小乌龟测试

ROS2小乌龟测试

下载turtlesim功能包

source /opt/ros/humble/setup.bash
git clone https://github.com/ros/ros_tutorials.git -b humble-devel

# 创建工作空间
mkdir -p turtle_dev/src && cd turtle_dev/src

解决依赖

rosdep install -i --from-path src --rosdistro eloquent -y

构建空间

colcon build
不能在python virtual environment下构建

设置环境变量

. install/setup.bash

运行节点

ros2 run turtlesim turtlesim_node

ros2 run turtlesim turtlesim_node
ros2 run turtlesim turtle_teleop_key

查看信息

查看节点信息

ros2 node list
ros2 node info /turtlesim

查看话题列表和话题内容

ros2 topic list # -t 参数显示话题传输的数据类型
ros2 topic echo /turtle1/pose

查看话题用的带宽

ros2 topic bw /turtle1/pose

使用命令行发布话题
ros2 topic pub -r 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}}"

使用service生成新的小乌龟

ros2 service
ros2 service call /spawn turtlesim/srv/Spawn "{x: 2, y: 2, theta: 0.2, name: ''}"

action机制给小乌龟发目标点

ros2 action
ros2 action send_goal /turtle1/rotate_absolute turtlesim/action/RotateAbsolute "theta: 3"
posted @ 2024-11-01 19:56  sgqmax  阅读(27)  评论(0编辑  收藏  举报