Good night, thanks for the tip and sorry for the mistake. I did not know I had this command.
What I would like my 3 pi to do was read the line more accurately, using PID in the case. But still detecting when there was a fault in the track, because when I tested it on the track of the school, which is not totally straight, because I was not using PID I noticed that for it to stay centralized it stays moving at all times during the path.
That’s because I’m using the code:
else if(position < 1100)
{
set_motors(-70,90);
reto = 0;
}
else
{
set_motors(90,-70);
reto = 0;
}
I have already tried to change the values, of both the readings and the engines, but he continues to “difficulties” to make the turns, and I noticed that he loses more time than necessary. This would not happen if I used the PID because it makes the way with the least possible error. But I tried to increment the white-detect code, but I could not.
This code:
int main()
{
unsigned int sensors[5];
unsigned char reto;
unsigned int last_proportional=0;
long integral=0;
initialize();
reto = 0;
while(1)
{
unsigned int position = read_line(sensors,IR_EMITTERS_ON);
if(sensors[0] < 400 && sensors[1] < 400 && sensors[2] < 400 && sensors[3] < 400 && sensors[4] < 400 && reto)
{
set_motors(100,100);
}
int proportional = ((int)position) - 2000;
int derivative = proportional - last_proportional;
integral += proportional;
last_proportional = proportional;
int power_difference = proportional/10 + integral/55000 + derivative*1/1;
const int max = 80;
if(power_difference > max)
power_difference = max;
else if(power_difference < -max)
power_difference = -max;
else if(power_difference <0)
{
set_motors(max+power_difference, max);
reto = 1;
}
else
{
set_motors(max, max-power_difference);
reto = 0;
}
}
}
From what I know, the PID uses a value of proportion, so there would have to be an exception in this code so that even with PID, the 3pi would know what to do when there was no more line.
Thank You!