Skip to content

Commit

Permalink
Plane: wrap Watt Limiiter in #if AP_BATTERY_WATT_MAX_ENABLED
Browse files Browse the repository at this point in the history
  • Loading branch information
magicrub committed Nov 21, 2023
1 parent 28f6b28 commit f4605e3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
2 changes: 2 additions & 0 deletions ArduPlane/Plane.h
Original file line number Diff line number Diff line change
Expand Up @@ -586,10 +586,12 @@ class Plane : public AP_Vehicle {
// this controls throttle suppression in auto modes
bool throttle_suppressed;

#if AP_BATTERY_WATT_MAX_ENABLED
// reduce throttle to eliminate battery over-current
int8_t throttle_watt_limit_max;
int8_t throttle_watt_limit_min; // for reverse thrust
uint32_t throttle_watt_limit_timer_ms;
#endif

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

Expand Down
4 changes: 4 additions & 0 deletions ArduPlane/servos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,7 @@ void Plane::throttle_voltage_comp(int8_t &min_throttle, int8_t &max_throttle) co
/*
calculate any throttle limits based on the watt limiter
*/
#if AP_BATTERY_WATT_MAX_ENABLED
void Plane::throttle_watt_limiter(int8_t &min_throttle, int8_t &max_throttle)
{
uint32_t now = millis();
Expand Down Expand Up @@ -466,6 +467,7 @@ void Plane::throttle_watt_limiter(int8_t &min_throttle, int8_t &max_throttle)
min_throttle = constrain_int16(min_throttle, min_throttle + throttle_watt_limit_min, 0);
}
}
#endif // #if AP_BATTERY_WATT_MAX_ENABLED

/*
setup output channels all non-manual modes
Expand Down Expand Up @@ -509,8 +511,10 @@ void Plane::set_servos_controlled(void)
// compensate for battery voltage drop
throttle_voltage_comp(min_throttle, max_throttle);

#if AP_BATTERY_WATT_MAX_ENABLED
// apply watt limiter
throttle_watt_limiter(min_throttle, max_throttle);
#endif

SRV_Channels::set_output_scaled(SRV_Channel::k_throttle,
constrain_float(SRV_Channels::get_output_scaled(SRV_Channel::k_throttle), min_throttle, max_throttle));
Expand Down

0 comments on commit f4605e3

Please sign in to comment.