Integrate current
The current counter on the shunt can't be activated for some reason.
This commit is contained in:
@ -20,6 +20,7 @@ void shunt_init() {
|
||||
shunt_data.energy = 0;
|
||||
shunt_data.current_counter = 0;
|
||||
shunt_data.last_message = 0;
|
||||
shunt_data.last_current_message = 0;
|
||||
}
|
||||
|
||||
void shunt_check() {
|
||||
@ -46,6 +47,12 @@ void shunt_handle_can_msg(uint16_t id, const uint8_t *data) {
|
||||
switch (id) {
|
||||
case CAN_ID_SHUNT_CURRENT:
|
||||
shunt_data.current = result;
|
||||
if (shunt_data.last_current_message > 0) {
|
||||
uint32_t now = HAL_GetTick();
|
||||
float dt = (now - shunt_data.last_current_message) * 0.001f;
|
||||
shunt_data.current_counter += shunt_data.current * dt;
|
||||
}
|
||||
shunt_data.last_current_message = HAL_GetTick();
|
||||
break;
|
||||
case CAN_ID_SHUNT_VOLTAGE1:
|
||||
shunt_data.voltage_bat = result;
|
||||
@ -63,7 +70,10 @@ void shunt_handle_can_msg(uint16_t id, const uint8_t *data) {
|
||||
shunt_data.power = result;
|
||||
break;
|
||||
case CAN_ID_SHUNT_CURRENT_COUNTER:
|
||||
shunt_data.current_counter = result;
|
||||
// TODO: Use this when we get the shunt to emit current counter data (the
|
||||
// shunt apparently emits As, not mAs)
|
||||
|
||||
// shunt_data.current_counter = result * 1000;
|
||||
break;
|
||||
case CAN_ID_SHUNT_ENERGY_COUNTER:
|
||||
shunt_data.energy = result;
|
||||
|
||||
Reference in New Issue
Block a user