Submarine failsafe

I thought I should start this thread again as the last was getting confusing (for me)

My submarine sketch is complete, other than for a failsafe routine. The attached sketch is the full routine with lines added at 8, and 184 – 197, based on some code I was provided here. I have a 36 MHZ Tx, and when it is turned off the input, normally between 1100 and 1900, fluctuates wildly, so it should be perfect for failsafe pick up.

The lines I have added are working on 4 seconds. When I load the sketch everything operates perfectly until 4 seconds. Then failsafe is activated without the Tx being turned off. I clearly need to add something to these lines about the Rx input fluctuations, but where do these go? I want everything to work normally until the Tx is turned off, then after 4 seconds failsafe is activated. It is a sub so a lag is fine.

Cheers John.. this thing is nearly done!

subsketchlatest15failsafe.ino (19.7 KB)

I've got eye-ache.
Please format your code before posting.

The code at lines 184... is the right sort of thing.

Serial.available() reports how many characters are in the input buffer. It has nothing to do with a connection. You can have a valid connection that is intentionally not sending anything.

Perhaps you need to arrange to send something every second (say) so that the failsafe time period is reset. You can easily arrange for the Arduino to ignore these data if that is what you want.

...R

I haven't even got to the code yet, as I'm trying to make sense of grammar in the post.

johnredearth wrote:

I have a 36 MHZ Tx, and when it is turned off the input, normally between 1100 and 1900, fluctuates wildly, so it should be perfect for failsafe pick up

Let's break this down.
You have a 36MHz transmitter, correct?
Where in relation to the Arduino is this gear and how is it connected to the Arduino?
Is the 36MHz effecting the Arduino as in RFI?

You say,

and when it is turned off the input

what input to what ?

Then you say,

normally between 1100 and 1900, fluctuates wildly

what is normal, what is 1100 and 1900, is it time, frequency or light years?

Then you say,

so it should be perfect for failsafe pick up

what on Earth are you talking about?

Can i suggest you provide far greater clarity about what you are describing and wanting to do?


Paul

Rockwallaby has posted the same questions as first came to mind when I read the first post. You need some method to determine that the "input" is "fluctuating wildly" Exactly what conditional statement would capture that, depends on which input you're reading and how you define fluctuating wildly.

I believe that I asked twice in the other thread where the serial input is coming from in this portion of code.

static unsigned long msLastRX;        //time of most recent reception
    
    if (Serial.available()){
        int servoAng = Serial.read();
        servoBallast.write(servoAng);
        msLastRX = millis();
    }
    
    if (millis() - msLastRX >= FAILSAFE_MS) {
        digitalWrite(PISTON_SURFACE_PIN, LOW); //do whatever you need here
        while (1);        //stops the sketch
    }

As it stands if you don't get any serial input for 4 seconds the system will enter the infinite while loop.

I also asked what you got in ServoAng as opposed to what you expected to get.

Can you please answer these questions here ?

You guys again… such happy fellows.

A Christmas cheer answer would be: ‘Wow, you have done fantastically given you only saw an arduino three months ago.’ Fortunately I don't need that.

A reword.. better grammar!

My submarine sketch is complete, other than for a failsafe routine. The attached sketch is the full routine with lines added at 8, and 184 - 197, based on some code I was provided here.

I have a 36 MHZ Tx, transmitting to a corresponding Rx, four channels of which are connected to the Arduino. The reading in the serial monitor of, for example ‘unballastin,’ as is the usual case I believe with RC, between 1100 and 1900. (1500 neutral) I do not know the nomenclature of the aforementioned numbers.

When I turn the transmitter off, the reading fluctuates wildly between 0-2000 at least.

What I want is code which recognises the transmitter when it is off, which can then in turn, turn on a failsafe function.

As it stands if you don't get any serial input for 4 seconds the system will enter the infinite while loop.

I also asked what you got in ServoAng as opposed to what you expected to get.


I don’t know anything about ServoAng. I tried to print it but it is undeclared. I really don’t understand the code. I don’t know what I expected. Therefore I can’t, and couldn’t previously, answer the questions.


Is the 36MHz effecting the Arduino as in RFI? (Could you please spell out acronyms pls).I guess you mean the receiver?

