Search code examples
pythonnumpyrospy

rospy rosaria AttributeError: 'list' object has no attribute 'x'


I am trying to send commands to a Pioneer P3-AT (EDIT: 3-AT or P3-AT, both names are used) using RosAria. I know that RosAria works since when I am in the terminal I can move the robot using the following command:

rostopic pub /RosAria/cmd_vel geometry_msgs/Twist '{linear: {x: 0.9, y: 0.0}, angular: {x: 0.0, y: 0.0, z: 0.0}}'

I am now trying move the robot using a python script with rospy. This is the part where I publish the velocity command:

import rospy
from geometry_msgs.msg import Twist

topic = rospy.Publisher('/RosAria/cmd_vel', Twist, queue_size=10)
linear = [ 0, 0, 0 ]
angular = [ 0, 0, 0 ]
rospy.sleep(1) # waiting for subscribers
test = topic.publish(linear, angular)

This is the error message (most important parts):

Traceback (most recent call last):
File "robotControl.py", line 32, in startServer
  test = topic.publish(linear, angular)
packages/geometry_msgs/msg/_Twist.py", line 71, in serialize
buff.write(_get_struct_6d().pack(_x.linear.x, _x.linear.y, _x.linear.z, _x.angular.x, _x.angular.y, _x.angular.z))

AttributeError: 'list' object has no attribute 'x'

The same error appears when I'm using sets or numpy arrays. If I try to publish values in another format (not two lists) it will give an error that the format is not expected. Also adding or removing entry from either list does not resolve this error.

So my question now is why it says that I don't have an x value? Do I need to use vectors (since they have designated x, y and z values)?


Solution

  • SOLVED IT: Previously I used two lists but I looked it up and geometry_msgs/Twist needs two geometry_msgs/Vector3 variables. I added this import:

    from geometry_msgs.msg import Vector3
    

    and changed the linear and angular declarations to:

    linear = Vector3(0.8, 0, 0)
    angular = Vector3(0, 0, 0)
    now it works like a charm!