Getting sensor data

By design, the sensor fusion modules of path manager and attitude manager are the only consumers of sensor data. No other module should be accessing the sensor instances.

Within the sensor fusion modules, instances of each required sensor class are created and data is pulled from them by using the getResult() method. Here is an example:

 

#include "IMU.hpp" #include "gps.hpp" /*********************************************************************************************************************** * Variables **********************************************************************************************************************/ static IMU *imuObj; static Gps *gpsObj; /*********************************************************************************************************************** * Code **********************************************************************************************************************/ void SensorFusion_Init(void) { imuObj = ICM20602::GetInstance(); gpsObj = NEOM8 ::GetInstance(); } void SensorFusion_Execute(SensorResult *sensResult) { IMUData_t imuData = imuObj->etResult(); GpsData_t GpsData = gpsObj->getResult(); sensResult.result = DoCrazyMath(&imuData, &GpsData); }

 

Testing Sensor fusion algorithms

 

Developers of sensor fusion modules need a good way to test their algorithms. That means they need a way to decouple themselves from the hardware when they’re testing with banks of data. The way to do that is to write a derived sensor class that inherits from the abstract base class that exists at every sensor’s interface. The derived class can pull data from a file, matlab model, or wherever the bank of test data exists instead of from hardware.

That derived class can be placed inside the sensor interface file along with all the other derived classed.

I’ve modified the example above to show how this should be done.

#include "IMU.hpp" #include "gps.hpp" /*********************************************************************************************************************** * Variables **********************************************************************************************************************/ static IMU *imuObj; static Gps *gpsObj; /*********************************************************************************************************************** * Code **********************************************************************************************************************/ void SensorFusion_Init(void) { #ifdef TARGET_BUILD imuObj = ICM20602::GetInstance(); gpsObj = NEOM8 ::GetInstance(); #elif defined(TEST_BUILD) imuObj = matlabIMU::GetInstance(); gpsObj = matlabGps::GetInstance(); #endif } void SensorFusion_Execute(SensorResult *sensResult) { IMUData_t imuData = imuObj.getResult(); GpsData_t GpsData = gpsObj.getResult(); sensResult.result = DoCrazyMath(&imuData, &GpsData); }