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

How to visualize a real robot in Rviz

asked 2016-09-18 20:55:18 -0500

Cerin gravatar image

How do you run Rviz so that it shows the joint positions of a real robot in real-time?

I've written a URDF file descibing a simple 2-wheeled cylindrical robot with a pan/tilt head, and I can visualize it in Rviz perfectly by running the launch file:

<launch>

  <arg name="model" default="$(find myrobot_description)/urdf/myrobot.urdf.xacro"/>
  <arg name="gui" default="true" />
  <arg name="rvizconfig" default="$(find myrobot_description)/rviz/urdf.rviz" />

  <param name="robot_description" command="$(find xacro)/xacro.py $(arg model)" />
  <param name="use_gui" value="$(arg gui)"/>

  <node name="joint_state_publisher" pkg="joint_state_publisher" type="joint_state_publisher" />
  <node name="robot_state_publisher" pkg="robot_state_publisher" type="state_publisher" />
  <node name="rviz" pkg="rviz" type="rviz" args="-d $(arg rvizconfig)" required="true" />

</launch>

I also implemented a node, running on the actual robot, that publishes angles of the pan/tilt head as JointState messages on the /joint_state topic, and when I manually move the joints, rostopic echo /joint_states shows messages like:

header: 
  seq: 21
  stamp: 
    secs: 1474249855
    nsecs: 537719964
  frame_id: ''
name: ['base_link_to_neck_joint']
position: [6.230825429619756]
velocity: []
effort: []

However, when I run that same launch file on the robot, along with my custom joint publisher node, Rviz only shows the joints flicker briefly, then reset back to the default position. Why is this?

I tried removing the joint_state_publisher node in the launch file, thinking that was interfering with my custom publisher, but then when I launch Rviz, my model looks all mangled and it reports "no transformation" for all of my links. How do I fix that?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2016-09-19 03:12:56 -0500

gvdhoorn gravatar image

updated 2016-09-19 04:05:54 -0500

As far as I can tell you have all the pieces in place, you just need to change one thing:

<param name="use_gui" value="$(arg gui)"/>

<node name="joint_state_publisher" pkg="joint_state_publisher" type="joint_state_publisher" />

Setting the use_gui parameter will tell the joint_state_publisher that you want it to broadcast (fake) joint states based on the values of the sliders in the UI that it spawns for you.

As in this case you already have a node publishing joint states, you don't need joint_state_publisher at all. Just leave it out of your launch file and I expect things will start to work.

Note that in some situations, joint_state_publisher is actually needed even when you have driver nodes interfacing with real hardware. One example would be if you have multiple drivers each publishing on a different topic and you want a single joint_states topic that aggregates all the partial ones into a global JointState. In that case you'd use the source_list parameter to tell joint_state_publisher which topics it should merge. See wiki/joint_state_publisher - Parameters for more info on that.


Edit: just noticed:

I tried removing the joint_state_publisher node in the launch file, thinking that was interfering with my custom publisher, but then when I launch Rviz, my model looks all mangled and it reports "no transformation" for all of my links. How do I fix that?

Make sure you have nodes publishing JointStates for all the joints in your URDF. If you don't, robot_state_publisher will not be able to do FK for all joints, leading to missing TF frames, and the error you saw.

edit flag offensive delete link more

Comments

You're right, disabling the jSP gui or modifying my custom node to track and publish all joints simultaneously both fixed the problem.

Cerin gravatar image Cerin  ( 2016-09-19 09:53:51 -0500 )edit

Good to hear you got it to work.

Just to be clear: you don't have to publish joint states for all joints from that single node, as long as the aggregate of all joint_states topics contains information on all joints. Multiple nodes can publish JointStates, which JSP can then combine.

gvdhoorn gravatar image gvdhoorn  ( 2016-09-19 10:11:40 -0500 )edit

Question Tools

2 followers

Stats

Asked: 2016-09-18 20:55:18 -0500

Seen: 4,903 times

Last updated: Sep 19 '16