mirror of
https://github.com/ArduPilot/ardupilot
synced 2025-03-03 04:03:59 -04:00
Plane: cleanup abort of NAV_SCRIPT
use the same enable flag for tricks and auto NAV_SCRIPT_TIME and ensure we disable if the script stops controlling
This commit is contained in:
parent
06edc9a139
commit
500ac9b99c
@ -537,7 +537,7 @@ void Plane::update_alt()
|
|||||||
update_flight_stage();
|
update_flight_stage();
|
||||||
|
|
||||||
#if AP_SCRIPTING_ENABLED
|
#if AP_SCRIPTING_ENABLED
|
||||||
if (plane.nav_scripting.enabled) {
|
if (nav_scripting_active()) {
|
||||||
// don't call TECS while we are in a trick
|
// don't call TECS while we are in a trick
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -508,8 +508,7 @@ void Plane::stabilize()
|
|||||||
if (control_mode == &mode_training) {
|
if (control_mode == &mode_training) {
|
||||||
stabilize_training(speed_scaler);
|
stabilize_training(speed_scaler);
|
||||||
#if AP_SCRIPTING_ENABLED
|
#if AP_SCRIPTING_ENABLED
|
||||||
} else if ((control_mode == &mode_auto &&
|
} else if (nav_scripting_active()) {
|
||||||
mission.get_current_nav_cmd().id == MAV_CMD_NAV_SCRIPT_TIME) || (nav_scripting.enabled && nav_scripting.current_ms > 0)) {
|
|
||||||
// scripting is in control of roll and pitch rates and throttle
|
// scripting is in control of roll and pitch rates and throttle
|
||||||
const float aileron = rollController.get_rate_out(nav_scripting.roll_rate_dps, speed_scaler);
|
const float aileron = rollController.get_rate_out(nav_scripting.roll_rate_dps, speed_scaler);
|
||||||
const float elevator = pitchController.get_rate_out(nav_scripting.pitch_rate_dps, speed_scaler);
|
const float elevator = pitchController.get_rate_out(nav_scripting.pitch_rate_dps, speed_scaler);
|
||||||
@ -519,9 +518,6 @@ void Plane::stabilize()
|
|||||||
const float rudder = yawController.get_rate_out(nav_scripting.yaw_rate_dps, speed_scaler, false);
|
const float rudder = yawController.get_rate_out(nav_scripting.yaw_rate_dps, speed_scaler, false);
|
||||||
steering_control.rudder = rudder;
|
steering_control.rudder = rudder;
|
||||||
}
|
}
|
||||||
if (AP_HAL::millis() - nav_scripting.current_ms > 50) { //set_target_throttle_rate_rpy has not been called from script in last 50ms
|
|
||||||
nav_scripting.current_ms = 0;
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
} else if (control_mode == &mode_acro) {
|
} else if (control_mode == &mode_acro) {
|
||||||
stabilize_acro(speed_scaler);
|
stabilize_acro(speed_scaler);
|
||||||
|
@ -518,9 +518,7 @@ private:
|
|||||||
float throttle_pct;
|
float throttle_pct;
|
||||||
uint32_t start_ms;
|
uint32_t start_ms;
|
||||||
uint32_t current_ms;
|
uint32_t current_ms;
|
||||||
bool done;
|
|
||||||
} nav_scripting;
|
} nav_scripting;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
@ -1127,7 +1125,7 @@ private:
|
|||||||
|
|
||||||
#if AP_SCRIPTING_ENABLED
|
#if AP_SCRIPTING_ENABLED
|
||||||
// support for NAV_SCRIPT_TIME mission command
|
// support for NAV_SCRIPT_TIME mission command
|
||||||
bool nav_scripting_active(void) const;
|
bool nav_scripting_active(void);
|
||||||
bool nav_script_time(uint16_t &id, uint8_t &cmd, float &arg1, float &arg2, int16_t &arg3, int16_t &arg4) override;
|
bool nav_script_time(uint16_t &id, uint8_t &cmd, float &arg1, float &arg2, int16_t &arg3, int16_t &arg4) override;
|
||||||
void nav_script_time_done(uint16_t id) override;
|
void nav_script_time_done(uint16_t id) override;
|
||||||
|
|
||||||
|
@ -1160,10 +1160,10 @@ float Plane::get_wp_radius() const
|
|||||||
*/
|
*/
|
||||||
void Plane::do_nav_script_time(const AP_Mission::Mission_Command& cmd)
|
void Plane::do_nav_script_time(const AP_Mission::Mission_Command& cmd)
|
||||||
{
|
{
|
||||||
nav_scripting.done = false;
|
nav_scripting.enabled = true;
|
||||||
nav_scripting.id++;
|
nav_scripting.id++;
|
||||||
nav_scripting.start_ms = AP_HAL::millis();
|
nav_scripting.start_ms = AP_HAL::millis();
|
||||||
nav_scripting.current_ms = 0;
|
nav_scripting.current_ms = nav_scripting.start_ms;
|
||||||
|
|
||||||
// start with current roll rate, pitch rate and throttle
|
// start with current roll rate, pitch rate and throttle
|
||||||
nav_scripting.roll_rate_dps = plane.rollController.get_pid_info().target;
|
nav_scripting.roll_rate_dps = plane.rollController.get_pid_info().target;
|
||||||
@ -1181,18 +1181,25 @@ bool Plane::verify_nav_script_time(const AP_Mission::Mission_Command& cmd)
|
|||||||
const uint32_t now = AP_HAL::millis();
|
const uint32_t now = AP_HAL::millis();
|
||||||
if (now - nav_scripting.start_ms > cmd.content.nav_script_time.timeout_s*1000U) {
|
if (now - nav_scripting.start_ms > cmd.content.nav_script_time.timeout_s*1000U) {
|
||||||
gcs().send_text(MAV_SEVERITY_INFO, "NavScriptTime timed out");
|
gcs().send_text(MAV_SEVERITY_INFO, "NavScriptTime timed out");
|
||||||
nav_scripting.done = true;
|
nav_scripting.enabled = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nav_scripting.done;
|
return !nav_scripting.enabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if we are in a NAV_SCRIPT_* command
|
// check if we are in a NAV_SCRIPT_* command
|
||||||
bool Plane::nav_scripting_active(void) const
|
bool Plane::nav_scripting_active(void)
|
||||||
{
|
{
|
||||||
return !nav_scripting.done &&
|
if (AP_HAL::millis() - nav_scripting.current_ms > 200) {
|
||||||
control_mode == &mode_auto &&
|
// set_target_throttle_rate_rpy has not been called from script in last 200ms
|
||||||
mission.get_current_nav_cmd().id == MAV_CMD_NAV_SCRIPT_TIME;
|
nav_scripting.enabled = false;
|
||||||
|
nav_scripting.current_ms = 0;
|
||||||
|
}
|
||||||
|
if (control_mode == &mode_auto &&
|
||||||
|
mission.get_current_nav_cmd().id != MAV_CMD_NAV_SCRIPT_TIME) {
|
||||||
|
nav_scripting.enabled = false;
|
||||||
|
}
|
||||||
|
return nav_scripting.enabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
// support for NAV_SCRIPTING mission command
|
// support for NAV_SCRIPTING mission command
|
||||||
@ -1216,7 +1223,7 @@ bool Plane::nav_script_time(uint16_t &id, uint8_t &cmd, float &arg1, float &arg2
|
|||||||
void Plane::nav_script_time_done(uint16_t id)
|
void Plane::nav_script_time_done(uint16_t id)
|
||||||
{
|
{
|
||||||
if (id == nav_scripting.id) {
|
if (id == nav_scripting.id) {
|
||||||
nav_scripting.done = true;
|
nav_scripting.enabled = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1228,6 +1235,7 @@ void Plane::set_target_throttle_rate_rpy(float throttle_pct, float roll_rate_dps
|
|||||||
nav_scripting.yaw_rate_dps = constrain_float(yaw_rate_dps, -g.acro_yaw_rate, g.acro_yaw_rate);
|
nav_scripting.yaw_rate_dps = constrain_float(yaw_rate_dps, -g.acro_yaw_rate, g.acro_yaw_rate);
|
||||||
nav_scripting.throttle_pct = constrain_float(throttle_pct, aparm.throttle_min, aparm.throttle_max);
|
nav_scripting.throttle_pct = constrain_float(throttle_pct, aparm.throttle_min, aparm.throttle_max);
|
||||||
nav_scripting.current_ms = AP_HAL::millis();
|
nav_scripting.current_ms = AP_HAL::millis();
|
||||||
|
nav_scripting.enabled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// enable NAV_SCRIPTING takeover in modes other than AUTO using script time mission commands
|
// enable NAV_SCRIPTING takeover in modes other than AUTO using script time mission commands
|
||||||
|
@ -29,7 +29,7 @@ void ModeCruise::update()
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if AP_SCRIPTING_ENABLED
|
#if AP_SCRIPTING_ENABLED
|
||||||
if (plane.nav_scripting.enabled) {
|
if (plane.nav_scripting_active()) {
|
||||||
// while a trick is running unlock heading and zero altitude offset
|
// while a trick is running unlock heading and zero altitude offset
|
||||||
locked_heading = false;
|
locked_heading = false;
|
||||||
lock_timer_ms = 0;
|
lock_timer_ms = 0;
|
||||||
@ -53,7 +53,7 @@ void ModeCruise::update()
|
|||||||
void ModeCruise::navigate()
|
void ModeCruise::navigate()
|
||||||
{
|
{
|
||||||
#if AP_SCRIPTING_ENABLED
|
#if AP_SCRIPTING_ENABLED
|
||||||
if (plane.nav_scripting.enabled) {
|
if (plane.nav_scripting_active()) {
|
||||||
// don't try to navigate while running trick
|
// don't try to navigate while running trick
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,7 @@ void ModeLoiter::update()
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if AP_SCRIPTING_ENABLED
|
#if AP_SCRIPTING_ENABLED
|
||||||
if (plane.nav_scripting.enabled) {
|
if (plane.nav_scripting_active()) {
|
||||||
// while a trick is running we reset altitude
|
// while a trick is running we reset altitude
|
||||||
plane.set_target_altitude_current();
|
plane.set_target_altitude_current();
|
||||||
plane.next_WP_loc.set_alt_cm(plane.target_altitude.amsl_cm, Location::AltFrame::ABSOLUTE);
|
plane.next_WP_loc.set_alt_cm(plane.target_altitude.amsl_cm, Location::AltFrame::ABSOLUTE);
|
||||||
@ -100,7 +100,7 @@ void ModeLoiter::navigate()
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if AP_SCRIPTING_ENABLED
|
#if AP_SCRIPTING_ENABLED
|
||||||
if (plane.nav_scripting.enabled) {
|
if (plane.nav_scripting_active()) {
|
||||||
// don't try to navigate while running trick
|
// don't try to navigate while running trick
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -562,7 +562,7 @@ void Plane::set_servos_controlled(void)
|
|||||||
SRV_Channels::set_output_scaled(SRV_Channel::k_throttle, get_throttle_input(true));
|
SRV_Channels::set_output_scaled(SRV_Channel::k_throttle, get_throttle_input(true));
|
||||||
}
|
}
|
||||||
#if AP_SCRIPTING_ENABLED
|
#if AP_SCRIPTING_ENABLED
|
||||||
} else if (plane.nav_scripting.current_ms > 0 && nav_scripting.enabled) {
|
} else if (nav_scripting_active()) {
|
||||||
SRV_Channels::set_output_scaled(SRV_Channel::k_throttle, plane.nav_scripting.throttle_pct);
|
SRV_Channels::set_output_scaled(SRV_Channel::k_throttle, plane.nav_scripting.throttle_pct);
|
||||||
#endif
|
#endif
|
||||||
} else if (control_mode == &mode_stabilize ||
|
} else if (control_mode == &mode_stabilize ||
|
||||||
|
Loading…
Reference in New Issue
Block a user