Help Setting Up Fail Safe

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?

What exactly is your RC receiver receiving? The seemingly obvious answer to your problem is for the receiver to know when the transmitter stops. Why have you not addressed this?

That is what I'm lost about as well. I would think nothing would be getting received and pulsein would time out, but that's not the case for some reason. The serial monitor just shows the same values over and over again while nothing is being received, and that is getting sent to the esc and the motors keep going when the transmitter is off. Not even a constant value either, it's whatever the last input was that keeps repeating.

I see no code reacting to that condition.

I see printing that may happen so frequently that it fills the print output buffer and slows everything down which pulseIn() does slow everything down as well.

In a trivial way I find myself wondering about why a hoverboard would have wheels?

The receiver manual is here: https://cdn.shopify.com/s/files/1/0609/8324/7079/files/R88.pdf

It says this about fail-safe:

FAIL-SAFE PROTECTION
1. Press the [BIND] button once within 10 seconds of the receiver being
powered ON, and the receiver will save all the current channel values
of the remote control as the fail-safe value

I could guess that for a model aircraft, a loss of transmission means that the receiver continues to issue a predefined command sequence to keep the thing stable until (hopefully) the link is restored.

For a hoverboard, I guess you want the thing to slow down to a stop if there is a transmission failure.

I don't actually see how, on the receiver, you identify a loss of transmission.

Failure to receive a pulse in code is quite easy. When you get a pulse set a timer. Continually monitor that timer to see if it gets stale and act if it does.

You didn't make it clear in your post, but perhaps the key is as quoted by @6v6gt:

FAIL-SAFE PROTECTION

  1. Press the [BIND] button once within 10 seconds of the receiver being
    powered ON, and the receiver will save all the current channel values
    of the remote control as the fail-safe value

I read that as you need to set your transmitter up to send the positions you would like the servos to go to in the event of loss of transmission, and then press the BIND button.

Maybe you did that, but it's not clear in your original post.

Time to get busy and fix your program so it works the way you want it to work!

What happens if you are on a hill and something happens to your signal?

I would not consider the Arduino "fail safe", it is a hobby computer.

The obvious answer is the manufacturers definition is fail safe means your model will still be able to limp home if the signal fails, while your definition is the model will crash and burn if the signal fails. I suspect the manufacturers definition sill allow more units to be sold that your definition.

Got it!

I initially had it bound with the D8 protocol and tried the fail-safe setup that was in that manual with throttle down and it was holding last recieved value while the transmitter was powered off.

Re-bound using the D16 protocol since I saw you can setup fail-safe on the transmitter. Did so with throttle down. Still was having the holding last recieved value issue.

Then while bound with D16, did the "press the bind button within 10 seconds to save current channel values" trick and it started working.

Now when I power off the transmitter, the values read 1000 for durationCh, and 0 for escvalue, which is exactly what I wanted. No extra coding required, nice! haha.

Not sure why switching protocols worked but it works so I don't really care and I'm happy. hahah.

Wow, what a very useful reply to someone new asking for help in a forum.

Definition depends on what you are trying to control and what is determined to be the safe state. Safe state is different depending on the vehicle. For example, an FPV drone without return to home functionality has a safe state of crash and burn. Falling out of the sky is prefered, rather than it throttling to who knows where at whatever speed. Which could be 80+mph. For large RC car, I'd prefer it to stop when signal is lost instead of continuing in whatever direction it's facing with no control. And this isn't a model being manufactured to sell units. Obviously. It's a rc reciever that you can put in anything. Obviously. So the safe is determined by the use. Obviously.

Or you might consider that what is posted on this forum isn't just for YOU even if no one else matters to you and there are no views but your own.

I was talking about that particular individual's replys in this particular post that were unhelpful and one was a straight up incorrect assumption, making it seem like it was "obvious" just made him look like a pretentious tool. And no where in what I said did I imply this forum was just for me, I don't understand where you are getting that. Other's supplied useful information and added to the conversation without just being condescending for.... yeah, can't think of a reason why someone would do that here when someone is asking for help and trying to problem solve as a group with people more experienced.

From you same way you are doubling down on ego now.