8000 Modernize the Codebase with PlatformIO (+refactor) by PhilippMolitor · Pull Request #4 · nickrehm/dRehmFlight · GitHub
[go: up one dir, main page]

Skip to content

Modernize the Codebase with PlatformIO (+refactor) - #4

Closed
PhilippMolitor wants to merge 9 commits into
nickrehm:masterfrom
PhilippMolitor:master
Closed

PhilippMolitor wants to merge 9 commits into
nickrehm:masterfrom
PhilippMolitor:master

Conversation

@PhilippMolitor
@PhilippMolitor PhilippMolitor commented Oct 10, 2022 •
Copy link
Copy Markdown

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:

  • Remove older versions from git folders (git handles versioning fine by using commits (and tags!))
  • Move to PlatformIO
  • Make PlatformIO compile succeed with default settings
    • Refactor order of declarations
    • Add region pragmas for scaffolding
    • Fix syntax / define errors
  • Check for other configs to compile
    • MPU9050
    • PPM_RX
    • SBUS_RX
    • DSM_RX
  • Move to external MPU6050 dependency as a showcase (reduces code in this repo)
  • Move other foreign libs to external dependencies
    • MPU9250
    • SBUS_RX
    • DSM_RX (not in PlatformIO registry, stays in /libs for now as a copy)
  • Remove unused TFMPlus library
  • Split some code from main.cpp to other files - this would make it easier for new users to find the relevant part of code for them
    • Move global variables to their own .h file to be able to include those from different files
    • Refactor global variables to a struct to enhance visibility and overview
    • Move RC link code to external again (the previous architecture works in arduino IDE, but had some no-nos in it)
    • Move Mixers to their own directory so one could add new mixer types easily and without removing the current one
  • Test builds on actual mo 8000 dels (I currently have nothing to test this on)
    • MPU9250
    • MPU6050
    • SBUS RX
    • DSM RX

Other ideas:

  • Move PDF documentation to markdown (/docs folder) - this would allow git contributors to actively change documentation if necessary.
  • Add docs for getting started with this repo and vscode + platformio
  • Make configuration of IMU hardware / RX Hardware / Pinout / Debug printing easier to modify without changing the source - maybe we could leverage some tricks from the platformio.ini environment configurations

@nickrehm
Copy link
Copy Markdown
Owner

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:

  • putting all the code in one script rather than separating out into different folders/files
  • including libraries rather than requiring them be installed with the compiler (even including additional, unused libraries....tfmplus library is for me and some of my projects when I need it, and it did require some modifications over the source library :))...avoids the "why won't my code compile?" questions, especially if versioning starts becoming an issue
  • arduino ide: less scary to newcomers

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

0