Directly written goal value does not work, only user inputted goal works
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 ...