Skip to content

Commit 336a912

Browse files
committed
Integrated changes from minimal branch
1 parent 5934762 commit 336a912

25 files changed

+703
-290
lines changed

README.md

Lines changed: 267 additions & 68 deletions
Large diffs are not rendered by default.

examples/HMBGC_example/HMBGC_example.ino

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ void setup() {
4242

4343
// power supply voltage
4444
// default 12V
45-
motor.power_supply_voltage = 12;
45+
motor.voltage_power_supply = 12;
4646

4747
// set FOC loop to be used
4848
// ControlType::voltage
@@ -51,10 +51,16 @@ void setup() {
5151
// ControlType::angle
5252
motor.controller = ControlType::velocity;
5353

54+
// contoller configuration based on the controll type
5455
// velocity PI controller parameters
5556
// default K=1.0 Ti = 0.003
5657
motor.PI_velocity.K = 0.3;
57-
motor.PI_velocity.Ti = 0.01;
58+
motor.PI_velocity.Ti = 0.003;
59+
//defualt voltage_power_supply/2
60+
motor.PI_velocity.voltage_limit = 6;
61+
// jerk control using voltage voltage ramp
62+
// default value is 300 volts per sec ~ 0.3V per millisecond
63+
motor.PI_velocity.voltage_ramp = 300;
5864

5965
// use debugging with serial for motor init
6066
// comment out if not needed

examples/angle_control/angle_control.ino

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,27 @@
44
#define arduinoInt1 2 // Arduino UNO interrupt 0
55
#define arduinoInt2 3 // Arduino UNO interrupt 1
66

7-
// angle set point variable
8-
float target_angle = 0;
9-
107
// BLDCMotor( int phA, int phB, int phC, int pp, int en)
118
// - phA, phB, phC - motor A,B,C phase pwm pins
129
// - pp - pole pair number
1310
// - enable pin - (optional input)
14-
BLDCMotor motor = BLDCMotor(9, 10, 11, 11, 8);
11+
BLDCMotor motor = BLDCMotor(9, 5, 6, 11, 8);
1512
// Encoder(int encA, int encB , int cpr, int index)
1613
// - encA, encB - encoder A and B pins
1714
// - ppr - impulses per rotation (cpr=ppr*4)
18-
// - index pin - (optional input)
19-
Encoder encoder = Encoder(arduinoInt1, arduinoInt2, 8192, 4);
20-
// interrupt ruotine intialisation
15+
// - index pin - (optional input)
16+
Encoder encoder = Encoder(arduinoInt1, arduinoInt2, 8192, A0);
17+
18+
// Interrupt rutine intialisation
19+
// channel A and B callbacks
2120
void doA(){encoder.handleA();}
2221
void doB(){encoder.handleB();}
22+
// index calback interrupt code
23+
// please set the right PCINT(0,1,2)_vect parameter
24+
// PCINT0_vect - index pin in between D8 and D13
25+
// PCINT1_vect - index pin in between A0 and A5 (recommended)
26+
// PCINT2_vect - index pin in between D0 and D7
27+
ISR (PCINT1_vect) { encoder.handleIndex(); }
2328

2429
void setup() {
2530
// debugging port
@@ -40,15 +45,18 @@ void setup() {
4045

4146
// power supply voltage
4247
// default 12V
43-
motor.power_supply_voltage = 12;
48+
motor.voltage_power_supply = 12;
4449

4550
// index search velocity - default 1rad/s
4651
motor.index_search_velocity = 1;
4752
// index search PI contoller parameters
4853
// default K=0.5 Ti = 0.01
49-
motor.PI_velocity_index_search.K = 0.3;
54+
motor.PI_velocity_index_search.K = 0.1;
5055
motor.PI_velocity_index_search.Ti = 0.01;
51-
motor.PI_velocity_index_search.u_limit = 3;
56+
//motor.PI_velocity_index_search.voltage_limit = 3;
57+
// jerk control using voltage voltage ramp
58+
// default value is 100
59+
motor.PI_velocity_index_search.voltage_ramp = 100;
5260

5361

5462
// set FOC loop to be used
@@ -58,12 +66,18 @@ void setup() {
5866
// ControlType::angle
5967
motor.controller = ControlType::angle;
6068

69+
70+
// contoller configuration based on the controll type
6171
// velocity PI controller parameters
62-
// default K=0.5 Ti = 0.01
72+
// default K=1.0 Ti = 0.003
6373
motor.PI_velocity.K = 0.3;
64-
motor.PI_velocity.Ti = 0.007;
65-
motor.PI_velocity.u_limit = 5;
66-
74+
motor.PI_velocity.Ti = 0.003;
75+
//defualt voltage_power_supply/2
76+
motor.PI_velocity.voltage_limit = 6;
77+
// jerk control using voltage voltage ramp
78+
// default value is 300 volts per sec ~ 0.3V per millisecond
79+
motor.PI_velocity.voltage_ramp = 300;
80+
6781
// angle P controller
6882
// default K=70
6983
motor.P_angle.K = 20;
@@ -89,6 +103,9 @@ void setup() {
89103
_delay(1000);
90104
}
91105

106+
// angle set point variable
107+
float target_angle = 0;
108+
92109
void loop() {
93110
// iterative state calculation calculating angle
94111
// and setting FOC pahse voltage
@@ -131,6 +148,8 @@ void motor_monitor() {
131148
case ControlType::voltage:
132149
Serial.print(motor.voltage_q);
133150
Serial.print("\t");
151+
Serial.print(motor.shaft_angle);
152+
Serial.print("\t");
134153
Serial.println(motor.shaft_velocity);
135154
break;
136155
}

examples/change_direction/change_direction.ino

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,23 @@
88
// - phA, phB, phC - motor A,B,C phase pwm pins
99
// - pp - pole pair number
1010
// - enable pin - (optional input)
11-
BLDCMotor motor = BLDCMotor(9, 10, 11, 11, 8);
11+
BLDCMotor motor = BLDCMotor(9, 5, 6, 11, 8);
1212
// Encoder(int encA, int encB , int cpr, int index)
1313
// - encA, encB - encoder A and B pins
1414
// - ppr - impulses per rotation (cpr=ppr*4)
15-
// - index pin - (optional input)
16-
Encoder encoder = Encoder(arduinoInt1, arduinoInt2, 8192, 4);
17-
// interrupt ruotine intialisation
15+
// - index pin - (optional input)
16+
Encoder encoder = Encoder(arduinoInt1, arduinoInt2, 8192, A0);
17+
18+
// Interrupt rutine intialisation
19+
// channel A and B callbacks
1820
void doA(){encoder.handleA();}
1921
void doB(){encoder.handleB();}
22+
// index calback interrupt code
23+
// please set the right PCINT(0,1,2)_vect parameter
24+
// PCINT0_vect - index pin in between D8 and D13
25+
// PCINT1_vect - index pin in between A0 and A5 (recommended)
26+
// PCINT2_vect - index pin in between D0 and D7
27+
ISR (PCINT1_vect) { encoder.handleIndex(); }
2028

2129
void setup() {
2230
// debugging port
@@ -37,28 +45,37 @@ void setup() {
3745

3846
// power supply voltage
3947
// default 12V
40-
motor.power_supply_voltage = 12;
48+
motor.voltage_power_supply = 12;
4149

4250
// index search velocity - default 1rad/s
4351
motor.index_search_velocity = 1;
4452
// index search PI contoller parameters
4553
// default K=0.5 Ti = 0.01
46-
motor.PI_velocity_index_search.K = 0.3;
54+
motor.PI_velocity_index_search.K = 0.1;
4755
motor.PI_velocity_index_search.Ti = 0.01;
48-
motor.PI_velocity_index_search.u_limit = 3;
49-
56+
//motor.PI_velocity_index_search.voltage_limit = 3;
57+
// jerk control using voltage voltage ramp
58+
// default value is 100
59+
motor.PI_velocity_index_search.voltage_ramp = 100;
60+
5061
// set FOC loop to be used
5162
// ControlType::voltage
5263
// ControlType::velocity
5364
// ControlType::velocity_ultra_slow
5465
// ControlType::angle
5566
motor.controller = ControlType::velocity;
5667

68+
// contoller configuration based on the controll type
5769
// velocity PI controller parameters
5870
// default K=1.0 Ti = 0.003
5971
motor.PI_velocity.K = 0.3;
60-
motor.PI_velocity.Ti = 0.007;
61-
motor.PI_velocity.u_limit = 4;
72+
motor.PI_velocity.Ti = 0.003;
73+
//defualt voltage_power_supply/2
74+
motor.PI_velocity.voltage_limit = 6;
75+
// jerk control using voltage voltage ramp
76+
// default value is 300 volts per sec ~ 0.3V per millisecond
77+
motor.PI_velocity.voltage_ramp = 300;
78+
6279

6380
// use debugging with serial for motor init
6481
// comment out if not needed
@@ -129,6 +146,8 @@ void motor_monitor() {
129146
case ControlType::voltage:
130147
Serial.print(motor.voltage_q);
131148
Serial.print("\t");
149+
Serial.print(motor.shaft_angle);
150+
Serial.print("\t");
132151
Serial.println(motor.shaft_velocity);
133152
break;
134153
}

examples/find_pole_pairs_number/find_pole_pairs_number.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ void setup() {
3232

3333
// power supply voltage
3434
// default 12V
35-
motor.power_supply_voltage = 12;
35+
motor.voltage_power_supply = 12;
3636

3737
// set FOC loop to be used
3838
motor.controller = ControlType::voltage;

examples/minimal_example/minimal_example.ino

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ Encoder encoder = Encoder(2, 3, 8192, 4);
1616
// interrupt ruotine intialisation
1717
void doA(){encoder.handleA();}
1818
void doB(){encoder.handleB();}
19+
// please set the right PCINT(0,1,2)_vect parameter
20+
ISR (PCINT2_vect) { encoder.handleIndex(); }
1921

2022
void setup() {
2123
// debugging port
@@ -27,6 +29,14 @@ void setup() {
2729
// velocity control
2830
motor.controller = ControlType::velocity;
2931

32+
// contoller configuration based on the controll type
33+
motor.PI_velocity.K = 0.3;
34+
motor.PI_velocity.Ti = 0.003;
35+
motor.PI_velocity.voltage_limit = 6;
36+
// jerk control using voltage voltage ramp
37+
motor.PI_velocity.voltage_ramp = 300;
38+
39+
3040
// link the motor to the sensor
3141
motor.linkEncoder(&encoder);
3242
// intialise motor

examples/velocity_control/velocity_control.ino

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@
44
#define arduinoInt1 2 // Arduino UNO interrupt 0
55
#define arduinoInt2 3 // Arduino UNO interrupt 1
66

7-
// velocity set point variable
8-
float target_velocity = 0;
9-
10-
117
// BLDCMotor( int phA, int phB, int phC, int pp, int en)
128
// - phA, phB, phC - motor A,B,C phase pwm pins
139
// - pp - pole pair number
@@ -17,10 +13,18 @@ BLDCMotor motor = BLDCMotor(9, 10, 11, 11, 8);
1713
// - encA, encB - encoder A and B pins
1814
// - ppr - impulses per rotation (cpr=ppr*4)
1915
// - index pin - (optional input)
20-
Encoder encoder = Encoder(arduinoInt1, arduinoInt2, 8192, 4);
21-
// interrupt ruotine intialisation
16+
Encoder encoder = Encoder(arduinoInt1, arduinoInt2, 8192, A0);
17+
18+
// Interrupt rutine intialisation
19+
// channel A and B callbacks
2220
void doA(){encoder.handleA();}
2321
void doB(){encoder.handleB();}
22+
// index calback interrupt code
23+
// please set the right PCINT(0,1,2)_vect parameter
24+
// PCINT0_vect - index pin in between D8 and D13
25+
// PCINT1_vect - index pin in between A0 and A5 (recommended)
26+
// PCINT2_vect - index pin in between D0 and D7
27+
ISR (PCINT1_vect) { encoder.handleIndex(); }
2428

2529
void setup() {
2630
// debugging port
@@ -41,28 +45,36 @@ void setup() {
4145

4246
// power supply voltage
4347
// default 12V
44-
motor.power_supply_voltage = 12;
48+
motor.voltage_power_supply = 12;
4549

4650
// index search velocity - default 1rad/s
4751
motor.index_search_velocity = 1;
4852
// index search PI contoller parameters
4953
// default K=0.5 Ti = 0.01
5054
motor.PI_velocity_index_search.K = 0.1;
5155
motor.PI_velocity_index_search.Ti = 0.01;
52-
motor.PI_velocity_index_search.u_limit = 3;
53-
54-
// set FOC loop to be used
56+
//motor.PI_velocity_index_search.voltage_limit = 3;
57+
// jerk control using voltage voltage ramp
58+
// default value is 100
59+
motor.PI_velocity_index_search.voltage_ramp = 100;
60+
61+
// set control loop type to be used
5562
// ControlType::voltage
5663
// ControlType::velocity
5764
// ControlType::velocity_ultra_slow
5865
// ControlType::angle
5966
motor.controller = ControlType::velocity;
6067

68+
// contoller configuration based on the controll type
6169
// velocity PI controller parameters
62-
// default K=0.5 Ti = 0.01
70+
// default K=1.0 Ti = 0.003
6371
motor.PI_velocity.K = 0.3;
6472
motor.PI_velocity.Ti = 0.003;
65-
73+
//defualt voltage_power_supply/2
74+
motor.PI_velocity.voltage_limit = 6;
75+
// jerk control using voltage voltage ramp
76+
// default value is 300 volts per sec ~ 0.3V per millisecond
77+
motor.PI_velocity.voltage_ramp = 300;
6678

6779
// use debugging with serial for motor init
6880
// comment out if not needed
@@ -81,6 +93,9 @@ void setup() {
8193
_delay(1000);
8294
}
8395

96+
// velocity set point variable
97+
float target_velocity = 0;
98+
8499
void loop() {
85100
// iterative state calculation calculating angle
86101
// and setting FOC pahse voltage

0 commit comments

Comments
 (0)