Skip to content

Commit

Permalink
Merge pull request #16 from simplefoc/dev
Browse files Browse the repository at this point in the history
1.0.2 Release merge
  • Loading branch information
runger1101001 authored Oct 15, 2022
2 parents 9525cb3 + 61e0232 commit d4fce56
Show file tree
Hide file tree
Showing 32 changed files with 1,326 additions and 55 deletions.
31 changes: 15 additions & 16 deletions .github/workflows/ccpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,46 +21,45 @@ jobs:
- adafruit:samd:adafruit_metro_m4 # samd51
- esp32:esp32:esp32 # esp32
- esp32:esp32:esp32s2 # esp32s2
- STM32:stm32:GenF1:pnum=BLUEPILL_F103C8 # stm32 bluepill
- STM32:stm32:Nucleo_64:pnum=NUCLEO_F411RE # stm32 nucleo
- STMicroelectronics:stm32:GenF1:pnum=BLUEPILL_F103C8 # stm32 bluepill
- STMicroelectronics:stm32:Nucleo_64:pnum=NUCLEO_F411RE # stm32 nucleo
- arduino:mbed_rp2040:pico # rpi pico
include:
- arduino-boards-fqbn: arduino:avr:uno
sketch-names: '**.ino'
sketches-exclude: calibrated mt6816_spi
required-libraries: Simple FOC
- arduino-boards-fqbn: arduino:sam:arduino_due_x
required-libraries: Simple FOC
sketch-names: '**.ino'
sketches-exclude: calibrated
- arduino-boards-fqbn: arduino:samd:nano_33_iot
required-libraries: Simple FOC
sketch-names: '**.ino'
required-libraries: Simple FOC
sketches-exclude: calibrated
- arduino-boards-fqbn: arduino:mbed_rp2040:pico
required-libraries: Simple FOC
sketch-names: '**.ino'
sketches-exclude: calibrated
- arduino-boards-fqbn: adafruit:samd:adafruit_metro_m4
platform-url: https://adafruit.github.io/arduino-board-index/package_adafruit_index.json
required-libraries: Simple FOC
sketch-names: '**.ino'
sketches-exclude: calibrated
# - arduino-boards-fqbn: esp32:esp32:esp32doit-devkit-v1
# platform-url: https://dl.espressif.com/dl/package_esp32_index.json
# required-libraries: Simple FOC
# sketch-names: '**.ino'
- arduino-boards-fqbn: esp32:esp32:esp32 # esp32
platform-url: https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_dev_index.json
required-libraries: Simple FOC
sketch-names: '**.ino'
sketches-exclude: calibrated
- arduino-boards-fqbn: esp32:esp32:esp32s2 # esp32s2
platform-url: https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_dev_index.json
required-libraries: Simple FOC
sketch-names: '**.ino'
- arduino-boards-fqbn: STM32:stm32:GenF1:pnum=BLUEPILL_F103C8
platform-url: https://github.com/stm32duino/BoardManagerFiles/raw/master/STM32/package_stm_index.json
sketches-exclude: calibrated
- arduino-boards-fqbn: STMicroelectronics:stm32:GenF1:pnum=BLUEPILL_F103C8
platform-url: https://github.com/stm32duino/BoardManagerFiles/raw/main/package_stmicroelectronics_index.json
required-libraries: Simple FOC
sketch-names: '**.ino'
- arduino-boards-fqbn: STM32:stm32:Nucleo_64:pnum=NUCLEO_F411RE
platform-url: https://github.com/stm32duino/BoardManagerFiles/raw/master/STM32/package_stm_index.json
sketches-exclude: calibrated mt6816_spi
- arduino-boards-fqbn: STMicroelectronics:stm32:Nucleo_64:pnum=NUCLEO_F411RE
platform-url: https://github.com/stm32duino/BoardManagerFiles/raw/main/package_stmicroelectronics_index.json
required-libraries: Simple FOC
sketch-names: '**.ino'
# Do not cancel all jobs / architectures if one job fails
fail-fast: false
steps:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.project
.DS_Store
19 changes: 16 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,25 @@

