Skip to content

Commit d4fce56

Browse files
Merge pull request #16 from simplefoc/dev
1.0.2 Release merge
2 parents 9525cb3 + 61e0232 commit d4fce56

32 files changed

+1326
-55
lines changed

.github/workflows/ccpp.yml

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,46 +21,45 @@ jobs:
2121
- adafruit:samd:adafruit_metro_m4 # samd51
2222
- esp32:esp32:esp32 # esp32
2323
- esp32:esp32:esp32s2 # esp32s2
24-
- STM32:stm32:GenF1:pnum=BLUEPILL_F103C8 # stm32 bluepill
25-
- STM32:stm32:Nucleo_64:pnum=NUCLEO_F411RE # stm32 nucleo
24+
- STMicroelectronics:stm32:GenF1:pnum=BLUEPILL_F103C8 # stm32 bluepill
25+
- STMicroelectronics:stm32:Nucleo_64:pnum=NUCLEO_F411RE # stm32 nucleo
2626
- arduino:mbed_rp2040:pico # rpi pico
2727
include:
2828
- arduino-boards-fqbn: arduino:avr:uno
29-
sketch-names: '**.ino'
29+
sketches-exclude: calibrated mt6816_spi
3030
required-libraries: Simple FOC
3131
- arduino-boards-fqbn: arduino:sam:arduino_due_x
3232
required-libraries: Simple FOC
33-
sketch-names: '**.ino'
33+
sketches-exclude: calibrated
3434
- arduino-boards-fqbn: arduino:samd:nano_33_iot
35-
required-libraries: Simple FOC
36-
sketch-names: '**.ino'
35+
required-libraries: Simple FOC
36+
sketches-exclude: calibrated
3737
- arduino-boards-fqbn: arduino:mbed_rp2040:pico
3838
required-libraries: Simple FOC
39-
sketch-names: '**.ino'
39+
sketches-exclude: calibrated
4040
- arduino-boards-fqbn: adafruit:samd:adafruit_metro_m4
4141
platform-url: https://adafruit.github.io/arduino-board-index/package_adafruit_index.json
4242
required-libraries: Simple FOC
43-
sketch-names: '**.ino'
43+
sketches-exclude: calibrated
4444
# - arduino-boards-fqbn: esp32:esp32:esp32doit-devkit-v1
4545
# platform-url: https://dl.espressif.com/dl/package_esp32_index.json
4646
# required-libraries: Simple FOC
4747
# sketch-names: '**.ino'
4848
- arduino-boards-fqbn: esp32:esp32:esp32 # esp32
4949
platform-url: https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_dev_index.json
5050
required-libraries: Simple FOC
51-
sketch-names: '**.ino'
51+
sketches-exclude: calibrated
5252
- arduino-boards-fqbn: esp32:esp32:esp32s2 # esp32s2
5353
platform-url: https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_dev_index.json
5454
required-libraries: Simple FOC
55-
sketch-names: '**.ino'
56-
- arduino-boards-fqbn: STM32:stm32:GenF1:pnum=BLUEPILL_F103C8
57-
platform-url: https://github.com/stm32duino/BoardManagerFiles/raw/master/STM32/package_stm_index.json
55+
sketches-exclude: calibrated
56+
- arduino-boards-fqbn: STMicroelectronics:stm32:GenF1:pnum=BLUEPILL_F103C8
57+
platform-url: https://github.com/stm32duino/BoardManagerFiles/raw/main/package_stmicroelectronics_index.json
5858
required-libraries: Simple FOC
59-
sketch-names: '**.ino'
60-
- arduino-boards-fqbn: STM32:stm32:Nucleo_64:pnum=NUCLEO_F411RE
61-
platform-url: https://github.com/stm32duino/BoardManagerFiles/raw/master/STM32/package_stm_index.json
59+
sketches-exclude: calibrated mt6816_spi
60+
- arduino-boards-fqbn: STMicroelectronics:stm32:Nucleo_64:pnum=NUCLEO_F411RE
61+
platform-url: https://github.com/stm32duino/BoardManagerFiles/raw/main/package_stmicroelectronics_index.json
6262
required-libraries: Simple FOC
63-
sketch-names: '**.ino'
6463
# Do not cancel all jobs / architectures if one job fails
6564
fail-fast: false
6665
steps:

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
.project
2+
.DS_Store

README.md

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,25 @@
22

