Skip to content

Commit

Permalink
more comments
Browse files Browse the repository at this point in the history
  • Loading branch information
mcells committed Sep 29, 2024
1 parent e4b8039 commit 0285076
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions src/common/base_classes/FOCMotor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ int FOCMotor::characteriseMotor(float voltage){
float current_electric_angle = electricalAngle();

float correction_factor = 1.5f; // 1.5 for 3 phase motors, because we measure over a series-parallel connection. TODO: what about 2 phase motors?

SIMPLEFOC_DEBUG("MOT: Measuring phase to phase resistance, keep motor still...");

// Apply zero volts
setPhaseVoltage(0, 0, current_electric_angle);
Expand Down Expand Up @@ -117,6 +119,8 @@ int FOCMotor::characteriseMotor(float voltage){
_delay(100);

//start inductance measurement
SIMPLEFOC_DEBUG("MOT: Measuring inductance, keep motor still...");

unsigned long t0 = 0;
unsigned long t1a = 0;
unsigned long t1b = 0;
Expand All @@ -125,9 +129,8 @@ int FOCMotor::characteriseMotor(float voltage){

uint iterations = 5;
uint cycles = 4;
uint risetime_us = 200;
uint settle_us = 100000;
float timeconstant = 0.0f;
uint risetime_us = 200; // short for worst case scenario with low inductance
uint settle_us = 100000; // long for worst case scenario with high inductance

for (size_t i = 0; i < iterations; i++)
{
Expand Down Expand Up @@ -159,8 +162,6 @@ int FOCMotor::characteriseMotor(float voltage){
float dt = 0.5f*(t1a + t1b - 2*t0)/1000000.0f;
inductanceq += fabs(- (resistance * dt) / log((voltage - resistance * fabs(l_currents.q - zerocurrent.q)) / voltage))/correction_factor;

// SIMPLEFOC_DEBUG("MOT: Estimated Q-inductance in mH: ", inductanceq * 1000.0f);

}

inductanceq /= cycles;
Expand Down Expand Up @@ -194,18 +195,15 @@ int FOCMotor::characteriseMotor(float voltage){
float dt = 0.5f*(t1a + t1b - 2*t0)/1000000.0f;
inductanced += fabs(- (resistance * dt) / log((voltage - resistance * fabs(l_currents.d - zerocurrent.d)) / voltage))/correction_factor;


// SIMPLEFOC_DEBUG("MOT: Estimated D-inductance in mH: ", inductanced * 1000.0f);

}

inductanced /= cycles;
Ld = i == 0 ? inductanced : Ld * 0.6 + inductanced * 0.4;

SIMPLEFOC_DEBUG("MOT: Estimated D-inductance in mH: ", Ld * 1000.0f);

timeconstant = fabs(0.5f*(Ld + Lq) / resistance);
risetime_us = _constrain(1000000 * timeconstant, 100, 10000);
float timeconstant = fabs(0.5f*(Ld + Lq) / resistance); // Timeconstant of an RL circuit (L/R)
risetime_us = _constrain(1000000 * timeconstant, 100, 10000); // Wait as long as possible (due to limited timing accuracy & sample rate), but as short as needed (while the current still changes)
settle_us = 10 * risetime_us;
SIMPLEFOC_DEBUG("MOT: Estimated time constant in us: ", timeconstant * 1000000.0f);

Expand Down

0 comments on commit 0285076

Please sign in to comment.