Skip to content

Commit

Permalink
Plane: announce throttle limited by Battery Watt Limit
Browse files Browse the repository at this point in the history
  • Loading branch information
magicrub committed Nov 9, 2023
1 parent 1e47cc3 commit b8005c5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
1 change: 1 addition & 0 deletions ArduPlane/Plane.h
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,7 @@ class Plane : public AP_Vehicle {
int8_t throttle_watt_limit_max;
int8_t throttle_watt_limit_min; // for reverse thrust
uint32_t throttle_watt_limit_timer_ms;
uint32_t throttle_watt_limit_last_gcs_ms;

AP_FixedWing::FlightStage flight_stage = AP_FixedWing::FlightStage::NORMAL;

Expand Down
24 changes: 20 additions & 4 deletions ArduPlane/servos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -443,15 +443,19 @@ void Plane::throttle_watt_limiter(int8_t &min_throttle, int8_t &max_throttle)

} else if (throttle_watt_limit_min == 0 && throttle_watt_limit_max == 0) {
// no limiting happening, nothing to do
if (throttle_watt_limit_last_gcs_ms > 0) {
throttle_watt_limit_last_gcs_ms = 0;
GCS_SEND_TEXT(MAV_SEVERITY_INFO, "Throttle no longer limited");
}
return;
}

// check to recover the throttle limit since we're not overloading
const int8_t most_limited_of_min_and_max = MAX(throttle_watt_limit_min, throttle_watt_limit_max);
const int8_t most_throttle_of_min_and_max = MAX(-min_throttle, max_throttle);
int8_t most_limited_of_min_and_max = MAX(throttle_watt_limit_min, throttle_watt_limit_max);
int8_t most_throttle_of_min_and_max = (most_limited_of_min_and_max == throttle_watt_limit_min) ? -min_throttle : max_throttle;

// if we're limiting all the way (min or max == 0) then the delay is larger
const uint32_t recovery_delay_ms = most_limited_of_min_and_max >= most_throttle_of_min_and_max ? 5000 : 1000;
// if we're limiting all the way (demand - min/max == 0) then the delay is larger
const uint32_t recovery_delay_ms = most_limited_of_min_and_max == most_throttle_of_min_and_max ? 5000 : 1000;

if (now_ms - throttle_watt_limit_timer_ms >= recovery_delay_ms) {
// it has been 1 second since last over-current, or 5s if throttle is pushed all the way down to 0%, check if we can resume higher throttle.
Expand All @@ -470,6 +474,18 @@ void Plane::throttle_watt_limiter(int8_t &min_throttle, int8_t &max_throttle)
}
}

// announce to user so they are aware of this event happening every 5 seconds
if (now_ms - throttle_watt_limit_last_gcs_ms >= 5000) {
if (throttle_watt_limit_last_gcs_ms == 0) {
// initial message is handled differently because it will always show max-1 which isn't very useful.
// Need to give it a few seconds to see how much we're actually limiting the throttle
GCS_SEND_TEXT(MAV_SEVERITY_CRITICAL, "Throttle limited by battery Watt limit!");
} else {
GCS_SEND_TEXT(MAV_SEVERITY_CRITICAL, "Throttle limited to %d%%", most_limited_of_min_and_max);
}
throttle_watt_limit_last_gcs_ms = now_ms;
}

max_throttle = constrain_int16(max_throttle, 0, max_throttle - throttle_watt_limit_max);
if (min_throttle < 0) {
min_throttle = constrain_int16(min_throttle, min_throttle + throttle_watt_limit_min, 0);
Expand Down

0 comments on commit b8005c5

Please sign in to comment.