Robotics StackExchange | Archived questions

Trouble subscribing to pose information of ar_pose_marker

I am writing a node to have a hectorquadrotor follow a moving AR tag. For this I am subscribing to the pose information in the topic /arposemarker 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 /arposemarker topic I keep getting errors. A copy of my python node is below: the line xar = 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 artrackalvarmsgs.msg import AlvarMarkers from geometrymsgs.msg import Point, Twist

xar = 0.0 yar = 0.0 z_ar = 0.0

def newOdom (msg): global xar global yar 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.initnode("speedcontroller")

sub = rospy.Subscriber("/arposemarker", AlvarMarkers, newOdom) pub = rospy.Publisher("/cmdvel", Twist, queuesize=1)

speed = Twist()

r = rospy.Rate(4)

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

while not rospy.isshutdown(): incx = goal.x - xar incy = goal.y - yar incz = 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()

Asked by mjc1021 on 2018-12-13 15:49:35 UTC

Comments

Answers