I'm currently working on some software to drive the ESCs for a quadcopter. Within my ESC class, I need to initialise the PWM pins and wait around 5s for the ESCs to validate, before sending any other throttle values to them.
At the moment, my class stands as follows.
In ESC.h
class ESC
{
private:
int ESCPin;
bool ESCInitialised;
//Timer Objects
SimpleTimer startupTimer;
void endInit();
public:
void initESC(int pin);
bool isInitialised() const { return ESCInitialised; };
void setPWM(uint16_t dut);
};
In ESC.cpp
#include "ESC.h"
void ESC::initESC(int pin){
ESCInitialised = false;
ESCPin = pin;
InitTimersSafe();
SetPinFrequency(ESCPin, 500);
pwmWriteHR(ESCPin,32768);
startupTimer.setTimeout(5000, endInit);
}
void ESC::setPWM(uint16_t dut){
pwmWriteHR(ESCPin, dut);
}
void ESC::endInit(){
ESCInitialised = true;
}
I want the ESCInitialised boolean to remain private, as it shouldn't be modifiable by any other class, so I'm using the public getter method isInitialised() to return it. Once the one-shot timer has ended, it should call the endInit() function to set the ESCinitialised bool to true, so that the main code can determine when to pass new throttle values through.
In its current state, I am receiving the error
In static member function 'static void ESC::endInit()':
ESC.h:14: error: invalid use of member 'ESC::ESCInitialised' in static
member function
bool ESCInitialised;
Any advice would be much appreciated.