Skip to content

Commit

Permalink
[hal] Fix scaling factor for decoding PDH channel currents from CAN
Browse files Browse the repository at this point in the history
The original value caused an issue where currents above 15A would roll over to 0 for channels 20-23. Note this will require at least PDH firmware  v24.0.0 to get a correct current reading on those channels.
  • Loading branch information
jfabellera committed Sep 14, 2023
1 parent 57b2d6f commit b9362a7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
16 changes: 8 additions & 8 deletions hal/src/main/native/athena/rev/PDHFrames.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -947,12 +947,12 @@ bool PDH_status_3_channel_15_breaker_fault_is_in_range(uint8_t value)

uint8_t PDH_status_3_channel_20_current_encode(double value)
{
return (uint8_t)(value / 0.0625);
return (uint8_t)(value / 0.125);
}

double PDH_status_3_channel_20_current_decode(uint8_t value)
{
return ((double)value * 0.0625);
return ((double)value * 0.125);
}

bool PDH_status_3_channel_20_current_is_in_range(uint8_t value)
Expand All @@ -964,12 +964,12 @@ bool PDH_status_3_channel_20_current_is_in_range(uint8_t value)

uint8_t PDH_status_3_channel_21_current_encode(double value)
{
return (uint8_t)(value / 0.0625);
return (uint8_t)(value / 0.125);
}

double PDH_status_3_channel_21_current_decode(uint8_t value)
{
return ((double)value * 0.0625);
return ((double)value * 0.125);
}

bool PDH_status_3_channel_21_current_is_in_range(uint8_t value)
Expand All @@ -981,12 +981,12 @@ bool PDH_status_3_channel_21_current_is_in_range(uint8_t value)

uint8_t PDH_status_3_channel_22_current_encode(double value)
{
return (uint8_t)(value / 0.0625);
return (uint8_t)(value / 0.125);
}

double PDH_status_3_channel_22_current_decode(uint8_t value)
{
return ((double)value * 0.0625);
return ((double)value * 0.125);
}

bool PDH_status_3_channel_22_current_is_in_range(uint8_t value)
Expand All @@ -998,12 +998,12 @@ bool PDH_status_3_channel_22_current_is_in_range(uint8_t value)

uint8_t PDH_status_3_channel_23_current_encode(double value)
{
return (uint8_t)(value / 0.0625);
return (uint8_t)(value / 0.125);
}

double PDH_status_3_channel_23_current_decode(uint8_t value)
{
return ((double)value * 0.0625);
return ((double)value * 0.125);
}

bool PDH_status_3_channel_23_current_is_in_range(uint8_t value)
Expand Down
16 changes: 8 additions & 8 deletions hal/src/main/native/athena/rev/PDHFrames.h
Original file line number Diff line number Diff line change
Expand Up @@ -383,29 +383,29 @@ struct PDH_status_3_t {
uint8_t channel_15_breaker_fault : 1;

/**
* Range: 0..511 (0..31.9375 A)
* Scale: 0.0625
* Range: 0..255.5 (0..31.9375 A)
* Scale: 0.125
* Offset: 0
*/
uint8_t channel_20_current : 8;

/**
* Range: 0..511 (0..31.9375 A)
* Scale: 0.0625
* Range: 0..255.5 (0..31.9375 A)
* Scale: 0.125
* Offset: 0
*/
uint8_t channel_21_current : 8;

/**
* Range: 0..511 (0..31.9375 A)
* Scale: 0.0625
* Range: 0..255.5 (0..31.9375 A)
* Scale: 0.125
* Offset: 0
*/
uint8_t channel_22_current : 8;

/**
* Range: 0..511 (0..31.9375 A)
* Scale: 0.0625
* Range: 0..255.5 (0..31.9375 A)
* Scale: 0.125
* Offset: 0
*/
uint8_t channel_23_current : 8;
Expand Down

0 comments on commit b9362a7

Please sign in to comment.