Shipped this project!
This code predicts the apogee that the rocket will achieve during its flight, while the flight is happening.
Okay… Where do I even begin to explain this code. It might look like a small file, but this was easily one of the MOST difficult things I’ve ever done. Predicting drag and velocity using a filter was genuinely so hard, and I had to learn what crazy things like “quarternions” were to accurately differentiate tilt. I also had to use some calculus to integrate velocity and acceleration, which was also not fun. But in the end it predicted the apogee pretty well (I think it predicted 599 ft when it actually went 603ft on the second flight). The flight in the video that I showed went 676 ft but because I set the drag coefficient too low and messed up some integrals, it predicted 720 ft. But yeah, I’m really proud of how it came out and you guys can use the same code if you ever want to build a mid power rocket… Anyways, thanks for reading this and I hope that viewing this code helps you realize just how hard it was for me to build this and pack it in a rocket successfully…
OH MY GOD I forgot to mention that the Arduino we used had only 4096 bytes of memory, so optimizing that was ABSOLUTELY INSANE. No Idea how I managed to fit suich a complex algorithm in there but literally EVERY variable, function, and everything I coded had to be extremely specific otherwise the arduino just gave up and corrupted the data (which happened on one of the first tests)!