Trouble subscribing to pose information of ar_pose_marker

asked 2018-12-13 14:49:35 -0500

mjc1021 gravatar image

I am writing a node to have a hector_quadrotor follow a moving AR tag. For this I am subscribing to the pose information in the topic /ar_pose_marker and setting a goal for the quadrotor to always be at position (ar tag X position minus 1, ar tag Y position, ar tag Z position plus 1). The problem I'm having is when I try to subscribe to the /ar_pose_marker topic I keep getting errors. A copy of my python node is below: the line x_ar = msg.pose.pose.position.x produces the error "AttributeError: 'AlvarMarkers' object has no attribute 'pose' ". I also tried x_ar = msg.markers[0].pose.pose.position.x which produced the error "IndexError: list index out of range".

#!/usr/bin/env python

import rospy from ar_track_alvar_msgs.msg import AlvarMarkers from geometry_msgs.msg import Point, Twist

x_ar = 0.0 y_ar = 0.0 z_ar = 0.0

def newOdom (msg): global x_ar global y_ar global z_ar

x_ar = msg.pose.pose.position.x
y_ar = msg.pose.pose.position.y
z_ar = msg.pose.pose.position.z

rospy.init_node("speed_controller")

sub = rospy.Subscriber("/ar_pose_marker", AlvarMarkers, newOdom) pub = rospy.Publisher("/cmd_vel", Twist, queue_size=1)

speed = Twist()

r = rospy.Rate(4)

goal = Point () goal.x = 1.0 goal.y = 0 goal.z = -1.0

while not rospy.is_shutdown(): inc_x = goal.x - x_ar inc_y = goal.y - y_ar inc_z = goal.z - z_ar

if inc_x > 0.1:
    speed.linear.x = -0.1
else:
    speed.linear.x = 0.0

if inc_y > 0.1:
    speed.linear.y = -0.1
else:
    speed.linear.y = 0.0

if inc_z < -0.1:
    speed.linear.z = 0.1
else:
    speed.linear.z = 0.0


pub.publish(speed)
r.sleep()
edit retag flag offensive close merge delete