Hello
Thanks for your help~
I try to adjust the code:
[code]
int last_proportional = 0;
long integral=0;
unsigned long time_delay = millis();
while(1)
{
// Normally, we will be following a line. The code below is
// similar to the 3pi-linefollower-pid example, but the maximum
// speed is turned down to 60 for reliability.
// Get the position of the line.
unsigned int sensors[5];
unsigned int position = read_line_white(sensors,IR_EMITTERS_ON);
// The "proportional" term should be 0 when we are on the line.
int proportional = ((int)position) - 2000;
// Compute the derivative (change) and integral (sum) of the
// position.
int derivative = proportional - last_proportional;
integral += proportional;
// Remember the last position.
last_proportional = proportional;
// Compute the difference between the two motor power settings,
// m1 - m2. If this is a positive number the robot will turn
// to the left. If it is a negative number, the robot will
// turn to the right, and the magnitude of the number determines
// the sharpness of the turn.
int power_difference = proportional/10 + integral/20000 + derivative*5/2;
// Compute the actual motor settings. We never set either motor
// to a negative value.
const int max = 130; // the maximum speed
if(power_difference > max)
power_difference = max;
if(power_difference < -max)
power_difference = -max;
if(power_difference < 0)
set_motors(max+power_difference,max);
else
set_motors(max,max-power_difference);
if(get_ms() - time_delay > 200)
{
if(sensors[1] > 800 && sensors[2] > 800 && sensors[3] > 800)
{
// There is no line visible ahead, and we didn't see any
// intersection. Must be a dead end.
return;
}
else if(sensors[0] < 800 || sensors[4] < 800)
{
// Found an intersection.
return;
}
}
if(get_ms()-time_delay >= 800)
{
const int max = 200; // the maximum speed
if(power_difference > max)
power_difference = max;
if(power_difference < -max)
power_difference = -max;
if(power_difference < 0)
set_motors(max+power_difference,max);
else
set_motors(max,max-power_difference);
}
if(get_ms()-time_delay > 2000)
{
const int max = 130; // the maximum speed
if(power_difference > max)
power_difference = max;
if(power_difference < -max)
power_difference = -max;
if(power_difference < 0)
set_motors(max+power_difference,max);
else
set_motors(max,max-power_difference);
}
// We use the inner three sensors (1, 2, and 3) for
// determining whether there is a line straight ahead, and the
// sensors 0 and 4 for detecting lines going to the left and
// right.
if(get_ms() - time_delay > 200)
{
if(sensors[1] > 800 && sensors[2] > 800 && sensors[3] > 800)
{
// There is no line visible ahead, and we didn’t see any
// intersection. Must be a dead end.
return;
}
else if(sensors[0] < 800 || sensors[4] < 800)
{
// Found an intersection.
return;
}
}
}
}][/code]
But there is a problem,
When I try run,
the 3pi is acceleration,this is true,
but it can not stop 3pi to turn right or turn left.
This is a big problem!
I think it is because 3pi do not slow down
But how can I slow down 3pi?
After that,I try to put in a condition that set 3pi acceleration in 800 ms~2000 ms
but after 2000 ms,3pi had stopped…
Where do I modify code wrong?
How can I solve this problem?
Can any one help me as soon as possible?
Sorry,I have a competition this weekend…