Search code examples
c++constructorarduinosensorsmotion

Initialising a C++ library in Arduino


I'm trying to use this six axis complementary filter library to interpret data from the LSM6DS3 motion sensor.

Calling it inside my Arduino sketch, I get this error. Sorry for the dumb question, I'm just starting out learning this:

#include "SparkFunLSM6DS3.h" 
#include "Wire.h"
#include "SPI.h"
#include "six_axis_comp_filter.h"


LSM6DS3 myIMU; // Constructor for the motion sensor (this works)
CompSixAxis test; // this breaks

when I try to initialise an instance of the CompSixAxis class it gives me this error:

no matching function for call to 'CompSixAxis::CompSixAxis()'


Solution

  • The class CompSixAxis dose not have a default constructor. This means you cannot use it like

    CompSixAxis test;
    

    As that requires a default constructor. In order to construct the object you will need to use the constructor with the form

    CompSixAxis(float deltaTime, float tau);
    

    So your updated code would look like

    CompSixAxis test(some_value, some_other_value);