...
The first thing your’e going to want to do, (after you’ve designed a general architecture for you your module), is figure out how a user would interact with your module. That means deciding on what api to expose and writing out the interface. In the case of the attitude manager state machine, we’ve decided to go with an architecture where the user needs some way of getting the state machine to “run”, they need some way to read the current state of the state machine, and they needs some way of setting the state machine to a certain state. That’s it! Notice how simple that is ? Although the state machine internals will eventually be fairly complicated, it is your responsibility as a designer to make life as easy as possible for the person interacting with it. So here is what the interface looks like right now (attitudeManager.hpp):
...
An now, when we run the unit tests, we will see everything passes! This new test will run everytime every time you run all the other tests, and eventually when things get merged, Everytime Every time someone pushes to our repo. What it’s done is give us insurance forever that whatever happens, attitudeManager objects always start in the “fetchInstructionsmode” state.
Writing your second test
Ok so we’re starting in the correct state, great. The next piece of functionality we’d like to have is for the state machine to flow between states correctly. That is, when the state machine is in the “sensorFusionMode” state, running execute once should take it to the “PidLoopMode” state. Here is the test that expresses that:
Code Block | ||
---|---|---|
| ||
TEST(AttitudeManagerFSM, SensorFusionTransitionToPID) { /***********************SETUP***********************/ attitudeManager attMng; /********************DEPENDENCIES*******************/ /********************STEPTHROUGH********************/ attMng.setState(sensorFusionMode::getInstance()); attMng.execute(); /**********************ASSERTS**********************/ ASSERT_EQ(*(attMng.getCurrentState()), PIDloopMode::getInstance()); } |
You should be able to see what’s going on: we just set the state machine to the sensorFusionMode state, run execute once and check to see