Skip to content

Commit df56542

Browse files
committed
Updating library to latest version
1 parent 395b6cd commit df56542

File tree

5 files changed

+14
-7
lines changed

5 files changed

+14
-7
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
*This fork adds the following features:*
2+
- *FOCMotor: thread-safe 'target' and 'controller' fields*
3+
- *BLDCMotor: make 'alignSensor()' virtual*
4+
- *Commander: allow contexts on onCommand callbacks*
5+
16
# SimpleFOClibrary - **Simple** Field Oriented Control (FOC) **library** <br>
27
### A Cross-Platform FOC implementation for BLDC and Stepper motors<br> based on the Arduino IDE and PlatformIO
38

src/BLDCMotor.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,11 @@ class BLDCMotor: public FOCMotor
9191
return FOCMotor::characteriseMotor(voltage, 1.5f);
9292
}
9393

94-
private:
94+
protected:
9595
// FOC methods
9696

9797
/** Sensor alignment to electrical 0 angle of the motor */
98-
int alignSensor();
98+
virtual int alignSensor();
9999
/** Current sense and motor phase alignment */
100100
int alignCurrentSense();
101101
/** Motor and sensor alignment to the sensors absolute 0 angle */

src/common/base_classes/FOCMotor.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#ifndef FOCMOTOR_H
22
#define FOCMOTOR_H
33

4+
#include <atomic>
5+
46
#include "Arduino.h"
57
#include "Sensor.h"
68
#include "CurrentSense.h"
@@ -159,7 +161,7 @@ class FOCMotor
159161
int characteriseMotor(float voltage, float correction_factor);
160162

161163
// state variables
162-
float target; //!< current target value - depends of the controller
164+
std::atomic<float> target; //!< current target value - depends of the controller
163165
float feed_forward_velocity = 0.0f; //!< current feed forward velocity
164166
float shaft_angle;//!< current motor angle
165167
float electrical_angle;//!< current electrical angle
@@ -199,7 +201,7 @@ class FOCMotor
199201

200202
// configuration structures
201203
TorqueControlType torque_controller; //!< parameter determining the torque control type
202-
MotionControlType controller; //!< parameter determining the control loop to be used
204+
std::atomic<MotionControlType> controller; //!< parameter determining the control loop to be used
203205

204206
// controllers and low pass filters
205207
PIDController PID_current_q{DEF_PID_CURR_P,DEF_PID_CURR_I,DEF_PID_CURR_D,DEF_PID_CURR_RAMP, DEF_POWER_SUPPLY};//!< parameter determining the q current PID config

src/communication/Commander.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Commander::Commander(char eol, bool echo){
1111
}
1212

1313

14-
void Commander::add(char id, CommandCallback onCommand, const char* label ){
14+
void Commander::add(char id, std::function<void(char*)> onCommand, const char* label ){
1515
call_list[call_count] = onCommand;
1616
call_ids[call_count] = id;
1717
call_label[call_count] = (char*)label;

src/communication/Commander.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ class Commander
9191
* @param onCommand - function pointer void function(char*)
9292
* @param label - string label to be displayed when scan command sent
9393
*/
94-
void add(char id , CommandCallback onCommand, const char* label = nullptr);
94+
void add(char id , std::function<void(char*)> onCommand, const char* label = nullptr);
9595

9696
// printing variables
9797
VerboseMode verbose = VerboseMode::user_friendly; //!< flag signaling that the commands should output user understanable text
@@ -243,7 +243,7 @@ class Commander
243243
bool isSentinel(char ch);
244244
private:
245245
// Subscribed command callback variables
246-
CommandCallback call_list[20];//!< array of command callback pointers - 20 is an arbitrary number
246+
std::function<void(char*)> call_list[20];//!< array of command callback pointers - 20 is an arbitrary number
247247
char call_ids[20]; //!< added callback commands
248248
char* call_label[20]; //!< added callback labels
249249
int call_count = 0;//!< number callbacks that are subscribed

0 commit comments

Comments
 (0)