mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-03 13:58:53 +08:00
auterion pm: set max current based on eeprom
This commit is contained in:
committed by
Ramon Roche
parent
900f108a2e
commit
38c776784e
@@ -96,6 +96,7 @@ void PowerMonitorSelectorAuterion::try_eeprom_start()
|
|||||||
EepromBlockPm eeprom_block_pm = _eeprom_blocks_pm[ii];
|
EepromBlockPm eeprom_block_pm = _eeprom_blocks_pm[ii];
|
||||||
|
|
||||||
uint16_t dev_type = eeprom_block_pm.dev_type;
|
uint16_t dev_type = eeprom_block_pm.dev_type;
|
||||||
|
set_max_current(dev_type, eeprom_block_pm.max_current);
|
||||||
set_shunt_value(dev_type, eeprom_block_pm.shunt_value);
|
set_shunt_value(dev_type, eeprom_block_pm.shunt_value);
|
||||||
int ret_val = start_pm(_buses[i].bus_number, dev_type, eeprom_block_pm.i2c_addr, _buses[i].id);
|
int ret_val = start_pm(_buses[i].bus_number, dev_type, eeprom_block_pm.i2c_addr, _buses[i].id);
|
||||||
|
|
||||||
@@ -368,6 +369,19 @@ bool PowerMonitorSelectorAuterion::is_user_configured(const uint16_t dev_type) c
|
|||||||
return sens_en != 0;
|
return sens_en != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PowerMonitorSelectorAuterion::set_max_current(const uint16_t dev_type, const float max_current) const
|
||||||
|
{
|
||||||
|
const char *ina_type = get_ina_type(dev_type);
|
||||||
|
|
||||||
|
if (ina_type == nullptr) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
char param_name[PARAM_MAX_LEN];
|
||||||
|
snprintf(param_name, sizeof(param_name), "INA%s_CURRENT", ina_type);
|
||||||
|
set_float_param(param_name, max_current);
|
||||||
|
}
|
||||||
|
|
||||||
void PowerMonitorSelectorAuterion::set_shunt_value(const uint16_t dev_type, const float shunt_value) const
|
void PowerMonitorSelectorAuterion::set_shunt_value(const uint16_t dev_type, const float shunt_value) const
|
||||||
{
|
{
|
||||||
const char *ina_type = get_ina_type(dev_type);
|
const char *ina_type = get_ina_type(dev_type);
|
||||||
@@ -378,12 +392,16 @@ void PowerMonitorSelectorAuterion::set_shunt_value(const uint16_t dev_type, cons
|
|||||||
|
|
||||||
char param_name[PARAM_MAX_LEN];
|
char param_name[PARAM_MAX_LEN];
|
||||||
snprintf(param_name, sizeof(param_name), "INA%s_SHUNT", ina_type);
|
snprintf(param_name, sizeof(param_name), "INA%s_SHUNT", ina_type);
|
||||||
|
set_float_param(param_name, shunt_value);
|
||||||
|
}
|
||||||
|
|
||||||
float current_shunt_value = 0;
|
void PowerMonitorSelectorAuterion::set_float_param(const char *param_name, const float param_val) const
|
||||||
param_get(param_find(param_name), ¤t_shunt_value);
|
{
|
||||||
|
float current_param_value = 0;
|
||||||
|
param_get(param_find(param_name), ¤t_param_value);
|
||||||
|
|
||||||
if (fabsf(current_shunt_value - shunt_value) > FLT_EPSILON) {
|
if (fabsf(current_param_value - param_val) > FLT_EPSILON) {
|
||||||
param_set(param_find(param_name), &(shunt_value));
|
param_set(param_find(param_name), &(param_val));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -160,7 +160,9 @@ private:
|
|||||||
const char *get_start_command(const uint16_t dev_type) const;
|
const char *get_start_command(const uint16_t dev_type) const;
|
||||||
|
|
||||||
bool is_user_configured(const uint16_t dev_type) const;
|
bool is_user_configured(const uint16_t dev_type) const;
|
||||||
|
void set_max_current(const uint16_t dev_type, const float max_current) const;
|
||||||
void set_shunt_value(const uint16_t dev_type, const float shunt_value) const;
|
void set_shunt_value(const uint16_t dev_type, const float shunt_value) const;
|
||||||
|
void set_float_param(const char *param_name, const float param_val) const;
|
||||||
const char *get_ina_type(const uint16_t dev_type) const;
|
const char *get_ina_type(const uint16_t dev_type) const;
|
||||||
uint16_t crc16_update(const uint16_t current_crc, const uint8_t *data_p, size_t length) const;
|
uint16_t crc16_update(const uint16_t current_crc, const uint8_t *data_p, size_t length) const;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user