2019-01-15 13:46:13 -04:00
|
|
|
#include "mode.h"
|
|
|
|
#include "Plane.h"
|
|
|
|
|
2021-09-10 03:28:21 -03:00
|
|
|
#if HAL_QUADPLANE_ENABLED
|
|
|
|
|
2019-01-15 13:46:13 -04:00
|
|
|
bool ModeQStabilize::_enter()
|
2021-08-14 15:59:06 -03:00
|
|
|
{
|
|
|
|
quadplane.throttle_wait = false;
|
2021-09-04 16:21:25 -03:00
|
|
|
return true;
|
2021-08-14 15:59:06 -03:00
|
|
|
}
|
|
|
|
|
2019-01-15 13:46:13 -04:00
|
|
|
void ModeQStabilize::update()
|
|
|
|
{
|
|
|
|
// set nav_roll and nav_pitch using sticks
|
2021-03-09 12:05:25 -04:00
|
|
|
// Beware that QuadPlane::tailsitter_check_input (called from Plane::read_radio)
|
|
|
|
// may alter the control_in values for roll and yaw, but not the corresponding
|
|
|
|
// radio_in values. This means that the results for norm_input would not necessarily
|
|
|
|
// be correct for tailsitters, so get_control_in() must be used instead.
|
|
|
|
// normalize control_input to [-1,1]
|
|
|
|
const float roll_input = (float)plane.channel_roll->get_control_in() / plane.channel_roll->get_range();
|
|
|
|
const float pitch_input = (float)plane.channel_pitch->get_control_in() / plane.channel_pitch->get_range();
|
2021-02-19 14:30:26 -04:00
|
|
|
|
2021-03-09 12:05:25 -04:00
|
|
|
// then scale to target angles in centidegrees
|
2021-07-14 17:15:49 -03:00
|
|
|
if (plane.quadplane.tailsitter.active()) {
|
2021-02-19 14:30:26 -04:00
|
|
|
// tailsitters are different
|
|
|
|
set_tailsitter_roll_pitch(roll_input, pitch_input);
|
|
|
|
return;
|
|
|
|
}
|
2019-04-13 14:58:53 -03:00
|
|
|
|
2022-08-05 12:08:59 -03:00
|
|
|
if (!plane.quadplane.option_is_set(QuadPlane::OPTION::INGORE_FW_ANGLE_LIMITS_IN_Q_MODES)) {
|
2021-02-19 14:30:26 -04:00
|
|
|
// by default angles are also constrained by forward flight limits
|
|
|
|
set_limited_roll_pitch(roll_input, pitch_input);
|
|
|
|
} else {
|
|
|
|
// use angle max for both roll and pitch
|
|
|
|
plane.nav_roll_cd = roll_input * plane.quadplane.aparm.angle_max;
|
2019-01-15 13:46:13 -04:00
|
|
|
plane.nav_pitch_cd = pitch_input * plane.quadplane.aparm.angle_max;
|
2021-02-19 14:30:26 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-14 15:59:06 -03:00
|
|
|
// quadplane stabilize mode
|
|
|
|
void ModeQStabilize::run()
|
|
|
|
{
|
2023-05-01 22:05:00 -03:00
|
|
|
const uint32_t now = AP_HAL::millis();
|
|
|
|
if (quadplane.tailsitter.in_vtol_transition(now)) {
|
|
|
|
// Tailsitters in FW pull up phase of VTOL transition run FW controllers
|
|
|
|
Mode::run();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-09-26 05:56:28 -03:00
|
|
|
plane.quadplane.assign_tilt_to_fwd_thr();
|
|
|
|
|
2021-08-14 15:59:06 -03:00
|
|
|
// special check for ESC calibration in QSTABILIZE
|
|
|
|
if (quadplane.esc_calibration != 0) {
|
|
|
|
quadplane.run_esc_calibration();
|
2023-05-01 22:05:00 -03:00
|
|
|
plane.stabilize_roll();
|
|
|
|
plane.stabilize_pitch();
|
2021-08-14 15:59:06 -03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// normal QSTABILIZE mode
|
|
|
|
float pilot_throttle_scaled = quadplane.get_pilot_throttle();
|
|
|
|
quadplane.hold_stabilize(pilot_throttle_scaled);
|
2023-05-01 22:05:00 -03:00
|
|
|
|
|
|
|
// Stabilize with fixed wing surfaces
|
|
|
|
plane.stabilize_roll();
|
|
|
|
plane.stabilize_pitch();
|
2021-08-14 15:59:06 -03:00
|
|
|
}
|
|
|
|
|
2021-02-19 14:30:26 -04:00
|
|
|
// set the desired roll and pitch for a tailsitter
|
|
|
|
void ModeQStabilize::set_tailsitter_roll_pitch(const float roll_input, const float pitch_input)
|
|
|
|
{
|
|
|
|
// separate limit for roll, if set
|
|
|
|
if (plane.quadplane.tailsitter.max_roll_angle > 0) {
|
|
|
|
// roll param is in degrees not centidegrees
|
|
|
|
plane.nav_roll_cd = plane.quadplane.tailsitter.max_roll_angle * 100.0f * roll_input;
|
2019-01-15 13:46:13 -04:00
|
|
|
} else {
|
2021-02-19 14:30:26 -04:00
|
|
|
plane.nav_roll_cd = roll_input * plane.quadplane.aparm.angle_max;
|
2019-01-15 13:46:13 -04:00
|
|
|
}
|
2019-04-13 14:58:53 -03:00
|
|
|
|
2021-02-19 14:30:26 -04:00
|
|
|
// angle max for tailsitter pitch
|
|
|
|
plane.nav_pitch_cd = pitch_input * plane.quadplane.aparm.angle_max;
|
2021-11-09 22:15:32 -04:00
|
|
|
|
|
|
|
plane.quadplane.transition->set_VTOL_roll_pitch_limit(plane.nav_roll_cd, plane.nav_pitch_cd);
|
2019-01-15 13:46:13 -04:00
|
|
|
}
|
|
|
|
|
2023-10-11 04:41:54 -03:00
|
|
|
// set the desired roll and pitch for normal quadplanes, also limited by forward flight limits
|
2021-02-19 14:30:26 -04:00
|
|
|
void ModeQStabilize::set_limited_roll_pitch(const float roll_input, const float pitch_input)
|
|
|
|
{
|
|
|
|
plane.nav_roll_cd = roll_input * MIN(plane.roll_limit_cd, plane.quadplane.aparm.angle_max);
|
2024-01-18 21:50:36 -04:00
|
|
|
// pitch is further constrained by PTCH_LIM_MIN/MAX which may impose
|
2021-02-19 14:30:26 -04:00
|
|
|
// tighter (possibly asymmetrical) limits than Q_ANGLE_MAX
|
|
|
|
if (pitch_input > 0) {
|
2024-01-18 21:50:36 -04:00
|
|
|
plane.nav_pitch_cd = pitch_input * MIN(plane.aparm.pitch_limit_max*100, plane.quadplane.aparm.angle_max);
|
2021-02-19 14:30:26 -04:00
|
|
|
} else {
|
2024-01-18 21:50:36 -04:00
|
|
|
plane.nav_pitch_cd = pitch_input * MIN(-plane.pitch_limit_min*100, plane.quadplane.aparm.angle_max);
|
2021-02-19 14:30:26 -04:00
|
|
|
}
|
|
|
|
}
|
2021-09-10 03:28:21 -03:00
|
|
|
|
|
|
|
#endif
|