Nick
About to throw an arduino..*cough*F450 Master Race
Hello all,
Brand new to this quadcopter stuff. I've build a 450 quad using an Arduino Uno as the flight controller. Though the arduino has a PID library ( don't really understand how to integrate it into my code ), I am trying to code my own flight stabilizing algorithm but can't get it quite right.
Here is a snippet of code regarding the algorithm:
Basically, the algorithm is a graph of y=((x+16)^5/20596298).5 which looks like
It seems more stable with this than without any stabilization so I think it's a step in the right direction. It's not nearly stable enough to hover without being tethered to a table that I am testing on. Any suggestions on what to do? Just learn to use the PID library for the Arduino or am I going in the right direction?
ps. I put more effort into this post than most of my life's school work so someone heeeelp me.
Brand new to this quadcopter stuff. I've build a 450 quad using an Arduino Uno as the flight controller. Though the arduino has a PID library ( don't really understand how to integrate it into my code ), I am trying to code my own flight stabilizing algorithm but can't get it quite right.
Here is a snippet of code regarding the algorithm:
Code:
float angle_x = alpha*gyro_angle_x + (1.0 - alpha)*accel_angle_x; // Current Pitch of quad
float angle_y = alpha*gyro_angle_y + (1.0 - alpha)*accel_angle_y; // Current Roll of quad
raw = joystick[0]/11.25; // The Throttle input from 0 to 90
throttle[0] = raw+40-(stabilize(angle_x))-(stabilize(angle_y)); // Top Left motor
throttle[1] = raw+40-(stabilize(angle_x))+(stabilize(angle_y)); // Top right Motor
throttle[2] = raw+40+(stabilize(angle_x))+(stabilize(angle_y)); // Bottom Right Motor
throttle[3] = raw+40+(stabilize(angle_x))-(stabilize(angle_y)); // Bottom Left Motor
for (int motor = 0; motor <= 3; motor++) {
throttle[motor] = manageSpeed(throttle[motor]); // Run manageSpeed for each motor...
}
motor1.write(throttle[0]); //Write the throttle to the quad motors
motor2.write(throttle[1]);
motor3.write(throttle[2]);
motor4.write(throttle[3]);
double stabilize (double angle) { //function for the algorithm
double afterAngle = angle + 16;
if(angle<0){
return(-(abs(pow(afterAngle,5)/20596298)+.5)); // <---------- algorithm for negative angle!!!
}else{
return(abs(pow(afterAngle,5)/20596298)+.5); // <---------- algorithm for positive angle!!!
}
}
double manageSpeed(double theSpeed) //keeps the throttle between the min and max of the ESC
{
if(theSpeed <= 40){
return(40);
}
else if (theSpeed >= 110) {
return(110);
}
else {
return(theSpeed);
}
}
Basically, the algorithm is a graph of y=((x+16)^5/20596298).5 which looks like
It seems more stable with this than without any stabilization so I think it's a step in the right direction. It's not nearly stable enough to hover without being tethered to a table that I am testing on. Any suggestions on what to do? Just learn to use the PID library for the Arduino or am I going in the right direction?
ps. I put more effort into this post than most of my life's school work so someone heeeelp me.