Skip to content

Commit 18cb05c

Browse files
committed
feat v2.1.1
1 parent 780cfdc commit 18cb05c

36 files changed

+449
-139
lines changed

_includes/js/custom.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ var libraires =[
1010
"MagneticSensor.h",
1111
"MagneticSensorSPI.h",
1212
"MagneticSensorI2C.h",
13+
"MagneticSensorPWM.h",
1314
"MagneticSensorAnalog.h",
1415
"MySensor.h",
1516
"Sensor.h"
@@ -66,6 +67,7 @@ var classNames = [
6667
"MagneticSensorSPI",
6768
"MagneticSensorI2C",
6869
"MagneticSensorAnalog",
70+
"MagneticSensorPWM",
6971
"HallSensor",
7072
"PciListenerImp",
7173
"PciManager",

docs/simplefoc_library/code/communication/commander/index.md

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,42 @@ This g-code like interface provides callback to configure and tune any:
3232

3333
Furthermore commander enables you to easily create your own commands and extend this interface in any way you might need for your particular application.
3434

35+
## What happens when user sends a command?
36+
When the commander received the string:
37+
38+
<img src="extras/Images/cmd1.png" class="width20">
39+
40+
It first checks the command id, identifies its `M` and sends the remaining string to the motor handling callback. Then the motor callback checks what is the coommand id, finds `V` and sends the remaining string to the PID velocity callbacK. Then the PID velocity callback scans the command id and finds it is the `D`, so derivative gain and sets the value.
41+
42+
Commander | Motor callback (cmd id `M` ) | PID callback (cmd id `V` )
43+
--- | ---| ---
44+
<img src="extras/Images/cmd2.png" > | <img src="extras/Images/cmd3.png" > | <img src="extras/Images/cmd4.png" >
45+
46+
The other example is if the commander receives:
47+
48+
<img src="extras/Images/cmd5.png" class="width20">
49+
50+
First id that it finds is `O`, which is for example motor. It calls the callback that is assigned to this command (which is in this case motor callback) with the string remaining string. Then the motor callback finds the command `E` and knows its the status (enabled/disabled) either getting or getting. It checks the value and sees that the value is empty, which means the user has sent a get request.
51+
52+
Commander | Motor callback (cmd id `O` )
53+
--- | ---
54+
<img src="extras/Images/cmd6.png" class="img100"> | <img src="extras/Images/cmd7.png" class="img100">
55+
56+
3557
## Using the commander interface
3658
Command interface is implemented in the `Commander` class.
3759
```cpp
3860
// Commander interface constructor
39-
// - optionally receives HardwareSerial/Stream instance
40-
Commander commander = Commander(Serial);
61+
// - serial - optionally receives HardwareSerial/Stream instance
62+
// - eol - optionally receives eol character - by default it is the newline: "\n"
63+
// - echo - option echo last typed character (for command line feedback) - defualt false
64+
Commander commander = Commander(Serial, "\n", false);
4165
```
66+
The end of line (eol) character is an optional input of the `Commander` class which represents end of command character. User can define its own end of command characters here, but by default the character used is newline character `\n`. For example i
67+
68+
<blockquote class="warning"><p class="heading">BEWARE: EOL characters</p> Different operating systems have different EOL characters by default. Newline character is probably the most common one but there is also the carriage return '\r' for linux users. Be sure to provide it to the constructor of the Commander class if you wish to use it with your setup!</blockquote>
69+
70+
The echo flag can be used as a debugging feature but it is not recommended to be used for real time motor control and configuration!
4271

4372
Next step would be to add the commander function that reads the `Serial` instance that you provided into the Arduino `loop()`:
4473
```cpp
@@ -292,7 +321,10 @@ When using a standard callback for `BLDCMotor` and `StepperMotor` classes:`comma
292321
- **R** - Motor phase resistance
293322
- **S** - Sensor offsets
294323
- **M** - sensor offset
295-
- **E** - sensor electrical zero
324+
- **E** - sensor electrical zero
325+
- **W** - PWM settings
326+
- **T** - pwm modulation type
327+
- **C** - pwm waveform centering boolean
296328
- **M** - Monitoring control
297329
- **D** - downsample monitoring
298330
- **C** - clear monitor
@@ -531,11 +563,9 @@ void loop() {
531563

532564
## *Simple**FOC**Studio* by [@JorgeMaker](https://github.com/JorgeMaker)
533565

534-
SimpleFOCStudio is an awesome application built by [@JorgeMaker](https://github.com/JorgeMaker) which we will try to keep up to date with out library. It is a python application that uses commander interface for tunning and configuring the motor. More info about it will come soon.
535-
536-
<img src="https://raw.githubusercontent.com/JorgeMaker/SimpleFOCStudio/main/DOC/SimpleFOCStudio.gif">
566+
SimpleFOCStudio is an awesome application built by [@JorgeMaker](https://github.com/JorgeMaker) which we will try to keep up to date with out library. It is a python application that uses commander interface for tunning and configuring the motor.
537567

538-
To install this application follow the readme in the [git repository](https://github.com/JorgeMaker/SimpleFOCStudio).
568+
<img src="https://raw.githubusercontent.com/JorgeMaker/SimpleFOCStudio/main/DOC/new_gif.gif" class="width80">
539569

540-
For more info about this application and <span class="simple">Simple<span class="foc">FOC</span>library</span> make sure to follow [the community forum](https://community.simplefoc.com).
570+
For more info how to install and use this application visit the studio [docs <i class="fa fa-external-link"></i>](studio).
541571

docs/simplefoc_library/code/index.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
layout: default
33
title: Writing the Code
4-
nav_order: 6
4+
nav_order: 3
55
description: "Arduino Simple Field Oriented Control (FOC) library ."
66
permalink: /code
77
has_children: True
@@ -24,7 +24,7 @@ Let's start by including the library header file:
2424
First step when writing the code is initializing and configuring the position sensor.
2525
The library supports these position sensors:
2626
- [Encoders](encoder): Optical, Capacitive, Magnetic encoders (ABI)
27-
- [Magnetic sensors](magnetic_sensor): SPI, I2C or Analog
27+
- [Magnetic sensors](magnetic_sensor): SPI, I2C, Analog or PWM
2828
- [Hall sensors](hall_sensors): 3xHall sonde, Magnetic sensor (UVW interface)
2929

3030
Choose position sensor to use with this example:

docs/simplefoc_library/code/sensors/encoder.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ encoder.quadrature = Quadrature::OFF;
3434
```
3535
<blockquote class="warning"><p class="heading">CPR, PPR?!</p> PPR (pulses per revolution) - this is the physical number of impulses the encoder has per revolution. CPR (counts per revolution) - this is amount you are going to have in your counter after the full rotation of the encoder. Now depending on whether you use quadrature mode (counting each edge of the impulse) or not (counting just the rising edge) you will have different CPR for the same PPR. For quadrature mode you will have CPR = 4xPPR and if not using quadrature mode you will have CPR=PPR</blockquote>
3636

37-
Additionally the encoder has one more important parameter and this is the pullup location. MAny encoders require pullups and in cases when you have an encoder that needs one and you don't have one on your hands you can use Arduino pullups. That is set by changing the value of the `encoder.pullup` variable. The default value is set to `Pullup::EXTERN` but if you would like to change it to use the MCU ones do:
37+
Additionally the encoder has one more important parameter and this is the pullup location. MAny encoders require pullups and in cases when you have an encoder that needs one and you don't have one on your hands you can use Arduino pullups. That is set by changing the value of the `encoder.pullup` variable. The default value is set to `Pullup::USE_EXTERN` but if you would like to change it to use the MCU ones do:
3838
```cpp
3939
// check if you need internal pullups
40-
// Pullup::EXTERN - external pullup added - default
41-
// Pullup::INTERN - needs internal arduino pullup
42-
encoder.pullup = Pullup::INTERN;
40+
// Pullup::USE_EXTERN - external pullup added - default
41+
// Pullup::USE_INTERN - needs internal arduino pullup
42+
encoder.pullup = Pullup::USE_INTERN;
4343
```
4444
<blockquote class="warning"><p class="heading">Arduino Pullup 20kΩ</p> Be careful when using internal pullups, Arduino has relatively high valued pullups around 20kΩ, which means that you might have some problems for higher velocities (for shorted impulse durations). Recommended pull-up values are in between 1kΩ and 5kΩ.</blockquote>
4545

@@ -272,7 +272,7 @@ void setup() {
272272
encoder.quadrature = Quadrature::ON;
273273
274274
// check if you need internal pullups
275-
encoder.pullup = Pullup::EXTERN;
275+
encoder.pullup = Pullup::USE_EXTERN;
276276
277277
// initialize encoder hardware
278278
encoder.init();

docs/simplefoc_library/code/sensors/hall_sensor.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ HallSensor sensor = HallSensor(2, 3, 4, 11);
2727

2828
## Step 2. Configuration
2929

30-
Additionally the hall senso has one more optional parameter you may set, the pullup location. Hall sensors usually require pullups and in cases when your sensor needs one and you don't have one on your hands you can use Arduino pullups. That is set by changing the value of the `sensor.pullup` variable. The default value is set to `Pullup::EXTERN` but if you would like to change it to use the MCU ones do:
30+
Additionally the hall senso has one more optional parameter you may set, the pullup location. Hall sensors usually require pullups and in cases when your sensor needs one and you don't have one on your hands you can use Arduino pullups. That is set by changing the value of the `sensor.pullup` variable. The default value is set to `Pullup::USE_EXTERN` but if you would like to change it to use the MCU ones do:
3131
```cpp
3232
// use internal pullups
33-
sensor.pullup = Pullup::INTERN;
33+
sensor.pullup = Pullup::USE_INTERN;
3434
```
3535
<blockquote class="warning"><p class="heading">Arduino Pullup 20kΩ</p> Be careful when using internal pullups, Arduino has relatively high valued pullups around 20kΩ, which means that you might have some problems for higher velocities (for shorted impulse durations). Recommended pull-up values are in between 1kΩ and 5kΩ.</blockquote>
3636

@@ -202,7 +202,7 @@ void setup() {
202202
Serial.begin(115200);
203203
204204
// check if you need internal pullups
205-
sensor.pullup = Pullup::EXTERN;
205+
sensor.pullup = Pullup::USE_EXTERN;
206206
207207
// initialize sensor hardware
208208
sensor.init();
@@ -248,7 +248,7 @@ void setup() {
248248
Serial.begin(115200);
249249

250250
// check if you need internal pullups
251-
sensor.pullup = Pullup::EXTERN;
251+
sensor.pullup = Pullup::USE_EXTERN;
252252

253253
// initialize sensor hardware
254254
sensor.init();

docs/simplefoc_library/code/sensors/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ This library supports *off-the-shelf* these types of position sensors:
2222
- Sensor that uses precise magnetic field measurement to estimate the position.
2323
- They come with multitude of different communication standards such as: SPI, SSI, I2C, ABI, UVW, PWM...
2424
- **Supported communications:** ([releases <i class="fa fa-tag"></i>](https://github.com/simplefoc/Arduino-FOC/releases))
25-
- SPI, I2C, Analog
25+
- SPI, I2C, Analog, PWM
2626
- UVW (*using the hall sensor interface*)
2727
- ABI (*using the encoder interface*)
2828
- Examples : [AS5048A <i class="fa fa-external-link"></i>](https://www.ebay.com/itm/AS5048-Magnetic-Encoder-PWM-SPI-Interface-14-Bit-Precision-For-Brushless-Motor/153636871434?hash=item23c5789d0a:g:oOMAAOSwd-5ddaWQ), [AS5047U <i class="fa fa-external-link"></i>](https://www.mouser.fr/ProductDetail/ams/AS5X47U-TS_EK_AB?qs=sGAEpiMZZMve4%2FbfQkoj%252BBDLPCj82ZLyYIPEtADg0FE%3D), [AS5600 <i class="fa fa-external-link"></i>](https://www.ebay.com/itm/1PC-New-AS5600-magnetic-encoder-sensor-module-12bit-high-precision/303401254431?hash=item46a41fbe1f:g:nVwAAOSwTJJd8zRK)

docs/simplefoc_library/code/sensors/magnetic/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ Magnetic sensors implementation in this library ([current version <i class="fa f
2222
- **SPI** - [MagneticSensorSPI](magnetic_sensor_spi)
2323
- **I2C** - [MagneticSensorI2C](magnetic_sensor_i2c)
2424
- **Analog** - [MagneticSensorAnalog](magnetic_sensor_analog)
25+
- **PWM** - [MagneticSensorPWM](magnetic_sensor_pwm)
2526
- **ABI** - *equivalent to encoder sensors* - [encoder docs <i class="fa fa-external-link"></i>](encoder)
2627
- **UVW** - *equivalent to hall sensors* - [hall sensors docs <i class="fa fa-external-link"></i>](hall_sensors).
2728

docs/simplefoc_library/code/sensors/magnetic/magnetic_sensor_analog.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ The parameters of the class are
2727
- `min_raw_count` - the smallest expected reading. Whilst you might expect it to be 0 it is often ~15. Getting this wrong results in a small click once per revolution
2828
- `max_raw_count` - the largest value read. Whilst you might expect it to be 2^10 = 1023 it is often ~ 1020. Note: For ESP32 (with 12bit ADC the value will be nearer 4096)
2929

30+
<blockquote class="info"> <p class="heading"> 💡 Find out min and max</p>
31+
Every mcu is a bit different and every sensor as well so we advise you to use the provided example in the <code class="highlighter-rouge">examples/sensor_test/magentic_sensor_analog_example/find_raw_min_max</code> to find out the maximal and minimal values of your sensor.
32+
</blockquote>
3033
Finally after the initialization the only thing you need to do afterwards is to call the `init()` function. This function initializes the sensor hardware. So your magnetic sensor initialization code will look like:
3134
```cpp
3235
MagneticSensorAnalog sensor = MagneticSensorAnalog(A1, 14, 1020);
@@ -38,7 +41,7 @@ void loop(){
3841
}
3942
```
4043

41-
If you wish to use more than one magnetic sensor, make sure you connect their `chip_select` pins to different arduino pins and follow the same idea as above, here is a simple example:
44+
If you wish to use more than one magnetic sensor, make sure you connect their ADC pins to different arduino pins and follow the same idea as above, here is a simple example:
4245
```cpp
4346
MagneticSensorAnalog sensor1 = MagneticSensorAnalog(A1, 14, 1020);
4447
MagneticSensorAnalog sensor2 = MagneticSensorAnalog(A2, 14, 1020);

0 commit comments

Comments
 (0)