Skip to content

Commit

Permalink
add pmu.soc_pct parameter and improve node name
Browse files Browse the repository at this point in the history
  • Loading branch information
PonomarevDA committed Jan 18, 2024
1 parent db881ee commit 40f267b
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 3 deletions.
3 changes: 2 additions & 1 deletion Src/dronecan_application/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]: </br> - Value of -1 means auto estimation (doesn't work at the moment), </br> - [0, 100] means constant, </br> - [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.
6 changes: 5 additions & 1 deletion Src/dronecan_application/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint8_t>(IntParamsIndexes::INTEGER_PARAMS_AMOUNT), NUM_OF_STR_PARAMS);
paramsLoadFromFlash();
Expand All @@ -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();
Expand Down
8 changes: 7 additions & 1 deletion Src/dronecan_application/modules/pmu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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{};
Expand Down Expand Up @@ -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;

Expand Down
9 changes: 9 additions & 0 deletions Src/dronecan_application/params.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ uavcan.node.id:
min: 0
max: 255

pmu.soc_pct:
type: Integer
note: "Percent of the full charge [-1, 127]: </br> - Value of -1 means auto estimation (doesn't work at the moment), </br> - [0, 100] means constant, </br> - [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.
Expand Down

0 comments on commit 40f267b

Please sign in to comment.