Reputation: 449
Could anyone please tell me, how to display two robots in one instance of RViz?
This question can be broken into two:
Any help is greatly appreciated. Thank you.
Upvotes: 2
Views: 1914
Reputation: 449
I have figured it out. Full code at robotics.snowcron.com, in a "multiple robots" section. The solution is rather lengthy, as it covers both RViz and Gazebo, and (especially) makes Nav2 work with those. Here is a brief description.
With these changes, Nav2 works with multiple robots, they "see" each other and even TRYING to avoid collisions. I also painted robots (dynamically) in different colors :)
Upvotes: 1
Reputation: 41
I managed this in rviz2 with the method described below. This worked well for me, but there may be more ways to go.
In my case the robots were not the identical so the urdfs were streamed on separate topics. To do this I gave each robot its own description topic. I used a robot_state_publisher from the tutorials for each unique robot (named RAS_TN_DB and RAS_TN_PU) to make the descriptions available for rviz.
$ ros2 topic list
/RAS_TN_DB/joint_states
/RAS_TN_DB/robot_description
/RAS_TN_PU/joint_states
/RAS_TN_PU/robot_description
/parameter_events
/rosout
/tf
/tf_static
It does not matter who broadcasts this information, as long as its available for rviz to figure out through the tf tree where each link is with respect to the fixed frame.
Initially I used the joint-state-publisher and the robot-state-publisher from the tutorials to get a consistent stream of my robots links positions. Using 'ros2 topic echo /tf' I could observe all transforms streamed, where frame_id and 'child_frame_id' were matching the names of links described in the urdf, or the name of the fixed frame.
Using tf_tree viewer I could see a tree leading back to my system's origin, in my case 'world'.
I hope this helps.
Upvotes: 1
Reputation: 96
To spawn and visualize multiple robots of the same type, you can use robot_state_publisher and the tf2_ros to handle the TF frames appropriately. This can be done using different namespaces for each robot.
from launch import LaunchDescription
from launch_ros.actions import Node
def generate_launch_description():
return LaunchDescription([
Node(
package='robot_state_publisher',
executable='robot_state_publisher',
namespace='robot1',
output='screen',
parameters=[{'robot_description': 'file://path_to_urdf/robot.urdf.xacro'}],
),
Node(
package='robot_state_publisher',
executable='robot_state_publisher',
namespace='robot2',
output='screen',
parameters=[{'robot_description': 'file://path_to_urdf/robot.urdf.xacro'}],
),
Node(
package='rviz2',
executable='rviz2',
name='rviz2'
),
])
Each instance of the robot is assigned its own namespace (robot1 and robot2), allowing each to have its own separate topics and parameters.
Upvotes: 2
Reputation: 449
I was able to do it by prefixing all frames with robot's names.
Upvotes: 1