33
![Library Compile](https://github.com/simplefoc/Arduino-FOC-drivers/workflows/Library%20Compile/badge.svg)
44
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
5-
5+
![Release](https://img.shields.io/badge/version-1.0.2-blue)
66

77
This library contains an assortment of drivers and supporting code for SimpleFOC.
88

99
The intent is to keep the core of SimpleFOC clean, and thus easy to maintain, understand and port to different platforms. In addition to this core, there are various drivers and supporting code which has grown around SimpleFOC, and which we would like to make available to the community.
1010

11-
## What's contained
11+
## New Release
12+
13+
v1.0.2 - Released Oct 2022, for Simple FOC 2.2.3
14+
15+
What's changed since 1.0.1?
16+
- Calibrated sensor by @MarethyuPrefect
17+
- New Sensors: MT6701, MA330, MT6816
18+
- Fixes bugs
19+
20+
21+
## What is included
1222

13-
What's here? See the sections below. Each driver or function should come with its own more detailed README.
23+
What is here? See the sections below. Each driver or function should come with its own more detailed README.
1424

1525
### Motor/Gate driver ICs
1626

@@ -27,6 +37,9 @@ What's here? See the sections below. Each driver or function should come with it
2737
- [TLE5012B SPI driver](src/encoders/tle5012b/) - SPI (half duplex) driver for TLE5012B absolute position magnetic rotary encoder IC.
2838
- [STM32 Hardware Encoder](src/encoders/stm32hwencoder/) - Hardware timer based encoder driver for ABI type quadrature encoders.
2939
- [SC60228 SPI driver](src/encoders/sc60228/) - SPI driver for SemiMent SC60288 magnetic encoder IC.
40+
- [MA330 SPI driver](src/encoders/ma330/) - SPI driver for the MPS MagAlpha MA330 absolute position magnetic rotary encoder IC.
41+
- [MT6816 SPI driver](src/encoders/mt6816/) - SPI driver for the MagnTek MT6816 absolute position magnetic rotary encoder IC.
42+
- [MT6701 SSI driver](src/encoders/mt6701/) - SSI driver for the MagnTek MT6701 absolute position magnetic rotary encoder IC.
3043

3144
### Communications
3245

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/**
2+
* Torque control example using voltage control loop.
3+
*
4+
* Most of the low-end BLDC driver boards doesn't have current measurement therefore SimpleFOC offers
5+
* you a way to control motor torque by setting the voltage to the motor instead hte current.
6+
*
7+
* This makes the BLDC motor effectively a DC motor, and you can use it in a same way.
8+
*/
9+
#include <SimpleFOC.h>
10+
#include <SimpleFOCDrivers.h>
11+
#include "encoders/calibrated/CalibratedSensor.h"
12+
13+
// magnetic sensor instance - SPI
14+
MagneticSensorSPI sensor = MagneticSensorSPI(AS5048_SPI, PB6);
15+
// BLDC motor & driver instance
16+
BLDCMotor motor = BLDCMotor(11);
17+
BLDCDriver3PWM driver = BLDCDriver3PWM(PB4,PC7,PB10,PA9);
18+
// instantiate the calibrated sensor object
19+
CalibratedSensor sensor_calibrated = CalibratedSensor(sensor);
20+
21+
// voltage set point variable
22+
float target_voltage = 2;
23+
24+
// instantiate the commander
25+
Commander command = Commander(Serial);
26+
27+
void doTarget(char* cmd) { command.scalar(&target_voltage, cmd); }
28+
29+
void setup() {
30+
31+
SPI.setMISO(PB14);
32+
SPI.setMOSI(PB15);
33+
SPI.setSCLK(PB13);
34+
35+
sensor.init();
36+
// Link motor to sensor
37+
motor.linkSensor(&sensor);
38+
// power supply voltage
39+
driver.voltage_power_supply = 20;
40+
driver.init();
41+
motor.linkDriver(&driver);
42+
// aligning voltage
43+
motor.voltage_sensor_align = 8;
44+
motor.voltage_limit = 20;
45+
// set motion control loop to be used
46+
motor.controller = MotionControlType::torque;
47+
48+
// use monitoring with serial
49+
Serial.begin(115200);
50+
// comment out if not needed
51+
motor.useMonitoring(Serial);
52+
motor.monitor_variables = _MON_VEL;
53+
motor.monitor_downsample = 10; // default 10
54+
55+
// initialize motor
56+
motor.init();
57+
58+
// set voltage to run calibration
59+
sensor_calibrated.voltage_calibration = 6;
60+
// Running calibration
61+
sensor_calibrated.calibrate(motor);
62+
63+
//Serial.println("Calibrating Sensor Done.");
64+
// Linking sensor to motor object
65+
motor.linkSensor(&sensor_calibrated);
66+
67+
// calibrated init FOC
68+
motor.initFOC();
69+
70+
// add target command T
71+
command.add('T', doTarget, "target voltage");
72+
73+
Serial.println(F("Motor ready."));
74+
75+
Serial.println(F("Set the target voltage using serial terminal:"));
76+
_delay(1000);
77+
}
78+
79+
void loop() {
80+
81+
motor.loopFOC();
82+
motor.move(target_voltage);
83+
command.run();
84+
motor.monitor();
85+
86+
}
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
/**
2+
* Comprehensive BLDC motor control example using magnetic sensor MT6816
3+
*
4+
* Using serial terminal user can send motor commands and configure the motor and FOC in real-time:
5+
* - configure PID controller constants
6+
* - change motion control loops
7+
* - monitor motor variabels
8+
* - set target values
9+
* - check all the configuration values
10+
*
11+
* See more info in docs.simplefoc.com/commander_interface
12+
*/
13+
#include <SimpleFOC.h>
14+
#include <SimpleFOCDrivers.h>
15+
#include <encoders/mt6816/MagneticSensorMT6816.h>
16+
17+
// magnetic sensor instance - MT6816 SPI mode
18+
MagneticSensorMT6816 sensor = MagneticSensorMT6816(5);
19+
20+
21+
// BLDC motor & driver instance
22+
BLDCMotor motor = BLDCMotor(7);
23+
BLDCDriver3PWM driver = BLDCDriver3PWM(32, 25, 26, 33);
24+
25+
// Inline Current Sense instance
26+
InlineCurrentSense current_sense = InlineCurrentSense(0.01, 50.0, 35, 34);
27+
28+
// commander interface
29+
Commander command = Commander(Serial);
30+
void onMotor(char* cmd){ command.motor(&motor, cmd); }
31+
32+
void setup() {
33+
34+
// initialise magnetic sensor hardware
35+
sensor.init();
36+
// link the motor to the sensor
37+
motor.linkSensor(&sensor);
38+
39+
// driver config
40+
// power supply voltage [V]
41+
driver.voltage_power_supply = 12;
42+
driver.init();
43+
// link driver
44+
motor.linkDriver(&driver);
45+
46+
// choose FOC modulation
47+
motor.foc_modulation = FOCModulationType::SpaceVectorPWM;
48+
49+
// set control loop type to be used
50+
motor.controller = MotionControlType::torque;
51+
52+
// contoller configuration based on the control type
53+
motor.PID_velocity.P = 0.2f;
54+
motor.PID_velocity.I = 20;
55+
motor.PID_velocity.D = 0;
56+
// default voltage_power_supply
57+
motor.voltage_limit = 12;
58+
59+
// velocity low pass filtering time constant
60+
motor.LPF_velocity.Tf = 0.01f;
61+
62+
// angle loop velocity limit
63+
motor.velocity_limit = 50;
64+
65+
// use monitoring with serial for motor init
66+
// monitoring port
67+
Serial.begin(115200);
68+
// comment out if not needed
69+
motor.useMonitoring(Serial);
70+
71+
current_sense.linkDriver(&driver);
72+
current_sense.init();
73+
current_sense.gain_b *= -1;
74+
current_sense.skip_align = true;
75+
motor.linkCurrentSense(&current_sense);
76+
77+
// initialise motor
78+
motor.init();
79+
// align encoder and start FOC
80+
motor.initFOC();
81+
82+
// set the inital target value
83+
motor.target = 2;
84+
85+
// define the motor id
86+
command.add('A', onMotor, "motor");
87+
88+
// Run user commands to configure and the motor (find the full command list in docs.simplefoc.com)
89+
Serial.println(F("Motor commands sketch | Initial motion control > torque/voltage : target 2V."));
90+
91+
_delay(1000);
92+
}
93+
94+
95+
void loop() {
96+
// iterative setting FOC phase voltage
97+
motor.loopFOC();
98+
99+
// iterative function setting the outter loop target
100+
// velocity, position or voltage
101+
// if tatget not set in parameter uses motor.target variable
102+
motor.move();
103+
104+
// user communication
105+
command.run();
106+
}

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=SimpleFOCDrivers
2-
version=1.0.1
2+
version=1.0.2
33
author=Simplefoc <[email protected]>
44
maintainer=Simplefoc <[email protected]>
55
sentence=A library of supporting drivers for SimpleFOC. Motor drivers chips, encoder chips, current sensing and supporting code.

src/encoders/aeat8800q24/AEAT8800Q24.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,5 +98,5 @@ uint8_t AEAT8800Q24::readRegister(uint8_t reg) {
9898
};
9999
void AEAT8800Q24::writeRegister(uint8_t reg, uint8_t value) {
100100
uint16_t cmd = 0x4000 | ((reg&0x1F)<<8) | value;
101-
uint16_t result = transfer16SPI(cmd);
101+
/*uint16_t result =*/ transfer16SPI(cmd);
102102
};

src/encoders/as5047/AS5047.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ uint16_t AS5047::readCorrectedAngle(){
4949

5050
uint16_t AS5047::readMagnitude(){
5151
uint16_t command = AS5047_MAGNITUDE_REG | AS5047_RW; // set r=1, result is 0x7FFD
52-
uint16_t cmdresult = spi_transfer16(command);
52+
/*uint16_t cmdresult =*/ spi_transfer16(command);
5353
uint16_t result = nop();
5454
return result;
5555
}
@@ -62,7 +62,7 @@ bool AS5047::isErrorFlag(){
6262

6363
AS5047Error AS5047::clearErrorFlag(){
6464
uint16_t command = AS5047_ERROR_REG | AS5047_RW; // set r=1, result is 0x4001
65-
uint16_t cmdresult = spi_transfer16(command);
65+
/*uint16_t cmdresult =*/ spi_transfer16(command);
6666
uint16_t result = nop();
6767
AS5047Error err = {
6868
.framingError = ((result&0x0001)!=0x0000),
@@ -75,7 +75,7 @@ AS5047Error AS5047::clearErrorFlag(){
7575

7676
AS5047Settings1 AS5047::readSettings1(){
7777
uint16_t command = AS5047_SETTINGS1_REG | AS5047_PARITY | AS5047_RW; // set r=1, result is 0xC018
78-
uint16_t cmdresult = spi_transfer16(command);
78+
/*uint16_t cmdresult =*/ spi_transfer16(command);
7979
AS5047Settings1 result = {
8080
.reg = nop()
8181
};
@@ -85,14 +85,14 @@ AS5047Settings1 AS5047::readSettings1(){
8585

8686
void AS5047::writeSettings1(AS5047Settings1 settings){
8787
uint16_t command = AS5047_SETTINGS1_REG; // set r=0, result is 0x0018
88-
uint16_t cmdresult = spi_transfer16(command);
89-
cmdresult = spi_transfer16(settings.reg);
88+
/*uint16_t cmdresult =*/ spi_transfer16(command);
89+
/*cmdresult =*/ spi_transfer16(settings.reg);
9090
}
9191

9292

9393
AS5047Settings2 AS5047::readSettings2(){
9494
uint16_t command = AS5047_SETTINGS2_REG | AS5047_RW; // set r=1, result is 0x4019
95-
uint16_t cmdresult = spi_transfer16(command);
95+
/*uint16_t cmdresult =*/ spi_transfer16(command);
9696
AS5047Settings2 result = {
9797
.reg = nop()
9898
};
@@ -102,7 +102,7 @@ AS5047Settings2 AS5047::readSettings2(){
102102

103103
AS5047Diagnostics AS5047::readDiagnostics(){
104104
uint16_t command = AS5047_DIAGNOSTICS_REG | AS5047_PARITY | AS5047_RW; // set r=1, result is 0xFFFC
105-
uint16_t cmdresult = spi_transfer16(command);
105+
/*uint16_t cmdresult =*/ spi_transfer16(command);
106106
AS5047Diagnostics result = {
107107
.reg = nop()
108108
};

src/encoders/as5047/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ void setup() {
5050
Here's how you can use it:
5151

5252
```c++
53+
// update the sensor (only needed if using the sensor without a motor)
54+
sensor1.update();
55+
5356
// get the angle, in radians, including full rotations
5457
float a1 = sensor1.getAngle();
5558

0 commit comments

Comments
 (0)