Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bms/pdb #415

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft

Bms/pdb #415

wants to merge 6 commits into from

Conversation

ariwasch
Copy link
Member

@ariwasch ariwasch commented Feb 6, 2022

No description provided.

Comment on lines 25 to 31
int cell_voltages[12];
bool is_cell_balancing = false;
int coloumb_count = 0;
const int battery_capacity = 22000; // mAh
int battery_percent_couloumb;
int battery_percent_voltage;
int battery_voltage;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our convention is to prefix private member variables with m_, eg. m_battery_voltage

Comment on lines 9 to 12
SPI spi(SDI, SDO, CLK); // mosi, miso, sclk
AnalogIn currentADC(CURR_ANLG_IN);
DigitalOut buzzer_en(BUZZER_EN);
DigitalOut chip_select(SAMPL);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These should be private member variables

buzzer_en.write(0);
chip_select.write(1);
spi.format(24, 3);
spi.frequency(1000000);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make this a constant (no magic numbers)

Comment on lines 30 to 33
int spi_message = 0b000000000000000000000000;
if (is_cell_balancing) {
spi_message = 0b111111111111111100000000;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: can make this a ternary expression:
int spi_message = (is_cell_balancing ? 0b111111111111111100000000 : 0b000000000000000000000000);

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also using hex here instead of binary might make it more readable

}

battery_voltage = 0;
for (int i = 0; i < 16; i++) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why 16? The size of your cell_voltages array is 12 so this will seg fault

Comment on lines 94 to 98
if (current < 0) {
current = 0;
} else if (current > 29) {
current = 29.1;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

} else if (current > 29) {
current = 29.1;
}
current = current * 1000; // converts Amps to MilliAmps
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: current *= 1000;

current = current * 1000; // converts Amps to MilliAmps
coloumb_count += current * 0.001; // converts to MilliAmp Seconds
int battery_capacity_seconds = battery_capacity * 3600; // converts to MilliAmp Seconds
battery_percent_couloumb = (1 - (coloumb_count / battery_capacity_seconds)) * 100;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Integer division will truncate, is this intended?

@@ -20,15 +20,12 @@ class PDBMonitoring final : public Module {
void load_monitoring();
void rail_monitoring();
void temperature_monitoring();
void LED_matrix();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like there were unintended changes to pdb_2021, can you revert these?

@@ -16,6 +16,9 @@ pdb_2021:
science_2021:
- SCIENCE_REV2_2021

bms_2022:
- PDB_REV2_2021
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should be making a new target for PDB_REV1_2022 (or whatever the rev number is) for the new PDB, keep PDB_REV2_2021 as it is

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants