I am working on line follower robot. I have 8 sensors for tracking line use L298 for driving motors. I use 18f452 20 MHz and PD algorithm in my codes.
If I set motor's speed slowly everything is normal but set to fast it is not follow the line and go out the line. I changed Kp and Kd values but I cannot set.
By the way road is white line is black.
...
11111011 error=+3
11110111 error=+1
11100111 error=0
11101111 error=-1
11011111 error=-3
..
Here is my code..anybody can look my pd routine and say where I am doing mistake?
Code:
.
.
.
char sensor;
int Kp =6;
int Kd=10;
volatile int motor_hiz=100;
signed int oransal_hesapla(void)
{
signed int errorp=0;
static signed int ultimo_errorp=0;
char contador_sensor=0;
signed int error = 0;
static signed int error_old = 0;
static signed int errord=0;
static signed int errord_old = 0;
static int16 tic = 1; // 1
static int16 tic_old = 1; //
#int_TIMER1
void TIMER1_isr(void)
{
set_timer1(60535);
signed int errort=0;
signed int proportional = oransal_hesapla();
signed int derivative = turevsel_hesapla();
if(errort>0)
{
set_pwm1_duty(motor_hiz - errort); //right MOTOR slow
set_pwm2_duty(motor_hiz); //left MOTOR full
}
else if(errort<0)
{
set_pwm1_duty(motor_hiz); //right MOTOR full
set_pwm2_duty(motor_hiz + errort); //left MOTOR slow
}
else
{
set_pwm1_duty(motor_hiz); //right MOTOR full
set_pwm2_duty(motor_hiz); //left MOTOR full
Interrupts should be small and fast, setting a few bits(flags) then return to main.
At slow speeds you've just got enough time to make it work, but the faster you go, the less time you have inside the ISR to do all of the code before another interrupt comes along.
So rethink the program(actually you don't need ISR).
suggestion
start of mainloop
Read the sensors port
compare to the 'offcourse' patterns( 'Switch' works great here)
do the PID math...
set the PWM data...
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum