Skip to content

Commit abc8d54

Browse files
Merge pull request #22 from simplefoc/master
Merge current master to dev branch before release
2 parents efe7940 + 497f638 commit abc8d54

File tree

9 files changed

+82
-76
lines changed

9 files changed

+82
-76
lines changed

docs/simplefoc_library/cheatsheet/build_flags.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,14 @@ Build flags control the way the compiler generates the code for <span class="sim
2121
Flag | Architecture | Description
2222
--- | --- | ---
2323
`SIMPLEFOC_DISABLE_DEBUG` | All | set this to disable the entire debugging code
24-
`SIMPLEFOC_PWM_ACTIVE_HIGH` | STM32, RP2040 | sets PWM polarity on phase PWM outputs - default is active high (true) but can be set to false for active low polarity. Affects both high and low side in 6-PWM mode
25-
`SIMPLEFOC_PWM_LOWSIDE_ACTIVE_HIGH` | STM32, RP2040 | sets PWM polarity on low side phase PWM outputs - default is active high (true) but can be set to false for active low polarity. Affects only low side FETs in 6-PWM mode. No effect in other modes.
26-
`SIMPLEFOC_PWM_HIGHSIDE_ACTIVE_HIGH` | STM32, RP2040 | sets PWM polarity on high side phase PWM outputs - default is active high (true) but can be set to false for active low polarity. Affects only high side FETs in 6-PWM mode. No effect in other modes.
24+
`SIMPLEFOC_PWM_ACTIVE_HIGH` | STM32, RP2040, ESP32 | sets PWM polarity on phase PWM outputs - default is active high (true) but can be set to false for active low polarity. Affects both high and low side in 6-PWM mode (STM32, RP2040)
25+
`SIMPLEFOC_PWM_LOWSIDE_ACTIVE_HIGH` | STM32, RP2040, ESP32 | sets PWM polarity on low side phase PWM outputs - default is active high (true) but can be set to false for active low polarity. Affects only low side FETs in 6-PWM mode. No effect in other modes.
26+
`SIMPLEFOC_PWM_HIGHSIDE_ACTIVE_HIGH` | STM32, RP2040, ESP32 | sets PWM polarity on high side phase PWM outputs - default is active high (true) but can be set to false for active low polarity. Affects only high side FETs in 6-PWM mode. No effect in other modes.
2727
`SIMPLEFOC_STM32_DEBUG` | STM32 | set to enable extra debug output for STM32 MCUs.
2828
`SIMPLEFOC_STM32_MAX_PINTIMERSUSED` | STM32 | maximum number of PWM pins configurable, default is 12 (up to 2x 6PWM, normally that's plenty)
2929
`SIMPLEFOC_SAMD_DEBUG` | SAMD21 / SAMD51 | set to enable extra debug output for SAMD MCUs.
3030
`SIMPLEFOC_SAMD_MAX_TCC_PINCONFIGURATIONS` | SAMD21 / SAMD51 | maximum number of PWM pins configurable, default is 24 (for up to 4x6PWM, that should be enough ;-) )
3131
`SIMPLEFOC_SAMD51_DPLL_FREQ` | SAMD21 / SAMD51 | expected frequency on DPLL, since we don't configure it ourselves. Typically this is the CPU frequency. For custom boards or overclockers you can override it using this define. Default is 120000000
3232
`SIMPLEFOC_DEBUG_RP2040` | RP2040 | set to enable extra debug output on Raspberry Pico.
3333
`SIMPLEFOC_ESP32_USELEDC` | ESP32 | force use of the LEDC PWM driver even on ESP32s that support MCPWM. Mainly useful for testing purposes, normally you would prefer MCPWM if it is available.
34+
`SIMPLEFOC_ESP32_HW_DEADTIME` | ESP32 | Select between MCPWM hardware deadtime and a software implementation allowing phase_state configuration. Defaults to hardware for being tested more.

docs/simplefoc_library/code/from_scratch.md

+24-19
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ grand_parent: Arduino <span class="simple">Simple<span class="foc">FOC</span>lib
1010

1111
# Let's get started
1212

