9
9
// - enable pin - (optional input)
10
10
BLDCMotor motor = BLDCMotor(9 , 10 , 11 , 11 );
11
11
12
- // // MagneticSensor(int cs, float _cpr, int _angle_register)
13
- // // cs - SPI chip select pin
14
- // // _cpr - counts per revolution
15
- // // _angle_register - (optional) angle read register - default 0x3FFF
16
- // MagneticSensor AS5x4x = MagneticSensor(10, 16384, 0x3FFF);
12
+ // MagneticSensor(int cs, float _cpr, int _angle_register)
13
+ // cs - SPI chip select pin
14
+ // _cpr - counts per revolution
15
+ // _angle_register - (optional) angle read register - default 0x3FFF
16
+ MagneticSensor AS5x4x = MagneticSensor(10 , 16384 , 0x3FFF );
17
17
18
18
19
- Encoder encoder = Encoder(2 , 3 , 8192 );
20
- // interrupt ruotine intialisation
21
- void doA (){encoder.handleA ();}
22
- void doB (){encoder.handleB ();}
19
+ // Encoder encoder = Encoder(2, 3, 8192);
20
+ // // interrupt ruotine intialisation
21
+ // void doA(){encoder.handleA();}
22
+ // void doB(){encoder.handleB();}
23
23
24
24
// // encoder interrupt init
25
25
// PciListenerImp listenerA(encoder.pinA, doA);
@@ -30,9 +30,9 @@ void setup() {
30
30
Serial.begin (115200 );
31
31
32
32
// initialise magnetic sensor hardware
33
- // AS5x4x.init();
34
- encoder.init ();
35
- encoder.enableInterrupts (doA,doB);
33
+ AS5x4x.init ();
34
+ // encoder.init();
35
+ // encoder.enableInterrupts(doA,doB);
36
36
37
37
// // interrupt intitialisation
38
38
// PciManager.registerListener(&listenerA);
@@ -69,8 +69,8 @@ void setup() {
69
69
70
70
71
71
// link the motor to the sensor
72
- // motor.linkSensor(&AS5x4x);
73
- motor.linkSensor (&encoder);
72
+ motor.linkSensor (&AS5x4x);
73
+ // motor.linkSensor(&encoder);
74
74
75
75
// use debugging with serial for motor init
76
76
// comment out if not needed
@@ -82,15 +82,15 @@ void setup() {
82
82
motor.initFOC ();
83
83
84
84
Serial.println (" Motor ready.\n " );
85
- Serial.println (" Update all the PI contorller paramters from the serial temrinal :" );
85
+ Serial.println (" Update all the PI controller parameters from the serial terminal :" );
86
86
Serial.println (" - Type P100.2 to you the PI_velocity.P in 100.2" );
87
87
Serial.println (" - Type I72.32 to you the PI_velocity.I in 72.32\n " );
88
88
Serial.println (" Update the time constant of the velocity filter:" );
89
89
Serial.println (" - Type F0.03 to you the LPF_velocity.Tf in 0.03\n " );
90
- Serial.println (" Check the loop executoion time (average):" );
90
+ Serial.println (" Check the loop execution time (average):" );
91
91
Serial.println (" - Type T\n " );
92
92
Serial.println (" Change control loop type by typing:" );
93
- Serial.println (" - C0 - angle contro " );
93
+ Serial.println (" - C0 - angle control " );
94
94
Serial.println (" - C1 - velocity control" );
95
95
Serial.println (" - C2 - voltage control\n " );
96
96
Serial.println (" Initial parameters:" );
@@ -106,7 +106,7 @@ void setup() {
106
106
}
107
107
108
108
// target velocity variable
109
- float target_velocity = 0 ;
109
+ float target = 0 ;
110
110
// loop stats variables
111
111
unsigned long t = 0 ;
112
112
long timestamp = _micros();
@@ -117,7 +117,7 @@ void loop() {
117
117
118
118
// iterative function setting the outter loop target
119
119
// velocity, position or voltage
120
- motor.move (target_velocity );
120
+ motor.move (target );
121
121
122
122
// keep track of loop number
123
123
t++;
@@ -209,9 +209,9 @@ void serialEvent() {
209
209
t = 0 ;
210
210
timestamp = _micros ();
211
211
}else {
212
- target_velocity = inputString.toFloat ();
213
- Serial.print (" Tagret Velocity : " );
214
- Serial.println (target_velocity );
212
+ target = inputString.toFloat ();
213
+ Serial.print (" Target : " );
214
+ Serial.println (target );
215
215
inputString = " " ;
216
216
}
217
217
inputString = " " ;
0 commit comments