Skip to content

Commit d597493

Browse files
committed
a big refactor without breaking the API
1 parent a48bcb6 commit d597493

File tree

14 files changed

+605
-1282
lines changed

14 files changed

+605
-1282
lines changed

src/BLDCMotor.cpp

Lines changed: 14 additions & 355 deletions
Large diffs are not rendered by default.

src/BLDCMotor.h

Lines changed: 17 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -32,46 +32,20 @@ class BLDCMotor: public FOCMotor
3232
*/
3333
virtual void linkDriver(BLDCDriver* driver);
3434

35-
/**
36-
* BLDCDriver link:
37-
* - 3PWM
38-
* - 6PWM
39-
*/
40-
BLDCDriver* driver;
35+
36+
float Ua, Ub, Uc;//!< Current phase voltages Ua,Ub and Uc set to motor
37+
38+
BLDCDriver* driver; //!< BLDCDriver instance
39+
// Methods implementing the FOCMotor interface
4140

4241
/** Motor hardware init function */
43-
int init() override;
42+
int init() override;
4443
/** Motor disable function */
4544
void disable() override;
4645
/** Motor enable function */
4746
void enable() override;
4847

4948
/**
50-
* Function initializing FOC algorithm
51-
* and aligning sensor's and motors' zero position
52-
*/
53-
int initFOC() override;
54-
/**
55-
* Function running FOC algorithm in real-time
56-
* it calculates the gets motor angle and sets the appropriate voltages
57-
* to the phase pwm signals
58-
* - the faster you can run it the better Arduino UNO ~1ms, Bluepill ~ 100us
59-
*/
60-
void loopFOC() override;
61-
62-
/**
63-
* Function executing the control loops set by the controller parameter of the BLDCMotor.
64-
*
65-
* @param target Either voltage, angle or velocity based on the motor.controller
66-
* If it is not set the motor will use the target set in its variable motor.target
67-
*
68-
* This function doesn't need to be run upon each loop execution - depends of the use case
69-
*/
70-
void move(float target = NOT_SET) override;
71-
72-
float Ua, Ub, Uc;//!< Current phase voltages Ua,Ub and Uc set to motor
73-
74-
/**
7549
* Method using FOC to set Uq to the motor at the optimal angle
7650
* Heart of the FOC algorithm
7751
*
@@ -81,6 +55,17 @@ class BLDCMotor: public FOCMotor
8155
*/
8256
void setPhaseVoltage(float Uq, float Ud, float angle_el) override;
8357

58+
/**
59+
* Method estimating the Back EMF voltage based
60+
* based on the current velocity and KV rating
61+
*
62+
* @param velocity Current motor velocity
63+
*/
64+
float estimateBEMF(float velocity) override;
65+
66+
67+
// Methods overriding the FOCMotor default behavior
68+
8469
/**
8570
* Measure resistance and inductance of a BLDCMotor and print results to debug.
8671
* If a sensor is available, an estimate of zero electric angle will be reported too.
@@ -91,15 +76,7 @@ class BLDCMotor: public FOCMotor
9176
return FOCMotor::characteriseMotor(voltage, 1.5f);
9277
}
9378

94-
private:
95-
// FOC methods
9679

97-
/** Sensor alignment to electrical 0 angle of the motor */
98-
int alignSensor();
99-
/** Current sense and motor phase alignment */
100-
int alignCurrentSense();
101-
/** Motor and sensor alignment to the sensors absolute 0 angle */
102-
int absoluteZeroSearch();
10380
};
10481

10582

0 commit comments

Comments
 (0)