-
Notifications
You must be signed in to change notification settings - Fork 2
[EN] PID
The purpose with creating a PID in our project is for the robot to be able to follow a black line to reach an objective. To do that, he will get the color sensor data to give movements orders so that the robot can follow the line.
The only goal of PID node is to do the calculations for the trajectory correction, to do that he communicate with multiple nodes as you can se below:
As you can see, the node compute without stopping, but it is the controller who decide if the PID commands are use for movement.
The PID is composed of multiple parameters configured at the creation of the node:
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.9,2.0,0,60)
Permit to subscribe to the sensor topic ('sensor'), and publish movements orders to the controller with the topic ('PID_cmd_vel'). Initialisation of 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*2.55))-40
white=self.valeurgb.c
angle=self.pidangle.compute(0.1,error)
msg = Twist() #RGB sensor
msg.linear.x=2#self.order.straight;
msg.angular.z=angle
self.publisher_.publish(msg)
self.i += 1
Gets the values of the sensor every half seconds with the function get_RGBvalue().
Computes and sends the movements parameters every half seconds with pid_send().
- [FR]
- [EN]