This project aimed to utilize sonar sensors to map out the vehicles surroundings and navigate through it. The project was a success and its functionality is showcased in the video beside. A rasberry pi was loaded with a OS and this was coded through the Thonny code editor. The code is very modular as there are functions with required input for movement of the wheels aswell as the rear servo. The logic is as follows; the base state is forward, when the front sonar reaches a distance on 17 cm, the robot stops and triple checks that there really is a object there, the sonar can sometimes be inaccurate, therefore multiple checks can help mitigate false positives. It then randomly selects to go right or left and the rear servo aims the rear sonar towards the wall. The robot then slowly creeps along the wall while the rear sonar checks whether or not the wall is still there. After the rear sonars distance readings exceed 20cm, the wall is considered passed and the robot returns to its original heading. If the robot encounters another wall in the process of following a preexisting one, it will do a 180 degree turn and see if it can go the other way around. Important to note is that the robot is not perfect, it can get stuck in certain scenarios due to imperfections in the floor or fluctuations in friction. The easy part of the project is the code. The physical components are more susceptibal to error as loose cables or components that dont share common ground can easily disable all functionality of the robot. It is very important to ensure that enough power is provided to all components and that everything shares common ground with the pi. This was a very educational project as i realised my poor planning caught up very quickly. Power deffiencies, common grounds and jumbled up cables hindered my work speed noticably. So ensure you have a clear plan and a good understanding of what the components require to work properly, and always double check your cables in case of errors.
The Roomba Project
Components:
Raspberry Pi
2 HC-SRO4 Sonar
2 DC Motors
1 Servo
Power Supply for Pi
2 battery packs
L298N Motor Controller
BreadBoard
6x 500 Ohm Resistors
L298N Motor Controller Guide HC-SRO4 Sonar Guide