@@ -563,8 +563,15 @@ void Mode::get_pilot_desired_lean_angles_rad(float &roll_out_rad, float &pitch_o
563563 return ;
564564 }
565565
566- // transform pilot's normalised roll or pitch stick input into a roll and pitch euler angle command
567- rc_input_to_roll_pitch_rad (channel_roll->norm_input_dz (), channel_pitch->norm_input_dz (), angle_max_rad, angle_limit_rad, roll_out_rad, pitch_out_rad);
566+ // fetch roll and pitch inputs
567+ float roll_in_norm = channel_roll->norm_input_dz ();
568+ float pitch_in_norm = channel_pitch->norm_input_dz ();
569+
570+ // apply SIMPLE mode transform to pilot inputs
571+ apply_simple_mode (roll_in_norm, pitch_in_norm);
572+
573+ // transform pilot's normalised roll or pitch stick input into a roll and pitch euler angle command
574+ rc_input_to_roll_pitch_rad (roll_in_norm, pitch_in_norm, angle_max_rad, angle_limit_rad, roll_out_rad, pitch_out_rad);
568575}
569576
570577// transform pilot's roll or pitch input into a desired velocity
@@ -579,6 +586,9 @@ Vector2f Mode::get_pilot_desired_velocity(float vel_max) const
579586 float roll_out_norm = channel_roll->norm_input_dz ();
580587 float pitch_out_norm = channel_pitch->norm_input_dz ();
581588
589+ // apply SIMPLE mode transform to pilot inputs
590+ apply_simple_mode (roll_out_norm, pitch_out_norm);
591+
582592 // convert roll and pitch inputs into velocity in NE frame
583593 vel_ne_ms = Vector2f (-pitch_out_norm, roll_out_norm);
584594 if (vel_ne_ms.is_zero ()) {
@@ -789,9 +799,6 @@ void Mode::land_run_horizontal_control()
789799 }
790800
791801 if (g.land_repositioning ) {
792- // apply SIMPLE mode transform to pilot inputs
793- update_simple_mode ();
794-
795802 // convert pilot input to reposition velocity
796803 // use half maximum acceleration as the maximum velocity to ensure aircraft will
797804 // stop from full reposition speed in less than 1 second.
@@ -1094,9 +1101,30 @@ float Mode::get_non_takeoff_throttle() const
10941101 return copter.get_non_takeoff_throttle ();
10951102}
10961103
1097- // Updates simple/super-simple heading reference based on current yaw and mode.
1098- void Mode::update_simple_mode (void ) {
1099- copter.update_simple_mode ();
1104+ // Rotates roll/pitch pilot input if simple or super simple mode is active.
1105+ // roll and pitch may be in any units/scale; the rotation is scale-independent
1106+ void Mode::apply_simple_mode (float &roll, float &pitch) const
1107+ {
1108+ // exit immediately if not in simple mode
1109+ if (copter.simple_mode == Copter::SimpleMode::NONE ) {
1110+ return ;
1111+ }
1112+
1113+ float roll_out, pitch_out;
1114+
1115+ if (copter.simple_mode == Copter::SimpleMode::SIMPLE ) {
1116+ // rotate roll, pitch input by -initial simple heading (i.e. north facing)
1117+ roll_out = roll*copter.simple_cos_yaw - pitch*copter.simple_sin_yaw ;
1118+ pitch_out = roll*copter.simple_sin_yaw + pitch*copter.simple_cos_yaw ;
1119+ } else {
1120+ // rotate roll, pitch input by -super simple heading (reverse of heading to home)
1121+ roll_out = roll*copter.super_simple_cos_yaw - pitch*copter.super_simple_sin_yaw ;
1122+ pitch_out = roll*copter.super_simple_sin_yaw + pitch*copter.super_simple_cos_yaw ;
1123+ }
1124+
1125+ // rotate roll, pitch input from north facing to vehicle's perspective
1126+ roll = roll_out*copter.ahrs .cos_yaw () + pitch_out*copter.ahrs .sin_yaw ();
1127+ pitch = -roll_out*copter.ahrs .sin_yaw () + pitch_out*copter.ahrs .cos_yaw ();
11001128}
11011129
11021130// Requests a mode change with the specified reason; returns true if accepted.
0 commit comments