Ask Your Question
0

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():
    rospy.init_node("listener",anonymous=True)
    rospy.Subscriber("/tag_detections",AprilTagDetectionArray,tagDetect)    
    rospy.spin()

if __name__ == '__main__':
    listener()

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/topics.py", line 750, in _invoke_callback
    cb(msg)
  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 message info

[apriltag_ros/AprilTagDetectionArray]:
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
0

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

Hi,

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

2 followers

Stats

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

Seen: 20 times

Last updated: Jun 29