赞
踩
介绍了在ubuntu20.04中使用ROS平台,实现对机器人进行路径规划的仿真过程
本文的教程对刚入门ROS的同学有一定的帮助
在windows上安装ubuntu20.04虚拟机
启动ubuntu20.04,Ctrl+Alt+T 打开终端
设置sources.list
sudo sh -c '. /etc/lsb-release && echo "deb http://mirrors.tuna.tsinghua.edu.cn/ros/ubuntu/ `lsb_release -cs` main" > /etc/apt/sources.list.d/ros-latest.list'
设置秘钥
sudo apt-key adv --keyserver 'hkp://keyserver.ubuntu.com:80' --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654
更新软件
sudo apt update && sudo apt upgrade -y
安装ros
sudo apt install -y ros-noetic-desktop-full
更新.bashrc文件
- echo "source /opt/ros/noetic/setup.bash" >> ~/.bashrc
- source ~/.bashrc
另外,推荐安装vscode和git、vim、cmake等软件
- sudo snap install --classic code
- sudo apt install -y git vim cmake terminator
在vscode软件中推荐安装插件如下:
- mv ~/catkin_ws ~/catkin_ws_back 2>/dev/null || :
- git clone https://gitee.com/lishan666/ros-robot-demo.git ~/catkin_ws
- cd ~/catkin_ws
- git submodule update --init --recursive
安装依赖包,编译项目
source ~/catkin_ws/install.sh
启动单个机器人导航的演示程序
roslaunch robot_nav single_nav.launch
启动两个机器人导航的演示程序
roslaunch robot_two_nav robots_navigation.launch
注意,如果提示[gazebo-2] process has died,可以先彻底关闭gzserver,再启动仿真环境
killall gzserver
后续关闭gazebo、rviz等软件的时候记得通过点击左上方的File->Quit
- mkdir -p ~/catkin_ws/src
- cd ~/catkin_ws/src
- catkin_create_pkg robot1 rospy
- catkin_create_pkg robot2 robot1 rospy
编译
- cd ~/catkin_ws
- catkin_make
新建包abot_description
- cd ~/catkin_ws/src
- catkin_create_pkg abot_description URDF xacro
在abot_description下新建4个文件夹,其中
- cd ~/catkin_ws/src/abot_description
- mkdir urdf meshes launch config
在urdf目录下新建abot.urdf文件,ros仿真中很大部分时间是在编辑该urdf文件
vim ~/catkin_ws/src/abot_description/urdf/abot.urdf
文件内容如下
- <?xml version="1.0"?>
- <robot name="abot">
- <link name="base_link">
- <visual>
- <origin xyz="0 0 0" rpy="0 0 0"/>
- <geometry>
- <box size="0.30 0.25 0.15"/>
- </geometry>
- <material name="yellow">
- <color rgba="1 1 0 1"/>
- </material>
- </visual>
- </link>
- </robot>
在launch目录下新建abot.launch文件
vim ~/catkin_ws/src/abot_description/launch/abot.launch
文件内容如下
- <launch>
- <!-- 设置 launch 文件的参数 -->
- <arg name="paused" default="false"/>
- <!-- <arg name="world_name" value="$(find
- abot_description)/map/abot_square.world"/> -->
- <arg name="use_sim_time" default="true"/>
- <arg name="gui" default="true"/>
- <arg name="headless" default="false"/>
- <arg name="debug" default="false"/>
- <arg name="x_pos" default="0"/>
- <arg name="y_pos" default="0"/>
- <arg name="z_pos" default="15"/>
-
- <!-- 运行 gazebo 仿真环境 -->
- <!-- <include file="$(find gazebo_ros)/launch/empty_world.launch">
- <arg name="world_name" value="$(arg world_name)"/>
- <arg name="debug" value="$(arg debug)" />
- <arg name="gui" value="$(arg gui)"/>
- <arg name="paused" value="$(arg paused)"/>
- <arg name="use_sim_time" value="$(arg use_sim_time)"/>
- <arg name="headless" value="$(arg headless)"/>
- </include> -->
-
- <!--robot motor -->
- <param name="robot_description"
- textfile="$(find abot_description)/urdf/abot.urdf"/>
-
- <!-- 运行 joint_state_publisher 节点,发布机器人的关节状态 -->
- <node name="joint_state_publisher" pkg="joint_state_publisher"
- type="joint_state_publisher">
- </node>
-
- <!-- 运行 robot_state_publisher 节点,发布 tf -->
- <node name="robot_state_publisher" pkg="robot_state_publisher"
- type="robot_state_publisher" output="screen">
- </node>
-
- <!-- 在 gazebo 中加载机器人模型-->
- <!-- <node name="urdf_spawner" pkg="gazebo_ros" type="spawn_model"
- respawn="false" output="screen"
- args="-urdf -model abot_model
- -x $(arg x_pos) -y $(arg y_pos) -z $(arg z_pos)
- -param robot_description"/> -->
- </launch>
新开一个终端,启动模型
roslaunch abot_description abot.launch
再新开一个终端,运行可视化工具
rosrun rviz rviz
在rviz软件界面中,修改坐标系将map修改为base_link
点击左下角的 add,添加机器人模型插件,选中 RobotModel 点击确定
在rviz界面按下键盘得ctrl+s,保存文件为~/catkin_ws/src/abot_description/config/abot.rviz
修改abot.launch文件,添加rviz节点内容如下
- <launch>
- <!-- 运行RVIZ可视化界面-->
- <node name="rviz" pkg="rviz" type="rviz"
- args="-d $(find abot_description)/config/abot.rviz" required="true">
- </node>
- </launch>
roslaunch wpb_home/wpb_home_tutorials gmapping.launch
启动仿真环境
roslaunch wpr_simulation wpb_simple.launch
- roslaunch wpr_simulation wpb_gmapping.launch
- rosrun wpr_simulation keyboard_vel_ctrl
- rosrun map_server map_saver -f map
导航
- roslaunch wpr_simulation wpb_stage_slam.launch
- roslaunch wpr_simulation wpb_demo_nav.launch
-
- roslaunch wpr_simulation wpb_hector.launch
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。