123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- #include "Sub.h"
- extern mavlink_rov_state_monitoring_t rov_message;
- 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;
- }
- last_yaw = ahrs.yaw_sensor;
- pitch_input_inc=0;
- yaw_press = (int16_t)(ahrs.yaw_sensor/100);
- last_input_ms = AP_HAL::millis();
- return true;
- }
- void Sub::handle_attitude_sport(){
- 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(0, (int16_t)((0.5-channel_throttle->norm_input())*5700*2), 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);
- }
- }
- }
- 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.relax_attitude_controllers();
- last_roll = 0;
- last_pitch = 0;
- last_yaw = ahrs.yaw_sensor;
- yaw_press = (int16_t)(ahrs.yaw_sensor/100);
- return;
- }
- motors.set_desired_spool_state(AP_Motors::DesiredSpoolState::THROTTLE_UNLIMITED);
- handle_attitude_sport();
-
-
- attitude_control.set_throttle_out(1.0-(float)PressLevel_f*0.1, false, g.throttle_filt);
- rov_message.pressure_level = int(PressLevel);
-
-
- 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());
-
-
-
-
-
-
-
- j=0;
- }
- }
|