PID for following a wall

asked 2021-09-03 23:56:27 -0500

sisko gravatar image

updated 2021-09-04 00:28:06 -0500

I need help understanding how to correctly implement a PID control. In the code below, I am attempting to implement a controller which will course correct 1.5 meters from a wall and drive parrallel to the wall. The function is supposed to compensate and correct when it is over or under the specified distance to the wall.

def follow_kerb(self) :
    move = Twist()

    avr = self.getAverage( self.clean_set(self.regions['1'])  + self.clean_set(self.regions['2']) )
    control = 0.5 * (1.5 - avr)

    move.linear.x = 0.2
    if control > 0 :
        move.angular.z += 0.2
        rospy.logerr("Turning [+]: AVG==> %s, CNTRL: %s", avr, control)
    if control < 0 :
        move.angular.z -= 0.2
        rospy.logwarn("Turning [-]: AVG==> %s, CNTRL: %s", avr, control)
    return move

The value of 1.5 is my set-point and the gap I want maintained between my robot and thw wall. avr is the average of all the laser readings on the right side of the robot which give the distance to the wall.

However, the effect is not as planned. I attached a screen recording which can be viewed at https://drive.google.com/file/d/1ufVT....

Can someone please help me understand what I'm doing wrong and how to better understand PID implmentation ?

edit retag flag offensive close merge delete

Comments

"avr is the average of all the laser readings on the right side of the robot" but you have no way of knowing your angle in reference to the wall, correct? So the further you rotate to the wall the higher the distance of all aft-right scans, correct?

Humpelstilzchen gravatar image Humpelstilzchen  ( 2021-09-04 02:40:30 -0500 )edit