Skip to content

Commit c6bac8b

Browse files
committed
update dor v2.2 + chinese translation
1 parent 9bed4e0 commit c6bac8b

File tree

26 files changed

+495
-76
lines changed

26 files changed

+495
-76
lines changed

_includes/js/custom.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ var funcNames = [
119119
"monitor_port",
120120
"println",
121121
"getVelocity",
122+
"update",
122123
"getAngle",
123124
"loopFOC",
124125
"move",
@@ -180,8 +181,10 @@ var structNames = [
180181
"VerboseMode"
181182
];
182183
var structProps = [
183-
"EXTERN",
184-
"INTERN",
184+
"USE_EXTERN",
185+
"USE_INTERN",
186+
"ON",
187+
"OFF",
185188
"ENABLE",
186189
"DISABLE",
187190
"angle",

_includes/nav.html

+3
Original file line numberDiff line numberDiff line change
@@ -62,5 +62,8 @@
6262
{%- endif -%}
6363
{%- endunless -%}
6464
{%- endfor -%}
65+
<li class="nav-item navigation-list-item" style="padding:5px">
66+
<a href="https://docs.simplefoc.com/docs_chinese" style="padding:0px"><i class="fa fa-language fa-lg"></i> Docs in Chinese</a>
67+
</li>
6568
</ul>
6669
</nav>

_layouts/default.html

+2-8
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,8 @@
2626
</div>
2727
<footer class="site-footer">
2828
<ul class="nav-custom nav-custom-bottom aux-nav">
29-
<li class="nav-item">
30-
<a href="https://simplefoc.com/" title="SimpleFOC project home"><i class="fa fa-home fa-lg"></i></a>
31-
</li>
32-
<li class="nav-item">
33-
<a href="https://github.com/simplefoc" ><i class="fa fa-github fa-lg"></i> </a>
34-
</li>
35-
<li class="nav-item">
36-
<a href="https://simplefoc.com/shop" ><i class="fa fa-shopping-cart fa-lg"></i> </a>
29+
<li class="nav-item">
30+
<a href="https://github.com/simplefoc" ><i class="fa fa-github fa-lg"></i> Github</a>
3731
</li>
3832
<li class="nav-item rm-md">
3933
<a href="https://community.simplefoc.com" title="SimpleFOC project home">

docs/simplefoc_library/code/current_sense/index.md

+20-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ Arduino <span class="simple">Simple<span class="foc">FOC</span>library</span> ha
1717
- [Low-side current sensing](low_side_current_sense) - *initial support*
1818
- [High-side current sensing](high_side_current_sense) - *Not supported yet*
1919

20-
up to this moment ( [check the releases <i class="fa fa-tag"></i>](https://github.com/simplefoc/Arduino-FOC/releases) ), Arduino <span class="simple">Simple<span class="foc">FOC</span>library</span> supports only in-line current sensing and implements initial support for the low-side current sensing on ESP32 boards (one motor) and on the stm32 based B_G431B_ESC1 boards.
20+
21+
<img src="extras/Images/comparison_cs.png" class="width40">
22+
23+
up to this moment ( [check the releases <i class="fa fa-tag"></i>](https://github.com/simplefoc/Arduino-FOC/releases) ), Arduino <span class="simple">Simple<span class="foc">FOC</span>library</span> supports only in-line current sensing and implements initial support for the low-side current sensing on ESP32 boards (one motor), samd21 (one motor) and on the stm32 based B_G431B_ESC1 boards (one motor).
2124

2225
Each one of the current sensing classes will implement all the necessary functionalities for simple and robust implementation of FOC algorithm:
2326
- Hardware config
@@ -38,5 +41,21 @@ The current sense code will be written in a way to support as many different dri
3841

3942
Also make sure to follow our [community forum](https://community.simplefoc.com), a lot of discussions is being held about current sensing and its applications!
4043

44+
## Current sensing support per MCU architecture
45+
46+
MCU | In-line | Low-side | High-side
47+
--- | --- |--- |---
48+
Arduino (8-bit) | ✔️ | ❌ | ❌
49+
Arduino DUE | ✔️ | ❌ | ❌
50+
stm32 | ✔️ | ❌ | ❌
51+
stm32 B_G431B_ESC1 | ✔️ | ✔️ (initial) | ❌
52+
esp32 | ✔️ | ✔️ (initial) | ❌
53+
esp8266 | ❌ | ❌ | ❌
54+
samd21 | ✔️ | ✔️ (initial) | ❌
55+
samd51 | ✔️ | ❌ | ❌
56+
teensy | ✔️ | ❌ | ❌
57+
Raspberry Pi Pico | ✔️ | ❌ | ❌
58+
Portenta H7 | ✔️ | ❌ | ❌
59+
4160
## Digging deeper
4261
For more theoretical explanations and source code implementations of the current sensing and its integration into the FOC and motion check out the [digging deeper section](digging_deeper).

docs/simplefoc_library/code/current_sense/inline.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ void setup() {
167167
void loop() {
168168

169169
PhaseCurrent_s currents = current_sense.getPhaseCurrents();
170-
float current_magnitude = current_sense.getCurrent();
170+
float current_magnitude = current_sense.getDCCurrent();
171171

172172
Serial.print(currents.a*1000); // milli Amps
173173
Serial.print("\t");

docs/simplefoc_library/code/current_sense/low_side.md

+192-3
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,199 @@ grand_grand_parent: Arduino <span class="simple">Simple<span class="foc">FOC</sp
99
---
1010

1111
# Low-side current sensing
12-
Low-side current sensing is probably the most common current sensing technique. The main reason why is because it does not require neither high-performance PWM rejection current sense amplifiers (as inline does) neither high-voltage supporting amplifiers (as high-side does). The shunt resistors are always placed in between low side mosfets and the ground making sure that the amplifiers always has very low voltages on its terminals. The main drawback of this approach is that since the current passing through the shunt resistors is phase current only if the corresponding low side mosfet is on we can only measure it in those moments. The PWM frequency is usually 20 to 50 kHz, which means that the low-side mosfets turns on and off 20,000 to 50,000 times per second, therefore the synchronization in between PWM setting and ADC acquisition is very very important.
12+
Low-side current sensing is probably the most common current sensing technique. The main reason why is because it does not require neither high-performance PWM rejection current sense amplifiers (as inline does) neither high-voltage supporting amplifiers (as high-side does). The shunt resistors are always placed in between low side mosfets and the ground making sure that the amplifiers always have very low voltages on their terminals. The main drawback of this approach is that, since the current passing through the shunt resistors is phase current only if the corresponding low side mosfet is ON, we can only measure it in those moments. The PWM frequency is usually 20 to 50 kHz, which means that the low-side mosfets turns on and off 20,000 to 50,000 times per second, therefore the synchronization in between PWM setting and ADC acquisition is very very important.
1313

14-
Low side current sensing will be implemented soon. The main issue at the moment is very hardware specific synchronisation procedure of the PWM generation and ADC triggering. Therefore it is possible that this implantation will be done one MCU architecture at the time.
14+
Low side current sensing for all the architectures is on our road-map and we are actively working on it. The main issue at the moment is very hardware specific synchronisation procedure of the PWM generation and ADC triggering. Therefore we are attacking one MCU architecture at the time. 😃
1515

1616

1717
<img src="extras/Images/low-side.png" class="width50">
18-
<img src="extras/Images/low_side_sync.png" class="width40">
18+
<img src="extras/Images/low_side_sync.png" class="width40">
19+
20+
21+
## Step 1. Hardware configuration
22+
23+
```cpp
24+
// LowsideCurrentSense constructor
25+
// - shunt_resistor - shunt resistor value
26+
// - gain - current-sense op-amp gain
27+
// - phA - A phase adc pin
28+
// - phB - B phase adc pin
29+
// - phC - C phase adc pin (optional)
30+
LowsideCurrentSense current_sense = LowsideCurrentSense(0.01, 20, A0, A1, A2);
31+
```
32+
To instantiate the low-side current sensor using the <span class="simple">Simple<span class="foc">FOC</span>library</span> just create an instance of the class `LowsideCurrentSense`. This class takes as a parameter shunt resistance value `shunt_resistor`, amplification gain `gain` and two or three ADC channel pins depending on the available measuring hardware that you might have. It is important to specify right adc channels for right driver/motor phase. So if your pin `A0` measures the phase current `A` and pin `A1` measures the phase current `B` make sure to put provide them to the constructor in that order.
33+
34+
<blockquote class="info">
35+
Field Oriented Control algorithm can run with both 2 or 3 phase current measurements.
36+
</blockquote>
37+
38+
The constructor of the `LowsideCurrentSense` class only allows you to specify one shunt resistor value and one amplification gain. If your hardware configuration has different shunt/amp values for different phases you can specify them by changing the `gain_x` attribute:
39+
```cpp
40+
// default values of per phase gains
41+
current_sense.gain_a = 1.0 / shunt_resistor / gain;
42+
current_sense.gain_b = 1.0 / shunt_resistor / gain;
43+
current_sense.gain_c = 1.0 / shunt_resistor / gain;
44+
```
45+
46+
For example [AliExpress DRV8302 board](https://fr.aliexpress.com/wholesale?catId=0&initiative_id=SB_20211003032006&SearchText=bldc+drv8302) has all the current sensing phases inverted inverted. So in its case you can specify:
47+
```cpp
48+
// inverse current sensing gain
49+
current_sense.gain_a *= -1;
50+
current_sense.gain_b *= -1;
51+
current_sense.gain_c *= -1;
52+
```
53+
54+
Once the current sense has been created it can be initialised. This `init()` function configures the ADC hardware for reading and finds the zero offsets of the ADC for each channel.
55+
```cpp
56+
// init current sense
57+
current_sense.init();
58+
```
59+
Once when your current sense has been intialised and calibrated you can start measuring the currents!
60+
61+
## Using the current sense with FOC algorithm
62+
To use the `LowsideCurrentSense` with the FOC algorithm all you need to do is to add it to link it with the `BLDCMotor` you wish to use it with:
63+
```cpp
64+
// link motor and current sense
65+
motor.linkCurrentSense(&current_sense);
66+
```
67+
The `BLDCMotor` class in the `initFOC()` function where it aligns all the sensors, will align the `LowsideCurrentSense` with the `BLDCDriver` that is linked to the motor.
68+
```cpp
69+
// prepare sensors for FOC
70+
motor.initFOC();
71+
```
72+
Function `initFOC()` will call two current sense class functions that are important:
73+
- `current_sense.driverSync(...)`
74+
- `current_sense.driverAlign(...)`
75+
76+
### Driver synchronisation `driverSync(...)`
77+
<img src="extras/Images/low_side_sync.png" class="width40">
78+
79+
Since the low-side current sensing technique requires triggering of the ADC acquisition exactly when all the low side mosfets are ON (when all the phases are grounded) the `driverSync()` synchronises the driver PWM with ADC conversion.
80+
81+
### Alignment with the motor phases `driverAlign(...)`
82+
83+
The alignment is done by calling the function:
84+
```cpp
85+
current_sense.driverAlign(&driver, voltage_sensor_align);
86+
```
87+
This function applies using the driver instance applies the voltage to each of the phases and checks if the measured currents correspond to the directions of the applied voltages.
88+
This alignment procedure is able to correct for:
89+
- Incorrect order of adc pins
90+
- Incorrect gain sign
91+
92+
If [monitoring](monitoring) is enabled for the motor during the `initFOC` the monitor will display the alignment status:
93+
- `0` - fail
94+
- `1` - success and nothing changed
95+
- `2` - success but pins reconfigured
96+
- `3` - success but gains inverted
97+
- `4` - success but pins reconfigured and gains inverted
98+
99+
100+
If you are sure in your configuration and if you wish to skip the alignment procedure you can specify set the `skip_align` flag before calling `motor.initFOC()`:
101+
```cpp
102+
// skip alignment procedure
103+
current_sense.skip_align = true;
104+
```
105+
106+
For example [AliExpress DRV8302 board](https://fr.aliexpress.com/wholesale?catId=0&initiative_id=SB_20211003032006&SearchText=bldc+drv8302) , you would have a code similar to this:
107+
```cpp
108+
// invert phase b gain
109+
current_sense.gain_a *=-1;
110+
current_sense.gain_b *=-1;
111+
current_sense.gain_c *=-1;
112+
// skip alignment
113+
current_sense.skip_align = true;
114+
...
115+
// align all sensors
116+
motor.initFOC();
117+
```
118+
119+
120+
## Standalone current sense
121+
122+
Since the low-side current sense has to be synchornised with PWM of a driver of interest it does not make sense to use it as a stand-alone sensor.
123+
But once when you liked the current sense with the `BLDCMotor` you can use it to get more info about your phase currents, overall current magnitude and DQ currents.
124+
125+
Reading the phase currents can be done by calling:
126+
```cpp
127+
PhaseCurrent_s current = current_sense.getPhaseCurrents();
128+
```
129+
This function returns the `PhaseCurrent_s` structure that which has three variables `a`, `b` and `c`. So you can print them out for example;
130+
```cpp
131+
Serial.println(current.a);
132+
Serial.println(current.b);
133+
Serial.println(current.c); // 0 if only two currents mode
134+
```
135+
If you are using only two phase current measurements in your `LowsideCurrentSense`, it will return the third current `current.c` equal to 0.
136+
137+
Sometimes the phase currents are hard to interpret, therefore this current sense class enables you to read the transformed current vector magnitude. The absolute DC current the motor is drawing.
138+
```cpp
139+
float current_mag = current_sense.getDCCurrent();
140+
```
141+
142+
Futhermore if you have an access to the position sensor of the motor connected to the driver you can get signed value of the DC current the motor is drawing by providing it to the `getDCCurrent` method.
143+
```cpp
144+
float current = current_sense.getDCCurrent(motor_electrical_angle);
145+
```
146+
147+
Finally if you have the access to the motor position sensor you current sense class will be able to tell you the FOC currents D and Q that your motor is drawing.
148+
```cpp
149+
DQCurrent_s current = current_sense.getFOCCurrents(motor_electrical_angle);
150+
```
151+
This function returns the `DQCurrent_s` structure which has two variables, `d` and `q`. You can print them out for example:
152+
```cpp
153+
Serial.println(current.d);
154+
Serial.println(current.q);
155+
```
156+
157+
### Example code
158+
Here is a simple example of a low-side current sense using the <span class="simple">Simple<span class="foc">FOC</span>library</span> and to read the motor currents directly.
159+
```cpp
160+
#include <SimpleFOC.h>
161+
162+
163+
// define the motor and the driver
164+
motor = ...
165+
driver = ...
166+
167+
// current sensor
168+
// shunt resistor value
169+
// gain value
170+
// pins phase A,B
171+
LowsideCurrentSense current_sense = LowsideCurrentSense(0.01, 50.0, A0, A2);
172+
173+
void setup() {
174+
175+
// init driver
176+
driver.init()
177+
...
178+
179+
// initialise the current sensing
180+
current_sense.init();
181+
motor.linkCurrentSense(&current_sense);
182+
183+
...
184+
motor.initFOC();
185+
...
186+
187+
Serial.begin(115200);
188+
Serial.println("Setup ready.");
189+
}
190+
191+
void loop() {
192+
// foc and motion controls
193+
motor.loopFOC();
194+
motor.move();
195+
196+
PhaseCurrent_s currents = current_sense.getPhaseCurrents();
197+
float current_magnitude = current_sense.getDCCurrent();
198+
199+
Serial.print(currents.a*1000); // milli Amps
200+
Serial.print("\t");
201+
Serial.print(currents.b*1000); // milli Amps
202+
Serial.print("\t");
203+
Serial.print(currents.c*1000); // milli Amps
204+
Serial.print("\t");
205+
Serial.println(current_magnitude*1000); // milli Amps
206+
}
207+
```

docs/simplefoc_library/code/drivers/index.md

+16
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,23 @@ Arduino <span class="simple">Simple<span class="foc">FOC</span>library</span> su
2222
- **6 PWM signals** ( 3 phase ) - `BLDCDriver6PWM`
2323
- [Stepper drivers <i class="fa fa-external-link"></i>](stepperdriver)
2424
- **4 PWM signals** ( 2 phase ) - `StepperDriver4PWM`
25+
- **2 PWM signals** ( 2 phase ) - `StepperDriver2PWM`
2526

2627

2728
The driver code is written in a way to support as many different drivers out there as possible and in a way to be fully interchangeable.
2829
These classes can be used as stand-alone classes and they can be used to set certain PWM value to the driver outputs, see example codes in `utils > driver_standalone_test`.
30+
31+
32+
## Driver support per MCU architecture
33+
34+
MCU | 2 PWM mode | 4PWM mode | 3 PWM mode | 6 PWM mode | pwm frequency config
35+
--- | --- |--- |--- |--- |---
36+
Arduino (8-bit) | ✔️ | ✔️ | ✔️ | ✔️ | ❌ (32kHz)
37+
Arduino DUE | ✔️ | ✔️ | ✔️ | ❌ | ✔️
38+
stm32 | ✔️ | ✔️ | ✔️ | ✔️ | ✔️
39+
esp32 | ✔️ | ✔️ | ✔️ | ✔️ | ✔️
40+
esp8266 | ✔️ | ✔️ | ✔️ | ❌ | ✔️
41+
samd21/51 | ✔️ | ✔️ | ✔️ | ✔️ | ✔️
42+
teensy | ✔️ | ✔️ | ✔️ | ❌ | ✔️
43+
Raspberry Pi Pico | ✔️ | ✔️ | ✔️ | ✔️ | ✔️
44+
Portenta H7 | ✔️ | ✔️ | ✔️ | ❌ | ✔️

docs/simplefoc_library/code/from_scratch.md

+3
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ void setup() {
3737
}
3838

3939
void loop() {
40+
// IMPORTANT
41+
// read sensor and update the internal variables
42+
sensor.update();
4043
// display the angle and the angular velocity to the terminal
4144
Serial.print(sensor.getAngle());
4245
Serial.print("\t");

docs/simplefoc_library/code/index.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,11 @@ For full documentation of the setup and all configuration parameters please visi
132132

133133

134134
## Step 3. <a href="current_sense" class="remove_dec"> Current sense setup</a>
135-
After the position sensor and the driver we can proceed to initializing and configuring the current sense, if available of course. If current sense is not available you can skip this step. The library supports one type of current sense architecture and that is in-line current sensing `InlineCurrentSense`.
135+
After the position sensor and the driver we can proceed to initializing and configuring the current sense, if available of course. If current sense is not available you can skip this step. The library supports two types of current sense architecture:
136+
- in-line current sensing `InlineCurrentSense`.
137+
- low-side current sensing `LowsideCurrentSense`.
136138

137-
`InlineCurrentSense` class instantiated by providing:
139+
`InlineCurrentSense` and `LowsideCurrentSense` classes are instantiated by providing:
138140
- shunt resistor value `shunt_resistance`
139141
- amplifier gain `gain`
140142
- `phase A, B (and optionally C) pin number

docs/simplefoc_library/code/sensors/encoder.md

+3
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,9 @@ void setup() {
284284
}
285285
286286
void loop() {
287+
// IMPORTANT - call as frequently as possible
288+
// update the sensor values
289+
encoder.update();
287290
// display the angle and the angular velocity to the terminal
288291
Serial.print(encoder.getAngle());
289292
Serial.print("\t");

docs/simplefoc_library/code/sensors/hall_sensor.md

+6
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,9 @@ void setup() {
214214
}
215215
216216
void loop() {
217+
// IMPORTANT - call as frequently as possible
218+
// update the sensor values
219+
sensor.update();
217220
// display the angle and the angular velocity to the terminal
218221
Serial.print(sensor.getAngle());
219222
Serial.print("\t");
@@ -262,6 +265,9 @@ void setup() {
262265
}
263266

264267
void loop() {
268+
// IMPORTANT - call as frequently as possible
269+
// update the sensor values
270+
sensor.update();
265271
// display the angle and the angular velocity to the terminal
266272
Serial.print(sensor.getAngle());
267273
Serial.print("\t");

0 commit comments

Comments
 (0)