ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

Control multiple robots separately using geometry_msgs/Twist

asked 2020-12-08 23:55:53 -0500

AMC gravatar image

updated 2022-08-17 11:46:33 -0500

lucasw gravatar image

Hi,

I am trying to control separately three robots by using a geometry_msgs/Twist command. The robots are spawning successfully and I am able to make them move using the following command (this command moves the three robots at the same time):

rostopic pub /cmd_vel geometry_msgs/Twist '[1.0, 0.0, 0.0]' '[0.0, 0.0, 0.0]'

My problem is that I would like to be able to control them separately using geometry_msgs/Twist command. (Ex. one robot going forward while the other one robot is going backward). But when I do a rostopic list, there is only one /cmd_vel and I would like to have a separate cmd_vel for each robot (/robot1/cmd_vel, /robot2/cmd_vel, etc.) to be able to use these commands :

rostopic pub /robot1/cmd_vel geometry_msgs/Twist '[1.0, 0.0, 0.0]' '[0.0, 0.0, 0.0]'
rostopic pub /robot2/cmd_vel geometry_msgs/Twist '[-1.0, 0.0, 0.0]' '[0.0, 0.0, 0.0]'
rostopic pub /robot3/cmd_vel geometry_msgs/Twist '[0.7, 0.0, 0.0]' '[0.0, 0.0, 0.0]'

I am currently using the libgazebo_ros_skid_steer_drive.so plugin as followed in my URDF:

<gazebo>
  <plugin name="skid_steer_drive_controller1" filename="libgazebo_ros_skid_steer_drive.so">
    <updateRate>100.0</updateRate>
    <robotNamespace>/</robotNamespace>
    <leftFrontJoint>exterior_left_front_wheel_joint</leftFrontJoint>
    <rightFrontJoint>exterior_right_front_wheel_joint</rightFrontJoint>
    <leftRearJoint>exterior_left_reer_wheel_joint</leftRearJoint>
    <rightRearJoint>exterior_right_reer_wheel_joint</rightRearJoint>
    <wheelSeparation>0.59196</wheelSeparation>
    <wheelDiameter>0.1524</wheelDiameter>
    <robotBaseFrame>plateau</robotBaseFrame>
    <torque>9.8</torque>
    <commandTopic>cmd_vel</commandTopic>
    <odometryTopic>odom</odometryTopic>
    <odometryFrame>odom</odometryFrame>
    <broadcastTF>false</broadcastTF>
  </plugin>
</gazebo>

Here are my two launch files : main.launch

<launch>
  <param name="/use_sim_time" value="true" />

  <!-- start world -->
  <node name="gazebo" pkg="gazebo_ros" type="gazebo"
   args="$(find robot_gazebo)/world/robot.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 robot_gazebo)/launch/robots.launch"/>
</launch>

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 $(find robot_description)/urdf/robot.urdf.xacro" />

  <group ns="robot1">
    <node name="spawn_foxtrot_model" pkg="gazebo_ros" type="spawn_model"
     args="-x -1.9064 -y 0 -z 0 -urdf -param /robot_description -model robot1"
     respawn="false" output="screen" >
      <param name="tf_prefix" value="robot1_tf" />
    </node>
  </group>

  <group ns="robot2">
    <node name="spawn_foxtrot_model" pkg="gazebo_ros" type="spawn_model"
     args="-x 0 -y -1.25 -z 0 -urdf -param /robot_description -model robot2"
     respawn="false" output="screen" >
      <param name="tf_prefix" value="robot2_tf" />
    </node>
  </group>

  <group ns="robot3">
    <node name="spawn_foxtrot_model" pkg="gazebo_ros" type="spawn_model"
     args="-x 0 -y 1.25 -z 0 -urdf -param /robot_description -model robot3"
     respawn="false" output="screen" >
      <param name="tf_prefix" value="robot3_tf" />
    </node>
  </group>

</launch>

I am not sure what I need to change to have separate cmd_vel for each robot (/robot1/cmd_vel, /robot2/cmd_vel, etc.)

PS. I followed that video : YouTube Tutorial that was an update to this : ROSanswers. I am using ROS Melodic.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2020-12-09 06:51:22 -0500

miura gravatar image

You should be able to do this by using remap as follows

<group ns="robot1">
  <node name="spawn_foxtrot_model" pkg="gazebo_ros" type="spawn_model"
    args="-x -1.9064 -y 0 -z 0 -urdf -param /robot_description -model robot1"
    respawn="false" output="screen" >
    <param name="tf_prefix" value="robot1_tf" />
    <remap from="cmd_vel" to="/robot1/cmd_vel" /> <!-- added -->
  </node>
</group>

See: http://wiki.ros.org/roslaunch/XML/remap

edit flag offensive delete link more

Comments

Thank you for your answer, but it doesn't seem to work. I updated my launch file as you suggested but when I do rostopic list, I only see /cmd_vel and not /robot1/cmd_vel, /robot2/cmd_vel, etc as expected. I don't know what might be the problem.

AMC gravatar image AMC  ( 2020-12-09 11:57:38 -0500 )edit

Question Tools

2 followers

Stats

Asked: 2020-12-08 23:55:53 -0500

Seen: 270 times

Last updated: Dec 09 '20