gazebo启动ros多机器人

在Gazebo仿真里面启动多个机器人

对多机器人来说,关键是处理好namespaces和tf_prefixes.
在设置导航模块时,每个机器人必须运行在自己的命令空间ns和tf_prefix,但与此同时,这些机器人还需要共享一张地图。所以要实现的效果是

                                  /map
       /robot1/robot_state_publisher    /robot2/robot_state_publisher
       /robot1/robot_pose_ekf           /robot2/robot_pose_ekf
       /robot1/amcl                     /robot2/amcl
       /robot1/move_base                /robot2/move_base

//先创建一个catkin_ws

mkdir catkin_ws
cd catkin_ws
mkdir src
cd src
catkin_create_pkg multi_robot rospy gazebo_ros
cd multi_robot
mkdir launch 
cd launch 
touch one_robot.launch //输入以下语句后关闭
<launch>
    <arg name="robot_name"/>
    <arg name="init_pose"/>
 
    <node name="spawn_minibot_model" pkg="gazebo_ros" type="spawn_model"
     args="$(arg init_pose) -urdf -param /robot_description -model $(arg robot_name)"
     respawn="false" output="screen" />
 
    <node pkg="robot_state_publisher" type="state_publisher" 
          name="robot_state_publisher" output="screen"/>
 
    <!-- The odometry estimator, throttling, fake laser etc. go here -->
    <!-- All the stuff as from usual robot launch file -->
</launch>
touch robots.launch//再建第二个文件,输入以下语句后关闭
<launch>
  <!-- No namespace here as we will share this description. 
       Access with slash at the beginning -->
  <param name="robot_description"
    command="$(find xacro)/xacro.py $(find turtlebot_description)/robots/kobuki_hexagons_asus_xtion_pro.urdf.xacro" />
<!--这里要根据具体打开的机器人模型更改-->
  <!-- BEGIN ROBOT 1-->
  <group ns="robot1">
    <param name="tf_prefix" value="robot1_tf" />
    <include file="$(find multi_robot)/launch/one_robot.launch" >
      <arg name="init_pose" value="-x 1 -y 1 -z 0" />
      <arg name="robot_name"  value="Robot1" />
    </include>
  </group>

  <!-- BEGIN ROBOT 2-->
  <group ns="robot2">
    <param name="tf_prefix" value="robot2_tf" />
    <include file="$(find multi_robot)/launch/one_robot.launch" >
      <arg name="init_pose" value="-x -1 -y 1 -z 0" />
      <arg name="robot_name"  value="Robot2" />
    </include>
  </group>
</launch>
touch main.launch //再建第三个文件,输入以下语句后关闭
<launch>
  <param name="/use_sim_time" value="true" />

  <!-- start world -->
  <node name="gazebo" pkg="gazebo_ros" type="gazebo" 
   args="$(find turtlebot_gazebo)/worlds/empty_wall.world" respawn="false" output="screen" />

  <!-- start gui -->
  <!-- <node name="gazebo_gui" pkg="gazebo" type="gui" respawn="false" output="screen"/> -->

  <!-- include our robots -->
  <include file="$(find multi_robot)/launch/robots.launch"/>
</launch>

//加入新建包的路径

gedit source ~/.bashrc 
source ~/catkin_ws/devel/setup.bash
source ~/.bashrc

//启动多机器人

roslaunch multi_robot main.launch

//让robot1机器人跑起来

rosrun teleop_twist_keyboard teleop_twist_keyboard.py /cmd_vel:=/robot1/cmd_vel

//新启动一个终端,让robot2机器人跑起来

rosrun teleop_twist_keyboard teleop_twist_keyboard.py /cmd_vel:=/robot2/cmd_vel

//这样就可以通过键盘控制机器人移动

https://answers.ros.org/question/41433/multiple-robots-simulation-and-navigation/
https://www.cnblogs.com/taiping/p/6701655.html
https://www.theconstructsim.com/ros-qa-130-how-to-launch-multiple-robots-in-gazebo-simulator/

发布了8 篇原创文章 · 获赞 1 · 访问量 175

猜你喜欢

转载自blog.csdn.net/Savage888777/article/details/105225295