Skip to content

Commit 232dcce

Browse files
committed
FEAT new communication protocol
1 parent d7fb9dc commit 232dcce

26 files changed

+360
-232
lines changed

keywords.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,6 @@ driverAlign KEYWORD2
8181
driverSync KEYWORD2
8282

8383

84-
voltage_q KEYWORD2
85-
voltage_d KEYWORD2
8684
current KEYWORD2
8785
current_measured KEYWORD2
8886
shaft_angle_sp KEYWORD2

src/BLDCMotor.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ void BLDCMotor::init() {
2727
if(monitor_port) monitor_port->println(F("MOT: Init"));
2828

2929
// if no current sensing and the user has set the phase resistance of the motor use current limit to calculate the voltage limit
30-
if( !current_sense && phase_resistance != NOT_SET ) {
30+
if( !current_sense && _isset(phase_resistance)) {
3131
float new_voltage_limit = current_limit * (phase_resistance*1.5); // v_lim = current_lim / (3/2 phase resistance) - worst case
3232
// use it if it is less then voltage_limit set by the user
3333
voltage_limit = new_voltage_limit < voltage_limit ? new_voltage_limit : voltage_limit;
@@ -86,7 +86,7 @@ int BLDCMotor::initFOC( float zero_electric_offset, Direction _sensor_direction
8686
int exit_flag = 1;
8787
// align motor if necessary
8888
// alignment necessary for encoders!
89-
if(zero_electric_offset != NOT_SET){
89+
if(_isset(zero_electric_offset)){
9090
// abosolute zero offset provided - no need to align
9191
zero_electric_angle = zero_electric_offset;
9292
// set the sensor direction - default CW
@@ -143,7 +143,7 @@ int BLDCMotor::alignSensor() {
143143
if(monitor_port) monitor_port->println(F("MOT: Align sensor."));
144144

145145
// if unknown natural direction
146-
if(sensor_direction == NOT_SET){
146+
if(!_isset(sensor_direction)){
147147
// check if sensor needs zero search
148148
if(sensor->needsSearch()) exit_flag = absoluteZeroSearch();
149149
// stop init if not found index
@@ -189,7 +189,7 @@ int BLDCMotor::alignSensor() {
189189
}else if(monitor_port) monitor_port->println(F("MOT: Skip dir calib."));
190190

191191
// zero electric angle not known
192-
if(zero_electric_angle == NOT_SET){
192+
if(!_isset(zero_electric_angle)){
193193
// align the electrical phases of the motor and sensor
194194
// set angle -90(270 = 3PI/2) degrees
195195
setPhaseVoltage(voltage_sensor_align, 0, _3PI_2);
@@ -288,7 +288,7 @@ void BLDCMotor::move(float new_target) {
288288
// if disabled do nothing
289289
if(!enabled) return;
290290
// set internal target variable
291-
if( new_target != NOT_SET ) target = new_target;
291+
if(_isset(new_target)) target = new_target;
292292
// get angular velocity
293293
shaft_velocity = shaftVelocity();
294294

@@ -309,7 +309,7 @@ void BLDCMotor::move(float new_target) {
309309
// if torque controlled through voltage
310310
if(torque_controller == TorqueControlType::voltage){
311311
// use voltage if phase-resistance not provided
312-
if(phase_resistance == NOT_SET) voltage.q = current_sp;
312+
if(!_isset(phase_resistance)) voltage.q = current_sp;
313313
else voltage.q = current_sp*1.5*phase_resistance;
314314
voltage.d = 0;
315315
}
@@ -322,7 +322,7 @@ void BLDCMotor::move(float new_target) {
322322
// if torque controlled through voltage control
323323
if(torque_controller == TorqueControlType::voltage){
324324
// use voltage if phase-resistance not provided
325-
if(phase_resistance == NOT_SET) voltage.q = current_sp;
325+
if(!_isset(phase_resistance)) voltage.q = current_sp;
326326
else voltage.q = current_sp*1.5*phase_resistance;
327327
voltage.d = 0;
328328
}

src/BLDCMotor.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "common/base_classes/FOCMotor.h"
66
#include "common/base_classes/Sensor.h"
77
#include "common/base_classes/BLDCDriver.h"
8+
#include "common/base_classes/CommunicationNode.h"
89
#include "common/foc_utils.h"
910
#include "common/time_utils.h"
1011
#include "common/defaults.h"

src/SimpleFOC.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,5 +108,6 @@ void loop() {
108108
#include "drivers/StepperDriver4PWM.h"
109109
#include "drivers/StepperDriver2PWM.h"
110110
#include "current_sense/InlineCurrentSense.h"
111+
#include "communication/Communicator.h"
111112

112113
#endif

src/StepperMotor.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ int StepperMotor::initFOC( float zero_electric_offset, Direction _sensor_direct
7272
int exit_flag = 1;
7373
// align motor if necessary
7474
// alignment necessary for encoders!
75-
if(zero_electric_offset != NOT_SET){
75+
if(!_isset(zero_electric_offset)){
7676
// abosolute zero offset provided - no need to align
7777
zero_electric_angle = zero_electric_offset;
7878
// set the sensor direction - default CW
@@ -179,7 +179,7 @@ void StepperMotor::move(float new_target) {
179179
// if disabled do nothing
180180
if(!enabled) return;
181181
// set internal target variable
182-
if( new_target != NOT_SET ) target = new_target;
182+
if(_isset(new_target) ) target = new_target;
183183
// get angular velocity
184184
shaft_velocity = shaftVelocity();
185185
// choose control loop

src/common/base_classes/BLDCDriver.h

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

4+
#include "Arduino.h"
5+
46
class BLDCDriver{
57
public:
68

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#ifndef COMNODE_h
2+
#define COMNODE_h
3+
4+
#include "Arduino.h"
5+
6+
/**
7+
* Interface class for communication
8+
*/
9+
class CommunicationNode{
10+
public:
11+
virtual String communicate(String use_command)=0;
12+
};
13+
14+
15+
#endif

0 commit comments

Comments
 (0)