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

How to move a turtle bot with specifc velocity

asked 2019-10-30 20:33:09 -0600

Satish gravatar image

updated 2019-10-30 22:23:58 -0600

I am using gazibo simulator to simulate multiple turtlebots, I have three robots, all the robots have to move to one goal point but with different velocities. Please suggest me how to set a velocity and move the robot to the point. I am using Twist() function to set the velocity Twist().linear.x = 0.5 but its not accurate.

And more over if I increase the velocity greater than 1, the robot is not going to the target. Below is my code, please let me know what is the problem in my code:

speed = Twist()
while abs(goal1.x-x) > 0.15 and abs(goal1.y-y) > 0.2:

if abs(angle_to_goal-theta) > 0.15:
    speed.linear.x = 0.0
    speed.angular.z = 0.5
    speed.linear.x = 1.5
    speed.angular.z = 0.0

Thank you

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2019-10-31 02:58:07 -0600

duck-development gravatar image

updated 2019-11-04 01:42:58 -0600

So as I Understand you code you first aim to target pos and then drive to it.

distance=sqrt(pow(goal1.x-x,2) + pow(goal1.y-y, 2)) 
if abs(angle_to_goal-theta) > 0.15:
  dir=(angle_to_goal-theta) /abs( angle_to_goal-theta) 
  angSpeed= min(0.5, abs( angle_to_goal-theta) / scale) 
  speed.linear.x = 0.0
  speed.angular.z = dir*angSpeed
  speed.linear.x = min(1.5, distance * scaleVel) 
  speed.angular.z = 0.0

Vou can tune the scale values for daster drive and rotate.

edit flag offensive delete link more


@duck-development, Thanks a lot for your response. when I use your logic the robot is not stopping at all. Please look below the code of mine. I can't post the complete code due to size constraints

   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])
    pub = rospy.Publisher("/robot2/cmd_vel", Twist, queue_size = 1)
    speed = Twist()
    inc_x = goal.x-x
    inc_y = goal.y-y
    angle_to_goal = atan2(inc_y, inc_x)
    distance=sqrt(pow(goal.x-x,2) + pow(goal.y-y, 2))
    while distance >= 0.5:
         Your Code

After while loop:

speed.angular.z =0.0
Satish gravatar image Satish  ( 2019-10-31 14:27:42 -0600 )edit

did you try to change the scale velues, make them smaller.

start the vehicle to drive to the target or does it only turns. because here we have a P-Controller to get it better you need an PID-Controller. you have to change the while to a if and insert a else with speed = 0 afer. because insde you whilee x y theta do not get updated. you clond provide a peste bin with you full code.

duck-development gravatar image duck-development  ( 2019-11-04 01:50:48 -0600 )edit

@duck-development, I am sorry, I did not fully understand your answer, I have created a new question with better explanation and modified full code. If you can please review and let me know what you think. Here is the link to the question: []

Satish gravatar image Satish  ( 2019-11-14 18:40:35 -0600 )edit

Question Tools


Asked: 2019-10-30 20:30:28 -0600

Seen: 987 times

Last updated: Nov 04 '19