13-
Once when you have your <span class="simple">Simple<span class="foc">FOC</span>library</span> [installed](installation) and you have all the necessary [hardware](supported_hardware), we can finally start the fun part, let's white the code and move the motor!
13+
Once you have your <span class="simple">Simple<span class="foc">FOC</span>library</span> [installed](installation) and you have all the necessary [hardware](supported_hardware), we can finally start the fun part, let's write the code and move the motor!
1414

1515
## Step 1. Testing the sensor
1616
The first sign that tells us that everything is well connected is if the sensor readings are good. To test the sensor please browse the library examples `examples/utils/sensor_test` and find the example for your sensor.
@@ -19,7 +19,7 @@ The example will have a structure something like this:
1919
#include <SimpleFOC.h>
2020

2121
Encoder encoder = Encoder(2, 3, 500);
22-
// interrupt routine intialisation
22+
// interrupt routine initialisation
2323
void doA(){encoder.handleA();}
2424
void doB(){encoder.handleB();}
2525

@@ -46,15 +46,15 @@ void loop() {
4646
Serial.println(sensor.getVelocity());
4747
}
4848
```
49-
Make sure to change the sensor parameters to suite your application, such as pin numbers, impulses per revolution, bus addresses and similar. Make sure to go through the [sensor docs](sensors) if you are not sure in some of the parameters.
49+
Make sure to change the sensor parameters to suit your application, such as pin numbers, impulses per revolution, bus addresses and similar. Make sure to go through the [sensor docs](sensors) if you are not sure about some of the parameters.
5050

5151

5252
If your sensor is well connected and if everything works well, you should have in your serial terminal an output of your sensor angle and velocity.
5353

5454
<blockquote class="info"> <p class="heading">☑️ Simple test</p> Make sure to test that one rotation of the motor gives you <b>6.28</b> radians of sensor angle.</blockquote>
5555

56-
## Step 2. Testing the driver
57-
Once your sensor is working you can proceed to the driver test. The simplest way to test the driver is to use the library examples. If you have a luxury of time you can test the driver using the examples in `examples/utils/driver_standalone_test` folder. These examples test the driver as a standalone module and with them you can set any voltage value to any of the driver phases.
56+
## Step 2. Testing just the driver
57+
Once your sensor is working you can proceed to the driver test. The simplest way to test the driver is to use the library examples. If you have the luxury of time you can test the driver using the examples in the `examples/utils/driver_standalone_test` folder. These examples test the driver as a standalone module and with them you can set any voltage value to any of the driver phases.
5858
```cpp
5959
#include <SimpleFOC.h>
6060
// BLDC driver instance
@@ -86,9 +86,13 @@ void loop() {
8686
Make sure that all phases output PWM signals, you can try to connect a small led light in between each phase and ground or just measure it with the multimeter.</blockquote>
8787

8888
## Step 2. Testing the driver + motor combination - open-loop
89-
If you already have your motor connected and if you are sure your driver works well we advise you to test the motor+driver combination using the Open-Loop control examples in the `examples/motion_control/open_loop_motion_control`. If your driver is not the same as the ones provided in the examples go though the [driver docs](drivers_config) and find the driver and the code that will work for you. Additionally you can browse through the examples in teh `examples/utils/driver_standalone_test` folder and see the used in there.
89+
If you already have your motor connected and if you are sure your driver works well we advise you to test the motor+driver combination using the Open-Loop control examples in the `examples/motion_control/open_loop_motion_control`. If your driver is not the same as the ones provided in the examples, go though the [driver docs](drivers_config) and find the driver and the code that will work for you. Additionally you can browse through the examples in the `examples/utils/driver_standalone_test` folder and see the used in there.
9090

91-
Now here is an example of the open-loop velocity control for the `BLDCDriver3PWM`:
91+
<blockquote class="info"> <p class="heading">Please Note</p>
92+
93+
Before you try this example, please take at least a short look at the rules just below the code. From here on, actual current is flowing through your electronics and your driver has no way of measuring it (at least not in this example). </blockquote>
94+
95+
Now, here is an example of the open-loop velocity control for the `BLDCDriver3PWM`:
9296
```cpp
9397
// Open loop motor control example
9498
#include <SimpleFOC.h>
@@ -144,7 +148,8 @@ void loop() {
144148
```
145149
This example code has few very important rules.
146150
1. Make sure you use the right driver class and right pwm pins, this one is usually very simple and you can find a lot of docs about these things in our [driver docs](drivers_config). If you are not sure and cannot seem to make it work please do not hesitate to ask in our [community forum](https://community.simplefoc.com).
147-
2. Make sure to use proper voltage limit. `motor.voltage_limit` will directly determine the current passing through the motor: `current = phase_resistance*motor.voltage_limit`. So to avoid too high currents please try to find what is the phase resistance of your motor and set the `motor.voltage_limit` such that the current does not surpass 2 Amps for example: `motor.voltage_limit = 2*phase_resistance`. The best option would be to provide your phase resistance value to the motor by setting the parameter `motor.phase_resistance` and then you can use `motor.current_limit` instead of the `motor.voltage_limit` making this issue much simpler. If you cannot find the phase resistance of your motor and cannot measure it with your multimeter start small: `motor.voltage_limit < 1;`
151+
2. Make sure to use a proper voltage limit. All of these examples assume you are using a gimbal type motor with high phase resistance (~10 Ohms). For higher power motors, the current will propably be too high, putting your motor+driver at risk. As a rule of thumb, if your motor has a servo type plug, you should be fine.
152+
`motor.voltage_limit` will directly determine the current passing through the motor: `current = phase_resistance*motor.voltage_limit`. So to avoid too high currents please try to find what is the phase resistance of your motor and set the `motor.voltage_limit` such that the current does not surpass 2 Amps for example: `motor.voltage_limit = 2*phase_resistance`. The best option would be to provide your phase resistance value to the motor by setting the parameter `motor.phase_resistance` and then you can use `motor.current_limit` instead of the `motor.voltage_limit` making this issue much simpler. If you cannot find the phase resistance of your motor and cannot measure it with your multimeter start small: `motor.voltage_limit < 1;`
148153
3. Make sure to put the right pole pair number. This you can find in most data-sheets, if you are not sure what is the true number don't worry this step in intended to test exactly this value. 😄
149154
150155
<blockquote class="info"> <p class="heading">☑️ Simple tests</p> 1. In velocity mode, set your target velocity of your motor to <b>6.28 rad/s</b>, this should be exactly one rotation per second.<br>2. In position mode, set the target position of <b>6.28 rad</b>, it should be exactly one rotation <br> If it is not that means your pole pairs number is probably not good,, try changing it until you get exactly one rotation (or one rotation per second in velocity mode)</blockquote>
@@ -234,17 +239,17 @@ Until now, you already know the good configuration of your sensor, your driver a
234239

235240
There are only two important steps to be taken here, make sure you use not too high `motor.voltage_sensor_align` value to prevent too high currents. The rule is the same as for the `motor.voltage_limit` for the open loop. If you are not sure what is your phase resistance, start small: `motor.voltage_sensor_align < 1`. Additionally, you can define the motor phase resistance as well and then use the `motor.current_limit` variable, this variable will limit the `motor.voltage_sensor_align` and you will not have to worry about it any more. But if you specify the phase resistance value you will no longer be setting voltage command to the motor but current command, see [torque control docs](voltage_torque_mode) for more info.
236241

237-
Second important tip is to use [monitoring](monitoring) functionality. This will help you to debug the possible issues that might arise and it will output the motor status during the initialization and the alignment. If the initialisation fails the motor will be disabled you will be able to move the motor by hand without any resistance, if the code works your motor will start spinning and you will be abele to set the voltage (current if `motor.phase_resistance` set) through the serial terminal.
242+
Second important tip is to use [monitoring](monitoring) functionality. This will help you to debug the possible issues that might arise and it will output the motor status during the initialization and the alignment. If the initialisation fails the motor will be disabled you will be able to move the motor by hand without any resistance, if the code works your motor will start spinning and you will be able to set the voltage (current if `motor.phase_resistance` set) through the serial terminal.
238243

239244
<blockquote class="info"> <p class="heading">☑️ Simple test</p>
240-
Make sure that the motor intialisation has finished well. Monitoring will tell you the sensnor offset, direciton, pole pairs check and it will tell you if it has been successful or if it failed. </blockquote>
245+
Make sure that the motor intialisation has finished well. Monitoring will tell you the sensor offset, direction, pole pairs check and it will tell you if it has been successful or if it failed. </blockquote>
241246

242247
## Step 5. Testing the current sense - if available
243248
If your setup has current sensing that is supported by the <span class="simple">Simple<span class="foc">FOC</span>library</span> then we would suggest you to still make sure that you can run at least closed-loop torque control using voltage (Step 3.) before doing this step.
244249

245-
The best way to start is to add the current sensing to the code of the torque control using voltage (step 3.) and output the d and q currents to the serial terminal using monitoring.
250+
The best way to start is to add the current sensing to the code of the torque control using voltage (Step 3.) and output the d and q currents to the serial terminal using monitoring.
246251

247-
Here is the an example of a such code:
252+
Here is the an example of such a code:
248253
```cpp
249254
#include <SimpleFOC.h>
250255

@@ -335,18 +340,18 @@ void loop() {
335340
command.run();
336341
}
337342
```
338-
This example code is almost exactly the same as the step 3. code so you should not have much troubles configuring motor, sensor and driver. In this step you will be testing if your current sense is working well. In the call of the `motor.monitor()` function the current sense will be read and the current d and q are going to be outputted to the serial terminal. You can open the Serial Plotter to visualise them.
343+
This example code is almost exactly the same as the Step 3. code so you should not have much trouble configuring motor, sensor and driver. In this step you will be testing if your current sense is working well. In the call of the `motor.monitor()` function the current sense will be read and the current d and q are going to be printed to the serial terminal. You can open the Serial Plotter to visualise them.
339344

340345
<blockquote class="info"> <p class="heading">☑️ Simple tests</p>
341-
1. Hold the motor with your hand and chaneg different target voltage/current values. Make sure that the current d is very close to 0 when the motor is static. And make sure that the current q is proportional to the voltage you are setting to the motor. <br>
342-
2. Leave the motor to rotate. See that your currents d and q drop to a lower level then for static motor. Also try to see that the current d is almost 0 for low velocities and starts rising proportionally to the motor velocity.
346+
1. Hold the motor with your hand and set different target voltage/current values. Make sure that the current d is very close to 0 when the motor is static. And make sure that the current q is proportional to the voltage you are setting to the motor. <br>
347+
2. Leave the motor to rotate. See that your currents d and q drop to a lower level than for static motor. Also try to see that the current d is almost 0 for low velocities and starts rising proportionally to the motor velocity.
343348
</blockquote>
344349

345350
Please go through the [current sense docs](current_sense) to see the supported sensors and all the configuration parameters.
346351

347352

348353
## Step 6. Full FOC motion control using current sensing - if available
349-
Once you have your motor, position sensor, driver and current sense configured and tested you can got proceed to the true foc control.
354+
Once you have your motor, position sensor, driver and current sense configured and tested you can now proceed to try out true field oriented control (FOC).
350355
```cpp
351356
#include <SimpleFOC.h>
352357

@@ -423,7 +428,7 @@ void setup() {
423428
// subscribe motor to the commander
424429
command.add('M', doMotor, "motor");
425430

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

429434
_delay(1000);
@@ -443,9 +448,9 @@ void loop() {
443448
}
444449
```
445450

446-
To see all of the FOC torque control parameters please visit the [torque control docs](torque_control). The goon news is that if you have set the phase resistance during the tuning the velocity and position motion control loops in step 4. you will most probably not need to retune them.
451+
To see all of the FOC torque control parameters please visit the [torque control docs](torque_control). The good news is that if you have set the phase resistance during tuning the velocity and position motion control loops in step 4, you will most probably not need to retune them.
447452

448-
However the most important tip is still to use the [commander interface](commander_interface) to tune hte torque control PID controller and Low pas filter parameters, this way you will be able to test quickly and change the parameters of controllers in real-time and see what will happen. One time you are satisfied you can write these values in code and quit using the commander.
453+
However the most important tip is still to use the [commander interface](commander_interface) to tune the torque control PID controller and Low pass filter parameters. This way you will be able to change and test the parameters of controllers in real-time and see what will happen. Once you are satisfied, you can write these values into your code and quit using the commander.
449454

450455
<blockquote class="info"> <p class="heading">☑️ Simple test</p>
451456
Set your target current to <b>0Amps</b> and try to move the motor by hand, make sure it feels like there is absolutely no resistance, like the motor is disabled. Then try to set a small current (<b><0.5A</b>) value and see if you can feel the motor force acting on your hand. If you can feel it you should be ready to go!

0 commit comments

Comments
 (0)