|
|
@ -5,7 +5,7 @@ void init_pids() |
|
|
|
// this creates symmetry with the P gain value preventing oscillations |
|
|
|
// this creates symmetry with the P gain value preventing oscillations |
|
|
|
|
|
|
|
|
|
|
|
max_stabilize_dampener = pid_stabilize_roll.kP() * 2500; // = 0.6 * 2500 = 1500 or 15° |
|
|
|
max_stabilize_dampener = pid_stabilize_roll.kP() * 2500; // = 0.6 * 2500 = 1500 or 15° |
|
|
|
max_yaw_dampener = pid_yaw.kP() * 6000; // .5 * 6000 = 3000 |
|
|
|
max_yaw_dampener = pid_yaw.kP() * 6000; // .5 * 6000 = 3000 |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -16,8 +16,6 @@ void output_stabilize() |
|
|
|
long rate; |
|
|
|
long rate; |
|
|
|
int dampener; |
|
|
|
int dampener; |
|
|
|
|
|
|
|
|
|
|
|
//pitch_sensor = roll_sensor = 0; // testing only |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// control +- 45° is mixed with the navigation request by the Autopilot |
|
|
|
// control +- 45° is mixed with the navigation request by the Autopilot |
|
|
|
// output is in degrees = target pitch and roll of copter |
|
|
|
// output is in degrees = target pitch and roll of copter |
|
|
|
rc_1.servo_out = rc_1.control_mix(nav_roll); |
|
|
|
rc_1.servo_out = rc_1.control_mix(nav_roll); |
|
|
@ -30,14 +28,10 @@ void output_stabilize() |
|
|
|
roll_error = constrain(roll_error, -2500, 2500); |
|
|
|
roll_error = constrain(roll_error, -2500, 2500); |
|
|
|
pitch_error = constrain(pitch_error, -2500, 2500); |
|
|
|
pitch_error = constrain(pitch_error, -2500, 2500); |
|
|
|
|
|
|
|
|
|
|
|
//Serial.printf("s: %d \t mix %d, err %d", (int)roll_sensor, (int)rc_1.servo_out, (int)roll_error); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// write out angles back to servo out - this will be converted to PWM by RC_Channel |
|
|
|
// write out angles back to servo out - this will be converted to PWM by RC_Channel |
|
|
|
rc_1.servo_out = pid_stabilize_roll.get_pid(roll_error, deltaMiliSeconds, 1.0); |
|
|
|
rc_1.servo_out = pid_stabilize_roll.get_pid(roll_error, deltaMiliSeconds, 1.0); |
|
|
|
rc_2.servo_out = pid_stabilize_pitch.get_pid(pitch_error, deltaMiliSeconds, 1.0); |
|
|
|
rc_2.servo_out = pid_stabilize_pitch.get_pid(pitch_error, deltaMiliSeconds, 1.0); |
|
|
|
|
|
|
|
|
|
|
|
//Serial.printf("\tpid: %d", (int)rc_1.servo_out); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// We adjust the output by the rate of rotation: |
|
|
|
// We adjust the output by the rate of rotation: |
|
|
|
// Rate control through bias corrected gyro rates |
|
|
|
// Rate control through bias corrected gyro rates |
|
|
|
// omega is the raw gyro reading |
|
|
|
// omega is the raw gyro reading |
|
|
@ -45,16 +39,11 @@ void output_stabilize() |
|
|
|
// Limit dampening to be equal to propotional term for symmetry |
|
|
|
// Limit dampening to be equal to propotional term for symmetry |
|
|
|
rate = degrees(omega.x) * 100; // 6rad = 34377 |
|
|
|
rate = degrees(omega.x) * 100; // 6rad = 34377 |
|
|
|
dampener = ((float)rate * stabilize_dampener); // 34377 * .175 = 6000 |
|
|
|
dampener = ((float)rate * stabilize_dampener); // 34377 * .175 = 6000 |
|
|
|
rc_1.servo_out -= constrain(dampener, -max_stabilize_dampener, max_stabilize_dampener); // limit to 1500 |
|
|
|
rc_1.servo_out -= constrain(dampener, -max_stabilize_dampener, max_stabilize_dampener); // limit to 1500 based on kP |
|
|
|
|
|
|
|
|
|
|
|
rate = degrees(omega.y) * 100; // 6rad = 34377 |
|
|
|
rate = degrees(omega.y) * 100; // 6rad = 34377 |
|
|
|
dampener = ((float)rate * stabilize_dampener); // 34377 * .175 = 6000 |
|
|
|
dampener = ((float)rate * stabilize_dampener); // 34377 * .175 = 6000 |
|
|
|
rc_2.servo_out -= constrain(dampener, -max_stabilize_dampener, max_stabilize_dampener); // limit to 1500 |
|
|
|
rc_2.servo_out -= constrain(dampener, -max_stabilize_dampener, max_stabilize_dampener); // limit to 1500 based on kP |
|
|
|
|
|
|
|
|
|
|
|
//Serial.printf(" yaw out: %d, d: %d", (int)rc_4.angle_to_pwm(), yaw_dampener); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Serial.printf("\trd: %d", roll_dampener); |
|
|
|
|
|
|
|
//Serial.printf("\tlimit: %d, PWM: %d", rc_1.servo_out, rc_1.angle_to_pwm()); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void |
|
|
|
void |
|
|
@ -66,30 +55,32 @@ clear_yaw_control() |
|
|
|
yaw_error = 0; |
|
|
|
yaw_error = 0; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void output_yaw_with_hold(boolean hold) |
|
|
|
void output_yaw_with_hold(boolean hold) |
|
|
|
{ |
|
|
|
{ |
|
|
|
Vector3f omega = dcm.get_gyro(); |
|
|
|
Vector3f omega = dcm.get_gyro(); |
|
|
|
|
|
|
|
|
|
|
|
if(hold){ |
|
|
|
if(hold){ |
|
|
|
// yaw hold |
|
|
|
// yaw hold |
|
|
|
|
|
|
|
|
|
|
|
if(rate_yaw_flag){ |
|
|
|
if(rate_yaw_flag){ |
|
|
|
// we are still in motion from rate control |
|
|
|
// we are still in motion from rate control |
|
|
|
if(fabs(omega.y) < .15){ |
|
|
|
if(fabs(omega.y) < .15){ |
|
|
|
//Serial.print("trans "); |
|
|
|
|
|
|
|
clear_yaw_control(); |
|
|
|
clear_yaw_control(); |
|
|
|
hold = true; // just to be explicit |
|
|
|
hold = true; // just to be explicit |
|
|
|
}else{ |
|
|
|
}else{ |
|
|
|
//Serial.print("coast "); |
|
|
|
|
|
|
|
// return to rate control until we slow down. |
|
|
|
// return to rate control until we slow down. |
|
|
|
hold = false; |
|
|
|
hold = false; |
|
|
|
} |
|
|
|
} |
|
|
|
}else{ |
|
|
|
}else{ |
|
|
|
//Serial.print("hold "); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} else { |
|
|
|
}else{ |
|
|
|
//Serial.print("rate "); |
|
|
|
|
|
|
|
// rate control |
|
|
|
// rate control |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// this indicates we are under rate control, when we enter Yaw Hold and |
|
|
|
|
|
|
|
// return to 0° per second, we exit rate control and hold the current Yaw |
|
|
|
rate_yaw_flag = true; |
|
|
|
rate_yaw_flag = true; |
|
|
|
yaw_error = 0; |
|
|
|
yaw_error = 0; |
|
|
|
} |
|
|
|
} |
|
|
@ -100,6 +91,8 @@ void output_yaw_with_hold(boolean hold) |
|
|
|
|
|
|
|
|
|
|
|
// limit the error we're feeding to the PID |
|
|
|
// limit the error we're feeding to the PID |
|
|
|
yaw_error = constrain(yaw_error, -6000, 6000); // limit error to 60 degees |
|
|
|
yaw_error = constrain(yaw_error, -6000, 6000); // limit error to 60 degees |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Apply PID and save the new angle back to RC_Channel |
|
|
|
rc_4.servo_out = pid_yaw.get_pid(yaw_error, deltaMiliSeconds, 1.0); // .5 * 6000 = 3000 |
|
|
|
rc_4.servo_out = pid_yaw.get_pid(yaw_error, deltaMiliSeconds, 1.0); // .5 * 6000 = 3000 |
|
|
|
|
|
|
|
|
|
|
|
// We adjust the output by the rate of rotation |
|
|
|
// We adjust the output by the rate of rotation |
|
|
@ -109,20 +102,16 @@ void output_yaw_with_hold(boolean hold) |
|
|
|
// Limit dampening to be equal to propotional term for symmetry |
|
|
|
// Limit dampening to be equal to propotional term for symmetry |
|
|
|
rc_4.servo_out -= constrain(dampener, -max_yaw_dampener, max_yaw_dampener); // -3000 |
|
|
|
rc_4.servo_out -= constrain(dampener, -max_yaw_dampener, max_yaw_dampener); // -3000 |
|
|
|
|
|
|
|
|
|
|
|
}else{ |
|
|
|
}else{ |
|
|
|
//yaw_error = 0; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// rate control |
|
|
|
// rate control |
|
|
|
|
|
|
|
|
|
|
|
long rate = degrees(omega.z) * 100; // 3rad = 17188 , 6rad = 34377 |
|
|
|
long rate = degrees(omega.z) * 100; // 3rad = 17188 , 6rad = 34377 |
|
|
|
rate = constrain(rate, -36000, 36000); // limit to something fun! |
|
|
|
rate = constrain(rate, -36000, 36000); // limit to something fun! |
|
|
|
long error = ((long)rc_4.control_in * 6) - rate; // control is += 6000 |
|
|
|
long error = ((long)rc_4.control_in * 6) - rate; // control is += 6000 * 6 = 36000 |
|
|
|
// -error = CCW, +error = CW |
|
|
|
// -error = CCW, +error = CW |
|
|
|
rc_4.servo_out = pid_acro_rate_yaw.get_pid(error, deltaMiliSeconds, 1.0); // .075 * 36000 = 2700 |
|
|
|
rc_4.servo_out = pid_acro_rate_yaw.get_pid(error, deltaMiliSeconds, 1.0); // .075 * 36000 = 2700 |
|
|
|
rc_4.servo_out = constrain(rc_4.servo_out, -2400, 2400); // limit to 2400 |
|
|
|
rc_4.servo_out = constrain(rc_4.servo_out, -2400, 2400); // limit to 2400 |
|
|
|
|
|
|
|
|
|
|
|
// this indicates we are under rate control, when we enter Yaw Hold and |
|
|
|
|
|
|
|
// return to 0° per second, we exit rate control and hold the current Yaw |
|
|
|
|
|
|
|
//rate_yaw_flag = true; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|