Sorry about your eyes. I have to attach it like that as it is too big otherwise. Would you like me to change the font?

As a final point I tried to ask a question a couple of weeks ago about some code to respond to a ‘double click.’ I really got abused. I tried again and someone, in a couple of lines answered my question, without sore eyes or anything. Is he out there now?

Sorry about your eyes. I have to attach it like that as it is too big otherwise. Would you like me to change the font?

No, I want you to use the auto-format tool before you post it.

As a final point I tried to ask a question a couple of weeks ago about some code to respond to a 'double click.' I really got abused. I tried again and someone, in a couple of lines answered my question, without sore eyes or anything. Is he out there now?

Link?

I don't know anything about ServoAng. I tried to print it but it is undeclared.

    int servoAng = Serial.read();

No, it's right there.

What I want is code which recognises the transmitter when it is off, which can then in turn, turn on a failsafe function.

Let's start at the beginning. Write a small sketch (***) to read each of the receiver outputs using the pulseIn() function and print the results to the serial monitor in columns across the serial monitor.

As you move the pots and/or switches on the transmitter the values displayed should vary.
Now turn the transmitter off. What happens to the values ?

*** Here is an early (untested) Christmas present

const byte inputPins[] = {2, 3, 4, 5, 6, 7}; //assume 6 channels for now

void setup()
{
  Serial.begin(115200);
  for (int p = 0; p < 6; p++)
  {
    pinMode(inputPins[p], INPUT);
  }
}

void loop()
{
  for (int p = 0; p < 6; p++)
  {
    Serial.print(pulseIn(inputPins[p], HIGH, 100));
    Serial.print("\t");
  }
  Serial.println();
}

Match the baud rate in the program with that in the serial monitor. Connect your receiver outputs to Arduino pins 2 to 7 and GND on the Arduino to GND on the receiver. Run the program. What do you see ?

Johnredearth:
You guys again… such happy fellows.

I thought I was being constructive in Reply #2

...R

As far as I can see, you're only using Serial for debugging on land - it won't get you anything when the submarine is submerged. Which means, I think, that you just need to detect an out of range condition on the one or more of the radio channels. Since you already have those, I think that this will do what you need:

  if (bUpdateFlags & BALLAST_FLAG) 
    {
    if (servoBallast.readMicroseconds() != unBallastIn) 
      {
      if(unBallastIn >= 1100 && unBallastIn <=1900) // These values may need tweaking to give a bit more leeway before invoking the failsafe
        {
        servoBallast.writeMicroseconds(unBallastIn);
        }
      else 
        {
 Failsafe(); // Call (as yet) nonexistant fail safe function
        }   
      }
    }

Thanks all. I have enough here to get the right answer. Will let you know when it does, although not sure I want to post it again. :astonished:

WildBill: What you say makes sense. I will work on that and construct what I need. Will let you know. The fact is though the boat will receive a signal down to 2 meters at least given that the Tx is 36 MHZ. They are being phased out in favour of 2.4 Ghz, which will not penetrate water. :confused:

Robin2 yes you were constructive thankyou. I didn’t mean to get you in the collateral damage

UKHeliBob I will do this. It may be the most successful

Comment: No, it's right there… re servoAng.. Well the IDE is telling me it’s not.

Comment: No, I want you to use the auto-format tool before you post it…. I didn’t know that this tool existed. Now I have found it thanks to your courteous direction, I will use it. Once again, sorry bout the eyes.

Have a lovely Christmas.. I mean it..

Comment: No, it's right there… re servoAng.. Well the IDE is telling me it's not.

Well, you've got to be really careful with that shift key.

Your system doesn't have anything to read on the serial port. You're capturing radio control signals via interrupts, not serial, presumably down to the two meters you mention since it remains controllable underwater.

So if you base your failsafe on four seconds of silence from serial input that will never arrive, small wonder that it triggers as soon as the four seconds are up.

Just as a totally separate issue. Sound travels much better in water than in air. So I'm wondering if you could perhaps embed control signals using audio for deeper penetration. It would certainly reach much further than any radio signal.

So if you base your failsafe on four seconds of silence from serial input that will never arrive, small wonder that it triggers as soon as the four seconds are up.

He has been told that several times in two threads on the subject but has never responded apart from increasing the delay from 1 second to 4 seconds.