How to program a 3 point turn
Sometimes I have gotten feedback like "Wow, it even does 3-point turns".. or "5 point turns".. or "It is even getting itself out of trouble" when I have shown people my project named "Wall racers" and similar projects.
Yesterday I was focused on making something else on this project - and because I have done some of these things so many times, I did not even think about it, but I had actually given this robot that ability.
It stroke me, because I was looking for something else that it should do, concentrated I was looking at a test run.. and it got too close to a corner to steer out.. and WOW! This not finished robot just reversed and maneuvered itself out in a way I had not expected, not seen before - and drove on. I thought it was about time to share this little trick.
I include the Wall Racers video as example, because at 00:59 and later, it gets stuck, and get's out again using this technique.
THE TRICK: Work with 2 levels, one called "Attention", and one called "Danger". This as opposite to just "If distance is greater than.. then.."
Let us assume that your robot can look to each side somehow, and that it constantly is fed the distance in front / to the sides perhaps.
Let us assume longer distance means higher value (like the raw return from a SRF05 that I usually work with)
Let Attention = 300
Let Danger = 150
Constantly, when checking distance in front, make a check if it is less than Attention.
1: (See the top video)
First the "normal" navigation:
If distance in front < Attention then Steer free, based on knowledge you have, turn the robot to the side where distance is greater.
Constantly check distance in front, and when checking distance, make a check if it is less than Attention.
If distance in front is not less than Attention, then return to normal mode, we got out without trouble.
To here is how many first robots goes. And if they get too close, they still try to steer free.. However:
2: (See the top video)
If distance in front is less than Danger, we have to make a 3 point turn. So A) steer to the opposite side, and B) start reversing.
Constantly check distance in front, and do not stop before
Distance in front > Attention. Note: this is greater than "Attention", not "just > Danger", in here lies the whole trick :) Without this, you will just get jammed.
(or *Safety override = true (more about this below))
3:(See the top video)
Then, just get back to normal drive (As in step 1), it will drive free by nomal turning the rest of the way :) And if necessary, the thing will make a 5 or more point turn out of it, by magic :)
On the video, in the end, the bot sees me, the cameraman, and starts from 1, would make another 3 point in front of me if it was to continue..
*Safety override: At this point your bot is actually reversing, and will not stop beforeit has a clear path in front. But it may actually be stuck on something, unable to reverse any further.
On RWR (Robot Wall Racers) I simply have a counter at this part, so if the car is not free within 3 seconds, it just goes in "Help me"- mode; Turning all off.
One could also make it try to drive forward again, see if it helps, and one could have sensors at the back, and make double-sided 3-point turns..
Since this sort of makes the robot "bounce" in some situations where you may actually just want it to "drive around", you may follow up with some "get back on track-code"or some "Get back and stick to the wall you where bouncing", depending on purpose of obstacle avoidance in general..