🖲️Misty OA
With the Obstacle Avoidance skill Misty will be able to drive and navigate your space without difficulties!
The idea behind this project is as simple as possible: if Misty detects a shorter distance between her sensors and a flat surface, for example, shorter than 40 cm, she changes direction and tries to avoid the obstacle by turning, going straight forward for a short distance, turning and checking the new distance.
To do so it will be necessary to use the TOF (Time of Flight) event that contains all the measurements of Misty's distance sensors.
The reason why there are two functions that look almost exactly the same is related to an hidden issue in this project: the old distances.
After Misty detects an obstacle a time.sleep() command is sent to allow her to comfortably stop and proceed to the next action. During this time the TOF event is still active and this means that Misty keeps recording the distances, after entering the if statement which corresponds to the obstacle detected gate. When Misty will start recording the new measures, these will be the old ones and the skill will not work according to the reality.
The easiest way to get rid of them is simply to unregister the whole event, so every information about it will be deleted. After we register a completely new event, with a similar callback function, where only the name is different, that will keep Misty's behaviour the same way. Then when Misty meets a new obstacle she'll move and then she will unregister this second event (the first event is called "TOF_event", the second "TOF_event_obstacle") and go back to the previous one.
With this flow, the two functions and events loop without bothering each other.
In the code, after detecting an object, Misty turns to the left, travels for two seconds forward, and then turns to the right to be in the correct position for the next check.
To make Misty turn to the right you can replace the misty.drive_time() commands with these:
Enjoy your Obstacle Avoidance skill with Misty, personalize it and share it to the world!
Last updated