Ask Your Question

Turtlebot driving to specifiy point with Twist

asked 2018-01-04 12:20:58 -0500

Baumboon gravatar image

updated 2018-01-05 06:23:00 -0500

Hello guys,

first of all i must excuse i messed up by posting this question wrong and it got to confusing so i delete it and post it correct again. A special excuse to jayess i messed up with copying my code correct he is fully right that at this point:

 if abs(angle_to_goal - theta) > 0.1:

        speed.linear.x = 0.0
        speed.angular.z = 0.1

Here needs to be bigger then 0.1 before here stands less...

So my question is how i can drive with my Turtlebot to a specific point or an array of points i give the robot. I am using Turtlebot package for ros kinetic and i run this in gazebo 7.0.

i tried this code:

#! /usr/bin/env python

import rospy
from nav_msgs.msg import Odometry
from tf.transformations import euler_from_quaternion
from geometry_msgs.msg import Point, Twist
from math import atan2
x = 0.0
y= 0.0
theta = 0.0
def newOdom(msg):
    global x
    global y
    global theta

    x = msg.pose.pose.position.x
    y = msg.pose.pose.position.y

    rot_q = msg.pose.pose.orientation
    (roll,pitch,theta) = euler_from_quaternion ([rot_q.x,rot_q.y,rot_q.z,rot_q.w])
sub = rospy.Subscriber("/odom",Odometry,newOdom)
pub = rospy.Publisher('cmd_vel_mux/input/navi', Twist, queue_size=1)
speed = Twist()
r = rospy.Rate(4)
goal = Point()
goal.x = 2
goal.y = 2
while not rospy.is_shutdown():
    inc_x = goal.x - x
    inc_y = goal.y - y

    angle_to_goal = atan2(inc_y,inc_x)

    if abs(angle_to_goal - theta) > 0.1:

        speed.linear.x = 0.0
        speed.angular.z = 0.1
        speed.linear.x = 0.5
        speed.angular.z = 0.0


So the program works for a few rotations but the turtlebot don´t reach the correct angle he drives most time before he reachs the correct angle and lands left of the target point.

I used this tutorial :

tutorial to drive to specific point with twist

He used same controller and the robot drives perfectly as he should... Only difference i use a turtlebot for it

edit retag flag offensive close merge delete


In the future, please don't delete a question because "it got messy"

jayess gravatar image jayess  ( 2018-01-04 12:23:27 -0500 )edit

You can always edit the question to clean it up.

tfoote gravatar image tfoote  ( 2018-01-04 12:24:23 -0500 )edit

Okay i am sorry... In the future I will do . So I hope now the problem is better to understand ?

Baumboon gravatar image Baumboon  ( 2018-01-04 12:28:27 -0500 )edit

2 Answers

Sort by » oldest newest most voted

answered 2018-01-08 11:05:32 -0500

Baumboon gravatar image

It seems to be an error through odometry... the odometry wasn´t correct i resetet world and robot position and now it works...

edit flag offensive delete link more

answered 2018-01-04 12:27:38 -0500

jayess gravatar image

Your script is going to behave like this. It's just a simple proportional controller. If you want to do something more advanced you should look at the nav stack tutorials.

edit flag offensive delete link more


Okay, but there is a huge derivation from correct angle around 25 degree.

I added some information in main question

Baumboon gravatar image Baumboon  ( 2018-01-04 12:33:59 -0500 )edit

What is the goal angle? I don't see one in your question. Just a goal Point.

jayess gravatar image jayess  ( 2018-01-04 20:10:47 -0500 )edit

I calculate the angle to goal with tan :

angle_to_goal = atan2(inc_y,inc_x)
Baumboon gravatar image Baumboon  ( 2018-01-05 04:39:10 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2018-01-04 12:20:58 -0500

Seen: 1,346 times

Last updated: Jan 08 '18