ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

Directly written goal value does not work, only user inputted goal works

asked 2019-06-09 05:31:20 -0500

Jojo gravatar image

updated 2019-06-17 17:22:02 -0500

jayess gravatar image

Hi, i am quite new to ros and trying out how to get to s specific goal. I am using Ros Kinetic, turtlebot3 package and writing the code in python. I followed the example here. It works if i input the goals from the keyboard but if i directly define the goals as a value, i get this error:

Traceback (most recent call last):
  File "/home/amr/catkin_ws/src/oe-161016_tier4/oe_161016_prj/src/turtle_sim.py", line 139, in <module>
    object.move2goal()
  File "/home/amr/catkin_ws/src/oe-161016_tier4/oe_161016_prj/src/turtle_sim.py", line 102, in move2goal
    while self.euclidean_distance(goal_pose) >= distance_tolerance:
  File "/home/amr/catkin_ws/src/oe-161016_tier4/oe_161016_prj/src/turtle_sim.py", line 55, in euclidean_distance
    return sqrt(pow((goal_pose.position.x - self.pose.pose[1].position.x), 2) +
AttributeError: 'Pose' object has no attribute 'pose'

I am assuming that asking the user for an input and just giving the direct goal value should be the same thing. I apparently cannot attch files because i need up to 5 points so below is my full code. Its not exactly the same as in the example because i am subscribing to the gazebo/modelstates topic and it has a different structure.

#!/usr/bin/env python
import rospy
from std_msgs.msg import String
from std_msgs.msg import Int32
from geometry_msgs.msg import Twist          # Import the Twist message from the geometry_msgs
from sensor_msgs.msg import LaserScan       # Import the LaserScan message from the sensor
from gazebo_msgs.msg import ModelStates  #import ModelState message from gazebo_msgs
from geometry_msgs.msg import Pose,Point         # Import the Pose message from the geometry_msgs
from tf.transformations import euler_from_quaternion
from goal_publisher.msg import PointArray
from math import pow, atan2, sqrt


PI= 3.1415926535897
repeat = 0
theta = 0.0
x = 0.0
y = 0.0
msg = 0.0
index_same=0.0

class MovetoGoals:
    def __init__(self):

        # Creates a node with name 'final_projekt_node' and make sure it is a
        # unique node (using anonymous=True).
        rospy.init_node('final_projekt_node', anonymous=True)

        # Publisher which will publish to the topic 'Twist'.
        self.pub = rospy.Publisher('cmd_vel',Twist, queue_size=10)

        # A subscriber to the topic 'Modelstate'. self.update_pose is called
        # when a message of type Pose is received.
        self.pose_sub = rospy.Subscriber('/gazebo/model_states',ModelStates, self.update_pose)
        self.goals_sub = rospy.Subscriber('/goals',PointArray,self.get_goals)
        self.dist_sub = rospy.Subscriber('/distance',Int32,self.distance_tracker)
        self.laser_sub = rospy.Subscriber('scan', LaserScan,self.detect_obstacle)# subscriber to subscribe to laser messages
        self.pose = Pose()
        self.current_distance = Int32()
        self.the_goals = PointArray()
        self.rate = rospy.Rate(2)

    def update_pose(self, data):
        """Callback function which is called when a new message of type Pose is
        received by the subscriber."""
        #print('in update_pose function')

        self.pose = data
        self.pose.pose[1].position.x = round(self.pose.pose[1].position.x, 4)
        self.pose.pose[1].position.y = round(self.pose.pose[1].position.y, 4)

        #print ('robots x position' self.pose.pose[1].position.x)

    def euclidean_distance(self,goal_pose):
        """Euclidean distance between current pose and the goal."""
        return sqrt(pow((goal_pose.position.x - self.pose.pose[1].position ...
(more)
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2019-06-09 13:10:02 -0500

billy gravatar image

updated 2019-06-09 13:10:34 -0500

sqrt(pow((goal_pose.position.x - self.pose.pose[1].position.x), 2) + AttributeError: 'Pose' object has no attribute 'pose'

That is the error. pose has position as attribute, but not pose. Where did you get this line from? It is not in the example. The corresponding lie from example is

return sqrt(pow((goal_pose.x - self.pose.x), 2) +
                    pow((goal_pose.y - self.pose.y), 2))

where they do not make reference to a second level of pose.

Looking at definition of pose messages on http://docs.ros.org/api/geometry_msgs... you'll see only position and orientation in a pose.

A representation of pose in free space, composed of position and orientation. 
Point position
Quaternion orientation
edit flag offensive delete link more

Comments

Thank you for your reply. I have updated my question.

Yes that line is not the same because i am subscribing to a different topic. And this topic(gazebo/modelstates) has a different structure. I unfortunately cannot attach a snapshot of what is being published to this topic but it has at least two positions and orientations, depending on the robot and other objects in the model

Jojo gravatar image Jojo  ( 2019-06-10 04:03:15 -0500 )edit

Question Tools

2 followers

Stats

Asked: 2019-06-09 05:27:29 -0500

Seen: 343 times

Last updated: Jun 17 '19