Skip to content

Commit

Permalink
fix formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
davidbeechey committed Jun 10, 2024
1 parent a8bcff9 commit 507a733
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions lib/sensors/inverter_current.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#include "adc_mux.hpp"

#include <inverter_current.hpp>
#include <cstdint>

#include <inverter_current.hpp>

namespace hyped::sensors {

InverterCurrent::InverterCurrent(core::ILogger &logger,
Expand All @@ -28,21 +29,24 @@ std::optional<core::Float> InverterCurrent::readCurrent()
}

// 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;
static const int MIN_CURRENT = -75;
// Since the ADC isn't differential, we need to differentiate the reference signal and the output
// signal
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;
const int reference_voltage = 1.65;
const core::Float virtual_ground = MAX_VOLTAGE / 2;

// Calculate the current
const int inverter_current_voltage = *inverter_current * (MAX_VOLTAGE - virtual_ground) + virtual_ground;
const core::Float current = sensor_voltage * ((MAX_CURRENT - MIN_CURRENT) / (MAX_VOLTAGE - MIN_VOLTAGE)) + MIN_CURRENT;
const int inverter_current_voltage
= *inverter_current * (MAX_VOLTAGE - virtual_ground) + virtual_ground;
const core::Float current
= sensor_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;
const core::Float current_difference = current - reference_voltage_biased;
return current_difference;
}

Expand Down

0 comments on commit 507a733

Please sign in to comment.