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

aruco_detect, can't access fiducial_id

asked 2021-09-24 07:21:35 -0600

Roshan gravatar image

Hello, I'm trying to acces the fiducial_id in aruco_detect, but I get this error message:

error: ‘fiducial_msgs::FiducialTransformArray_<std::allocator<void> >::_transforms_type’ {aka ‘class std::vector<fiducial_msgs::FiducialTransform_<std::allocator<void> >, std::allocator<fiducial_msgs::FiducialTransform_<std::allocator<void> > > >’} has no member named ‘fiducial_id’
   25 |     h.transforms.fiducial_id;

I'm not sure why it's saying this, because it should be there according to this:

>rosmsg info fiducial_msgs/FiducialTransformArray 
std_msgs/Header header
  uint32 seq
  time stamp
  string frame_id
int32 image_seq
fiducial_msgs/FiducialTransform[] transforms
  int32 fiducial_id
  geometry_msgs/Transform transform
    geometry_msgs/Vector3 translation
      float64 x
      float64 y
      float64 z
    geometry_msgs/Quaternion rotation
      float64 x
      float64 y
      float64 z
      float64 w
  float64 image_error
  float64 object_error
  float64 fiducial_area

This how where I'm trying to access it:

#include "ros/ros.h"
#include <iostream>
#include <fstream>
#include "fiducial_msgs/FiducialTransformArray.h"
using namespace std;


void counterCallback(const fiducial_msgs::FiducialTransformArray::ConstPtr msg){

    int update_time;
    ROS_INFO("Hello");

}

int main(int argc,char **argv){
    ros::init(argc,argv,"marker_detect");/*Initialiserer node med navn*/
    ros::NodeHandle n;

    ros::Subscriber sub = n.subscribe<fiducial_msgs::FiducialTransformArray>("fiducial_transforms",10,counterCallback);
    fiducial_msgs::FiducialTransformArray h;
    h.transforms.fiducial_id;

    ros::spin();
    return 0;
}
edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
1

answered 2021-09-24 07:29:36 -0600

gvdhoorn gravatar image

As the name implies, fiducial_msgs::FiducialTransformArray is an array (or list).

You cannot access the field of a single element without first indexing into the array.

h.transforms.fiducial_id does indeed not exist.

h.transforms[i].fiducial_id, where i ∈ ℕ, does exist. It would mean you're accessing the fiducial_id field of the i-th element in h.transforms.

For a related question (but with rospy), see #q359824.

edit flag offensive delete link more

Comments

Oh, thank you. That explains it!

Roshan gravatar image Roshan  ( 2021-09-24 07:38:57 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2021-09-24 07:21:35 -0600

Seen: 162 times

Last updated: Sep 24 '21