Publishing joint velocity with joint_state_publisher

asked 2019-10-18 15:17:09 -0600

umopapisdnquap gravatar image

updated 2019-10-19 07:43:56 -0600

I'm new to ROS. Currently I am following a tutorial on how to publish joint states of your robot: link here. I'm trying to apply this to my own robot. I'm able to publish joint positions and visualize them in Rviz without any problem.

However, when I try publishing joint velocities from sensor_msgs. It doesn't work. If I don't publish joint positions, but only joint velocities, the program does not run. There are missing links and joints (apart from my base link) in the tf tree. And if I do publish the joint positions, my joint velocities get overwritten by the joint positions and the robot does not move.

Any suggestions on this issue? Thanks in advance


Edit: My code has the same structure as in this tutorial.

while (ros::ok()) {
    //update joint_state
    joint_state.header.stamp = ros::Time::now();
    joint_state.name.resize(6);
    joint_state.position.resize(6);
    joint_state.name[0] ="joint1";
    joint_state.position[0] = joint1_trans;
    joint_state.name[1] ="joint2";
    joint_state.position[1] = joint2_rot;
    joint_state.name[2] ="joint3";
    joint_state.position[2] = joint3_rot;
    ...
}

which are published by: joint_pub.publish(joint_state);

Now, I'm trying to set the velocities in a similar manner: joint_state.velocity[0] = ...:

joint_state.name.resize(6);
joint_state.position.resize(6);
joint_state.velocity.resize(6);
joint_state.name[0] ="joint1";
joint_state.position[0] = joint1_trans;
joint_state.velocity[0] = joint1_vel;
joint_state.name[1] ="joint2";
joint_state.position[1] = joint2_rot;
joint_state.velocity[1] = joint2_vel;
...

but this does not work. The joint_state.position[0] overwrites this and nothing happens in Rviz. If I leave out joint_state.position[0], my robot gets messed up in Rviz.

rostopic echo /joint_states gives the following:

header: 
  seq: 375
  stamp: 
    secs: 1571488752
    nsecs: 533079554
  frame_id: ''
name: [joint1, joint2, joint3, joint4, joint5, joint6]
position: [0.0, 0.0, 0, 0.0, 0.0, 0.0]
velocity: [0.2, 0.2, 0.0, 0.0, 0.0, 0.0]
effort: []

There you can see my messages are coming through, but these velocities are not getting displayed by Rviz. Because the joint position stays on 0. Is there a way to only send joint.velocity, and also getting the joint.position updated and displayed correctly in Rviz?

edit retag flag offensive close merge delete

Comments

It's slightly unclear to me what your actual problem is.

Could you please show us how (ie: with code snippets) you are publishing joint positions, but not joint velocities?

Did you understand from the message's comments that you can publish both positions and velocities (and efforts in fact) at the same time?

gvdhoorn gravatar imagegvdhoorn ( 2019-10-19 06:28:51 -0600 )edit

Please show the exact code you use for the velocities.

Do you also .resize(6) the velocity vector?

gvdhoorn gravatar imagegvdhoorn ( 2019-10-19 07:21:35 -0600 )edit
2

Please add these sort of updates to your original question text. Use the edit button/link for that.

And again: please show all relevant code. How do you instantiate the message fi?

How do you publish it?

And please show some rostopic echo output of the joint_states topic.

Do you have any other joint_state_publisher instances running?

gvdhoorn gravatar imagegvdhoorn ( 2019-10-19 07:28:40 -0600 )edit

Thank you for your suggestions, I'm quite new to ROS. I edited my post as you can see now.

umopapisdnquap gravatar imageumopapisdnquap ( 2019-10-19 07:43:25 -0600 )edit

Is there a way to only send joint.velocity, and also getting the joint.position updated and displayed correctly in Rviz?

RViz does not visualise velocity, only position. A sufficiently high upate-rate for your positions results in something similar to animation, but velocities are not used nor shown.

gvdhoorn gravatar imagegvdhoorn ( 2019-10-19 08:31:29 -0600 )edit

Okay, that was what I was suspecting. Thanks a lot for the confirmation.

umopapisdnquap gravatar imageumopapisdnquap ( 2019-10-19 08:37:19 -0600 )edit
1

I'm slightly confused. Was/is your problem with your JointState publisher not working correctly, or with the fact that RViz does not visualise velocity (whatever that may mean)?

gvdhoorn gravatar imagegvdhoorn ( 2019-10-19 14:50:05 -0600 )edit