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

How to move a turtle bot with specifc velocity

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
else:
speed.linear.x = 1.5
speed.angular.z = 0.0
pub.publish(speed)
r.sleep()


Thank you

edit retag close merge delete

Sort by ยป oldest newest most voted

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))
scale=0.3
scaleVel=0.3
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
else:
speed.linear.x = min(1.5, distance * scaleVel)
speed.angular.z = 0.0


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

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:


After while loop:

speed.angular.z =0.0
pub.publish(speed)

( 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.

( 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: [https://answers.ros.org/question/3376...]

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