7
7
// - phA, phB, phC - motor A,B,C phase pwm pins
8
8
// - pp - pole pair number
9
9
// - enable pin - (optional input)
10
- BLDCMotor motor = BLDCMotor(9 , 10 , 11 , 14 );
10
+ BLDCMotor motor = BLDCMotor(9 , 10 , 11 , 11 );
11
11
12
12
// // MagneticSensor(int cs, float _cpr, int _angle_register)
13
13
// // cs - SPI chip select pin
@@ -16,14 +16,14 @@ BLDCMotor motor = BLDCMotor(9, 10, 11, 14);
16
16
// MagneticSensor AS5x4x = MagneticSensor(10, 16384, 0x3FFF);
17
17
18
18
19
- Encoder encoder = Encoder(A0, A1, 2048 );
19
+ Encoder encoder = Encoder(2 , 3 , 8192 );
20
20
// interrupt ruotine intialisation
21
21
void doA (){encoder.handleA ();}
22
22
void doB (){encoder.handleB ();}
23
23
24
- // encoder interrupt init
25
- PciListenerImp listenerA (encoder.pinA, doA);
26
- PciListenerImp listenerB (encoder.pinB, doB);
24
+ // // encoder interrupt init
25
+ // PciListenerImp listenerA(encoder.pinA, doA);
26
+ // PciListenerImp listenerB(encoder.pinB, doB);
27
27
28
28
void setup () {
29
29
// debugging port
@@ -32,11 +32,11 @@ void setup() {
32
32
// initialise magnetic sensor hardware
33
33
// AS5x4x.init();
34
34
encoder.init ();
35
- // encoder.enableInterrupts(doA,doB);
35
+ encoder.enableInterrupts (doA,doB);
36
36
37
- // interrupt intitialisation
38
- PciManager.registerListener (&listenerA);
39
- PciManager.registerListener (&listenerB);
37
+ // // interrupt intitialisation
38
+ // PciManager.registerListener(&listenerA);
39
+ // PciManager.registerListener(&listenerB);
40
40
41
41
// power supply voltage
42
42
// default 12V
@@ -89,6 +89,18 @@ void setup() {
89
89
Serial.println (" - Type F0.03 to you the LPF_velocity.Tf in 0.03\n " );
90
90
Serial.println (" Check the loop executoion time (average):" );
91
91
Serial.println (" - Type T\n " );
92
+ Serial.println (" Change control loop type by typing:" );
93
+ Serial.println (" - C0 - angle contro" );
94
+ Serial.println (" - C1 - velocity control" );
95
+ Serial.println (" - C2 - voltage control\n " );
96
+ Serial.println (" Initial parameters:" );
97
+ Serial.print (" PI velocity P: " );
98
+ Serial.print (motor.PI_velocity .P );
99
+ Serial.print (" ,\t I: " );
100
+ Serial.print (motor.PI_velocity .I );
101
+ Serial.print (" ,\t Low passs filter Tf: " );
102
+ Serial.println (motor.LPF_velocity .Tf ,4 );
103
+
92
104
_delay (1000 );
93
105
94
106
}
@@ -158,23 +170,23 @@ void serialEvent() {
158
170
Serial.print (" ,\t I: " );
159
171
Serial.print (motor.PI_velocity .I );
160
172
Serial.print (" ,\t Low passs filter Tf: " );
161
- Serial.println (motor.LPF_velocity .Tf );
173
+ Serial.println (motor.LPF_velocity .Tf , 4 );
162
174
}else if (inputString.charAt (0 ) == ' I' ){
163
175
motor.PI_velocity .I = inputString.substring (1 ).toFloat ();
164
176
Serial.print (" PI velocity P: " );
165
177
Serial.print (motor.PI_velocity .P );
166
178
Serial.print (" ,\t I: " );
167
179
Serial.print (motor.PI_velocity .I );
168
180
Serial.print (" ,\t Low passs filter Tf: " );
169
- Serial.println (motor.LPF_velocity .Tf );
181
+ Serial.println (motor.LPF_velocity .Tf , 4 );
170
182
}else if (inputString.charAt (0 ) == ' F' ){
171
183
motor.LPF_velocity .Tf = inputString.substring (1 ).toFloat ();
172
184
Serial.print (" PI velocity P: " );
173
185
Serial.print (motor.PI_velocity .P );
174
186
Serial.print (" ,\t I: " );
175
187
Serial.print (motor.PI_velocity .I );
176
188
Serial.print (" ,\t Low passs filter Tf: " );
177
- Serial.println (motor.LPF_velocity .Tf );
189
+ Serial.println (motor.LPF_velocity .Tf , 4 );
178
190
}else if (inputString.charAt (0 ) == ' T' ){
179
191
Serial.print (" Average loop time is (microseconds): " );
180
192
Serial.println ((_micros () - timestamp)/t);
0 commit comments