Hello.
I am going to build a quadcopter by myself.
As a Reciever i want to use a nRF24L01 module like the "cheap-ass quadcopter" by iforce2d (Youtube).
I downloaded his reciever sketch, but in his sketch the "reciever" transmittes a "safe" Signal to the FlightController, when the nRF24l01 recieves nothing.
My Goal is, that the reciever sends nothing to the FC, if the nRF recieves nothing, to use the Failsafe mode of the FC.
I am not a good coder (beginning in school).
This is, what i did:
Original:
if ( now - lastRecvTime > 1000 ) {
// signal lost?
resetData();
}
void resetData()
{
// 'safe' values to use when no radio input is detected
data.throttle = 0;
data.yaw = 127;
data.pitch = 127;
data.roll = 127;
setPPMValuesFromData();
}
I changed to:
if ( now - lastRecvTime > 1000 ) {
// signal lost?
failSafe();
}
void failSafe(){
while (!radio.available()){
delay(100);
}
setPPMValuesFromData();
}
Do you think, this works?
The Idea is, to wait 100ms an then check again for signals.
I cannot test it, because the modules didn't arrive yet. Original Youtube Video
I don't think your solution is satisfactory. The delay() function should never be used in any program that needs to be responsive - and what needs that more than a quadcopter.
My second thought is that it may be sufficient to comment-out all the code in the resetData() function so it does nothing.
My third thought is that a much more sophisticated solution may be needed to avoid a crash.
If you really do need something with a time interval look at how millis() is used to manage timing in Several Things at a Time
Robin2:
I don't think your solution is satisfactory. The delay() function should never be used in any program that needs to be responsive - and what needs that more than a quadcopter.
My second thought is that it may be sufficient to comment-out all the code in the resetData() function so it does nothing.
My third thought is that a much more sophisticated solution may be needed to avoid a crash.
If you really do need something with a time interval look at how millis() is used to manage timing in Several Things at a Time
...R
Thanks a Lot!
Good to know, that delay is a bad Idea, i didn't knew this.
I may try your second thought Edit: If i comment it out, it will keep sending the latest Values to the Flight controller
To your third thought: If the Flight Controller gets no signal from the Reciever (this is, what i am trying to do) it uses GPS to return to where it startet
PaulS:
No. If there is no radio signal, do nothing for 1/10th of a second. Repeat until there IS a radio signal, then land. Clearly, that is a BAD idea.
The original code was correct. Why did you change it? Other than giving the function a better name, your changes were detrimental.
This is exactly, what i want.
This is just the code for the reciever.
In the original code the Reciever would send "safe" Values to the Flight Controller.
What i want is, that the Reciever sents NOTHING.
The FlightController recognizes, when there is no input and flies to where it startet.
macrrec:
Edit: If i comment it out, it will keep sending the latest Values to the Flight controller
In that case we need to know a lot more about the program. So far you have only posted snippets.
You probably also need to consider how to deal with the situation where the missing signal reappears - perhaps briefly.
If there is an independent fail-safe system my inclination would be to cause the Aduino program to stop for ever if the signal is lost for a pre-defined time. Otherwise you run the risk of the fail-safe system and the Arduino fighting each other.
If you really need to make the Arduino stop sending stuff you could just make an endless loop that could only be stopped by switching off the Arduino
void failSafe(){
while(1);
}
I don't know if it would be wise to do some "clean-up" before going into the endless loop.