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

Jojo's profile - activity

2021-08-09 11:20:32 -0500 received badge  Famous Question (source)
2019-11-13 06:12:50 -0500 received badge  Notable Question (source)
2019-11-13 06:12:50 -0500 received badge  Famous Question (source)
2019-06-26 07:00:48 -0500 marked best answer List index out of range

Hi, I am new to python and ros and i am trying to get to different goals defined by me but I get the error: list imdex out of range and i dont know why because as far as i know, the list index is not out of range. my code is below and also the error:

#!/usr/bin/env python
import rospy
import math
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
target = 90
kp=0.5

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 = ModelStates()
        self.current_distance = Int32()
        self.the_goals = PointArray()
        self.rate = rospy.Rate(10)

    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):

        return sqrt(pow((goal_pose.x - self.pose.pose[1].position.x), 2) +
                    pow((goal_pose.y - self.pose.pose[1].position.y), 2))

    def linear_vel(self,goal_pose, constant=1):

        #return constant * (self.euclidean_distance(goal_pose))
        return abs(1.0)

    def steering_angle(self, goal_pose):

        return atan2(goal_pose.y - self.pose.pose[1].position.y,goal_pose.x - self.pose.pose[1].position.x)

    def angular_vel(self,goal_pose, constant=2):

        global theta
        self.pose.pose[1].orientation = self.pose.pose[1].orientation
        (roll, pitch, theta) = euler_from_quaternion([self.pose.pose[1].orientation.x, self.pose.pose[1].orientation.y, self.pose.pose[1].orientation.z, self.pose.pose[1].orientation.w])
        #print ('theta at update pose is', + theta)
        #print ('theta is', + theta)
        return constant * (self.steering_angle(goal_pose) - theta)
        #return 0.3

    def get_goals(self,the_goals):
        global x
        global y
        x = the_goals.goals[0].x
        y = the_goals.goals[0].y
        #print x
        #print y

    def distance_tracker(self,distance):
        self.current_distance ...
(more)
2019-06-26 07:00:48 -0500 received badge  Scholar (source)
2019-06-20 09:03:55 -0500 commented answer List index out of range

Solved it .Thanks

2019-06-20 09:03:35 -0500 received badge  Supporter (source)
2019-06-20 09:03:28 -0500 commented question List index out of range

Thank you for edting my question and the tips on posting a code here. I have solved the problem with the answer given be

2019-06-18 03:46:11 -0500 received badge  Popular Question (source)
2019-06-18 03:20:03 -0500 received badge  Notable Question (source)
2019-06-17 17:21:11 -0500 marked best answer 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 ...
(more)
2019-06-17 14:41:44 -0500 edited question List index out of range

List index out of range Hi, I am new to python and ros and i am trying to get to different goals defined by me but I get

2019-06-17 14:39:50 -0500 asked a question List index out of range

List index out of range Hi, I am new to python and ros and i am trying to get to different goals defined by me but I get

2019-06-11 06:48:14 -0500 received badge  Popular Question (source)
2019-06-10 04:04:52 -0500 edited question Directly written goal value does not work, only user inputted goal works

Directly written goal value does not work, only user inputted goal works Hi, i am quite new to ros and trying out how to

2019-06-10 04:04:52 -0500 received badge  Editor (source)
2019-06-10 04:03:15 -0500 commented answer Directly written goal value does not work, only user inputted goal works

Thank you for your reply. I have updated my question. Yes that line is not the same because i am subscribing to a diff

2019-06-10 03:54:05 -0500 edited question Directly written goal value does not work, only user inputted goal works

Directly written goal value does not work, only user inputted goal works Hi, i am quite new to ros and trying out how to

2019-06-09 06:15:11 -0500 asked a question Directly written goal value does not work, only user inputted goal works

Directly written goal value does not work, only user inputted goal works Hi, i am quite new to ros and trying out how to