Don't know how to fix my Callback function parameters in subscriber node that is subscribed to a topic of message type ar_track_alvar_msgs/AlvarMarkers
(using ubuntu 16.04 using ros kinetic) This is my callback function and subscriber initialization. (Btw I am kind of a noob to c++ and ros). I come from basic experience in java. The main issues I see in my code are that the parameters for my callback function are probably wrong and i don't know how to access the poses and header inside of markers[] which is in AlvarMarkers.msg which is inside ar_track_alvar_msgs, which are being published to the ar_pose_marker topic. I just need to know what parameters I need to put into the callback function and why my parameters are incorrect and also if my subscriber initialization parameters look fine. I've already read and replicated the tutorials for Writing a simple publisher and subscriber in C++ the thing is that the messages being published over my topic are different types than the ones in the tutorial version of the subscriber.
void poseMarkerCallback(const ar_track_alvar_msgs::AlvarMarkersConstptr& markers[])
{
if(!started)
{
positions[1] = msg->markers[sizeof markers / sizeof *markers -1].pose.position.y;
times[1] = (msg->markers[sizeof markers / sizeof *markers -1].pose.header.stamp.sec) + (msg-> markers[sizeof markers / sizeof *markers -1].pose.header.stamp.nsec/1,000,000,000); //get ar_pose_marker value
positions[2] = 0;
times[2] = 0;
started = true;
}
else
{
positions[2] = positions[1];
times[2] = times[1];
positions[1] = msg->markers[sizeof markers / sizeof *markers -1].pose.position.y;
times[1] = (msg->markers[sizeof markers / sizeof *markers -1].header.stamp.sec) + (msg->markers[sizeof markers / sizeof *markers -1].header.stamp.nsec/1,000,000,000); //get ar_pose_marker value
}
velocity = (positions[1]-positions[2])/(times[1]-times[2]);
ROS_INFO("Velocity:[%d]" + velocity, msg->data.c_str());
}
ros::Subscriber sub2 = n.subscribe("ar_pose_marker", 1000, poseMarkerCallback); //this is inside of int main
Your code's indentation is all screwed up atm - making it hard to read. Getting the preformatted text to work is a bit tricky. Usually I copy-paste code directly from Editor/IDE, highlight code, and then hit
101010
button. Seem to break less often that way.just edited the post, hopefully that looks a little better.