I am working on creating an autonomous quad copter. I am trying to make a kill switch with the radio controller I have.
My Thoughts:
Create and interrupt and connect the receiver to the interrupt pin(pin 2) of the Arduino Mega.
So I will have the Throttle stick of the radio controller all the way up and when I want to kill the quad copter I would move the stick down or too a "low". This will in turn queue the interrupt and turn the motors off on the quad copter off.
After trying this I had no success. I believe it is due to the pin not being able to read the signal from the receiver to tell whether it has changed or not.
Is anyone able to help me code up with kill switch yo use?
kpelkey151:
Is anyone able to help me code up with kill switch yo use?
Having a stick position on the RC transmitter activate a 'kill' command is fine, but the way you're proposing to implement that on the Arduino side isn't sensible. You need the Arduino to receive the digital signal from the RC receiver, measure the pulse length and determine the stick position from that, and then compare that to a threshold value to see whether the stick is in the 'kill' position. Nothing about that involves any interrupts.
Hmmm, i will have to look into pulsein. You think an interrupt is not the best method? Just use a loop condition? I am not to use to arduino programming and figured that would be the best way. Where should I start?
Connect one of the receiver outputs to pin 7 and GND to GND. The serial output will vary with the Tx stick or switch position. Now you can take action, such as shutting down the motors, based on the value.
Note, however, that using the value from only one channel as a "kill" could be dangerous because it would be easy to trigger it by mistake. It would be better to read the value of two inputs and only if both of them were in the correct position, perhaps low throttle and full left rudder, disarm the system.
Ok, thank you for the example. I will have to look into whether I want to use multiple stick positions or not. Atm I would rather have it be killed easily.
Don't make it easy to do by mistake. Quads don't glide too well !
You will not be able to use an interrupt to interpret an RC input because it is a pwm signal which constantly alternates between HIGH and LOW, so catching it with an interrupt will be challenging.
UKHeliBob:
Note, however, that using the value from only one channel as a "kill" could be dangerous because it would be easy to trigger it by mistake. It would be better to read the value of two inputs and only if both of them were in the correct position, perhaps low throttle and full left rudder, disarm the system.
That's a good point. It would probably be a good idea to require the 'kill' command to remain active for some short period (e.g. one second) before it takes effect, so that any glitch in the RC signal doesn't wreck your project.
Have you considered having some way to detect whether your receiver is still generating a credible control signal? It might be useful to have a way of detecting when the RC system has failed, for example because the model has gone out of range. Obviously a kill switch that relied on the RC system would be useless in that situation.
Are you planning for the Arduino to control the transmitter and for that to control the quad in turn, or for the Arduino to be on the quad and directly in control of it ? I hope that whichever method you use the quad can be controlled by a human at a moment's notice and that human input always overrides the autonomous controls.
You could, of course, buy or make an Ardupilot and associated hardware such as the GPS receiver.
PeterH:
Have you considered having some way to detect whether your receiver is still generating a credible control signal? It might be useful to have a way of detecting when the RC system has failed, for example because the model has gone out of range. Obviously a kill switch that relied on the RC system would be useless in that situation.
I was planning on having the throttle stick up at max. So that if it did loose signal it would kill the quad since the signal would drop. It would not keep replicating a max throttle signal would it?
UKHeliBob:
Are you planning for the Arduino to control the transmitter and for that to control the quad in turn, or for the Arduino to be on the quad and directly in control of it ? I hope that whichever method you use the quad can be controlled by a human at a moment's notice and that human input always overrides the autonomous controls.
You could, of course, buy or make an Ardupilot and associated hardware such as the GPS receiver.
Have you got any experience of flying RC quads ?
Hi, my partner and I are doing this for a school project. We only have about 3 weeks to finish it up so we are not taking every "proper" step. So being able to set up a control for human input may be a little outside our time frame. Our project is to basically build an autonomous quadcopter. We are using a KK2.1 board to supply flight stabilization. We plan on attaching the arduino to the copter and have the arduino read in multiple HC-SR04 sonar sensors to create and altitude hold and obstacle avoidance. So that is where we need the kill switch in case it just starts flying away. The step after getting that done would be to implement a GPS system so that it can navigate from one point to another.
So far our progress was to be able to fly it with the remote control through the KK2 board. The other day we were able to replicate RC signals and control the motors with the arduino. We have yet to figure out what proper settings should be to make the quad go forward, backward and so on. We wanted to make sure we had a kill switch before we started testing any altitude hold code with the sensor. So any help or tips would be much appreciated.
kpelkey151:
I was planning on having the throttle stick up at max. So that if it did loose signal it would kill the quad since the signal would drop. It would not keep replicating a max throttle signal would it?
I think you have some more thinking to do here. The throttle servo output won't "drop" in the sense of moving to the zero throttle position if the receiver loses the radio signal. There are some expensive RC receivers which revert to a configured default state when they lose signal, but in my experience the common inexpensive receivers either stop putting out a signal completely, or put out erratic positions based on random noise, when they lose the transmitted radio signal. Depending what sort of motor controller you're using and how it's connected to the receiver that might well cause the controller to cut power (since it is no longer receiver a signal) but I wouldn't assume that unless you have actually tested it with your specific speed controller. In any case, if your throttle control signal is going from the receiver to the motor driver via the Arduino then the Arduino would likely continue to output a valid throttle control signal unless you design your sketch so that it turns off the motors when it loses the input signal.
To implement a 'kill' using the KK2 board you need to send low throttle and left yaw simultaneously. This puts the KK2 into safe mode as I expect you already know. In this state power is off to motors and it will not accept any further control inputs until it gets low throttle and right yaw which arms it again.
Frankly it scares the pants off me that you are proposing to let loose an autonomous quad with no way of controlling it manually. What size is this quad ? At least a 450 I imagine which implies quite a weight and size.