Skip to content

Commit 678c578

Browse files
committed
refactored the back-emf support using KV rating of the motor - rpm/V
1 parent bed08d7 commit 678c578

File tree

7 files changed

+15
-9
lines changed

7 files changed

+15
-9
lines changed

examples/hardware_specific_examples/Odrive_examples/odrive_example_encoder/odrive_example_encoder.ino

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
// Odrive M0 encoder pinout
2222
#define M0_ENC_A PB4
2323
#define M0_ENC_B PB5
24+
#define M0_ENC_Z PC9
2425

2526

2627
// Odrive M1 motor pinout
@@ -36,6 +37,7 @@
3637
// Odrive M1 encoder pinout
3738
#define M1_ENC_A PB6
3839
#define M1_ENC_B PB7
40+
#define M1_ENC_Z PC15
3941

4042
// M1 & M2 common enable pin
4143
#define EN_GATE PB12
@@ -59,11 +61,12 @@ void doMotor(char* cmd) { command.motor(&motor, cmd); }
5961
// current sensing on B and C phases, phase A not connected
6062
LowsideCurrentSense current_sense = LowsideCurrentSense(0.0005f, 10.0f, _NC, M0_IB, M0_IC);
6163

62-
Encoder encoder = Encoder(M0_ENC_A, M0_ENC_B, 500);
64+
Encoder encoder = Encoder(M0_ENC_A, M0_ENC_B, 500,M0_ENC_Z);
6365
// Interrupt routine intialisation
6466
// channel A and B callbacks
6567
void doA(){encoder.handleA();}
6668
void doB(){encoder.handleB();}
69+
void doI(){encoder.handleIndex();}
6770

6871
void setup(){
6972

@@ -80,7 +83,7 @@ void setup(){
8083

8184
// initialize encoder sensor hardware
8285
encoder.init();
83-
encoder.enableInterrupts(doA, doB);
86+
encoder.enableInterrupts(doA, doB, doI);
8487
// link the motor to the sensor
8588
motor.linkSensor(&encoder);
8689

examples/hardware_specific_examples/Odrive_examples/odrive_example_spi/odrive_example_spi.ino

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
// Odrive M0 encoder pinout
2222
#define M0_ENC_A PB4
2323
#define M0_ENC_B PB5
24+
#define M0_ENC_Z PC9
2425

2526

2627
// Odrive M1 motor pinout
@@ -36,6 +37,7 @@
3637
// Odrive M1 encoder pinout
3738
#define M1_ENC_A PB6
3839
#define M1_ENC_B PB7
40+
#define M1_ENC_Z PC15
3941

4042
// M1 & M2 common enable pin
4143
#define EN_GATE PB12

src/BLDCMotor.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// BLDCMotor( int pp , float R)
55
// - pp - pole pair number
66
// - R - motor phase resistance
7-
// - KV - motor kv rating
7+
// - KV - motor kv rating (rmp/v)
88
BLDCMotor::BLDCMotor(int pp, float _R, float _KV)
99
: FOCMotor()
1010
{
@@ -13,7 +13,7 @@ BLDCMotor::BLDCMotor(int pp, float _R, float _KV)
1313
// save phase resistance number
1414
phase_resistance = _R;
1515
// save back emf constant KV = 1/KV
16-
K_bemf = _isset(_KV) ? 1.0/_KV : NOT_SET;
16+
K_bemf = _isset(_KV) ? 1.0f/_KV/_RPM_TO_RADS : NOT_SET;
1717

1818
// torque control type is voltage by default
1919
torque_controller = TorqueControlType::voltage;

src/StepperMotor.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// StepperMotor(int pp)
66
// - pp - pole pair number
77
// - R - motor phase resistance
8-
// - KV - motor kv rating
8+
// - KV - motor kv rating (rmp/v)
99
StepperMotor::StepperMotor(int pp, float _R, float _KV)
1010
: FOCMotor()
1111
{
@@ -14,7 +14,7 @@ StepperMotor::StepperMotor(int pp, float _R, float _KV)
1414
// save phase resistance number
1515
phase_resistance = _R;
1616
// save back emf constant KV = 1/KV
17-
K_bemf = _isset(_KV) ? 1.0/_KV : NOT_SET;
17+
K_bemf = _isset(_KV) ? 1.0f/_KV/_RPM_TO_RADS : NOT_SET;
1818

1919
// torque control type is voltage by default
2020
// current and foc_current not supported yet

src/StepperMotor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class StepperMotor: public FOCMotor
2424
StepperMotor class constructor
2525
@param pp pole pair number
2626
@param R motor phase resistance
27-
@param KV motor KV rating (1/K_bemf)
27+
@param KV motor KV rating (1/K_bemf) - rpm/V
2828
*/
2929
StepperMotor(int pp, float R = NOT_SET, float KV = NOT_SET);
3030

src/common/foc_utils.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#define _2PI 6.28318530718f
2525
#define _3PI_2 4.71238898038f
2626
#define _PI_6 0.52359877559f
27+
#define _RPM_TO_RADS 0.10471975512f
2728

2829
#define NOT_SET -12345.0
2930
#define _HIGH_IMPEDANCE 0

src/communication/Commander.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,9 +224,9 @@ void Commander::motor(FOCMotor* motor, char* user_command) {
224224
case CMD_KV_RATING:
225225
printVerbose(F("Motor KV: "));
226226
if(!GET){
227-
motor->K_bemf = 1.0f/value;
227+
motor->K_bemf = 1.0f/value/_RPM_TO_RADS;
228228
}
229-
if(_isset(motor->K_bemf)) println(1.0f/motor->K_bemf);
229+
if(_isset(motor->K_bemf)) println(1.0f/motor->K_bemf/_RPM_TO_RADS);
230230
else println(0);
231231
break;
232232
case CMD_SENSOR:

0 commit comments

Comments
 (0)