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

Revision history [back]

click to hide/show revision 1
initial version

I have searched high and low for a true answer to your question, but I think whatever is causing this is insufficiently documented to the point it is unsolvable.

I think the way around this is to avoid the /joint_states topic, and instead generate a custom topic within a Gazebo plugin that will publish the necessary data. My own Gazebo plugin is able to smoothly output current joint states exactly synched with the simulation time steps (by using the OnUpdate() function within the plugin).

public: void OnUpdate()
    {
              ROS_INFO_STREAM(this->model->GetJoint(joint_name[i][j][k])->GetVelocity(0));
    }

In the above example I have it printing to the terminal, but you can also create a ros topic within the plugin to publish to.

I have searched high and low for a true answer to your question, but I think whatever is causing this is insufficiently documented to the point it is unsolvable.

I think the way around this is to avoid the /joint_states topic, and instead generate a custom topic within a Gazebo plugin that will publish the necessary data. My own Gazebo plugin is able to smoothly output current joint states exactly synched with the simulation time steps (by using the OnUpdate() function within the plugin).

public: void OnUpdate()
    {
              ROS_INFO_STREAM(this->model->GetJoint(joint_name[i][j][k])->GetVelocity(0));
    }

In the above example I have it printing to the terminal, but you can also create a ros topic within the plugin to publish to.

EDIT: while the above method will still work (and may be best for certain time sensitive topics), this issue is definitely caused by the implementation of Nagle's algorithm for connections. Nagle's algorithm groups messages together and sends them as a block in order to save bandwidth at the expense of latency. Therefore the rate that messages get sent at I believe depends on the size and frequency of those messages. You don't need to modify the publisher, which seems weird but that's how it is.

To disable Nagle's algorithm you need to modify the ROS subscriber, below are my original subscriber, then modified to dissable Nagle.

sub5 = nh_.subscribe("/dd_robot/joint_states", 5, &variables::joint_states_Callback, this);
sub5 = nh_.subscribe("/dd_robot/joint_states", 5, &variables::joint_states_Callback, this, ros::TransportHints().tcpNoDelay());