Hello fellow programmers!
I have been playing around with a couple quad-projects lately, and as my flight-controller broke yesterday I just ordered a new one. Meanwhile, I was thinking about using my Arduino Uno as a flight-controller (although without any kind of stabilization-modes).
So all I want the Uno to do is basically to recieve signals from the reciever, and calculate these signals so that it will be able to control the 4 motors the way I want it to.
I am a terrible rookie with programming, and my Arduino-skills are very limited. I'm quite sure there is an easier way of creating my program, as my program seem to be kindof "heavy" and makes the Uno slow and a little bugged. Not sure about this though, that's why I wanted to ask the more experienced people in here
Here is my program anyway. Don't mind what I chose to call the different channels, as I'm not sure what to call them!(elevator, yaw, etc)
#include <Servo.h>
Servo motor1, motor2, motor3, motor4;
int thrin = 2;
int elein = 3;
int rudin = 4;
int ailin = 5;
int thr;
int ele;
int rud;
int ail;
int M1;
int M2;
int M3;
int M4;
int gain = 5;
int lol1 = 0;
int lol2 = 0;void setup () {
motor1.attach(8);
motor2.attach(9);
pinMode(thrin, INPUT);
pinMode(elein, INPUT);
pinMode(rudin, INPUT);
pinMode(ailin, INPUT);
}void loop() {
thr = map(pulseIn(thrin, HIGH, 25000), 1000, 2000, 0, 100);
ele = map(pulseIn(elein, HIGH, 25000), 1000, 2000, -gain, gain);
rud = map(pulseIn(rudin, HIGH, 25000), 1000, 2000, -gain, gain);
ail = map(pulseIn(ailin, HIGH, 25000), 1000, 2000, -gain, gain);
M1 = constrain(map(thr + ele + rud, 0, 100, 1000, 2000), 1000, 2000);
M2 = constrain(map(thr - ele + rud, 0, 100, 1000, 2000), 1000, 2000);
M3 = constrain(map(thr - ele - rud, 0, 100, 1000, 2000), 1000, 2000);
M4 = constrain(map(thr + ele - rud, 0, 100, 1000, 2000), 1000, 2000);
motor1.write(M1);
motor2.write(M2);
}
Rudder is supposed to be pitch(?), not rudder. I did not yet include rudder as this is only a test-program. First I need to optimize the program!
I only included Motor 1 and Motor 2 for now, as it is only a test. I would like to recieve inputs on how I can make my program better and quicker, and easier for the Uno-board to work with. Tried to Google around, without any success on finding exactly what I want.
Any tips/inputs will be greatly appreciated, thanks in advance!
And BTW, I'm new to the forum and by some reason it won't work in Internet Explorer, only Firefox. I can access your forum in IE if im logged out, but as soon as I log in I can visit all of the Arduino-pages, except the forum-part. Any thoughts on why?
Sorry about a messy post.
Thanks again.
edit: Forgot to mention that the program does work with reciever connected. When I turn left on the RC-control, the quad will turn left, and so on.