mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-31 21:51:36 +08:00
Consider the throttle load for battery voltage calculation
This commit is contained in:
@@ -918,6 +918,11 @@ int commander_thread_main(int argc, char *argv[])
|
|||||||
struct system_power_s system_power;
|
struct system_power_s system_power;
|
||||||
memset(&system_power, 0, sizeof(system_power));
|
memset(&system_power, 0, sizeof(system_power));
|
||||||
|
|
||||||
|
/* Subscribe to actuator controls (outputs) */
|
||||||
|
int actuator_controls_sub = orb_subscribe(ORB_ID_VEHICLE_ATTITUDE_CONTROLS);
|
||||||
|
struct actuator_controls_s actuator_controls;
|
||||||
|
memset(&actuator_controls, 0, sizeof(actuator_controls));
|
||||||
|
|
||||||
control_status_leds(&status, &armed, true);
|
control_status_leds(&status, &armed, true);
|
||||||
|
|
||||||
/* now initialized */
|
/* now initialized */
|
||||||
@@ -1199,13 +1204,17 @@ int commander_thread_main(int argc, char *argv[])
|
|||||||
|
|
||||||
if (updated) {
|
if (updated) {
|
||||||
orb_copy(ORB_ID(battery_status), battery_sub, &battery);
|
orb_copy(ORB_ID(battery_status), battery_sub, &battery);
|
||||||
|
orb_copy(ORB_ID_VEHICLE_ATTITUDE_CONTROLS, actuator_controls_sub, &actuator_controls);
|
||||||
|
|
||||||
/* only consider battery voltage if system has been running 2s and battery voltage is valid */
|
/* only consider battery voltage if system has been running 2s and battery voltage is valid */
|
||||||
if (hrt_absolute_time() > start_time + 2000000 && battery.voltage_filtered_v > 0.0f) {
|
if (hrt_absolute_time() > start_time + 2000000 && battery.voltage_filtered_v > 0.0f) {
|
||||||
status.battery_voltage = battery.voltage_filtered_v;
|
status.battery_voltage = battery.voltage_filtered_v;
|
||||||
status.battery_current = battery.current_a;
|
status.battery_current = battery.current_a;
|
||||||
status.condition_battery_voltage_valid = true;
|
status.condition_battery_voltage_valid = true;
|
||||||
status.battery_remaining = battery_remaining_estimate_voltage(battery.voltage_filtered_v, battery.discharged_mah);
|
|
||||||
|
/* get throttle (if armed), as we only care about energy negative throttle also counts */
|
||||||
|
float throttle = (armed.armed) ? fabsf(actuator_controls.control[3]) : 0.0f;
|
||||||
|
status.battery_remaining = battery_remaining_estimate_voltage(battery.voltage_filtered_v, battery.discharged_mah, throttle);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -281,15 +281,17 @@ void rgbled_set_pattern(rgbled_pattern_t *pattern)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
float battery_remaining_estimate_voltage(float voltage, float discharged)
|
float battery_remaining_estimate_voltage(float voltage, float discharged, float throttle_normalized)
|
||||||
{
|
{
|
||||||
float ret = 0;
|
float ret = 0;
|
||||||
static param_t bat_v_empty_h;
|
static param_t bat_v_empty_h;
|
||||||
static param_t bat_v_full_h;
|
static param_t bat_v_full_h;
|
||||||
static param_t bat_n_cells_h;
|
static param_t bat_n_cells_h;
|
||||||
static param_t bat_capacity_h;
|
static param_t bat_capacity_h;
|
||||||
|
static param_t bat_v_load_drop_h;
|
||||||
static float bat_v_empty = 3.2f;
|
static float bat_v_empty = 3.2f;
|
||||||
static float bat_v_full = 4.0f;
|
static float bat_v_full = 4.0f;
|
||||||
|
static float bat_v_load_drop = 0.1f;
|
||||||
static int bat_n_cells = 3;
|
static int bat_n_cells = 3;
|
||||||
static float bat_capacity = -1.0f;
|
static float bat_capacity = -1.0f;
|
||||||
static bool initialized = false;
|
static bool initialized = false;
|
||||||
@@ -300,20 +302,22 @@ float battery_remaining_estimate_voltage(float voltage, float discharged)
|
|||||||
bat_v_full_h = param_find("BAT_V_FULL");
|
bat_v_full_h = param_find("BAT_V_FULL");
|
||||||
bat_n_cells_h = param_find("BAT_N_CELLS");
|
bat_n_cells_h = param_find("BAT_N_CELLS");
|
||||||
bat_capacity_h = param_find("BAT_CAPACITY");
|
bat_capacity_h = param_find("BAT_CAPACITY");
|
||||||
|
bat_v_load_drop_h = param_find("BAT_V_LOAD_DROP");
|
||||||
initialized = true;
|
initialized = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (counter % 100 == 0) {
|
if (counter % 100 == 0) {
|
||||||
param_get(bat_v_empty_h, &bat_v_empty);
|
param_get(bat_v_empty_h, &bat_v_empty);
|
||||||
param_get(bat_v_full_h, &bat_v_full);
|
param_get(bat_v_full_h, &bat_v_full);
|
||||||
|
param_get(bat_v_load_drop_h, &bat_v_load_drop);
|
||||||
param_get(bat_n_cells_h, &bat_n_cells);
|
param_get(bat_n_cells_h, &bat_n_cells);
|
||||||
param_get(bat_capacity_h, &bat_capacity);
|
param_get(bat_capacity_h, &bat_capacity);
|
||||||
}
|
}
|
||||||
|
|
||||||
counter++;
|
counter++;
|
||||||
|
|
||||||
/* remaining charge estimate based on voltage */
|
/* remaining charge estimate based on voltage and internal resistance (drop under load) */
|
||||||
float remaining_voltage = (voltage - bat_n_cells * bat_v_empty) / (bat_n_cells * (bat_v_full - bat_v_empty));
|
float remaining_voltage = (voltage - bat_n_cells * (bat_v_empty - (bat_v_load_drop * throttle_normalized)) / (bat_n_cells * (bat_v_full - bat_v_empty));
|
||||||
|
|
||||||
if (bat_capacity > 0.0f) {
|
if (bat_capacity > 0.0f) {
|
||||||
/* if battery capacity is known, use discharged current for estimate, but don't show more than voltage estimate */
|
/* if battery capacity is known, use discharged current for estimate, but don't show more than voltage estimate */
|
||||||
|
|||||||
@@ -80,8 +80,9 @@ void rgbled_set_pattern(rgbled_pattern_t *pattern);
|
|||||||
*
|
*
|
||||||
* @param voltage the current battery voltage
|
* @param voltage the current battery voltage
|
||||||
* @param discharged the discharged capacity
|
* @param discharged the discharged capacity
|
||||||
|
* @param throttle_normalized the normalized throttle magnitude from 0 to 1. Negative throttle should be converted to this range as well, as it consumes energy.
|
||||||
* @return the estimated remaining capacity in 0..1
|
* @return the estimated remaining capacity in 0..1
|
||||||
*/
|
*/
|
||||||
float battery_remaining_estimate_voltage(float voltage, float discharged);
|
float battery_remaining_estimate_voltage(float voltage, float discharged, float throttle_normalized);
|
||||||
|
|
||||||
#endif /* COMMANDER_HELPER_H_ */
|
#endif /* COMMANDER_HELPER_H_ */
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ PARAM_DEFINE_FLOAT(TRIM_YAW, 0.0f);
|
|||||||
*
|
*
|
||||||
* @group Battery Calibration
|
* @group Battery Calibration
|
||||||
*/
|
*/
|
||||||
PARAM_DEFINE_FLOAT(BAT_V_EMPTY, 3.4f);
|
PARAM_DEFINE_FLOAT(BAT_V_EMPTY, 3.3f);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Full cell voltage.
|
* Full cell voltage.
|
||||||
@@ -65,7 +65,7 @@ PARAM_DEFINE_FLOAT(BAT_V_EMPTY, 3.4f);
|
|||||||
*
|
*
|
||||||
* @group Battery Calibration
|
* @group Battery Calibration
|
||||||
*/
|
*/
|
||||||
PARAM_DEFINE_FLOAT(BAT_V_FULL, 3.9f);
|
PARAM_DEFINE_FLOAT(BAT_V_FULL, 4.15f);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Number of cells.
|
* Number of cells.
|
||||||
|
|||||||
Reference in New Issue
Block a user