koolguy
Active Member
Hi,
I am working on Line follower robot with two sensor connected with variable 20K making voltage divider. directly to ADC input ...it is working fine..
i want to add PID for gaining more speed and control...
so, this link tutorial for one sensors..
how to set offset and other const parameters?
I am working on Line follower robot with two sensor connected with variable 20K making voltage divider. directly to ADC input ...it is working fine..
i want to add PID for gaining more speed and control...
so, this link tutorial for one sensors..
how to set offset and other const parameters?
Code:
Kp = 10 ! Initialize our three variables
offset = 45
Tp = 50
Loop forever
LightValue = read light sensor ! what is the current light reading?
error = LightValue - offset ! calculate the error by subtracting the offset
Turn = Kp * error ! the "P term", how much we want to change the motors' power
powerA = Tp + Turn ! the power level for the A motor
powerC = Tp - Turn ! the power level for the C motor
MOTOR A direction=forward power=powerA ! issue the command with the new power level in a MOTOR block
MOTOR C direction=forward power=powerC ! same for the other motor but using the other power level
end loop forever ! done with this loop, go back to the beginning and do it again