Skip to content

Commit a09f828

Browse files
committed
Merge branch 'dev' into runger1101001-dev
2 parents 88e9c84 + ed90016 commit a09f828

File tree

77 files changed

+1988
-432
lines changed

Some content is hidden

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

77 files changed

+1988
-432
lines changed

.github/workflows/ccpp.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
- arduino-boards-fqbn: arduino:avr:uno # arudino uno - compiling almost all examples
2222
sketch-names: '**.ino'
2323
required-libraries: PciManager
24-
sketches-exclude: bluepill_position_control, esp32_position_control, esp32_i2c_dual_bus_example, stm32_i2c_dual_bus_example, magnetic_sensor_spi_alt_example, osc_esp32_3pwm, osc_esp32_fullcontrol, nano33IoT_velocity_control, smartstepper_control
24+
sketches-exclude: bluepill_position_control, esp32_position_control, esp32_i2c_dual_bus_example, stm32_i2c_dual_bus_example, magnetic_sensor_spi_alt_example, osc_esp32_3pwm, osc_esp32_fullcontrol, nano33IoT_velocity_control, smartstepper_control,esp32_current_control_low_side, stm32_spi_alt_example, esp32_spi_alt_example, B_G431B_ESC1_position_control
2525

2626
- arduino-boards-fqbn: arduino:sam:arduino_due_x # arduino due - one full example
2727
sketch-names: single_full_control_example.ino
@@ -38,15 +38,15 @@ jobs:
3838

3939
- arduino-boards-fqbn: esp32:esp32:esp32doit-devkit-v1 # esp32
4040
platform-url: https://dl.espressif.com/dl/package_esp32_index.json
41-
sketch-names: esp32_position_control.ino, esp32_i2c_dual_bus_example.ino
41+
sketch-names: esp32_position_control.ino, esp32_i2c_dual_bus_example.ino, esp32_current_control_low_side.ino, esp32_spi_alt_example.ino
4242

4343
- arduino-boards-fqbn: STM32:stm32:GenF1:pnum=BLUEPILL_F103C8 # bluepill - hs examples
4444
platform-url: https://github.com/stm32duino/BoardManagerFiles/raw/master/STM32/package_stm_index.json
45-
sketch-names: bluepill_position_control.ino, stm32_i2c_dual_bus_example.ino, magnetic_sensor_spi_alt_example.ino
45+
sketch-names: bluepill_position_control.ino, stm32_i2c_dual_bus_example.ino, stm32_spi_alt_example.ino
4646

4747
- arduino-boards-fqbn: STM32:stm32:Nucleo_64:pnum=NUCLEO_F411RE # one full example
4848
platform-url: https://github.com/stm32duino/BoardManagerFiles/raw/master/STM32/package_stm_index.json
49-
sketch-names: single_full_control_example.ino
49+
sketch-names: single_full_control_example.ino, stm32_spi_alt_example.ino
5050

5151

5252

