Skip to content

SNS - Inverter Current - #97

Open
davidbeechey wants to merge 20 commits into
masterfrom
sns-inverter_current
Open

SNS - Inverter Current#97
davidbeechey wants to merge 20 commits into
masterfrom
sns-inverter_current

Conversation

@davidbeechey

Copy link
Copy Markdown
Contributor

Sensors implementation for the inverter current sensor.

Datasheet: https://www.lem.com/sites/default/files/products_datasheets/hob-p_series.pdf

@davidbeechey davidbeechey self-assigned this Apr 5, 2024

@TomLonergan03 TomLonergan03 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

very good start, a few things that can be nicer (I should have thought a bit harder about the adc mux tbh)

Comment thread lib/sensors/inverter_current.cpp Outdated
Comment thread lib/sensors/inverter_current.cpp Outdated
Comment thread lib/sensors/inverter_current.cpp Outdated

@TomLonergan03 TomLonergan03 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is all good, one more thing to do is add a test command to the debug REPL. You need to get the i2c object, then construct the sensor, and create a command that reads from the sensor, as well as doing the TOML parsing required.
LMK if you have questions on how that works

@TomLonergan03 TomLonergan03 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good, just needs lab time

Comment thread lib/debug/commands/inverter_current_commands.cpp Outdated
Comment thread lib/debug/commands/inverter_current_commands.cpp Outdated

@licornes-fluos licornes-fluos left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Other than the changes requested by Tom, all seems fine

@licornes-fluos licornes-fluos added the needs-testing Awaiting testing in the lab before merge label May 13, 2024
logger.log(core::LogLevel::kDebug, "Inverter current: %d", *current);
};
auto read_command
= std::make_unique<Command>(read_command_name, read_command_description, read_command_handler);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

There should also be a usage entry here

static const core::Float MIN_VOLTAGE = -3.3;

// These can be adjusted
const int reference_voltage = 1.65;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

const int ... = 1.65;

most type understanding webdev smdh (i'm totally not one now)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

💀

Comment on lines +34 to +40
static const int MAX_CURRENT = 75;
static const int MIN_CURRENT = -75;
static const core::Float MAX_VOLTAGE = 3.3;
static const core::Float MIN_VOLTAGE = -3.3;

// These can be adjusted
const int reference_voltage = 1.65;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

all of these should be in the header

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

good point

= inverter_current_voltage * ((MAX_CURRENT - MIN_CURRENT) / (MAX_VOLTAGE - MIN_VOLTAGE))
+ MIN_CURRENT;
const core::Float reference_voltage_biased = reference_voltage + virtual_ground;
const core::Float current_difference = current - reference_voltage_biased;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

what does this do? I doubt it's valid to subtract a voltage from an amperage

// The sensor maps -75A to 75A into -3V to 3V
// Since the ADC isn't differential, we need to differentiate the reference signal and the output
// signal
static const int MAX_CURRENT = 75;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

int should be sized, std::uint32_t or whatever suits


// These can be adjusted
const int reference_voltage = 1.65;
const core::Float virtual_ground = MAX_VOLTAGE / 2;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

what is the difference between reference voltage and virtual ground?

@TomLonergan03 TomLonergan03 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Lint also

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-testing Awaiting testing in the lab before merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants