More sophisticated object avoidance

As we mentioned previously, the preceding behavior can leave the robot stuck. It will appear to be indecisive regarding some obstacles, and will occasionally end up ramming things. It may not stop in time, or turn into things. It's time to make a better one that will behave a bit more smoothly.

So, what is our strategy? Well, first, let's think in terms of the nearest sensor and the furthest. We can work off of the speeds of the motor nearest to it, the motor further from it, and a time delay. The reason for the time delay is so that we can do things such as turn right away from a wall, and not alternate between two states just in front of it. Let's build some code, similar to the last behavior, around ...

Get Learn Robotics Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.