README.md

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,32 @@ Therefore this is an attempt to:
1616
- ***NEW*** 📢: *Medium-power* BLDC driver (<30Amps): [Arduino <span class="simple">Simple<b>FOC</b>PowerShield</span> ](https://github.com/simplefoc/Arduino-SimpleFOC-PowerShield).
1717
- See also [@byDagor](https://github.com/byDagor)'s *fully-integrated* ESP32 based board: [Dagor Brushless Controller](https://github.com/byDagor/Dagor-Brushless-Controller)
1818

19-
##### <b> Release notes be:</b> <i>Simple<b>FOC</b>library</i> v2.1.1
20-
> - bugfixes commander
21-
> - bugfix `voltage_limit` when provided `phase_resistance`
22-
> - bugfix `hall_sensor` examples
23-
> - added examples fot the PowerShield
24-
> - added initial support for `MagneticSensorPWM`
25-
> - SAMD51 support
26-
> - **initial support for Raspberry pi Pico**
27-
> - added examples to find the raw max and min of the analog and pwm sensor
28-
> - extension of the `Commander` interface
29-
> - added pwm centering option `WC`
30-
> - added pwm modulation cmd `WT`
31-
> - improved esp32 implementation to avoid the need for mcpwm.h changes by @tschundler
32-
> - issue #62: motor.shaft_angle setting in the motor.initFOC()
33-
> - issue #76: esp32 division by zero
34-
> - issue #46: commander end of line character - by @maxlem
35-
> - [community fix](https://community.simplefoc.com/t/as5600-dead-spot-around-0/208) AS5600 register value
36-
> - renamed `Pullup::EXTERN` and `Pullup::INTERN` to `Pullup::USE_EXTERN` and `Pullup::USE_INTERN`
19+
20+
<blockquote class="info">
21+
<p class="heading">NEW RELEASE 📢: <span class="simple">Simple<span class="foc">FOC</span>library</span> v2.2 - <a href="https://github.com/simplefoc/Arduino-FOC/releases/tag/v2.2">see release</a></p>
22+
<ul>
23+
<li>Sensor floating point error bugfix (initial solution) #83, #37</li>
24+
<li>Sensor class restructuring - <b>slight API change</b> - <a href="https://docs.simplefoc.com/sensors">docs</a></li>
25+
<li>Restructured the generic code and simplified adding new mcus: <b>IMPORTANT: an additional compiler flag needed for PlatformIO</b> see <a href="https://github.com/simplefoc/Arduino-FOC/issues/99">issue</a> and <a href="https://docs.simplefoc.com/library_platformio">PlatformIO docs</a></li>
26+
<li>Removed initial jump #110, #111</li>
27+
<li>Double to float transformation of the code - performance increase by <a href="https://github.com/sDessens">@sDessens</a> (#100), <a href="https://github.com/KaSroka">@KaSroka</a> (#100) </li>
28+
<li> <a href="https://docs.simplefoc.com/docs_chinese"><b>Docs webiste translated to Chinese!</b></a> 🎉: Awesome work 😃 by <a href="https://github.com/MINQING1101">@MINQING1101</a>, <a href="https://github.com/Deng-ge-open-source">@Deng-ge-open-source</a> and <a href="https://github.com/mingggggggg">@mingggggggg</a></li>
29+
<li>New MCU support - <a href="https://docs.simplefoc.com/microcontrollers">docs</a>
30+
<ul>
31+
<li>Support for arduino leonardo #108 </li>
32+
<li>Initial support for portenta h7 board in collaboration with <img src="https://docs.simplefoc.com/extras/Images/arduino.png" height="15px"><a href="https://www.arduino.cc/">Arduino</a></li>
33+
<li>Initial support for esp8266</li>
34+
</ul>
35+
</li>
36+
<li>Low side current sensing initial support - <a href="https://docs.simplefoc.com/current_sense">docs</a>
37+
<ul>
38+
<li>Initial support for stm32 B_G431B_ESC1 by <a href="https://github.com/sDessens">@sDessens</a>: PR #73</li>
39+
<li>Initial support for samd21 by <a href="https://github.com/maxlem">@maxlem</a>: PR #79</li>
40+
<li>Initial support for esp32 by <a href="https://github.com/maxlem">@byDagor</a></li>
41+
</ul>
42+
</li>
43+
</ul>
44+
</blockquote>
3745

3846
## Arduino *SimpleFOClibrary* v2.1
3947

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
/**
2+
* B-G431B-ESC1 position motion control example with encoder
3+
*
4+
*/
5+
#include <SimpleFOC.h>
6+
7+
// Motor instance
8+
BLDCMotor motor = BLDCMotor(11);
9+
BLDCDriver6PWM driver = BLDCDriver6PWM(PHASE_UH, PHASE_UL, PHASE_VH, PHASE_VL, PHASE_WH, PHASE_WL);
10+
LowsideCurrentSense currentSense = LowsideCurrentSense(0.003, -64.0/7.0, OP1_OUT, OP2_OUT, OP3_OUT);
11+
12+
13+
// encoder instance
14+
Encoder encoder = Encoder(HALL2, HALL3, 2048, HALL1);
15+
16+
// Interrupt routine intialisation
17+
// channel A and B callbacks
18+
void doA(){encoder.handleA();}
19+
void doB(){encoder.handleB();}
20+
void doIndex(){encoder.handleIndex();}
21+
22+
// angle set point variable
23+
float target_angle = 0;
24+
// instantiate the commander
25+
Commander command = Commander(Serial);
26+
void doTarget(char* cmd) { command.scalar(&target_angle, cmd); }
27+
28+
void setup() {
29+
30+
// initialize encoder sensor hardware
31+
encoder.init();
32+
encoder.enableInterrupts(doA, doB);
33+
34+
// link the motor to the sensor
35+
motor.linkSensor(&encoder);
36+
37+
// driver config
38+
// power supply voltage [V]
39+
driver.voltage_power_supply = 12;
40+
driver.init();
41+
// link the motor and the driver
42+
motor.linkDriver(&driver);
43+
44+
// current sensing
45+
currentSense.init();
46+
// no need for aligning
47+
currentSense.skip_align = true;
48+
motor.linkCurrentSense(&currentSense);
49+
50+
// aligning voltage [V]
51+
motor.voltage_sensor_align = 3;
52+
// index search velocity [rad/s]
53+
motor.velocity_index_search = 3;
54+
55+
// set motion control loop to be used
56+
motor.controller = MotionControlType::velocity;
57+
58+
// contoller configuration
59+
// default parameters in defaults.h
60+
61+
// velocity PI controller parameters
62+
motor.PID_velocity.P = 0.2;
63+
motor.PID_velocity.I = 20;
64+
// default voltage_power_supply
65+
motor.voltage_limit = 6;
66+
// jerk control using voltage voltage ramp
67+
// default value is 300 volts per sec ~ 0.3V per millisecond
68+
motor.PID_velocity.output_ramp = 1000;
69+
70+
// velocity low pass filtering time constant
71+
motor.LPF_velocity.Tf = 0.01;
72+
73+
// angle P controller
74+
motor.P_angle.P = 20;
75+
// maximal velocity of the position control
76+
motor.velocity_limit = 4;
77+
78+
79+
// use monitoring with serial
80+
Serial.begin(115200);
81+
// comment out if not needed
82+
motor.useMonitoring(Serial);
83+
84+
// initialize motor
85+
motor.init();
86+
// align encoder and start FOC
87+
motor.initFOC();
88+
89+
// add target command T
90+
command.add('T', doTarget, "target angle");
91+
92+
Serial.println(F("Motor ready."));
93+
Serial.println(F("Set the target angle using serial terminal:"));
94+
_delay(1000);
95+
}
96+
97+
// angle set point variable
98+
float target_angle = 0;
99+
100+
void loop() {
101+
// main FOC algorithm function
102+
103+
// Motion control function
104+
motor.move(target_angle);
105+
106+
// function intended to be used with serial plotter to monitor motor variables
107+
// significantly slowing the execution down!!!!
108+
// motor.monitor();
109+
110+
// user communication
111+
command.run();
112+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
-DHAL_OPAMP_MODULE_ENABLED

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// MOSI 9
99
// SCK 14
1010
// magnetic sensor instance - SPI
11-
MagneticSensorSPI sensor = MagneticSensorSPI(AS5147_SPI, 10);
11+
MagneticSensorSPI sensor = MagneticSensorSPI(AS5147_SPI, 15);
1212

1313
// I2C Magnetic sensor instance (AS5600 example)
1414
// make sure to use the pull-ups!!

examples/hardware_specific_examples/SimpleFOC-PowerShield/version_v02/single_full_control_example/single_full_control_example.ino

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ InlineCurrentSense current_sense = InlineCurrentSense(0.001, 50.0, A0, A1);
1616

1717
// commander communication instance
1818
Commander command = Commander(Serial);
19-
void doMotor(char* cmd){ command.motor(&motor, cmd); }
19+
// void doMotor(char* cmd){ command.motor(&motor, cmd); }
20+
void doTarget(char* cmd){ command.scalar(&motor.target, cmd); }
2021

2122
void setup() {
2223

@@ -74,10 +75,11 @@ void setup() {
7475
motor.target = 0;
7576

7677
// subscribe motor to the commander
77-
command.add('M', doMotor, "motor");
78+
// command.add('M', doMotor, "motor");
79+
command.add('T', doTarget, "target");
7880

7981
// Run user commands to configure and the motor (find the full command list in docs.simplefoc.com)
80-
Serial.println(F("Motor commands sketch | Initial motion control > torque/current : target 0Amps."));
82+
Serial.println("Motor ready.");
8183

8284
_delay(1000);
8385
}

examples/hardware_specific_examples/SimpleFOCShield/version_v2/double_full_control_example/double_full_control_example.ino

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,10 @@ InlineCurrentSense current_sense2 = InlineCurrentSense(0.01, 50.0, A1, A3);
3232

3333
// commander communication instance
3434
Commander command = Commander(Serial);
35-
void doMotor1(char* cmd){ command.motor(&motor1, cmd); }
36-
void doMotor2(char* cmd){ command.motor(&motor2, cmd); }
35+
// void doMotor1(char* cmd){ command.motor(&motor1, cmd); }
36+
// void doMotor2(char* cmd){ command.motor(&motor2, cmd); }
37+
void doTarget1(char* cmd){ command.scalar(&motor1.target, cmd); }
38+
void doTarget2(char* cmd){ command.scalar(&motor2.target, cmd); }
3739

3840
void setup() {
3941

@@ -111,11 +113,13 @@ void setup() {
111113
motor2.target = 2;
112114

113115
// subscribe motor to the commander
114-
command.add('A', doMotor1, "motor 1");
115-
command.add('B', doMotor2, "motor 2");
116+
// command.add('A', doMotor1, "motor 1");
117+
// command.add('B', doMotor2, "motor 2");
118+
command.add('A', doTarget1, "target 1");
119+
command.add('B', doTarget2, "target 2");
116120

117121
// Run user commands to configure and the motor (find the full command list in docs.simplefoc.com)
118-
Serial.println(F("Double motor sketch ready."));
122+
Serial.println("Motors ready.");
119123

120124
_delay(1000);
121125
}

examples/hardware_specific_examples/SimpleFOCShield/version_v2/single_full_control_example/single_full_control_example.ino

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ InlineCurrentSense current_sense = InlineCurrentSense(0.01, 50.0, A0, A2);
1717

1818
// commander communication instance
1919
Commander command = Commander(Serial);
20-
void doMotor(char* cmd){ command.motor(&motor, cmd); }
20+
void doTarget(char* cmd){ command.scalar(&motor.target, cmd); }
21+
// void doMotor(char* cmd){ command.motor(&motor, cmd); }
2122

2223
void setup() {
2324

@@ -73,10 +74,11 @@ void setup() {
7374
motor.target = 2;
7475

7576
// subscribe motor to the commander
76-
command.add('M', doMotor, "motor");
77-
77+
command.add('T', doTarget, "target");
78+
// command.add('M', doMotor, "motor");
79+
7880
// Run user commands to configure and the motor (find the full command list in docs.simplefoc.com)
79-
Serial.println(F("Motor commands sketch | Initial motion control > torque/voltage : target 2V."));
81+
Serial.println("Motor ready.");
8082

8183
_delay(1000);
8284
}

examples/utils/calibration/alignment_and_cogging_test/alignment_and_cogging_test.ino

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ void testAlignmentAndCogging(int direction) {
2121
motor.move(0);
2222
_delay(200);
2323

24+
sensor.update();
2425
float initialAngle = sensor.getAngle();
2526

2627
const int shaft_rotation = 720; // 720 deg test - useful to see repeating cog pattern
@@ -40,6 +41,7 @@ void testAlignmentAndCogging(int direction) {
4041
_delay(5);
4142

4243
// measure
44+
sensor.update();
4345
float sensorAngle = (sensor.getAngle() - initialAngle) * 180 / PI;
4446
float sensorElectricAngle = sensorAngle * motor.pole_pairs;
4547
float electricAngleError = electricAngle - sensorElectricAngle;

examples/utils/calibration/find_pole_pair_number/encoder/find_pole_pairs_number/find_pole_pairs_number.ino

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ void setup() {
6464
motor.move(0);
6565
_delay(1000);
6666
// read the encoder angle
67+
encoder.update();
6768
float angle_begin = encoder.getAngle();
6869
_delay(50);
6970

@@ -75,6 +76,7 @@ void setup() {
7576
}
7677
_delay(1000);
7778
// read the encoder value for 180
79+
encoder.update();
7880
float angle_end = encoder.getAngle();
7981
_delay(50);
8082
// turn off the motor

0 commit comments

Comments
 (0)