subscriber and publisher not in sync
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.