Can an ultrasonic sensor be used mixed with a line following script

Title says everything..

Title says everything

Superknowsstuff:
Title says everything..

If that is all the information you are going to supply, then the answer is yes, no, and possibly.

Paul

Paul_KD7HB:
.... possibly.

Maybe even probably.

You should certainly be able to have all the sensors read often enough by splitting things up into functions like this:

void loop()
{
readTheLineSensors();
readTheObstacleSensors();
...
...
}

Then based on some criteria which you would have to be able to write down in words before going any further, you could perhaps switch between operating modes. So if it's in line mode and happily zooming around the track and sees an obstacle in a certain distance it could switch modes and go round it.

Then you would need to have described in words how you would expect it to go about finding the track again on the other side, so to speak.

And what happens if it's on the track, in line follow mode, and sees an obstacle ahead but unbeknownst to it yet, there's a 90 degree turn in the track which will take it away from the obstacle anyway... It would try to avoid but the track would have kept it safe.... how far can you look ahead.

I reckon the coding for a thing like this will be relatively* straight forward; certainly reading a bunch of sensors in more-or-less-real-time is feasible in principle. The tricky part is going to be to write down what you want it to do.

Start by laying out a track in your house or driveway and you just walk round it and try to describe what oyu did to (eg) regain the track after the dog walked in front of you and you went off.

THAT's the really difficult part..... If you can't write it down, makes it impossible to code.

(* For some definition of relatively.)

In fact, this would be a fascinating exercise:

  • Lay out a track of human dimensions that you can walk round
  • Make a cardboard doobry to fit over your head, so all you can see is say 1-2m of the track ahead, and nothing else
  • Get a pointed stick say 4m long and hold it out in front of you like a lance
  • Switch to mental line follower mode and walk the track
  • When you feel the tip of the lance hit something, switch to avoidance mode
  • Then (and here's the tricky part) decide what you should do to get round the obstacle and join the path again....

I'm pretty sure that would prove that it's easy to read the sensors in real time: keep your eye on the path and feel for the lance to jab the dog*. But the difficult part is to decide what to do with the knowledge.

  • just kidding