Skip to content

Tick Guide

To create a new tick, the header file should be placed in the include/ticks/ directory, and the source file should be placed in the src/ticks/ directory.

Virtual Methods

A Tick is just a subclass of the abstract base Tick class. To create this derivation, you must override the following virtual methods:

tick() The actual code that is run every "tick."
getWait() Returns in milliseconds how long to wait between calls to tick. Can be a constant value, or dependent on some internal state.

Tick ID

In addition, the constructor for the derived class will have to pass up a TickID. This is a unique identifier which help other parts of the system figure out what Tick is currently running.

First, you will have to go to include/ticks/ids.hpp and add a new ID to the TickID enumerated class. Then, to ensure that the tick ID can be converted to a string you will have to add a case statement for the new id to the TICK_ID_TO_STR function. You just need to follow the format that is already there and use the provided macro.

Once the Tick ID is established, in the constructor for your Tick class you will need to pass up the tick ID to the super class's constructor.

Internal State

Generally, if there is data that only needs to exist for the lifetime of the tick, then that data should be entirely contained within the Tick class and not placed in the global MissionState object.

If an outside piece of code needs to communicate with the currently running Tick, then it will be able to acquire a shared pointer to the tick using the LockPtr class (see below section). This means that when you are creating a tick you can add public functions and any interface you want, and other parts of the system will be able to call those functions.

For an example of this, you can see the PathValidate tick.

LockPtr

Code outside of the tick (e.g. the gcs server) that needs to access the currently running tick can use the LockPtr class to acquire a locking pointer to the currently running tick. Note: be careful when you are doing this, as while the LockPtr is in scope, nothing else will be able to access the Tick, due to the fact that it will be locked down.