State - Terrapin-Rocket-Team/SRAD-Avionics GitHub Wiki

Home/Documentation/State

The State Class (State.h)

Note: This class is expected to be heavily rewritten for the 24/25 year. If this notice is still here, then the information here may be out of date.

The State class is designed to hold information about the position, velocity, acceleration, orientation, stage, and time of the rocket. This is collectively referred to as the "state" of the rocket. The class is updated by main.cpp at 10hz, which causes it to query various sensors, fuse the data together as necessary, and update internal variables. It then updates a string with all the data we wish to record, and uses the RecordData library to save it.

The flow of the class is as follows:

  1. The class is instantiated during the setup() function of main.cpp.

    • It is told whether it will record its own data (rather than relying on main to do it) and whether it will use a Kalman Filter or not.
  2. Also in setup(), the class is given pointers to the sensors it will use.

    • It's designed to easily give it different sensors without reworking the class as a whole
  3. State.init() is called in setup() to initialize the class.

    • This causes it to try and begin each of the sensors, and returns false if any of them fail.
    • It initializes the Kalman Filter if it's being used.
    • It readies a CSV header based on which sensors successfully initialized.
  4. State.updateState() is called in main.cpp at 10hz in the loop() function.

    • This function queries the sensors for data, fuses it together or runs it through the Kalman Filter, and updates the internal variables.
    • It determines which stage of flight it's in using various parameters that mark a new stage being entered.
    • It then updates the string with all the data we wish to record.
    • If it's set to record its own data, it does so here.
  5. Every half a second, State.transmit() is called by main to transmit a string of telemetry data to the ground station.

    • main takes care of transmitting a second time if the string of data is too long for a single radio packet.

Other Information

  • The class is designed to be easily extensible. It's easy to add new sensors or new data to the class.

  • Both the Kalman filter and stage detection have been pain points throughout the 23/24 year. Improvements will need to be made to them to help Avionics meet their goals for the 24/25 year. (Charge Deployment, etc.)

  • The MMFS repo is being actively worked on, and much of the responsibility of this class will move to a more abstract "Base" State class for the 24/25 year.

    • This includes the Kalman Filter.

See Also

⚠️ **GitHub.com Fallback** ⚠️