Sensor Interface - Terrapin-Rocket-Team/SRAD-Avionics GitHub Wiki
Home/Documentation/Sensor Interface
The Sensor Interface (Sensor.h
)
This is the base class that is used for all the different types of sensors attached to the flight computer. The only component that is not a sensor is the radio. The sensor interface is used to ensure that all sensors have the same basic functionality, and to allow for easy swapping of sensors. This is especially useful for testing, as we can swap out a real sensor for a fake one that returns known values.
Note: The getDataString()
and getStaticDataString()
functions are expected to return heap-allocated char*
s. This is because the State
class is responsible for freeing the memory after the data is used. getCsvHeader()
is expected to return a char[]
as a string literal (i.e. Don't delete[]
it).
This enum is used to identify the type of sensor that is being used. It is used in the State
class to determine which variables to assign to any given sensor.
Values:
BAROMETER_
GPS_
IMU_
-
LIGHT_SENSOR_
-- (not currently used in Avionics) -
RADIO_
-- (not a sensor, but included for possible future use) -
RTC_
-- (not currently used in Avionics) -
UNKNOWN_
-- (This is not really implemented and should not be used)
Rather than list out all the functions here, I will refer you to the header file for the Sensor
class. This is the base class for all sensors, and all sensors should inherit from this class. The functions are documented in the header file.
Some important ideas to note:
- The
Sensor
class is an abstract class, meaning that it cannot be instantiated. It is only used as a base class for other classes. -
update()
is intended to be where the sensor reads its data and stores it in a local variable. This is called by the [State
](State) class every tick. The sensors should refrain from making calls over SPI or I2C outside this function to prevent bus contention. - The sensor type interfaces (like
GPS.h
andIMU.h
) override thegetType()
andgetTypeString()
functions rather than leaving it to the fully derived implementation. This just makes it a bit easier to use. - The
Sensor
class has a dependency on our customRecordData
library for logging data to the SD card, allowing all derived classes to easily record data.