Controls 2
Controls 2
Controls 2
Experiment 2
Line follower
Group Number 10
Daksh Pakal, 210070023
Snehaa Reddy, 210070067
Shravani Kode, 210070082
October 3, 2023
1
1 Objective
Design and implement a PID controller for the Spark V robot to make it follow
a continuous black track, using the IR sensors provided on the robot for this
purpose. Additionally, to tune the parameters such that the track is traced
within 30s.
Spark V robot is based on ATMEGA16 microcontroller. It is programmed using
AVR Programmer tool in Embedded C. It allows movement in 8 possible ways
which can be adjusted by changing the value of the registers.
These 8 are FWD, REV, RIGHT, LEFT, SOFT RIGHT, SOFT LEFT, SOFT
RIGHT 2, SOFT LEFT 2.
We have only used LEFT and RIGHT for our algorithm. Additionally the Spark
V allows speed control using PWM. It has 3 IR sensors under its panel, each of
which give reading from 0-255 based on the reflectivity of the surface it is held
against.
2 Control Algorithm
2.1 Aurdino Code
int main(void)
{
init_devices();
lcd_set_4bit();
lcd_init();
int error=0
int prev_error = 0;
unsigned int kp = 9.2 , kd = 3.2 ;
int control_signal;
while(1){
l=ADC_Conversion(3);
c=ADC_Conversion(4);
r=ADC_Conversion(5);
lcd_print(1, 1, l, 3);
lcd_print(1, 5, c, 3);
lcd_print(1, 9, r, 3);
error = r-l;
2
if(control_signal == 0 || c >= 9){
forward();
}
velocity(x,x);
left();
}
else if(abs(control_signal) < 4 && c >= 8) {
velocity(x,x);
forward();
}
else{
forward();
}
prev_error = error;
_delay_ms(100);
2.2 Explanation
We are basically trying to control the velocity using a PID controller. We have
defined a control signal variable which stores the pid output. There are 4 total
possible types of situations:
• Whenever there is supposed to be a right turn the error term which is the
difference between the right and the left sensor value will be positive. Also
the previous error will be less than the current error. Therefore the pid
output value i.e. control signal variable will be positive. We can detect
this condition and make the bot to move rightwards using right() function
with the velocity depending on the control signal.
• Whenever there is supposed to be a left turn the error term which is the
difference between the right and the left sensor value will be negative.
Also the previous error will be less in magnitude than the current error.
Therefore the pid output value i.e. control signal variable will be negative.
We can detect this condition and make the bot to move leftwards using
left() function with the velocity depending on the control signal.
3
• The major challenge was to cross the plus shaped obstacle in the track.
We realised that during this location the pid output goes to zero. So in
order to detect this we have included another else if condition telling the
bot to move forward.
• We made a crucial mistake of not noting the sensor values across the
different regions of the track. Because of this we faced a lot of issues in
tuning the PID parameters.
• The bot allotted to our team had one faulty center which always lead the
bot to prefer onr side more than needed using the turns.
4 Results
• kp = 9.2
• kd = 3.2
• ki = 0
• total time taken to complete the path = 26.9 seconds