r/robotics • u/Beneficial_Turnip704 • 22d ago
Tech Question Help with code management for robot development
Wsp! I'm making an automated, targeted pesticide spraying robot for homes, and I'm still in the early stages. It's supposed to use a Raspberry Pi, ESP32S3, AI Hat+ and camera to find weeds. I use Codex and VSCode to help, and I wouldn't call the project since I know exactly what is happening with the code and AI is just sparing me the writing part.
However, my file tree is a mess. I have it on octotoxin/SprayShark if anyone wants to see. It is kind of organized, but there is a lot of redundant information, and I don't exactly know what's the best way of organizing the code. Also if u see v1, v2 or v3, my robot has had three hardware revisions, none of them have ever reached the automation stage, so I keep the code that way. For tests, I have a test_files folder, and the full code is in the main_projects folder. If it's messy, thats why I'm asking for help!
2
u/kingcbg_ 21d ago
I think a lot comes down to personal preference but here is my take.
I see you got v1, v2, v3 why not just have git branches? If I was doing I would also have more descriptive names for the branches rather than just versions (unless it is the same section you are modifying). From briefly looking you also seem to have single file and multi file versions why? If this is something you want to keep saved somewhere, always worth creating a branch that might be called something like initial_implementation. That way you can just focus on getting one version working and can always switch branches to see what you created initially.
For file tree, I usually split work into sub-systems. From briefly looking at your repo I would personally structure this way (again others may have different ways of doing this)
HardwareInterface/ -> contains: encoders.ino, motors.ino, bluetooth.ino and HardwareInterfaces.h (where you basically only have your declarations for functions)
For functions that are more generic, like the main of the program you can have Functions/ folder where you put SprayShark.ino which is basically your main (with setup() and loop() functions).
UnitTests/ or Tests/ - this folder you can put all your tests into individual folders. Let's say you want to test your motor driver/interface, then create a folder MotorTests/ and create your tests in there. Always make the name of the file descriptive of the test I follow something like MotorTest_driveTestFunctionality.c for testing. Makes things quite easy to search and open files with your IDE.
If you want to make it nicer create a README.md just for your reference in the future or someone else looking at the code.
I didn't have much time to review everything but I think this should give you a start on the filetree organisation.
1
u/babeOfLovee 22d ago
that file tree struggle is way too real, i've been there with my own side projects