4
4
#define arduinoInt1 2 // Arduino UNO interrupt 0
5
5
#define arduinoInt2 3 // Arduino UNO interrupt 1
6
6
7
- // angle set point variable
8
- float target_angle = 0 ;
9
-
10
7
// BLDCMotor( int phA, int phB, int phC, int pp, int en)
11
8
// - phA, phB, phC - motor A,B,C phase pwm pins
12
9
// - pp - pole pair number
13
10
// - enable pin - (optional input)
14
- BLDCMotor motor = BLDCMotor(9 , 10 , 11 , 11 , 8 );
11
+ BLDCMotor motor = BLDCMotor(9 , 5 , 6 , 11 , 8 );
15
12
// Encoder(int encA, int encB , int cpr, int index)
16
13
// - encA, encB - encoder A and B pins
17
14
// - 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
21
20
void doA (){encoder.handleA ();}
22
21
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 (); }
23
28
24
29
void setup () {
25
30
// debugging port
@@ -40,15 +45,18 @@ void setup() {
40
45
41
46
// power supply voltage
42
47
// default 12V
43
- motor.power_supply_voltage = 12 ;
48
+ motor.voltage_power_supply = 12 ;
44
49
45
50
// index search velocity - default 1rad/s
46
51
motor.index_search_velocity = 1 ;
47
52
// index search PI contoller parameters
48
53
// 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 ;
50
55
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 ;
52
60
53
61
54
62
// set FOC loop to be used
@@ -58,12 +66,18 @@ void setup() {
58
66
// ControlType::angle
59
67
motor.controller = ControlType::angle;
60
68
69
+
70
+ // contoller configuration based on the controll type
61
71
// velocity PI controller parameters
62
- // default K=0.5 Ti = 0.01
72
+ // default K=1.0 Ti = 0.003
63
73
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
+
67
81
// angle P controller
68
82
// default K=70
69
83
motor.P_angle .K = 20 ;
@@ -89,6 +103,9 @@ void setup() {
89
103
_delay (1000 );
90
104
}
91
105
106
+ // angle set point variable
107
+ float target_angle = 0 ;
108
+
92
109
void loop () {
93
110
// iterative state calculation calculating angle
94
111
// and setting FOC pahse voltage
@@ -131,6 +148,8 @@ void motor_monitor() {
131
148
case ControlType::voltage:
132
149
Serial.print (motor.voltage_q );
133
150
Serial.print (" \t " );
151
+ Serial.print (motor.shaft_angle );
152
+ Serial.print (" \t " );
134
153
Serial.println (motor.shaft_velocity );
135
154
break ;
136
155
}
0 commit comments