|
@@ -40,90 +40,53 @@ bool Sub::althold_init()
|
|
|
|
|
|
void Sub::handle_attitude()
|
|
|
{
|
|
|
- uint32_t tnow = AP_HAL::millis();
|
|
|
-
|
|
|
- motors.set_desired_spool_state(AP_Motors::DesiredSpoolState::THROTTLE_UNLIMITED);
|
|
|
-
|
|
|
-
|
|
|
- float target_roll, target_pitch, target_yaw;
|
|
|
-
|
|
|
-
|
|
|
- if (tnow - sub.set_attitude_target_no_gps.last_message_ms < 5000) {
|
|
|
- Quaternion(
|
|
|
- set_attitude_target_no_gps.packet.q
|
|
|
- ).to_euler(
|
|
|
- target_roll,
|
|
|
- target_pitch,
|
|
|
- target_yaw
|
|
|
- );
|
|
|
- target_roll = 100 * degrees(target_roll);
|
|
|
- target_pitch = 100 * degrees(target_pitch);
|
|
|
- target_yaw = 100 * degrees(target_yaw);
|
|
|
- last_roll_s = target_roll;
|
|
|
- last_pitch_s = target_pitch;
|
|
|
- last_yaw_s = target_yaw;
|
|
|
-
|
|
|
- attitude_control.input_euler_angle_roll_pitch_yaw(target_roll, target_pitch, target_yaw, true);
|
|
|
- } else {
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- int32_t pitch_input = 0;
|
|
|
-
|
|
|
-
|
|
|
- if (prepare_state == Horizontal)
|
|
|
- {
|
|
|
- pitch_input = 0;
|
|
|
- target_roll = 0;
|
|
|
- target_yaw = get_pilot_desired_yaw_rate(channel_yaw->get_control_in());
|
|
|
- }else if(prepare_state == Vertical)
|
|
|
- {
|
|
|
- pitch_input = -8000;
|
|
|
- target_roll = ((float)channel_yaw->get_control_in()*0.6);
|
|
|
-
|
|
|
- target_yaw = 0;
|
|
|
- }
|
|
|
- else{
|
|
|
- pitch_input = 0;
|
|
|
- }
|
|
|
- pitch_input_inc = constrain_int32(pitch_input,-9000,9000);
|
|
|
-
|
|
|
-
|
|
|
- if (abs(target_roll) > 300 ){
|
|
|
- attitude_control.input_rate_bf_roll_pitch_yaw(target_roll, 0, 0);
|
|
|
- last_yaw_s = ahrs.yaw_sensor;
|
|
|
- last_roll_s = ahrs.roll_sensor;
|
|
|
- last_input_ms_stable = tnow;
|
|
|
-
|
|
|
- }else if (abs(target_yaw) > 300) {
|
|
|
-
|
|
|
- attitude_control.input_rate_bf_roll_pitch_yaw(0, 0, target_yaw);
|
|
|
- last_yaw_s = ahrs.yaw_sensor;
|
|
|
-
|
|
|
- last_input_ms_stable = tnow;
|
|
|
- } else if (tnow < last_input_ms_stable + 250) {
|
|
|
-
|
|
|
- last_yaw_s = ahrs.yaw_sensor;
|
|
|
-
|
|
|
- attitude_control.input_rate_bf_roll_pitch_yaw(0, 0, 0);
|
|
|
- } else {
|
|
|
-
|
|
|
- attitude_control.input_euler_angle_roll_pitch_yaw(last_roll_s, (float)pitch_input_inc, last_yaw_s, true);
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- static int f = 0;
|
|
|
- f++;
|
|
|
- if(f>800)
|
|
|
- {
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- f=0;
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
+ uint32_t tnow = AP_HAL::millis();
|
|
|
+
|
|
|
+
|
|
|
+ float target_roll, target_pitch, target_yaw;
|
|
|
+
|
|
|
+
|
|
|
+ if (tnow - sub.set_attitude_target_no_gps.last_message_ms < 5000) {
|
|
|
+ Quaternion(
|
|
|
+ set_attitude_target_no_gps.packet.q
|
|
|
+ ).to_euler(
|
|
|
+ target_roll,
|
|
|
+ target_pitch,
|
|
|
+ target_yaw
|
|
|
+ );
|
|
|
+ target_roll = 100 * degrees(target_roll);
|
|
|
+ target_pitch = 100 * degrees(target_pitch);
|
|
|
+ target_yaw = 100 * degrees(target_yaw);
|
|
|
+ last_roll = target_roll;
|
|
|
+ last_pitch = target_pitch;
|
|
|
+ last_yaw = target_yaw;
|
|
|
+
|
|
|
+ attitude_control.input_euler_angle_roll_pitch_yaw(target_roll, target_pitch, target_yaw, true);
|
|
|
+ } else {
|
|
|
+
|
|
|
+ get_pilot_desired_lean_angles(channel_roll->get_control_in(), channel_pitch->get_control_in(), target_roll, target_pitch, attitude_control.get_althold_lean_angle_max());
|
|
|
+
|
|
|
+ target_yaw = get_pilot_desired_yaw_rate(channel_yaw->get_control_in());
|
|
|
+ if (abs(target_roll) > 300 || abs(target_pitch) > 300) {
|
|
|
+ last_roll = ahrs.roll_sensor;
|
|
|
+ last_pitch = ahrs.pitch_sensor;
|
|
|
+ last_yaw = ahrs.yaw_sensor;
|
|
|
+ last_input_ms = tnow;
|
|
|
+ attitude_control.input_rate_bf_roll_pitch_yaw(target_roll, target_pitch, target_yaw);
|
|
|
+ } else if (abs(target_yaw) > 300) {
|
|
|
+
|
|
|
+ attitude_control.input_rate_bf_roll_pitch_yaw(0, 0, target_yaw);
|
|
|
+ last_yaw = ahrs.yaw_sensor;
|
|
|
+ last_input_ms = tnow;
|
|
|
+ } else if (tnow < last_input_ms + 250) {
|
|
|
+
|
|
|
+ last_yaw = ahrs.yaw_sensor;
|
|
|
+ attitude_control.input_rate_bf_roll_pitch_yaw(0, 0, 0);
|
|
|
+ } else {
|
|
|
+
|
|
|
+ attitude_control.input_euler_angle_roll_pitch_yaw(last_roll, last_pitch, last_yaw, true);
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
|
|
@@ -147,8 +110,11 @@ void Sub::althold_run()
|
|
|
|
|
|
|
|
|
motors.set_desired_spool_state(AP_Motors::DesiredSpoolState::THROTTLE_UNLIMITED);
|
|
|
+
|
|
|
+ handle_attitude_sport();
|
|
|
+
|
|
|
+
|
|
|
|
|
|
- handle_attitude();
|
|
|
|
|
|
pos_control.update_z_controller();
|
|
|
|
|
@@ -156,12 +122,14 @@ void Sub::althold_run()
|
|
|
|
|
|
|
|
|
|
|
|
- motors.set_throttle(0.5+throttle_vehicle_frame.z + channel_throttle->norm_input()-0.5);
|
|
|
+
|
|
|
+ motors.set_throttle(throttle_vehicle_frame.z + 1.0-(float)PressLevel_f*0.1);
|
|
|
motors.set_forward(-throttle_vehicle_frame.x + channel_forward->norm_input());
|
|
|
motors.set_lateral(-throttle_vehicle_frame.y + channel_lateral->norm_input());
|
|
|
|
|
|
|
|
|
- Vector3f earth_frame_rc_inputs = ahrs.get_rotation_body_to_ned() * Vector3f(channel_forward->norm_input(), channel_lateral->norm_input(), (2.0f*(-0.5f+channel_throttle->norm_input())));
|
|
|
+
|
|
|
+ Vector3f earth_frame_rc_inputs = ahrs.get_rotation_body_to_ned() * Vector3f(channel_forward->norm_input(), channel_lateral->norm_input(), (2.0*(0.5-PressLevel_f*0.1)));
|
|
|
|
|
|
if (fabsf(earth_frame_rc_inputs.z) > 0.05f) {
|
|
|
|