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

Revision history [back]

The reason the value of derivativex is not being printed out is your ROS_ERROR statement's wrong.

ROS_ERROR("Hello %f", "derivativex");

You're specifying derivativex as a string literal by putting it inside "speech marks" so exactly those characters are being printed out. If you remove the speech marks then it will take the value of derivativex as you want.

ROS_ERROR("Hello %f", derivativex);

However there are more problems with your code you'll need to fix to get it doing exactly what you want. At the moment the loop in your callback is setting every element of vectorx to the most recent x value from the message, so your dx will anyways be zero.

Hope this helps you make some progress.

The reason the value of derivativex is not being printed out is your ROS_ERROR statement's wrong.

ROS_ERROR("Hello %f", "derivativex");

You're specifying derivativex as a string literal by putting it inside "speech marks" so exactly those characters are being printed out. If you remove the speech marks then it will take the value of derivativex as you want.

ROS_ERROR("Hello %f", derivativex);

However there are more problems with your code you'll need to fix to get it doing exactly what you want. At the moment the loop in your callback is setting every element of vectorx to the most recent x value from the message, so your dx will anyways be zero.

Hope this helps you make some progress.

Update:

I can give you some structural advice so you can update your program so it does what you want. But let me first confirm exactly what is it you're trying to do. You want your program to add each x value of palmpos to an array as they are received. When 100 positions have been received you want to calculate some values, empty the array and start the process again.

Firstly the callback function gets executed once in its entity each time a new palmpos message is received. If you put a loop inside it all of that loop will be executed everytime a new value is received.

You'll need to another class member variable to keep track of how many values have been received so far. Then inside the callback you'll want to add the single new value to the end of the array and increment the new variable which stores the number of messages received.

Then also inside the callback you'll want to check if there are now 100 messages stored. If there are you then want to perform your average calculation and reset the number of values received to zero to restart the progress.

Hope this helps.