Having trouble applying the C++ Subscriber application
I am trying to retrieve some values from a published topic, and using that data in my main function. I can almost make it work with global variables, but I believe that is poor programming etiquette? Before I continue debugging my global variable solution, I would like to know if there is a simpler, more efficient way. Here is the callback function:
void chatterCallback(const sensor_msgs::JointState msg)
{
for (int i=0;i<NUMBER_OF_JOINTS;i++)
{
std::cout << "The " << msg.name.at(i) << " is now at " << msg.position.at(i);
std::cout << " moving with velocity " << msg.velocity.at(i) << "\n";
}
}
I want to pass the data contained in the sensor_msgs::JointState to my main function, in order to start the program by ascertaining the robot's joint values. Also, I'm not sure the subscriber callback function is allowed to use sensor_msgs::JointState, rather than ConstPtr. The code works like this, though.