Skip to content

Commit

Permalink
Merge pull request #7 from simplefoc/dev
Browse files Browse the repository at this point in the history
1.0.2 Release
  • Loading branch information
runger1101001 authored Nov 28, 2023
2 parents 56d146e + 11917d8 commit 1d17888
Show file tree
Hide file tree
Showing 9 changed files with 76 additions and 26 deletions.
22 changes: 11 additions & 11 deletions .github/workflows/ccpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,32 +26,32 @@ jobs:
- arduino:mbed_rp2040:pico # rpi pico
include:
- arduino-boards-fqbn: arduino:avr:uno
required-libraries: Simple FOC
required-libraries: Simple FOC,SimpleFOCDrivers
- arduino-boards-fqbn: arduino:sam:arduino_due_x
required-libraries: Simple FOC
required-libraries: Simple FOC,SimpleFOCDrivers
- arduino-boards-fqbn: arduino:samd:nano_33_iot
required-libraries: Simple FOC
required-libraries: Simple FOC,SimpleFOCDrivers
- arduino-boards-fqbn: arduino:mbed_rp2040:pico
required-libraries: Simple FOC
required-libraries: Simple FOC,SimpleFOCDrivers
- 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
required-libraries: Simple FOC,SimpleFOCDrivers
# - 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
platform-url: https://espressif.github.io/arduino-esp32/package_esp32_index.json
required-libraries: Simple FOC,SimpleFOCDrivers
- 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
platform-url: https://espressif.github.io/arduino-esp32/package_esp32_index.json
required-libraries: Simple FOC,SimpleFOCDrivers
- 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
required-libraries: Simple FOC,SimpleFOCDrivers
- 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
required-libraries: Simple FOC,SimpleFOCDrivers
# Do not cancel all jobs / architectures if one job fails
fail-fast: false
steps:
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
# SimpleDCMotor


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


Release 1.0.2 for SimpleFOC 2.3.1 or later

:warning: code in development! Please help us test it!


