Turtlebot3 in gazebo simulation controlling with python node (using only odometry)

I am having a problem with the movement of the turtlebot3 (burger), I am using the proportional controller to move the robot from one point to another.
The problem is when I put two robots in the simulation facing each other, the controller works good with one robot but for the other robot, it produces zigzag and sometimes spiral motions.
There is something wrong with angles, I can’t figure out what. Can you please give a example where two robots in gazebo moving towards each other using the same controller?

Thank you,

Hi @jamiliffat163,
What course are you in? I’m not sure I remember the scenario. That being said, when using multiple robots, it is important that they use seperate namespaces, so their odometry and velocity commands don’t interfere with one another. I suspect that the issue is related to that

Hi @simon.steinmann91 , this is ont the scenario from course, I have been making my own proportional controller and this is the issue i am facing. I am using different name_space. when the desired angle is between 1.5 to 3.141 or from 3.141 to -1.5 the robot is not reacting normaly.

That sounds like an issue stemming from the use of Euler angles, as the Value jumps at the min and max value. Using quaternion angle representation would fix that issue.

Is there any way that we can fix the euler angles? because yes, I am using Euler angles.

Imean without the involvement of Quaternion?

You can the calculations in a way that takes the jump into account. That would involve several case checks, but for angles just around the jump point, things get difficult. That’s where quaternion is a superior orientation representation, as it does not suffer from that issue. Take a look at this:

This is how you can use quaternion to calculate the difference between two orientations:

from nav_msgs.msg import Odometry
from tf import transformations 

q = odom_robot1.pose.pose.orientation
q1 = [q.x, q.y, q.z, q.w]

q = odom_robot2.pose.pose.orientation
q2 = [q.x, q.y, q.z, -q.w] #w negative for inverse quaternion
quat_error = transformations.quaternion_multiply(q1, q2)   
euler_error = transformations.euler_from_quaternion(quat_error)

With this euler_error, which is the difference in angles, you can then control your twist message

1 Like

Thank you so much :slight_smile:
I will give it a try, Thanks again.

def set_heading (self,angle_to_goal):

    self.desired_heading = angle_to_goal
    
    #Here I am converting the desired_heading into quaternion because I have calculate this using atan2

    (self.quaternion_x, self.quaternion_y, self.quaternion_z, self.quaternion_w) = quaternion_from_euler(self.roll, self.pitch, self.desired_heading)

    self.orientation_list_desired = [self.quaternion_x, self.quaternion_y, self.quaternion_z, -self.quaternion_w]

#self.orientation_list contains the quaternion information about the robot and orientation_list_desired contains the desired orientation(which I calculated using the current roll, pitch of the robot and calculated desired heading…because, I assume that roll and pitch is not important for 2D environment )

    self.quat_error = transformations.quaternion_multiply(self.orientation_list, self.orientation_list_desired)   

    #Here I am converting the quaternion error into euler so I can control my twist message, I am using a proportional controller

(self.roll_error, self.pitch_error, self.yaw_error) = transformations.euler_from_quaternion(self.quat_error)

    print (self.yaw_error)

     self.speed.angular.z = self.k_angular *(self.yaw_error)

This didn’t work for me , maybe I am doing something wrong but couldn’t figure it out.The difference between the current and desired angle keep on increasing. and after some time the robot start spinning and then after few seconds it start moving in the opposite direction of the goal with zigzag motion.

Did you try reversing the rotation? Making self.k_angular negative

1 Like

Thank you :slight_smile: Now its working, I didn’t make the self.k_angular negative before. With negative its working good.
Thank you!

1 Like