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

subscriber and publisher not in sync

asked 2015-05-20 18:27:50 -0500

215 gravatar image

updated 2015-05-20 19:40:20 -0500

Hi guys.. I trying to perform some form of system identification on unit, but for some reason is the frequency by which i am logging with changing which mess up with my relation between my input and output..

My subscriber looks like this:

#include "ros/ros.h"
#include "sensor_msgs/JointState.h"
#include <vector>
#include <iostream>
#include <sstream>
#include <fstream>
#include <vector>
/**
 * This tutorial demonstrates simple receipt of messages over the ROS system.
 */

 using namespace std; 
double poss;
double velo;
bool writes;
vector<double> dif;
ofstream infile ("/home/User/pn.csv");
int i = 0;
void chatterCallback(const sensor_msgs::JointState::ConstPtr& msg)
{   



  if(writes == false && velo != msg->velocity[0])   
  {
    infile << msg->position[0] - poss << " , "; 
    cout << msg->velocity[0] << endl;  
    velo = msg->velocity[0];
    poss = msg->position[0];
    i++;
    cout << "i: " << i << endl;       
  }


}

int main(int argc, char **argv)
{
  writes = false;
  //writes = true;
  velo = 0;
  poss = 0;

  ros::init(argc, argv, "listener");

  ros::NodeHandle  a;



    ros::Subscriber sub1 = a.subscribe("/joint_states",1,chatterCallback);

    ros::spin();

  return 0;
}

The the topic is updated with 10 hz (Can be set as high i want), and the input signal is 1/100 hz. the input is different velocities with max vel. as the amplitude, as the vel. change to new value i save the difference in position difference in position from last to now.

At the beginning of the curve it seem to work flawlessly but near the top of the curve it seem to not get all data and the publisher and subscriber gets thus unsynced.

Is there anything wrong with the way i am doing it.. Or could this be done in a better way? It was not a problem at either 1 hertz or 1/10 hz.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2015-05-21 20:04:54 -0500

tfoote gravatar image

Exactly what you mean by unsynced is not clear from this description.

It sounds like you're losing data because the system cannot keep up with the flow. If writing to file is too slow, your receive queue size of 1 will drop incoming messages. And there's also possibly queuing with overflow on the publisher side. And also in the tcp stack, though unlikely in this case.

edit flag offensive delete link more

Comments

The problem is the receiver cannot follow the publisher. The publisher doesn't have any problem sending command => at what ever rate. The problem it that the receiver is able to follow when the frequency of the publisher becomes above 100.

215 gravatar image 215  ( 2015-05-22 03:21:58 -0500 )edit

As mentioned above it sounds like you're dropping messages out of your queue as you get faster. You should extend your queue size and make sure you have enough bandwidth between your publisher and subscriber to handle the full traffic load.

tfoote gravatar image tfoote  ( 2015-05-22 10:10:32 -0500 )edit

Question Tools

Stats

Asked: 2015-05-20 18:27:50 -0500

Seen: 614 times

Last updated: May 21 '15