Skip to content

Commit

Permalink
Better aircraft enable. Tuning PID
Browse files Browse the repository at this point in the history
  • Loading branch information
0xjairo committed Apr 8, 2012
1 parent 3497566 commit 27ffb9e
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,10 @@ int main(void) {
uint32 t_prev, dt;
uint32 cpu_util, cpu_util2;
uint32 tick50hz = 0;

bool throttle_enable;

float uRoll, uPitch, uYaw, uThrottle;
float KpRoll, KiRoll, KdRoll;
float m1, m2, m3;
float pidRoll, pidPitch, pidYaw;
float servoAngle;
Expand All @@ -81,15 +83,12 @@ int main(void) {
t_prev = 0;
uRoll = 0;


KpRoll = 0.00005; //rc.get_channel(CH_AUX1)*0.001; //
KiRoll = 0; //rc.get_channel(CH_AUX2)*0.001;
KdRoll = -0.000004; //rc.get_channel(CH_AUX3)*-0.00005;

rollCtrl.set_gains(KpRoll, KiRoll, KdRoll);
pitchCtrl.set_gains(KpRoll, KiRoll, KdRoll);
rollCtrl.set_gains( 0.0004, 0.00, 0.00000);
pitchCtrl.set_gains( 0.0005, 0.00, 0.00000);
yawCtrl.set_gains(1.0, 0, 0);

throttle_enable = 0;

while (1) {

t = micros();
Expand All @@ -102,6 +101,8 @@ int main(void) {
rc.update(); // update RC commands
ahrs.update();

throttle_enable = (rc.get_channel(CH_AUX4) > 0.5 && rc.status() == SUCCESS);

if (rc.status() == SUCCESS) {
uThrottle = rc.get_channel(CH_THROTTLE);
uRoll = 100 * (rc.get_channel(CH_ROLL) - 0.5);
Expand Down Expand Up @@ -133,7 +134,7 @@ int main(void) {
m3 = uThrottle + ( 0) * (pidRoll) + (+4.0/3.0) * pidPitch;

yawServo.set_offset(servoAngle);
if (rc.get_channel(CH_AUX4) > 0.5 && rc.status() == SUCCESS) {
if (throttle_enable) {
set_rotor_throttle(1, m1);
set_rotor_throttle(2, m2);
set_rotor_throttle(3, m3);
Expand All @@ -146,7 +147,10 @@ int main(void) {

// 10Hz loop
if (tick50hz % 5 == 0) {
toggleLED();
if(throttle_enable)
toggleLED();
else
digitalWrite(BOARD_LED_PIN, 0);
}

// 2Hz loop
Expand Down

0 comments on commit 27ffb9e

Please sign in to comment.