build error when accessing markers array inside of ar_track_alvar_msgs/AlvarMarkers being published through ar_pose_marker (c++)

asked 2018-07-03 11:21:51 -0600

randy2g gravatar image

Hello I am trying to make a subscriber node which has a callback funciton when a message of type ar_track_alvar_msgs/AlvarMarkers is published through the ar_pose_marker topic. I'm not sure why I can't access the poses and headers inside the AlvarMarkers which are inside the markers array. fyi I'm also using ros kinetic on ubuntu 16.04 Here are the errors my code is giving me:

     error: ‘markers’ was not declared in this scope
positions[1] = msg->markers[sizeof markers / sizeof *markers -1].pose.pose.position.y;

Also I am getting this error aswell:

error: invalid operands of types ‘const char [10]’ and ‘float’ to binary ‘operator+’
ROS_INFO_STREAM( "Velocity:" + velocity + " Average Velocity:"/**+averageVelocity*/ ) ;

Here is the code for my subscriber node, Also please ignore the commented code it's probably meaningless:

#include "ros/ros.h"
#include "std_msgs/String.h"
#include "ar_track_alvar_msgs/AlvarMarkers.h"
#include "tf/tf.h"
#include "tf/transform_datatypes.h"
#include "vector"


float positions[2];
float times[2];
bool started = false;
float velocity;
float averageVelocity;
int velocitiesSize = 0;
std::vector<float> velocites; 


/**void chatterCallback(const std_msgs::String::ConstPtr& msg)
{
  ROS_INFO("I heard: [%s]", msg->data.c_str());
}
*/
void poseMarkerCallback(const ar_track_alvar_msgs::AlvarMarkersConstPtr& msg)
//void poseMarkerCallback(ar_track_alvar_msgs::AlvarMarkers req)
{
//ar_track_alvar_msgs::AlvarMarkers markersConst *msg
    //if(!req.markers.empty()){
//tf::Position q(req.markers[0].pose.pose.position.y
        if(!started)
    {
//positions[1] = msg->pose.position.y; //get ar_pose_marker y value
positions[1] = msg->markers[sizeof markers / sizeof *markers -1].pose.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->pose.position.y//get ar_pose_marker value
positions[1] = msg->markers[sizeof markers / sizeof *markers -1].pose.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]);

/**
//FOR LATER
++velocitiesSize;
velocities.resize(velocitiesSize);
velocities[velocitiesSize-1] = velocity; 


for(auto const &element: velocitys)
averageVelocity+= element;

averageVelocity = averageVelocity/velocitesSize;
*/
    //  ROS_INFO("Velocity:[%d]" + velocity + "Average Velocity:" + averageVelocity, msg->data.c_str());
ROS_INFO_STREAM( "Velocity:" + velocity + " Average Velocity:"/**+averageVelocity*/ ) ;

}
int main(int argc, char **argv)
{

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


  ros::NodeHandle n;



//ros::Subscriber sub = n.subscribe("chatter", 1000, chatterCallback);
      ros::Subscriber sub2 = n.subscribe("ar_pose_marker", 1000, poseMarkerCallback);

  /**
   * ros::spin() will enter a loop, pumping callbacks.  With this version, all
   * callbacks will be called from within this thread (the main one).  ros::spin()
   * will exit when Ctrl-C is pressed, or the node is shutdown by the master.
   */
  ros::spin();

  return 0;
}
edit retag flag offensive close merge delete