Repository navigation
Modernize the Codebase with PlatformIO (+refactor) - #4
PhilippMolitor wants to merge 9 commits into
Conversation
|
I appreciate the work you are doing, but many of these changes are to things that were very intentionally done to make the code and process more friendly to people without software experience:
Again, everything you are doing is good practice and very useful, but you'd be surprised just how fast the perceived complexity goes up for someone that just wants to slap an 'if' statement in line with a pid controller and have it just work out of the box. One example of intentional "bad" practice is not using a mixing matrix in the control mixer to clean and speed things up. To understand the control mixing, you would need to understand matrix multiplication. Does your average middle schooler understand that? It is simply easier to do things the "wrong" way rather than teach an abundance of catch-up material to a newcomer. Not with the intention of teaching bad practices, but to skip ahead to the interesting principles without getting bogged down by the minutiae. Arduino ide flattens the learning curve, even though I'm sure platform io is also user friendly. I will look more into this as a potential replacement, because I do agree arduino ide is lacking in some departments. Maybe worth maintaining your own fork as the 'for developers' version of dRehmFlight? |
Hi Nick!
I learned about your project (like most) from Tom Stanton - great work! I really love the approach you took to create this firmware so far.
I am doing some embedded work from time to time, and the Arduino IDE sadly is very limited in its capabilities. This is why I decided to start porting your project to PlatformIO, a toolchain manager for embedded devices that directly integrates into VS Code as a plugin.
First of all: please don't get intimidated by the amount of changed code! Most removals are just removing the old version folders, as well as the external libraries from your /src folders. These are not needed as they are now downloaded automatically by PlatformIO. Most of the bigger changes are actually the auto formatting feature of VS code, normalizing the code to one consistent style that is enforced as soon as you press save. Then there were some changes in the order in which functions and variables are defined, because these need to be in order for normal C/C++, so one function knows that the other already exists.
The best way to review the changes would be to look at my current state of the src/main.cpp file. Most of the stuff will seem almost untouched, just in a different order.
With PlatformIO you get features such as automatic downloads of required toolchain components, native C/C++ support of VS Code (think modern auto completion, linting, auto formatting, etc), as well as dependency management.
Also, I see quite a good chance of easy portability to other platforms with this build system, such as the ESP32, RPI2040 or other widely available boards with adequate clock speeds and IO counts. I think this will help the project to be even more easily adapted for others and their projects.
Moving all libaries to external dependencies is also a nice to have here: Less code to maintain, and there were (almost) no modifications necessary to make them work with the existing code (the MPU9250 library uses some other method names for getting the realtime IMU data). Also, others can use any library on the PlatformIO registry by including the name and version in the platformio.ini file. No more copy/paste code! :)
BTW: this will also make the "getting started" part quite a bit faster for newbies. Most of the stuff happens by itself when opening this repo with vs code, such as installing platformio and other required stuff. The build/flash process then is just done with one click.
Status of this PR:
main.cppto other files - this would make it easier for new users to find the relevant part of code for themOther ideas: