|
@@ -1,25 +1,46 @@
|
|
|
#include "Sub.h"
|
|
|
+
|
|
|
+
|
|
|
extern mavlink_rov_state_monitoring_t rov_message;
|
|
|
+Quaternion attitude_desired_quat_;
|
|
|
+
|
|
|
|
|
|
+
|
|
|
+ * control_althold.pde - init and run calls for althold, flight mode
|
|
|
+ */
|
|
|
|
|
|
-
|
|
|
+
|
|
|
bool Sub::sport_init()
|
|
|
{
|
|
|
-
|
|
|
- pos_control.set_alt_target(0);
|
|
|
- if (prev_control_mode == ALT_HOLD) {
|
|
|
- last_roll = ahrs.roll_sensor;
|
|
|
- last_pitch = ahrs.pitch_sensor;
|
|
|
- } else {
|
|
|
- last_roll = 0;
|
|
|
- last_pitch = 0;
|
|
|
+ if(!control_check_barometer()) {
|
|
|
+ return false;
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ pos_control.set_max_speed_z(-get_pilot_speed_dn(), g.pilot_speed_up);
|
|
|
+ pos_control.set_max_accel_z(g.pilot_accel_z);
|
|
|
+ pos_control.relax_alt_hold_controllers();
|
|
|
+
|
|
|
+ pos_control.set_target_to_stopping_point_z();
|
|
|
+ holding_depth = true;
|
|
|
+ ahrs.get_quat_body_to_ned(attitude_desired_quat_);
|
|
|
+
|
|
|
+
|
|
|
+ last_roll = 0;
|
|
|
+ last_pitch = 0;
|
|
|
+
|
|
|
+
|
|
|
last_yaw = ahrs.yaw_sensor;
|
|
|
- pitch_input_inc=0;
|
|
|
- yaw_press = (int16_t)(ahrs.yaw_sensor/100);
|
|
|
last_input_ms = AP_HAL::millis();
|
|
|
+ last_input_ms_stable = AP_HAL::millis();
|
|
|
+
|
|
|
+ gcs().send_text(MAV_SEVERITY_INFO, " last_attitudeinit %d %d,%d ",(int)last_roll_s,(int)pitch_input_inc,(int)last_yaw_s);
|
|
|
+ gcs().send_text(MAV_SEVERITY_INFO, " init Z target %f %f",(float)pos_control.get_pos_target().z,barometer.get_altitude());
|
|
|
+
|
|
|
return true;
|
|
|
}
|
|
|
+
|
|
|
void Sub::handle_attitude_sport(){
|
|
|
uint32_t tnow = AP_HAL::millis();
|
|
|
|
|
@@ -51,15 +72,17 @@ void Sub::handle_attitude_sport(){
|
|
|
|
|
|
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;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ ahrs.get_quat_body_to_ned(attitude_desired_quat_);
|
|
|
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;
|
|
|
+
|
|
|
+ ahrs.get_quat_body_to_ned(attitude_desired_quat_);
|
|
|
last_input_ms = tnow;
|
|
|
} else if (tnow < last_input_ms + 250) {
|
|
|
|
|
@@ -67,57 +90,106 @@ void Sub::handle_attitude_sport(){
|
|
|
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);
|
|
|
+
|
|
|
+ attitude_control.input_quaternion(attitude_desired_quat_);
|
|
|
}
|
|
|
+ static int f = 0;
|
|
|
+ f++;
|
|
|
+ if(f>800)
|
|
|
+ {
|
|
|
+
|
|
|
+ gcs().send_text(MAV_SEVERITY_INFO, " sportrpy %f %f,%f ",(float)target_roll,(float)target_pitch,(float)target_yaw);
|
|
|
+
|
|
|
+ gcs().send_text(MAV_SEVERITY_INFO, " sportatd %f %f,%f ",(float)last_roll,(float)last_pitch,(float)last_yaw);
|
|
|
+ f=0;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
|
|
|
void Sub::sport_run()
|
|
|
{
|
|
|
-
|
|
|
+
|
|
|
if (!motors.armed()) {
|
|
|
motors.set_desired_spool_state(AP_Motors::DesiredSpoolState::GROUND_IDLE);
|
|
|
- attitude_control.set_throttle_out(0,true,g.throttle_filt);
|
|
|
+
|
|
|
+ attitude_control.set_throttle_out(0.5 ,true, g.throttle_filt);
|
|
|
attitude_control.relax_attitude_controllers();
|
|
|
+ pos_control.relax_alt_hold_controllers();
|
|
|
+
|
|
|
last_roll = 0;
|
|
|
last_pitch = 0;
|
|
|
last_yaw = ahrs.yaw_sensor;
|
|
|
- yaw_press = (int16_t)(ahrs.yaw_sensor/100);
|
|
|
+ holding_depth = false;
|
|
|
+ ahrs.get_quat_body_to_ned(attitude_desired_quat_);
|
|
|
+
|
|
|
+ static int f = 0;
|
|
|
+ f++;
|
|
|
+ if(f>800)
|
|
|
+ {
|
|
|
+
|
|
|
+ gcs().send_text(MAV_SEVERITY_INFO, " disarm Z target %f %f %f",(float)pos_control.get_pos_target().z,pos_control.get_alt(),barometer.get_altitude());
|
|
|
+ f=0;
|
|
|
+ }
|
|
|
return;
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
motors.set_desired_spool_state(AP_Motors::DesiredSpoolState::THROTTLE_UNLIMITED);
|
|
|
+
|
|
|
+ handle_attitude_sport();
|
|
|
+
|
|
|
+
|
|
|
|
|
|
- handle_attitude_sport();
|
|
|
|
|
|
-
|
|
|
-
|
|
|
- attitude_control.set_throttle_out(1.0-(float)PressLevel_f*0.1, false, g.throttle_filt);
|
|
|
+ pos_control.update_z_controller();
|
|
|
+
|
|
|
+
|
|
|
+ Vector3f throttle_vehicle_frame = ahrs.get_rotation_body_to_ned().transposed() * Vector3f(0, 0, motors.get_throttle_in_bidirectional());
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ motors.set_throttle(throttle_vehicle_frame.z + 1.0-(float)PressLevel_f*0.1);
|
|
|
rov_message.pressure_level = int(PressLevel);
|
|
|
+ motors.set_forward(-throttle_vehicle_frame.x + channel_forward->norm_input());
|
|
|
+ motors.set_lateral(-throttle_vehicle_frame.y + channel_lateral->norm_input());
|
|
|
|
|
|
-
|
|
|
-
|
|
|
- motors.set_forward(channel_forward->norm_input());
|
|
|
- motors.set_lateral(channel_lateral->norm_input());
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- static int j = 0;
|
|
|
- j++;
|
|
|
- if(j>800)
|
|
|
- {
|
|
|
- gcs().send_text(MAV_SEVERITY_INFO, " roll p y %d %d %d\n",(int16_t)(channel_lateral->norm_input()*5700),(int16_t)((0.5-channel_throttle->norm_input())*5700*2),channel_yaw->get_control_in());
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
+ 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) {
|
|
|
+
|
|
|
+ holding_depth = false;
|
|
|
+ pos_control.relax_alt_hold_controllers();
|
|
|
+
|
|
|
+ } else {
|
|
|
+ if (ap.at_surface) {
|
|
|
+ pos_control.set_alt_target(g.surface_depth - 10.0f);
|
|
|
+ holding_depth = true;
|
|
|
+ } else if (ap.at_bottom) {
|
|
|
+ pos_control.set_alt_target(inertial_nav.get_altitude() + 20.0f);
|
|
|
+
|
|
|
+ holding_depth = true;
|
|
|
+ } else if (!holding_depth) {
|
|
|
+ pos_control.set_target_to_stopping_point_z();
|
|
|
+ holding_depth = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ static int f = 0;
|
|
|
+ f++;
|
|
|
+ if(f>800)
|
|
|
+ {
|
|
|
|
|
|
- j=0;
|
|
|
- }
|
|
|
-}
|
|
|
+ gcs().send_text(MAV_SEVERITY_INFO, " Z target %f %f %f",(float)pos_control.get_pos_target().z,pos_control.get_alt(),barometer.get_altitude());
|
|
|
|
|
|
+ gcs().send_text(MAV_SEVERITY_INFO, " surface %d at_bottom %d ",ap.at_surface,ap.at_bottom);
|
|
|
+ f=0;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|