diff --git a/Src/dronecan_application/README.md b/Src/dronecan_application/README.md index 5bfee0d..2a4d7e0 100644 --- a/Src/dronecan_application/README.md +++ b/Src/dronecan_application/README.md @@ -3,7 +3,8 @@ The node has the following registers: | № | Register name | Description | | -- | ----------------------- | ----------- | | 1 | uavcan.node.id | Defines a node-ID. Allowed values [0,127]. | -| 2 | system.name | Defines custom node name. If empty, the node will use the default name. | +| 2 | pmu.soc_pct | Percent of the full charge [-1, 127]:
- Value of -1 means auto estimation (doesn't work at the moment),
- [0, 100] means constant,
- [101, 127] are incorrect values. | +| 3 | system.name | Defines custom node name. If empty, the node will use the default name. | > This docs was automatically generated. Do not edit it manually. diff --git a/Src/dronecan_application/application.cpp b/Src/dronecan_application/application.cpp index a48ec18..8dbba31 100644 --- a/Src/dronecan_application/application.cpp +++ b/Src/dronecan_application/application.cpp @@ -10,6 +10,10 @@ #include "periphery/adc/adc.hpp" #include "modules/pmu.hpp" +static bool isCharacter(uint8_t byte) { + return ((byte >= 'a' && byte <= 'z') || (byte >= 'A' && byte <= 'Z')); +} + void application_entry_point() { paramsInit(static_cast(IntParamsIndexes::INTEGER_PARAMS_AMOUNT), NUM_OF_STR_PARAMS); paramsLoadFromFlash(); @@ -21,7 +25,7 @@ void application_entry_point() { AdcPeriphery::init(); uavcanInitApplication(node_id); - uavcanSetNodeName(node_name); + uavcanSetNodeName(isCharacter(node_name[0]) ? node_name : "arl.pmu"); VtolPmu pmu; pmu.init(); diff --git a/Src/dronecan_application/modules/pmu.cpp b/Src/dronecan_application/modules/pmu.cpp index 654e215..92f8759 100644 --- a/Src/dronecan_application/modules/pmu.cpp +++ b/Src/dronecan_application/modules/pmu.cpp @@ -25,7 +25,8 @@ int8_t VtolPmu::init() { _battery_info.remaining_capacity_wh = NAN; _battery_info.full_charge_capacity_wh = NAN; _battery_info.hours_to_full_charge = 0; - _battery_info.state_of_health_pct = 0; + _battery_info.state_of_health_pct = 127; + _battery_info.state_of_charge_pct = 0; _battery_info.state_of_charge_pct_stdev = 0; DebugLogMessage_t msg{}; @@ -56,6 +57,11 @@ void VtolPmu::process() { void VtolPmu::_spin_once() { _last_spin_time_ms = HAL_GetTick(); + int8_t pmu_soc_pct = paramsGetIntegerValue(PARAM_PMU_SOC_PCT); + if (pmu_soc_pct >= 0) { + _battery_info.state_of_charge_pct = pmu_soc_pct; + } + float voltage = AdcPeriphery::get(AdcChannel::ADC_VIN) * ADC_VOLTAGE_MULTIPLIER; _battery_info.voltage = voltage; diff --git a/Src/dronecan_application/params.yaml b/Src/dronecan_application/params.yaml index 90edbda..909e241 100644 --- a/Src/dronecan_application/params.yaml +++ b/Src/dronecan_application/params.yaml @@ -7,6 +7,15 @@ uavcan.node.id: min: 0 max: 255 +pmu.soc_pct: + type: Integer + note: "Percent of the full charge [-1, 127]:
- Value of -1 means auto estimation (doesn't work at the moment),
- [0, 100] means constant,
- [101, 127] are incorrect values." + enum: PARAM_PMU_SOC_PCT + flags: mutable + default: -1 + min: 0 + max: 127 + system.name: type: String note: Defines custom node name. If empty, the node will use the default name.