StateTest - Terrapin-Rocket-Team/SRAD-Avionics GitHub Wiki
Home/Documentation/StateTest
The State Testing Class (StateTest.cpp
)
The StateTest
class is designed to test the State
class. It does this by creating a State
object and then updating it with fake sensor data before recording the results. It is a simple class that is mostly designed to test Kalman Filters and stage detection. The system has multiple gimmicks and inefficiencies that make it somewhat annoying to use.
This system runs code on the FC, and sends fake data to it over serial. This means that you need to have the FC connected to your computer over USB, and you need to have the SendData.py
script running. That script is located in the same directory as the StateTest
class, which is where everything related to this file is stored: The StateTest
folder.
You need to have Python and the Python package colorama
installed. If you don't have Python, you can download it from here. If you don't have colorama
, you can install it with pip install colorama
from a terminal (after Python is installed).
-
Switch your PlatformIO environment to
teensy41_TEST_STATE
. (SeeRunning Code on an Arduino) This setsStateTest.cpp
as the new main file and excludes themain.cpp
file from the build. -
Upload the code to the FC without opening the serial monitor. The
SendData.py
script will be the serial monitor for you.- PlatformIO should indicate to you which COM port the Arduino is connected to. Update the
SendData.py
script with this information. (Don't forget to save it.)
- PlatformIO should indicate to you which COM port the Arduino is connected to. Update the
-
Run the
SendData.py
script. It will send fake data to the FC, which will then process it and send it back to the script. I recommend opening the file location in a terminal and runningpython SendData.py
to start the script, so that it doesn't close itself when it's done. -
The script will send data from the
fake_data.csv
file to the FC. The FC will process it and send it back to the script. The script will then save the data to a new file calledtest_results.csv
.- If the format of the data has changed, you will need to go into the
TestUtils.h
file to update which columns correspond to which data.
- If the format of the data has changed, you will need to go into the
-
Once the script is done, you can open the
test_results.csv
file to see the results of the test.
-
It can only update roughly once every 50ms. This could probably be fixed, but the system was thrown together very quickly and is not very efficient.
-
The system is designed to test the Kalman Filter and stage detection. It is not designed to test the sensors themselves.
-
The output uses the State's
getStateString()
method which is a truncated version of thegetDataString()
method that only returns the values the state is storing, rather than raw data from the sensors (since it's not real data anyway).
The class uses "fake" sensors that are defined in their own Fake[Sensor].h
. It passes data to them using the TestUtils.h
file, which is used to define the columns of each data type, which are then parsed into numbers and sent to the relevant sensor.
Each Fake[Sensor]
has a new feedData()
method that takes in each of the values that the sensor should return.
During the loop, the State is updated as main would do, but the sensors given to the state are fake versions that return the data they are fed, rather than actual sensor data. It also feed the State a fake time, to help mitigate issues between update speed and the fake data's time steps.