-
Notifications
You must be signed in to change notification settings - Fork 2
[EN] PID
The purpose of creating a PID in our project is for the robot to be able to follow a black line to an objective. To do that, it will use color sensor data to give movements orders.
The sole goal of the PID node is to run the computations for trajectory correction. For this, the node is linked with multiple other nodes as you can see below:
As you can see, the node computes without ever stopping, but it is the controller node that decides if the PID commands are used for movement.
The PID is composed of multiple parameters configured at node creation:
class PID_controller:
def __init__(self,kp,ki,kd,isat):
self.kp = kp
self.ki = ki
self.kd = kd
self.isat = isat
self.old_error = 0
self.sum_integral = 0
- kp for the proportional component
- ki for the integral component
- kd for the derived component
- isat the maximum value for the error
def __init__(self):
super().__init__('turtlebot_pid')
self.publisher_ = self.create_publisher(Twist, 'PID_cmd_vel', 10)
self.subscription = self.create_subscription(rgbtype,'RGB_Value',self.get_RGBvalue,10)
self.subscription
timer_period = 0.5 # seconds
self.timer = self.create_timer(timer_period, self.pid_send)
self.i = 0
self.valeurgb= rgbtype()#specific topicof the RGB sensor
self.pidangle=PID_controller(0.2,0,0,60)
Subscribes to the sensor topic ('sensor'), and publish movements orders to the controller with the topic ('PID_cmd_vel'). Initialize the PID with the given settings.
def get_RGBvalue(self, msgsub):
self.valeurgb=msgsub
def pid_send(self):
error=((self.valeurgb.r+self.valeurgb.g+self.valeurgb.b)/3)-26
white=self.valeurgb.c
angle=self.pidangle.compute(0.1,error)
msg = Twist() #RGB sensor
msg.linear.x=0.5#self.order.straight;
msg.angular.z=angle
self.publisher_.publish(msg)
self.i += 1
We had to limit the speed to 0.5 because with a frequency of 0.5ms for the PID, we must have a slow a turtlebot. It fetches the sensor values every half second through the function get_RGBvalue().
Computes and sends the movements parameters every half seconds with pid_send().
- [FR]
- [EN]