![Library Compile](https://github.com/simplefoc/Arduino-FOC-drivers/workflows/Library%20Compile/badge.svg)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

![Release](https://img.shields.io/badge/version-1.0.2-blue)

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

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.

## What's contained
## New Release

v1.0.2 - Released Oct 2022, for Simple FOC 2.2.3

What's changed since 1.0.1?
- Calibrated sensor by @MarethyuPrefect
- New Sensors: MT6701, MA330, MT6816
- Fixes bugs


## What is included

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

### Motor/Gate driver ICs

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

### Communications

Expand Down
86 changes: 86 additions & 0 deletions examples/encoders/calibrated/calibrated.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/**
* Torque control example using voltage control loop.
*
* Most of the low-end BLDC driver boards doesn't have current measurement therefore SimpleFOC offers
* you a way to control motor torque by setting the voltage to the motor instead hte current.
*
* This makes the BLDC motor effectively a DC motor, and you can use it in a same way.
*/
#include <SimpleFOC.h>
#include <SimpleFOCDrivers.h>
#include "encoders/calibrated/CalibratedSensor.h"

// magnetic sensor instance - SPI
MagneticSensorSPI sensor = MagneticSensorSPI(AS5048_SPI, PB6);
// BLDC motor & driver instance
BLDCMotor motor = BLDCMotor(11);
BLDCDriver3PWM driver = BLDCDriver3PWM(PB4,PC7,PB10,PA9);
// instantiate the calibrated sensor object
CalibratedSensor sensor_calibrated = CalibratedSensor(sensor);

// voltage set point variable
float target_voltage = 2;

// instantiate the commander
Commander command = Commander(Serial);

void doTarget(char* cmd) { command.scalar(&target_voltage, cmd); }

void setup() {

SPI.setMISO(PB14);
SPI.setMOSI(PB15);
SPI.setSCLK(PB13);

sensor.init();
// Link motor to sensor
motor.linkSensor(&sensor);
// power supply voltage
driver.voltage_power_supply = 20;
driver.init();
motor.linkDriver(&driver);
// aligning voltage
motor.voltage_sensor_align = 8;
motor.voltage_limit = 20;
// set motion control loop to be used
motor.controller = MotionControlType::torque;

// use monitoring with serial
Serial.begin(115200);
// comment out if not needed
motor.useMonitoring(Serial);
motor.monitor_variables = _MON_VEL;
motor.monitor_downsample = 10; // default 10

// initialize motor
motor.init();

// set voltage to run calibration
sensor_calibrated.voltage_calibration = 6;
// Running calibration
sensor_calibrated.calibrate(motor);

//Serial.println("Calibrating Sensor Done.");
// Linking sensor to motor object
motor.linkSensor(&sensor_calibrated);

// calibrated init FOC
motor.initFOC();

// add target command T
command.add('T', doTarget, "target voltage");

Serial.println(F("Motor ready."));

Serial.println(F("Set the target voltage using serial terminal:"));
_delay(1000);
}

void loop() {

motor.loopFOC();
motor.move(target_voltage);
command.run();
motor.monitor();

}
106 changes: 106 additions & 0 deletions examples/encoders/mt6816/mt6816_spi/mt6816_spi.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/**
* Comprehensive BLDC motor control example using magnetic sensor MT6816
*
* Using serial terminal user can send motor commands and configure the motor and FOC in real-time:
* - configure PID controller constants
* - change motion control loops
* - monitor motor variabels
* - set target values
* - check all the configuration values
*
* See more info in docs.simplefoc.com/commander_interface
*/
#include <SimpleFOC.h>
#include <SimpleFOCDrivers.h>
#include <encoders/mt6816/MagneticSensorMT6816.h>

// magnetic sensor instance - MT6816 SPI mode
MagneticSensorMT6816 sensor = MagneticSensorMT6816(5);


// BLDC motor & driver instance
BLDCMotor motor = BLDCMotor(7);
BLDCDriver3PWM driver = BLDCDriver3PWM(32, 25, 26, 33);

// Inline Current Sense instance
InlineCurrentSense current_sense = InlineCurrentSense(0.01, 50.0, 35, 34);

// commander interface
Commander command = Commander(Serial);
void onMotor(char* cmd){ command.motor(&motor, cmd); }

void setup() {

// initialise magnetic sensor hardware
sensor.init();
// link the motor to the sensor
motor.linkSensor(&sensor);

// driver config
// power supply voltage [V]
driver.voltage_power_supply = 12;
driver.init();
// link driver
motor.linkDriver(&driver);

// choose FOC modulation
motor.foc_modulation = FOCModulationType::SpaceVectorPWM;

// set control loop type to be used
motor.controller = MotionControlType::torque;

// contoller configuration based on the control type
motor.PID_velocity.P = 0.2f;
motor.PID_velocity.I = 20;
motor.PID_velocity.D = 0;
// default voltage_power_supply
motor.voltage_limit = 12;

// velocity low pass filtering time constant
motor.LPF_velocity.Tf = 0.01f;

// angle loop velocity limit
motor.velocity_limit = 50;

// use monitoring with serial for motor init
// monitoring port
Serial.begin(115200);
// comment out if not needed
motor.useMonitoring(Serial);

current_sense.linkDriver(&driver);
current_sense.init();
current_sense.gain_b *= -1;
current_sense.skip_align = true;
motor.linkCurrentSense(&current_sense);

// initialise motor
motor.init();
// align encoder and start FOC
motor.initFOC();

// set the inital target value
motor.target = 2;

// define the motor id
command.add('A', onMotor, "motor");

// Run user commands to configure and the motor (find the full command list in docs.simplefoc.com)
Serial.println(F("Motor commands sketch | Initial motion control > torque/voltage : target 2V."));

_delay(1000);
}


void loop() {
// iterative setting FOC phase voltage
motor.loopFOC();

// iterative function setting the outter loop target
// velocity, position or voltage
// if tatget not set in parameter uses motor.target variable
motor.move();

// user communication
command.run();
}
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=SimpleFOCDrivers
version=1.0.1
version=1.0.2
author=Simplefoc <info@simplefoc.com>
maintainer=Simplefoc <info@simplefoc.com>
sentence=A library of supporting drivers for SimpleFOC. Motor drivers chips, encoder chips, current sensing and supporting code.
Expand Down
2 changes: 1 addition & 1 deletion src/encoders/aeat8800q24/AEAT8800Q24.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,5 +98,5 @@ uint8_t AEAT8800Q24::readRegister(uint8_t reg) {
};
void AEAT8800Q24::writeRegister(uint8_t reg, uint8_t value) {
uint16_t cmd = 0x4000 | ((reg&0x1F)<<8) | value;
uint16_t result = transfer16SPI(cmd);
/*uint16_t result =*/ transfer16SPI(cmd);
};
14 changes: 7 additions & 7 deletions src/encoders/as5047/AS5047.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ uint16_t AS5047::readCorrectedAngle(){

uint16_t AS5047::readMagnitude(){
uint16_t command = AS5047_MAGNITUDE_REG | AS5047_RW; // set r=1, result is 0x7FFD
uint16_t cmdresult = spi_transfer16(command);
/*uint16_t cmdresult =*/ spi_transfer16(command);
uint16_t result = nop();
return result;
}
Expand All @@ -62,7 +62,7 @@ bool AS5047::isErrorFlag(){

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

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

void AS5047::writeSettings1(AS5047Settings1 settings){
uint16_t command = AS5047_SETTINGS1_REG; // set r=0, result is 0x0018
uint16_t cmdresult = spi_transfer16(command);
cmdresult = spi_transfer16(settings.reg);
/*uint16_t cmdresult =*/ spi_transfer16(command);
/*cmdresult =*/ spi_transfer16(settings.reg);
}


AS5047Settings2 AS5047::readSettings2(){
uint16_t command = AS5047_SETTINGS2_REG | AS5047_RW; // set r=1, result is 0x4019
uint16_t cmdresult = spi_transfer16(command);
/*uint16_t cmdresult =*/ spi_transfer16(command);
AS5047Settings2 result = {
.reg = nop()
};
Expand All @@ -102,7 +102,7 @@ AS5047Settings2 AS5047::readSettings2(){

AS5047Diagnostics AS5047::readDiagnostics(){
uint16_t command = AS5047_DIAGNOSTICS_REG | AS5047_PARITY | AS5047_RW; // set r=1, result is 0xFFFC
uint16_t cmdresult = spi_transfer16(command);
/*uint16_t cmdresult =*/ spi_transfer16(command);
AS5047Diagnostics result = {
.reg = nop()
};
Expand Down
3 changes: 3 additions & 0 deletions src/encoders/as5047/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ void setup() {
Here's how you can use it:

```c++
// update the sensor (only needed if using the sensor without a motor)
sensor1.update();

// get the angle, in radians, including full rotations
float a1 = sensor1.getAngle();

Expand Down
Loading

0 comments on commit d4fce56

Please sign in to comment.