Our robot club had a competition in October which involved avoiding an obstacle while line following: robomo.com/Forum/viewtopic.php?f=25&t=1151
An IR sensor would be a nice addition but I didn’t use hardware at all, just software. I added timers and a swerve() function to the PID linefollowing code. The swerve() code just goes right for a second then goes left, when it returns the main code starts following the line again. It worked pretty well, the video is at
along with other bots which used sensors to detect the obstacle.
I noticed that others have figured out how to add IR rangefinders so I’ll try that also. Here is some code similar to what I used:
// This function swerves around a can.
void swerve()
{
set_motors(160, -160);
delay_ms(600);
set_motors(-160, 160);
delay_ms(1000);
return;
}
int main()
{
unsigned long get_ms();
unsigned long millis();
unsigned long ckMillis = 0;
time_reset();
millis();
// This is the "main loop" - it will run forever.
while(1)
{
if (swerveOnce == 0)
{
ckMillis = get_ms();
if(ckMillis > 2200)
{
swerve();
swerveOnce++;
set_motors(0, 0);
}
}
…