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

How do we align the robot's orientation each and every instant in delivering a PID controlled motion to a desired location x, y ?

asked 2021-03-27 02:43:32 -0600

Vignesh_93 gravatar image

updated 2021-03-27 07:36:57 -0600

ROS Developers!

Although its a basic conceptual stuck up, I am trying to implement a PID controller for the position control of the turtlebot w.r.t odom frame. From various sources I was able to come to some conclusions but still not a fully understandable concept. My control variable is again the velocity (both linear and angular). If anybody can direct me to some reference material which gives a glimpse of the control of the angular orientation of the robot to reach the desired location x, y or provide some basic conceptual guidance then it would be very helpful for me. or is there any built in packages which can be directly used please do direct me to the right forum.

thanks

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2021-03-31 06:44:06 -0600

Vignesh_93 gravatar image

CLosing the question as its solution is already available online. Below is snipped of my version of the function of a proportional controller, since I had defined inside a class I will be having self, self can be removed if defined outside the class:

while (not self.destination):
            robotPosition, currentOrientation = self.getOdom()
            errorX = x - robotPosition.x
            errorY = y - robotPosition.y
            self.distance = math.sqrt(errorX**2 + errorY**2)
            print(f"The distance error is {self.distance}")
            self.requiredPathAngle = math.atan2(errorY, errorX)
            self.errorOrientation = self.requiredPathAngle - currentOrientation 
            if abs(self.requiredPathAngle - currentOrientation) > 0.1 and self.distance > 0.2:
                if self.requiredPathAngle > currentOrientation:
                    self.speed.angular.z = self.kp*abs(self.errorOrientation)*self.CONSTANT_ANGULAR_SPEED
                else:
                    self.speed.angular.z = -self.kp*abs(self.errorOrientation)*self.CONSTANT_ANGULAR_SPEED
                self.speed.linear.x = 0.0
            else:
                self.speed.angular.z = 0.0
                if self.distance > 0.2:
                    self.speed.linear.x = self.kp*self.distance*self.CONSTANT_LINEAR_SPEED
                else:
                    self.speed.linear.x = 0.0
                    self.destination = True
                    print(f"Destination is reached and the final position value is {robotPosition.x}, {robotPosition.y}")
            self.velocityPublisher.publish(self.speed)
            rospy.sleep(rate)
edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2021-03-27 02:43:32 -0600

Seen: 507 times

Last updated: Mar 31 '21