Skip to content

Commit 37f065a

Browse files
committed
.
1 parent c72f063 commit 37f065a

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
@@ -81,11 +81,11 @@ class BLDCMotor: public FOCMotor
8181
*/
8282
void setPhaseVoltage(float Uq, float Ud, float angle_el) override;
8383

84-
private:
84+
protected:
8585
// FOC methods
8686

8787
/** Sensor alignment to electrical 0 angle of the motor */
88-
int alignSensor();
88+
virtual int alignSensor();
8989
/** Current sense and motor phase alignment */
9090
int alignCurrentSense();
9191
/** 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"
@@ -150,7 +152,7 @@ class FOCMotor
150152
float electricalAngle();
151153

152154
// state variables
153-
float target; //!< current target value - depends of the controller
155+
std::atomic<float> target; //!< current target value - depends of the controller
154156
float feed_forward_velocity = 0.0f; //!< current feed forward velocity
155157
float shaft_angle;//!< current motor angle
156158
float electrical_angle;//!< current electrical angle
@@ -190,7 +192,7 @@ class FOCMotor
190192

191193
// configuration structures
192194
TorqueControlType torque_controller; //!< parameter determining the torque control type
193-
MotionControlType controller; //!< parameter determining the control loop to be used
195+
std::atomic<MotionControlType> controller; //!< parameter determining the control loop to be used
194196

195197
// controllers and low pass filters
196198
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)