Currently controlling 2 hoverboard wheels with an rc reciever input and running into a roadblock on how to set up fail safe.
I have everything working properly and thought I could just set the fail safe on the rc reciever but when I turn off the transmitter while everything is running to test it, the last read value keeps looping causing the wheels to keep spinning at a constant speed without any way to control it until the transmitter is reconnected.
RC receiver: Radiomaster R88
Speed controllers: RioRand 350W 6-60V PWM DC Brushless Electric Motor Speed Controller with Hall
The rc receiver documentation said you can set the fail safe by pressing the bind button within 10 seconds of powering on, but that did not solve anything. It's still repeating the last read value over and over again.
Thought I could try to do it with code, but not sure how to do it and would like some help. My first thought was to have an if statement say if the same value is read for a certain amount of time then to zero out the controls to stop the motors. Only issue with that would be if I want to maintain a constant speed in normal operations, it would fail safe without me wanting it to.
Below is my code.
int CH1In = 2; //Ch1 rc reciever to arduino
int CH1OutR = 3; //arduino to speedcontroller Right
int CH2In = 4; //Ch2 rc reciever to arduino
int CH2OutL = 5; //arduino to speedcontroller Right
unsigned long durationCH1; //Ch1 pwm from rc reciever
unsigned long durationCH1con; //constrained Ch1 to 1000-2000
unsigned long durationCH2; //Ch2 pwm from rc reciever
unsigned long durationCH2con; //constrained Ch2 to 1000-2000
int escvalueCH1; //Ch1 pwm value for analogwrite function for speed controller
int escvalueCH2; //Ch1 pwm value for analogwrite function for speed controller
void setup() {
Serial.begin(115200);
pinMode(CH1In, INPUT);
pinMode(CH1OutR, OUTPUT);
pinMode(CH2In, INPUT);
pinMode(CH2OutL, OUTPUT);
}
void loop() {
durationCH1 = pulseIn(CH1In, HIGH);
durationCH1con = constrain(durationCH1, 1000, 2000);
escvalueCH1 = map(durationCH1con, 1000, 2000, 0, 255);
analogWrite(CH1OutR, escvalueCH1);
durationCH2 = pulseIn(CH2In, HIGH);
durationCH2con = constrain(durationCH2, 1000, 2000);
escvalueCH2 = map(durationCH2con, 1000, 2000, 0, 255);
analogWrite(CH2OutL, escvalueCH2);
Serial.print(durationCH1con);
Serial.print(" ");
Serial.print(escvalueCH1);
Serial.print(" ");
Serial.print(durationCH2con);
Serial.print(" ");
Serial.println(escvalueCH2);
}
Any ideas?