Skip to content

Commit

Permalink
[Bridge] Update 3 phase bridge current convention
Browse files Browse the repository at this point in the history
  • Loading branch information
sahil-kale committed Jan 8, 2024
1 parent 7704622 commit 4272a02
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 31 deletions.
35 changes: 12 additions & 23 deletions hwbridge/3phase/bridge_3phase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,25 +57,19 @@ class Bridge3Phase {
*/
class phase_voltage_t {
public:
/**
* @brief Phase U voltage
*/
/// @brief Phase U voltage
float u = 0.0f;

/**
* @brief Phase V voltage
*/
/// @brief Phase V voltage
float v = 0.0f;

/**
* @brief Phase W voltage
*/
/// @brief Phase W voltage
float w = 0.0f;

/**
* @brief Equal operator
* @param rhs The right hand side of the operator
* @return bool True if the phase voltages are equal
* @return True if the phase voltages are equal, false otherwise
*/
bool operator==(const phase_voltage_t& rhs) const {
const bool u_equal = math::float_equals(this->u, rhs.u);
Expand All @@ -87,34 +81,29 @@ class Bridge3Phase {

/**
* @brief Phase current readings in Amps
* @note Convention is that positive current is going into the stator neutral point
*/
class phase_current_t {
public:
phase_current_t() = default;
/**
* @brief Construct a phase current
* @param u Phase U current
* @param v Phase V current
* @param w Phase W current
* @param u Phase U current (A)
* @param v Phase V current (A)
* @param w Phase W current (A)
*/
phase_current_t(float u, float v, float w) : u(u), v(v), w(w) {}
/**
* @brief Phase U current
*/
/// @brief Phase U current (A)
float u = 0.0f;
/**
* @brief Phase V current
*/
/// @brief Phase V current (A)
float v = 0.0f;
/**
* @brief Phase W current
*/
/// @brief Phase W current (A)
float w = 0.0f;

/**
* @brief Equal operator
* @param rhs The right hand side of the operator
* @return bool True if the phase currents are equal
* @return True if the phase currents are equal, false otherwise
*/
bool operator==(const phase_current_t& rhs) const {
const bool u_equal = math::float_equals(this->u, rhs.u);
Expand Down
3 changes: 2 additions & 1 deletion hwbridge/3phase/phase_inductance_estimator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ PhaseInductanceEstimatorController::Result PhaseInductanceEstimatorController::r
// Calculate the phase inductance
// TODO: Perhaps take an average of the bus voltage during the measurement period? But it's likely super fast anyways
const float bus_voltage = input.bus_voltage;
const float current = input.phase_currents.u;
const float current =
input.phase_currents.u * -1.0f; // Negative current as positive current is going into the stator neutral
// V = 3/2*L_s * di/dt
// L_s = 2/3 * V / di/dt
// Note: the L_s is the phase inductance in a 3-phase system. When we measure the current in the singular phase that
Expand Down
4 changes: 3 additions & 1 deletion hwbridge/3phase/phase_resistance_estimator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@ PhaseResistanceEstimatorController::State PhaseResistanceEstimatorController::de
case State::MEASUREMENT_IN_PROGRESS: {
const utime_t measurement_end_time = measurement_start_time_ + params_.measurement_duration;
if (current_time >= measurement_end_time) {
const float current_diff = fabsf(params_.target_current - input.phase_currents.u);
const float input_current =
input.phase_currents.u * -1.0f; // Negative current as positive current is going into the stator neutral
const float current_diff = fabsf(params_.target_current - input_current);
const bool is_current_within_tolerance = (current_diff <= params_.current_tolerance);
if (is_current_within_tolerance) {
ret = State::ESTIMATE_COMPLETE;
Expand Down
8 changes: 4 additions & 4 deletions test/phase_Lest_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ void init_and_ready_to_finish_measurement_in_progress(basilisk_hal::MOCK_HAL_CLO

PhaseInductanceEstimatorControllerPublic::Input input;
input.bus_voltage = 24.0f;
input.phase_currents.u = 1.0f;
input.phase_currents.u = -1.0f;
input.phase_currents.v = 0.0f;
input.phase_currents.w = 0.0f;

Expand All @@ -172,7 +172,7 @@ void init_and_ready_to_finish_measurement_in_progress(basilisk_hal::MOCK_HAL_CLO
// Set the clock to be just after the measurement duration has elapsed
const utime_t faked_time_3 = faked_time + params.measurement_duration;
EXPECT_CALL(mock_clock, get_time_us()).WillRepeatedly(Return(faked_time_3));
input.phase_currents.u = 1.0f;
input.phase_currents.u = -1.0f;
}

// Test that we transition from MEASUREMENT_IN_PROGRESS to ESTIMATE_COMPLETE after the measurement duration has elapsed
Expand Down Expand Up @@ -230,7 +230,7 @@ TEST(PhaseInductanceEstimatorControllerTest, test_measurement_in_progress_to_est
EXPECT_CALL(mock_clock, get_time_us()).WillRepeatedly(Return(faked_time_3));

// Run the controller again
input.phase_currents.u = 1.6f;
input.phase_currents.u = -1.6f;
result = controller.run_phase_inductance_estimator(input);

// Check that the state is ESTIMATE_COMPLETE
Expand Down Expand Up @@ -280,7 +280,7 @@ TEST(PhaseInductanceEstimatorControllerTest, test_measurement_in_progress_to_err
init_and_ready_to_finish_measurement_in_progress(mock_clock, controller, params);
PhaseInductanceEstimatorControllerPublic::Input input;
input.bus_voltage = 0.0f;
input.phase_currents.u = 1.0f;
input.phase_currents.u = -1.0f;
input.phase_currents.v = 0.0f;
input.phase_currents.w = 0.0f;

Expand Down
4 changes: 2 additions & 2 deletions test/phase_Rest_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ TEST(PhaseResistanceEstimatorControllerTest, test_measurement_in_progress_to_est
EXPECT_CALL(mock_clock, get_time_us()).WillRepeatedly(Return(faked_time_2));

// Make the current the same as the target current
input.phase_currents.u = params.target_current;
input.phase_currents.u = -params.target_current;
result = controller.run_phase_resistance_estimator(input);

// Check that the state is MEASUREMENT_IN_PROGRESS
Expand Down Expand Up @@ -224,7 +224,7 @@ TEST(PhaseResistanceEstimatorController, test_current_not_within_margin) {
EXPECT_CALL(mock_clock, get_time_us()).WillRepeatedly(Return(faked_time_2));

// Make the current the same as the target current minus the margin plus a little bit
input.phase_currents.u = params.target_current - (params.current_tolerance + 0.01f);
input.phase_currents.u = -(params.target_current - (params.current_tolerance + 0.01f));

result = controller.run_phase_resistance_estimator(input);

Expand Down

0 comments on commit 4272a02

Please sign in to comment.