Terrapin-Rocket-Team / Multi-Mission-Flight-Software

An arudino library used by the Terrapin Rocket Team as the foundation of the team's flight software.
5 stars 0 forks source link

Add unit testing (and rework the sensors a bit) #51

Closed DrewBrandt closed 1 month ago

DrewBrandt commented 3 months ago

Summary:

This PR does a lot of restructuring and somewhat significantly modifies the behavior of the sensors.

I've added numerous (like, 50) unit tests for various parts of the base sensor classes, the state class, and the APRS encoding. These tests are only designed to be used on PlatformIO at the moment, and uses its structure for testing. They rely on the Unity testing framework which, according to Unity, is mostly just a collection of easy-to-run asserts. I don't know enough about how the Arduino IDE handles testing to know if this would compile properly on it. I did try to make sure that the library being used in the Arduino IDE would compile properly, though. Further testing for this is required.

Tests currently include:

More testing documentation to follow.

Changes:

Major:

Minor:

Major Notes:

The IMU implementation in this version is currently... well... not implemented. Changes to IMU hardware brought up the fact that we need to add math to get global frame from the IMU's local frame. I can do this math, but I feel more discussion needs to happen on wwhat this looks like. I think Ezra would say to not even worry about it because you can just put the raw values into the KF and still get the values you need (at least that's my understanding, but I admittedly don't understand how Kalman Filters work).

The State tests are currently not implemented as the IMU is still not implemented. Once all sensors are done, state tests can begin.

I will write documentation about how to both use and modify this code as I begin migrating the Avionics wiki over here. I think I may slightly change the layout so that the wiki is split into two broad categories: using the software and modifying the software. One goes over the API and the other dives into the internals to help people understand how it currently works so that they can make changes if necessary.

Updates after KF and RecordData updates:

varun-un commented 2 months ago

Should the Math folder be renamed to something like Utils if it now has utilities like the circular buffer

jhauerst commented 2 months ago

Before we merge I think we should have some documentation attached about how to use the unit tests somewhere, and how to setup Unity

If it doesn't build with the Arduino IDE, we may want to wait to merge it, but if the "fake" environment you mentioned works to at least avoid build errors, then it should be fine.

I agree that we should have at least some documentation on how to use the tests before this is merged. It doesn't have to be anything super detailed, just some basic steps for running the tests so that people will know how to use them.

mallamacimj commented 2 months ago

Should the Math folder be renamed to something like Utils if it now has utilities like the circular buffer

IMO we should move the circular buffer to a Utils folder but keep all the math in a math folder. I think that will be the most logical to anyone new to the code.

DrewBrandt commented 1 month ago

https://github.com/Terrapin-Rocket-Team/Multi-Mission-Flight-Software/wiki/Using-Unity-Unit-Testing-Framework

Basic Unity Docs

DrewBrandt commented 1 month ago

Updates after KF and RecordData updates:

jhauerst commented 1 month ago

Docs look good to me and tests ran without issue