Hi i am doing an apriltag following project. I am currently trying to test how to get distance between the tag and the camera. I have subscribed to the AprilTagDetectionArray msg.

My main question is how do i get the distance between the tag and my camera. Should i use the position or the orientation values? I want the robot to detect and then approach the tag.

I tried getting the values from both position and orientation but i am getting the error below.

#!/usr/bin/env python

import rospy
from apriltag_ros.msg import AprilTagDetectionArray

w = 0.0

def tagDetect(msg):
    global w
    w = msg.pose.pose.orientation.w  
    w = abs(w)
    rospy.loginfo("w = %s",w)

def listener():

if __name__ == '__main__':

but i am getting this error. how do i resolve this??

 [ERROR] [1593270010.489688]: bad callback: <function tagDetect at 0x7f53e4b62a28>
Traceback (most recent call last):
  File "/opt/ros/kinetic/lib/python2.7/dist-packages/rospy/topics.py", line 750, in _invoke_callback
  File "/home/zeus/catkin_ws/src/autonav/src/test.py", line 10, in tagDetect
    w = msg.pose.pose.position[0].x
AttributeError: 'AprilTagDetectionArray' object has no attribute 'pose'

Here is the message just in case.

std_msgs/Header header
  uint32 seq
  time stamp
  string frame_id
apriltag_ros/AprilTagDetection[] detections
  int32[] id
  float64[] size
  geometry_msgs/PoseWithCovarianceStamped pose
    std_msgs/Header header
      uint32 seq
      time stamp
      string frame_id
    geometry_msgs/PoseWithCovariance pose
      geometry_msgs/Pose pose
        geometry_msgs/Point position
          float64 x
          float64 y
          float64 z
        geometry_msgs/Quaternion orientation
          float64 x
          float64 y
          float64 z
          float64 w
      float64[36] covariance
  • $\begingroup$ how do i resolve the error? $\endgroup$ – sudhanv apte Jun 28 at 6:06

I can't comment, so writing this as an answer. Did you try calling msg.detections.pose.pose.orientation.w?

From your message definition hierarchy, is seems pose is under object detections.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.