Ask Your Question

Get topic values with script

asked 2020-06-27 10:13:14 -0500

sudhanv gravatar image

updated 2020-06-28 01:41:38 -0500

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.

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

Here is message info

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
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2020-06-29 14:40:35 -0500


It seems that your are not extracting the information correctly from the msg. As the error message you're getting says, AprilTagDetectionArray does not have a pose attribute.

You can see in its message definition that it actually has an array of AprilTagDetection objects, each one containing a PoseWithCovarianceStamped. So you need to adjust your code to read that.

Hope this helps!

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools



Asked: 2020-06-27 10:13:14 -0500

Seen: 20 times

Last updated: Jun 29