1
1
#include " SimpleFOC.h"
2
- // software interrupt library
3
- #include < PciManager.h>
4
- #include < PciListenerImp.h>
2
+ // // software interrupt library
3
+ // #include <PciManager.h>
4
+ // #include <PciListenerImp.h>
5
5
6
6
// BLDCMotor( int phA, int phB, int phC, int pp, int en)
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
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 );
17
-
18
-
19
- // Encoder encoder = Encoder(2, 3, 8192);
20
- // // interrupt ruotine intialisation
12
+ // Encoder sensor = Encoder(2, 3, 2048);
13
+ // interrupt ruotine intialisation
21
14
// void doA(){encoder.handleA();}
22
15
// void doB(){encoder.handleB();}
23
16
24
- // // encoder interrupt init
17
+ // encoder interrupt init
25
18
// PciListenerImp listenerA(encoder.pinA, doA);
26
19
// PciListenerImp listenerB(encoder.pinB, doB);
27
20
21
+
22
+ MagneticSensor sensor = MagneticSensor(10 ,16384 );
23
+
28
24
void setup () {
29
25
// debugging port
30
26
Serial.begin (115200 );
31
27
28
+ // as5047.init();
29
+
32
30
// initialise magnetic sensor hardware
33
- AS5x4x.init ();
34
- // encoder.init();
35
- // encoder.enableInterrupts(doA,doB);
31
+ sensor.init ();
32
+ // encoder.enableInterrupts(doA,doB);
36
33
37
34
// // interrupt intitialisation
38
35
// PciManager.registerListener(&listenerA);
@@ -69,8 +66,9 @@ void setup() {
69
66
70
67
71
68
// link the motor to the sensor
72
- motor.linkSensor (&AS5x4x);
73
- // motor.linkSensor(&encoder);
69
+ motor.linkSensor (&sensor);
70
+ // motor.linkSensor(&as5047);
71
+
74
72
75
73
// use debugging with serial for motor init
76
74
// comment out if not needed
@@ -81,15 +79,15 @@ void setup() {
81
79
// align encoder and start FOC
82
80
motor.initFOC ();
83
81
84
- Serial.println (" Motor ready. \n " );
85
- Serial.println (" Update all the PI controller parameters from the serial terminal :" );
86
- Serial.println (" - Type P100.2 to you the PI_velocity.P in 100.2 " );
87
- Serial.println (" - Type I72.32 to you the PI_velocity.I in 72.32 \n " );
88
- Serial.println (" Update the time constant of the velocity filter:" );
89
- Serial.println (" - Type F0.03 to you the LPF_velocity.Tf in 0.03 \n " );
90
- Serial.println (" Check the loop execution time (average) :" );
82
+ Serial.println (" \n \n" );
83
+ Serial.println (" PI controller parameters change :" );
84
+ Serial.println (" - P value : Prefix P (ex. P0.1) " );
85
+ Serial.println (" - I value : Prefix I (ex. I0.1) \n " );
86
+ Serial.println (" Velocity filter:" );
87
+ Serial.println (" - Tf value : Prefix F (ex. F0.001) \n " );
88
+ Serial.println (" Average loop execution time:" );
91
89
Serial.println (" - Type T\n " );
92
- Serial.println (" Change control loop type by typing :" );
90
+ Serial.println (" Control loop type:" );
93
91
Serial.println (" - C0 - angle control" );
94
92
Serial.println (" - C1 - velocity control" );
95
93
Serial.println (" - C2 - voltage control\n " );
@@ -102,7 +100,6 @@ void setup() {
102
100
Serial.println (motor.LPF_velocity .Tf ,4 );
103
101
104
102
_delay (1000 );
105
-
106
103
}
107
104
108
105
// target velocity variable
@@ -123,34 +120,6 @@ void loop() {
123
120
t++;
124
121
}
125
122
126
- // utility function intended to be used with serial plotter to monitor motor variables
127
- // significantly slowing the execution down!!!!
128
- void motor_monitor () {
129
- switch (motor.controller ) {
130
- case ControlType::velocity:
131
- Serial.print (motor.voltage_q );
132
- Serial.print (" \t " );
133
- Serial.print (motor.shaft_velocity_sp );
134
- Serial.print (" \t " );
135
- Serial.println (motor.shaft_velocity );
136
- break ;
137
- case ControlType::angle:
138
- Serial.print (motor.voltage_q );
139
- Serial.print (" \t " );
140
- Serial.print (motor.shaft_angle_sp );
141
- Serial.print (" \t " );
142
- Serial.println (motor.shaft_angle );
143
- break ;
144
- case ControlType::voltage:
145
- Serial.print (motor.voltage_q );
146
- Serial.print (" \t " );
147
- Serial.print (motor.shaft_angle );
148
- Serial.print (" \t " );
149
- Serial.println (motor.shaft_velocity );
150
- break ;
151
- }
152
- }
153
-
154
123
// Serial communication callback
155
124
void serialEvent () {
156
125
// a string to hold incoming data
0 commit comments