Get topic values with script
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