How to spawn multiple copies of the same robot with ros2_control?

asked 2023-04-15 07:13:11 -0500

Envilon gravatar image

updated 2023-04-15 19:17:23 -0500

Hello, I have a working setup with a single robot (manipulator) that I can run and control with a joint trajectory controller. I want to modify my setup to spawn multiple copies of the same robot in Gazebo and have them simultaneously perform the same trajectories. However, I am having trouble achieving this. I will describe my current working setup for a single robot and what I thought would be the steps to achieve a multi-robot setting.

Current Setup:

  • I'm running ROS 2 Humble with Gazebo 11.10.2 on Ubuntu 22.04 LTS
  • I have a custom robotic arm described in Xacro format controlled with ros2_control, and there is the gazebo_ros2_control plugin inside the URDF.
    • As a parameter of the plugin, I specify the controller YAML file that configures JointStateBroadcaster and JointTrajectoryController (position interfaces only)
  • In the launch file:

    • Start Gazebo with an empty world (using gazebo.launch.py from the gazebo_ros package)
    • Start the robot_state_publisher node with the URDF robot description as a parameter
    • Run spawn_entity.py from the gazebo_ros package to spawn the robot, using argument -topic /robot_description
    • When the spawn script exits, I start the joint_state_broadcaster node using the spawner from controller_manager package
    • After that, I start the joint_trajectory_controller in the same way
  • Robot is spawned in Gazebo. On the side, I start another ROS 2 node that publishes trajectories to /joint_trajectory_controller/joint_trajectory topic every few seconds -> Robot moves in Gazebo.

Going multi-robot:
So I thought, if I want three robots spawned, I'll just start three robot_state_publishers with different namespaces and run three spawn_entity.py scripts using different robot descriptions topics (with appropriate namespaces). However, the problem, I think, is that only a single /gazebo_ros2_control node starts. Where do I go from here? Is there an easier way?

edit retag flag offensive close merge delete