Expand Down Expand Up @@ -123,6 +130,7 @@ void setup() {
driver.voltage_power_supply = 10.0f;
driver.voltage_limit = 10.0f;
driver.pwm_frequency = 5000;
motor.torque_controller = TorqueControlType::voltage;
motor.controller = MotionControlType::torque;
Expand Down
4 changes: 2 additions & 2 deletions examples/dc-open-loop/dc-open-loop.ino
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
#include <Arduino.h>

#include "SimpleFOC.h"
#include "SimpleFOCDCMotor.h"
#include "SimpleDCMotor.h"

// DCDriver object - this is the only thing needed for open-loop control.
// There are different types to choose from, please select the correct one
// that matches your motor driver hardware.
DCDriverSpeedDir driver = DCDriverSpeedDir(2, 3);
DCDriver1PWM1Dir driver = DCDriver1PWM1Dir(2, 3);

/**
* Setup function, in which you should intialize the driver.
Expand Down
4 changes: 3 additions & 1 deletion examples/dc-torque-voltage/dc-torque-voltage.ino
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include <Arduino.h>

#include "SimpleFOC.h"
#include "SimpleFOCDCMotor.h"
#include "SimpleDCMotor.h"


// DCMotor object
Expand Down Expand Up @@ -46,6 +46,8 @@ void setup() {
// if you want, you can limit the voltage used by the driver.
// This value has to be same as or lower than the power supply voltage.
driver.voltage_limit = 10.0f;
// often, you will want to set a lower PWM frequency than the default
driver.pwm_frequency = 5000;
// init driver
driver.init();
// init sensor
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=SimpleDCMotor
version=1.0.0
version=1.0.2
author=Simplefoc <[email protected]>
maintainer=Simplefoc <[email protected]>
sentence=A library enabling DC motor control with SimpleFOC.
Expand Down
4 changes: 2 additions & 2 deletions src/DCMotor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ void DCMotor::init() {
enable();
_delay(50);

if (!_isset(sensor_direction)) {
if (sensor_direction==Direction::UNKNOWN) {
sensor_direction = Direction::CW;
SIMPLEFOC_DEBUG("MOT: Sensor Dir: CW");
}
Expand Down Expand Up @@ -140,7 +140,7 @@ void DCMotor::setPhaseVoltage(float Uq, float Ud, float angle_el) {
};


int DCMotor::initFOC(float zero_electric_offset, Direction sensor_direction) {
int DCMotor::initFOC() {
// nothing to do for DC motors
return 0; // always return failure
};
Expand Down
2 changes: 1 addition & 1 deletion src/DCMotor.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class DCMotor : public FOCMotor {
virtual void setPhaseVoltage(float Uq, float Ud, float angle_el) override;

// not implemented for DC motors
virtual int initFOC(float zero_electric_offset = NOT_SET , Direction sensor_direction = Direction::CW) override;
virtual int initFOC() override;
// not implemented for DC motors
virtual void loopFOC() override;

Expand Down
44 changes: 37 additions & 7 deletions src/drivers/DCDriver1PWM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,26 @@ DCDriver1PWM::DCDriver1PWM(int pinPWM, float threshold, int pinEN) {
};


void DCDriver1PWM::configureMicroseconds(int hz, int min_us, int zero_us, int max_us, bool active_high){
pwm_frequency = hz;
this->active_high = active_high;
pwm_period_us = 1000000.0f / hz;
threshold = (float)zero_us / pwm_period_us;
pwm_max = (float)max_us / pwm_period_us;
pwm_min = (float)min_us / pwm_period_us;
if (!active_high) {
float temp = 1.0f - pwm_min;
pwm_min = 1.0f - pwm_max;
pwm_max = temp;
threshold = 1.0f - threshold;
}
pwm_max = _constrain(pwm_max, 0.0f, 1.0f);
pwm_min = _constrain(pwm_min, 0.0f, 1.0f);
threshold = _constrain(threshold, 0.0f, 1.0f);
};



int DCDriver1PWM::init() {
if (pinEN!=NOT_SET) {
pinMode(pinEN, OUTPUT);
Expand All @@ -24,18 +44,28 @@ int DCDriver1PWM::init() {

void DCDriver1PWM::setPwm(float U){
U = _constrain(U, -voltage_limit, voltage_limit);
if (U>0.0f) {
U = ( U/voltage_power_supply ) * (1.0f-threshold);
U = _constrain(U,threshold,1.0f);
if (U>dead_zone) {
U = threshold + ( U/voltage_power_supply ) * (pwm_max - threshold);
_writeDutyCycle1PWM(U, params);
} else if (U<0.0f) {
U = _constrain(U, pwm_min, pwm_max);
} else if (U<-dead_zone) {
if (!scale_reverse)
U = ( -U/voltage_power_supply ) * (1.0f-threshold); // same scale as forward
U = threshold + ( U/voltage_power_supply ) * (pwm_max - threshold); // same scale as forward
else
U = ( -U/voltage_power_supply ) * (threshold); // full reverse scale
U = _constrain(U,threshold,1.0f);
U = threshold + ( U/voltage_power_supply ) * (threshold - pwm_min); // full reverse scale
U = _constrain(U, pwm_min, pwm_max);
_writeDutyCycle1PWM(U, params);
} else {
_writeDutyCycle1PWM(threshold, params);
}
};



void DCDriver1PWM::setPwmMicroseconds(int us){
float U = (float)us / pwm_period_us;
if (!active_high)
U = 1.0f - U;
U = _constrain(U, pwm_min, pwm_max);
_writeDutyCycle1PWM(U, params);
};
12 changes: 11 additions & 1 deletion src/drivers/DCDriver1PWM.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,24 @@ class DCDriver1PWM : public DCDriver {

virtual int init() override;

void configureMicroseconds(int hz, int min_us, int zero_us, int max_us, bool active_high = false);

/**
* Set phase voltages to the harware
* Positive voltages are associated with the "forward" direction, negative voltages with the "reverse" direction
* @param U voltage
*/
virtual void setPwm(float U) override;

void setPwmMicroseconds(int us);

int pinPWM;
bool scale_reverse = true; //!< if true, the reverse scale is full reverse, if false, the reverse scale is the same as the forward scale
float threshold = 0.5; //!< duty cycle above which the motor is considered to be "forward"
float threshold = 0.5f; //!< duty cycle above which the motor is considered to be "forward"
float pwm_max = 1.0f;
float pwm_min = 0.0f;
bool active_high = true;
float dead_zone = 0.0f;
protected:
float pwm_period_us = NOT_SET;
};

0 comments on commit 1d17888

Please sign in to comment.