Apriltag pkg - Node crash when trying to get position
Hello,
I'm trying to use a drone (iris model) with a camera in Gazebo to detect apriltag (AP). I cloned a usb-camera pkg, and the AP pkg. All works fine with the webcam. Now, I'm trying to use the position from the topic : /tag_detections_pose
to get the position x,y,z. I'm coding in C++ with ROS Kinetic and use Gazebo 7.
I'm using the code provided (as base) by PX4 : https://dev.px4.io/en/ros/mavros_offboard.html
So I included the type of message:
#include <geometry_msgs/PoseArray.h> // Tag detection
Then, I create a global variable and a call back function:
// Callback which will save the estimated local position of the Apriltag
geometry_msgs::PoseArray APtag_est_pos; // Tag detection
void APtag_est_pos_cb(const geometry_msgs::PoseArray::ConstPtr& AP_est_pos){
APtag_est_pos = *AP_est_pos;
ROS_INFO("CALLBACK AP");
// ROS_INFO("APtag est pos=[%f, %f, %f]", AP_est_pos->poses[2].position.x,
// AP_est_pos->poses[2].position.y,
// AP_est_pos->poses[2].position.z);
}
And finally I subscribe to the topic:
// The node subscribe to Topic "/tag_detections_pose", 10 msgs in buffer before deleting
ros::Subscriber APtag_est_pos_sub = nh.subscribe<geometry_msgs::PoseArray>
("tag_detections_pose", 10, APtag_est_pos_cb); // with or without the / ????
Like this it works, but if I try to uncomment the part that should give the position with ROS_INFO, I get this error :
[offb_node-5] process has died [pid 8044, exit code -11, cmd /home/mpperret/project_ws/devel/lib/waypoint_navigation/offb_node __name:=offb_node __log:=/home/mpperret/.ros/log/dbcc83d4-e8b8-11e8-acbf-54bf646662d7/offb_node-5.log].
Is someone know why ? Maybe I'm doing something wrong with the variable to get position x,y,z ?
Thanks in advance
First thing to check: are there always 3 poses present in
poses
?You asked that because of the poses[2] (doc here)? I don't really know bacause I use the same writing for the topic /gazebo/ModelStates (here) and it works.
And if you compared both they had the same structure. For me I would use pose(s)[0] to get into position. If you have an explication, I would appreciate.
Yes, that's why I ask.
re: using it somewhere else: that is great, but is not how this should be approached. If
AP_est_post->poses
does not contain at least 3 elements, you are indexing into (potentially) uninitialised memory, which typically leads to crashes.Static structure of the messages is not really relevant, as I hope you (now) understand.
So how could I save this information? What you said is true because when there is no AP, the topic message is "[-]" , and when there is one or more AP, the message is bigger. It's like a dynamical array with a defined structure. I don't know how to check if there is something or not.
That would be more of a basic C++ question, but
poses
is a std::vector, so you could check with methods such assize()
.I tried your suggestion and I get a value of 72. I'm pretty sure that is the memory size allocation for the variable. I'll do research on dynamical array or ask in a C++ forum. Thanks for your help. I will let you know if I found a solution.