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

I can't create a subscriber for ar_track_alvar.

asked 2021-09-20 07:23:26 -0500

yu_ki gravatar image

I would like to use the code below to subscribe to the position of the AR marker obtained by ” ar_track_alvar” . However, I am getting the error shown below.

Can you please tell me why I am getting the error? Also, please let me know the correct code.

The development environment is Ubuntu kinetic.

[code]
    #include <ros/ros.h>    
    #include <ar_track_alvar_msgs/AlvarMarkers.h>

    #include <iostream>

using namespace std;


void poseCallback(const ar_track_alvar_msgs::AlvarMarkers& pos){


    ROS_INFO("position (x,y,z) = (%f : %f : %f)  \n", pos->position.x, pos->position.y, pos->position.z);

}



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

  ros::init(argc, argv, "basic_simple_listener");
  ros::NodeHandle nh;


  ros::Subscriber sub = nh.subscribe<ar_track_alvar_msgs::AlvarMarkers>("ar_pose_marker", 100, poseCallback);

  ros::spin();

  return 0;
}

Here is the error

 error: ‘const AlvarMarkers {aka const struct ar_track_alvar_msgs::AlvarMarkers_<std::allocator<void> >}’ has no member named ‘position’
     ROS_INFO("position (x,y,z) = (%f : %f : %f)  \n", pos.position.x, pos->position.
edit retag flag offensive close merge delete

Comments

Can you please share your ar_track_alvar_msgs/AlvarMarkers.h msg file.

Ranjit Kathiriya gravatar image Ranjit Kathiriya  ( 2021-09-20 09:27:25 -0500 )edit

1 Answer

Sort by » oldest newest most voted
0

answered 2021-09-20 09:33:09 -0500

Ranjit Kathiriya gravatar image

Hello @yu_ki,

Instead of pos->position.x can you please try only pos->x. I think it will your msg header will be in this form.

for example position.msg

float64 x
float64 y
float64 z
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2021-09-20 07:23:26 -0500

Seen: 141 times

Last updated: Sep 20 '21