Skip to content

Commit

Permalink
AP_BattMonitor: make param BATT_WATT_MAX plane only
Browse files Browse the repository at this point in the history
  • Loading branch information
magicrub committed Apr 21, 2016
1 parent df922da commit 0e775f5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
7 changes: 7 additions & 0 deletions libraries/AP_BattMonitor/AP_BattMonitor.cpp
Expand Up @@ -58,13 +58,15 @@ const AP_Param::GroupInfo AP_BattMonitor::var_info[] = {

// 7 & 8 were used for VOLT2_PIN and VOLT2_MULT

#if APM_BUILD_TYPE(APM_BUILD_ArduPlane)
// @Param: _WATT_MAX
// @DisplayName: Maximum allowed power (Watts)
// @Description: If battery wattage (voltage * current) exceeds this value then the system will reduce max throttle (THR_MAX, TKOFF_THR_MAX and THR_MIN for reverse thrust) to satisfy this limit. This helps limit high current to low C rated batteries regardless of battery voltage. The max throttle will slowly grow back to THR_MAX (or TKOFF_THR_MAX ) and THR_MIN if demanding the current max and under the watt max. Use 0 to disable.
// @Units: Watts
// @Increment: 1
// @User: Advanced
AP_GROUPINFO("_WATT_MAX", 9, AP_BattMonitor, _watt_max[0], AP_BATT_MAX_WATT_DEFAULT),
#endif

// 10 is left for future expansion

Expand Down Expand Up @@ -119,13 +121,15 @@ const AP_Param::GroupInfo AP_BattMonitor::var_info[] = {
AP_GROUPINFO("2_CAPACITY", 17, AP_BattMonitor, _pack_capacity[1], AP_BATT_CAPACITY_DEFAULT),


#if APM_BUILD_TYPE(APM_BUILD_ArduPlane)
// @Param: 2_WATT_MAX
// @DisplayName: Maximum allowed current
// @Description: If battery wattage (voltage * current) exceeds this value then the system will reduce max throttle (THR_MAX, TKOFF_THR_MAX and THR_MIN for reverse thrust) to satisfy this limit. This helps limit high current to low C rated batteries regardless of battery voltage. The max throttle will slowly grow back to THR_MAX (or TKOFF_THR_MAX ) and THR_MIN if demanding the current max and under the watt max. Use 0 to disable.
// @Units: Amps
// @Increment: 1
// @User: Advanced
AP_GROUPINFO("2_WATT_MAX", 18, AP_BattMonitor, _watt_max[1], AP_BATT_MAX_WATT_DEFAULT),
#endif

#endif // AP_BATT_MONITOR_MAX_INSTANCES > 1

Expand Down Expand Up @@ -322,6 +326,7 @@ bool AP_BattMonitor::exhausted(uint8_t instance, float low_voltage, float min_ca
return false;
}

#if APM_BUILD_TYPE(APM_BUILD_ArduPlane)
// return true if any battery is pushing too much power
bool AP_BattMonitor::overpower_detected() const
{
Expand All @@ -340,3 +345,5 @@ bool AP_BattMonitor::overpower_detected(uint8_t instance) const
}
return false;
}
#endif

5 changes: 5 additions & 0 deletions libraries/AP_BattMonitor/AP_BattMonitor.h
Expand Up @@ -4,6 +4,7 @@
#include <AP_Common/AP_Common.h>
#include <AP_Param/AP_Param.h>
#include <AP_Math/AP_Math.h>
#include <AP_Vehicle/AP_Vehicle_Type.h>

// maximum number of battery monitors
#define AP_BATT_MONITOR_MAX_INSTANCES 2
Expand Down Expand Up @@ -108,12 +109,14 @@ class AP_BattMonitor
/// set_monitoring - sets the monitor type (used for example sketch only)
void set_monitoring(uint8_t instance, uint8_t mon) { _monitoring[instance].set(mon); }

#if APM_BUILD_TYPE(APM_BUILD_ArduPlane)
bool get_watt_max() { return get_watt_max(AP_BATT_PRIMARY_INSTANCE); }
bool get_watt_max(uint8_t instance) { return _watt_max[instance]; }

/// true when (voltage * current) > watt_max
bool overpower_detected() const;
bool overpower_detected(uint8_t instance) const;
#endif

static const struct AP_Param::GroupInfo var_info[];

Expand All @@ -127,7 +130,9 @@ class AP_BattMonitor
AP_Float _curr_amp_per_volt[AP_BATT_MONITOR_MAX_INSTANCES]; /// voltage on current pin multiplied by this to calculate current in amps
AP_Float _curr_amp_offset[AP_BATT_MONITOR_MAX_INSTANCES]; /// offset voltage that is subtracted from current pin before conversion to amps
AP_Int32 _pack_capacity[AP_BATT_MONITOR_MAX_INSTANCES]; /// battery pack capacity less reserve in mAh
#if APM_BUILD_TYPE(APM_BUILD_ArduPlane)
AP_Int16 _watt_max[AP_BATT_MONITOR_MAX_INSTANCES]; /// max battery power allowed. Reduce max throttle to reduce current to satisfy this limit
#endif

private:
BattMonitor_State state[AP_BATT_MONITOR_MAX_INSTANCES];
Expand Down

0 comments on commit 0e775f5

Please sign in to comment.