Skip to content

Commit 410e288

Browse files
committed
FEAT merge from dev version 1.5.0
2 parents 6d76f31 + ebe9aad commit 410e288

File tree

47 files changed

+1892
-207
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+1892
-207
lines changed

README.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@ Therefore this is an attempt to:
1010
- Demystify FOC algorithm and make a robust but simple Arduino library: [Arduino *SimpleFOClibrary*](https://docs.simplefoc.com/arduino_simplefoc_library_showcase)
1111
- Develop a modular BLDC driver board: [Arduino *SimpleFOCShield*](https://docs.simplefoc.com/arduino_simplefoc_shield_showcase).
1212

13-
> ***NEWS:*** 📢 Arduino *SimpleFOClibrary* now supports ESP32 boards! Check out the library [docs](https://docs.simplefoc.com/microcontrollers) to see how to use them with your project. You can also find full configuration in the library examples.
14-
15-
> ***NEWS:*** 📢 Arduino *SimpleFOClibrary* now supports magnetic sensors using I2C communication! Check out the library [docs](https://docs.simplefoc.com/sensors) to see how to use them with your project. You can also find full configuration in the library examples. <br>
16-
> ***BEWARE:*** 📢 The `MagneticSensor` class has been renamed and divided to `MagneticSensorSPI` and `MagneticSensorI2C` classes.
13+
<blockquote class="info"><p class="heading"><b>NEWS</b> 📢</p>New version of the Arduino <span class="simple">Simple<span class="foc">FOC</span>library</span> is out! (<a href="https://github.com/askuric/Arduino-FOC/releases">version 1.5.0 <i class="fa fa-tag"></i></a>) <br> <b>New features</b>:<ul><li> Open-loop motor control</li><li> Support Hall sensors</li><li> Support for Analog interface Magnetic sensor</li><li> New alignment procedure <br>- automatic sensor direction detection<br> - possibility to avoid alignment completely</li><li> PI controller updated to PID controller</li><li>...</li></ul>Big thanks to <a href="https://github.com/owennewo">@owennewo</a> for awesome suggestions and pull-requests!</blockquote>
1714

1815

1916

examples/hardware_specific_examples/Bluepill_examples/encoder/bluepill_position_control/bluepill_position_control.ino

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,21 +42,21 @@ void setup() {
4242
// default parameters in defaults.h
4343

4444
// velocity PI controller parameters
45-
motor.PI_velocity.P = 0.2;
46-
motor.PI_velocity.I = 20;
45+
motor.PID_velocity.P = 0.2;
46+
motor.PID_velocity.I = 20;
4747
// default voltage_power_supply
48-
motor.PI_velocity.voltage_limit = 6;
48+
motor.voltage_limit = 6;
4949
// jerk control using voltage voltage ramp
5050
// default value is 300 volts per sec ~ 0.3V per millisecond
51-
motor.PI_velocity.voltage_ramp = 1000;
51+
motor.PID_velocity.output_ramp = 1000;
5252

5353
// velocity low pass filtering time constant
5454
motor.LPF_velocity.Tf = 0.01;
5555

5656
// angle P controller
5757
motor.P_angle.P = 20;
5858
// maximal velocity of the position control
59-
motor.P_angle.velocity_limit = 4;
59+
motor.velocity_limit = 4;
6060

6161

6262
// use monitoring with serial

examples/hardware_specific_examples/Bluepill_examples/magnetic_sensor/bluepill_position_control/bluepill_position_control.ino

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ void setup() {
4343
// default parameters in defaults.h
4444

4545
// velocity PI controller parameters
46-
motor.PI_velocity.P = 0.2;
47-
motor.PI_velocity.I = 20;
46+
motor.PID_velocity.P = 0.2;
47+
motor.PID_velocity.I = 20;
4848
// maximal voltage to be set to the motor
49-
motor.PI_velocity.voltage_limit = 6;
49+
motor.voltage_limit = 6;
5050

5151
// velocity low pass filtering time constant
5252
// the lower the less filtered
@@ -55,7 +55,7 @@ void setup() {
5555
// angle P controller
5656
motor.P_angle.P = 20;
5757
// maximal velocity of the position control
58-
motor.P_angle.velocity_limit = 40;
58+
motor.velocity_limit = 40;
5959

6060
// use monitoring with serial
6161
Serial.begin(115200);

examples/hardware_specific_examples/DRV8305_driver/motor_full_control_serial_examples/encoder/full_control_serial/full_control_serial.ino

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,18 +64,18 @@ void setup() {
6464
motor.controller = ControlType::voltage;
6565

6666
// contoller configuration based on the controll type
67-
motor.PI_velocity.P = 0.2;
68-
motor.PI_velocity.I = 20;
67+
motor.PID_velocity.P = 0.2;
68+
motor.PID_velocity.I = 20;
6969
// default voltage_power_supply
70-
motor.PI_velocity.voltage_limit = 12;
70+
motor.voltage_limit = 12;
7171

7272
// velocity low pass filtering time constant
7373
motor.LPF_velocity.Tf = 0.01;
7474

7575
// angle loop controller
7676
motor.P_angle.P = 20;
7777
// angle loop velocity limit
78-
motor.P_angle.velocity_limit = 50;
78+
motor.velocity_limit = 50;
7979

8080
// use monitoring with serial for motor init
8181
// monitoring port

examples/hardware_specific_examples/ESP32/encoder/esp32_position_control/esp32_position_control.ino

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,21 +38,21 @@ void setup() {
3838
// default parameters in defaults.h
3939

4040
// velocity PI controller parameters
41-
motor.PI_velocity.P = 0.2;
42-
motor.PI_velocity.I = 20;
41+
motor.PID_velocity.P = 0.2;
42+
motor.PID_velocity.I = 20;
4343
// default voltage_power_supply
44-
motor.PI_velocity.voltage_limit = 6;
44+
motor.voltage_limit = 6;
4545
// jerk control using voltage voltage ramp
4646
// default value is 300 volts per sec ~ 0.3V per millisecond
47-
motor.PI_velocity.voltage_ramp = 1000;
47+
motor.PID_velocity.output_ramp = 1000;
4848

4949
// velocity low pass filtering time constant
5050
motor.LPF_velocity.Tf = 0.01;
5151

5252
// angle P controller
5353
motor.P_angle.P = 20;
5454
// maximal velocity of the position control
55-
motor.P_angle.velocity_limit = 4;
55+
motor.velocity_limit = 4;
5656

5757

5858
// use monitoring with serial

examples/hardware_specific_examples/ESP32/magnetic_sensor/esp32_position_control/esp32_position_control.ino

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ MagneticSensorSPI sensor = MagneticSensorSPI(10, 14, 0x3FFF);
1515
// SCL 22
1616
//MagneticSensorI2C sensor = MagneticSensorI2C(0x36, 12, 0x0E, 4);
1717

18+
// Analog output Magnetic sensor instance (AS5600)
19+
// MagneticSensorAnalog sensor = MagneticSensorAnalog(A1, 14, 1020);
20+
1821
// Motor instance
1922
BLDCMotor motor = BLDCMotor(25, 26, 27, 7);
2023

@@ -39,10 +42,10 @@ void setup() {
3942
// default parameters in defaults.h
4043

4144
// velocity PI controller parameters
42-
motor.PI_velocity.P = 0.2;
43-
motor.PI_velocity.I = 20;
45+
motor.PID_velocity.P = 0.2;
46+
motor.PID_velocity.I = 20;
4447
// maximal voltage to be set to the motor
45-
motor.PI_velocity.voltage_limit = 6;
48+
motor.voltage_limit = 6;
4649

4750
// velocity low pass filtering time constant
4851
// the lower the less filtered
@@ -51,7 +54,7 @@ void setup() {
5154
// angle P controller
5255
motor.P_angle.P = 20;
5356
// maximal velocity of the position control
54-
motor.P_angle.velocity_limit = 40;
57+
motor.velocity_limit = 40;
5558

5659
// use monitoring with serial
5760
Serial.begin(115200);

examples/hardware_specific_examples/HMBGC_example/position_control/position_control.ino

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,21 +56,21 @@ void setup() {
5656
// default parameters in defaults.h
5757

5858
// velocity PI controller parameters
59-
motor.PI_velocity.P = 0.2;
60-
motor.PI_velocity.I = 20;
59+
motor.PID_velocity.P = 0.2;
60+
motor.PID_velocity.I = 20;
6161
// default voltage_power_supply
62-
motor.PI_velocity.voltage_limit = 6;
62+
motor.voltage_limit = 6;
6363
// jerk control using voltage voltage ramp
6464
// default value is 300 volts per sec ~ 0.3V per millisecond
65-
motor.PI_velocity.voltage_ramp = 1000;
65+
motor.PID_velocity.output_ramp = 1000;
6666

6767
// velocity low pass filtering time constant
6868
motor.LPF_velocity.Tf = 0.01;
6969

7070
// angle P controller
7171
motor.P_angle.P = 20;
7272
// maximal velocity of the position control
73-
motor.P_angle.velocity_limit = 4;
73+
motor.velocity_limit = 4;
7474

7575

7676
// use monitoring with serial
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// Open loop motor control example
2+
#include <SimpleFOC.h>
3+
4+
// motor instance
5+
BLDCMotor motor = BLDCMotor(3, 10, 6, 11, 7);
6+
7+
void setup() {
8+
9+
// power supply voltage
10+
// default 12V
11+
motor.voltage_power_supply = 12;
12+
13+
// limiting motor movements
14+
motor.voltage_limit = 3; // rad/s
15+
motor.velocity_limit = 20; // rad/s
16+
// open loop control config
17+
motor.controller = ControlType::angle_openloop;
18+
19+
// init motor hardware
20+
motor.init();
21+
22+
23+
Serial.begin(115200);
24+
Serial.println("Motor ready!");
25+
_delay(1000);
26+
}
27+
28+
float target_position = 0; // rad/s
29+
30+
void loop() {
31+
// open loop angle movements
32+
// using motor.voltage_limit and motor.velocity_limit
33+
motor.move(target_position);
34+
35+
// receive the used commands from serial
36+
serialReceiveUserCommand();
37+
}
38+
39+
// utility function enabling serial communication with the user to set the target values
40+
// this function can be implemented in serialEvent function as well
41+
void serialReceiveUserCommand() {
42+
43+
// a string to hold incoming data
44+
static String received_chars;
45+
46+
while (Serial.available()) {
47+
// get the new byte:
48+
char inChar = (char)Serial.read();
49+
// add it to the string buffer:
50+
received_chars += inChar;
51+
// end of user input
52+
if (inChar == '\n') {
53+
54+
// change the motor target
55+
target_position = received_chars.toFloat();
56+
Serial.print("Target position: ");
57+
Serial.println(target_position);
58+
59+
// reset the command buffer
60+
received_chars = "";
61+
}
62+
}
63+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// Open loop motor control example
2+
#include <SimpleFOC.h>
3+
4+
// motor instance
5+
BLDCMotor motor = BLDCMotor(3, 10, 6, 11, 7);
6+
7+
void setup() {
8+
9+
// power supply voltage
10+
// default 12V
11+
motor.voltage_power_supply = 12;
12+
13+
// limiting motor movements
14+
motor.voltage_limit = 3; // rad/s
15+
motor.velocity_limit = 20; // rad/s
16+
17+
// open loop control config
18+
motor.controller = ControlType::velocity_openloop;
19+
20+
// init motor hardware
21+
motor.init();
22+
23+
24+
Serial.begin(115200);
25+
Serial.println("Motor ready!");
26+
_delay(1000);
27+
}
28+
29+
float target_velocity = 0; // rad/s
30+
31+
void loop() {
32+
// open loop velocity movement
33+
// using motor.voltage_limit and motor.velocity_limit
34+
motor.move(target_velocity);
35+
36+
// receive the used commands from serial
37+
serialReceiveUserCommand();
38+
}
39+
40+
// utility function enabling serial communication with the user to set the target values
41+
// this function can be implemented in serialEvent function as well
42+
void serialReceiveUserCommand() {
43+
44+
// a string to hold incoming data
45+
static String received_chars;
46+
47+
while (Serial.available()) {
48+
// get the new byte:
49+
char inChar = (char)Serial.read();
50+
// add it to the string buffer:
51+
received_chars += inChar;
52+
// end of user input
53+
if (inChar == '\n') {
54+
55+
// change the motor target
56+
target_velocity = received_chars.toFloat();
57+
Serial.print("Target velocity ");
58+
Serial.println(target_velocity);
59+
60+
// reset the command buffer
61+
received_chars = "";
62+
}
63+
}
64+
}

examples/motion_control/position_motion_control/encoder/angle_control/angle_control.ino

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,21 +67,22 @@ void setup() {
6767
// default parameters in defaults.h
6868

6969
// velocity PI controller parameters
70-
motor.PI_velocity.P = 0.2;
71-
motor.PI_velocity.I = 20;
70+
motor.PID_velocity.P = 0.2;
71+
motor.PID_velocity.I = 20;
72+
motor.PID_velocity.D = 0;
7273
// default voltage_power_supply
73-
motor.PI_velocity.voltage_limit = 6;
74+
motor.voltage_limit = 6;
7475
// jerk control using voltage voltage ramp
7576
// default value is 300 volts per sec ~ 0.3V per millisecond
76-
motor.PI_velocity.voltage_ramp = 1000;
77+
motor.PID_velocity.output_ramp = 1000;
7778

7879
// velocity low pass filtering time constant
7980
motor.LPF_velocity.Tf = 0.01;
8081

8182
// angle P controller
8283
motor.P_angle.P = 20;
8384
// maximal velocity of the position control
84-
motor.P_angle.velocity_limit = 4;
85+
motor.velocity_limit = 4;
8586

8687

8788
// use monitoring with serial

0 commit comments

Comments
 (0)