ROS系统环境搭建

ROS系统搭建

小乌龟:

rosrun turtlesim turtlesim_node

小乌龟运动控制:

rosrun turtlesim turtle_teleop_key cmd_vel:=/turtle1/cmd_vel

小乌龟节点监控:

rostopic echo /turtle1/pose

控制一个小乌龟一直转圈:

rostopic pub -r 10 /new_turtle/cmd_vel geometry_msgs/Twist “linear:
x: 1.0
y: 0.0
z: 0.0
angular:
x: 0.0
y: 0.0
z: 1.0”

制造一个新的小乌龟:

rosservice call /spawn 3 3 0.2 “new_turtle”

显示ros系统拓朴关系:

rqt_graph

启动ros

roscore

启动机器人仿真系统

roslaunch urdf01_rviz car.launch

ignition gazebo加载world文件

LIBGL_ALWAYS_SOFTWARE=0 MESA_GL_VERSION_OVERRIDE=4.5 ign gazebo -v 4 -r ogre worlds/factory.world

unbuntu升级

wget http://archive.ubuntu.com/ubuntu/dists/jammy-updates/main/dist-upgrader-all/current/jammy.tar.gz tar -xzf jammy.tar.gz

sudo ./jammy –frontend=DistUpgradeViewGtk3

ROS2

激活环境变量:

source /opt/ros/humble/setup.bash

机器人模型启动:

临时制定模型:

export TURTLEBOT3_MODEL=waffle

永久指定模型:

1
2
echo "export TURTLEBOT3_MODEL=waffle" >> ~/.bashrc
source ~/.bashrc

模型渲染:

ros2 launch turtlebot3_gazebo turtlebot3_world.launch.py

键盘控制机器人:

ros2 run turtlebot3_teleop teleop_keyboard

开启导航,开始建图

ros2 run slam_toolbox async_slam_toolbox_node –ros-args –params-file ~/slam_params.yaml -p use_sim_time:=true -p scan_topic:=/scan -p mode:=mapping

启动slam节点

ros2 launch turtlebot3_cartographer cartographer.launch.py \ use_sim_time:=true \ publish_map_updates:=true

手动启动slam节点(非常重要):

ros2 launch slam_toolbox online_async_launch.py

rviz2配置

ros2 run rviz2 rviz2 -d ~/turtlebot3_nav.rviz

开始自主导航地图

ros2 launch turtlebot3_navigation2 navigation2.launch.py \ use_sim_time:=false \ map:=~/turtlebot3_map.yaml

启动流程

# 终端1:启动 Gazebo 仿真环境(必须首先运行)

ros2 launch turtlebot3_gazebo turtlebot3_world.launch.py use_sim_time:=True

#终端2:启动导航 + SLAM(注意 use_sim_time 必须与 Gazebo 一致)

ros2 launch turtlebot3_navigation2 navigation2.launch.py use_sim_time:=True slam:=True

#终端3:启动slam导航节点

ros2 launch turtlebot3_cartographer cartographer.launch.py use_sim_time:=true publish_map_updates:=true

自动处理生命周期

#终端4:自动处理生命周期

ros2 launch nav2_bringup bringup_launch.py \ use_sim_time:=True \ map:=/home/linsen/turtlebot3_map_final.yaml \ autostart:=True

路径规划中断措施

ros2 run rqt_lifecycle rqt_lifecycle # 图形化状态管理(生命周期可视化工具)

ros2 lifecycle set /planner_server configure # 将节点切换到配置状态
ros2 lifecycle set /planner_server activate # 激活节点(开始运行)

查看地图文件

eog $(dirname /home/linsen/turtlebot3_map_final.yaml)/$(grep image turtlebot3_map_final.yaml | awk ‘{print $2}’)

自动导航流程

1.坐标初始化

ros2 topic pub /initialpose geometry_msgs/msg/PoseWithCovarianceStamped “{
header: {frame_id: ‘map’},
pose: {pose: {position: {x: 1.0, y: 1.0}, orientation: {z: 0.0, w: 1.0}}}
}”

2.map=>odom转化

ros2 run tf2_ros static_transform_publisher 0 0 0 0 0 0 map odom

3.仿真启动

ros2 launch turtlebot3_gazebo turtlebot3_world.launch.py

4.导航、地图初始化

ros2 launch turtlebot3_navigation2 navigation2.launch.py use_sim_time:=True map:=$HOME/turtlebot3_map_final.yaml


ROS系统环境搭建
https://shuzhanboke.github.io/2024/07/15/四足机器人独立开发/ROS仿真环境搭建/
作者
John Doe
发布于
2024年7月15日
许可协议