Skip to content

Commit 493273f

Browse files
committed
merge conflict relosution stm32mcu.cpp in drivers
2 parents bc2b355 + a9f4635 commit 493273f

File tree

21 files changed

+840
-319
lines changed

21 files changed

+840
-319
lines changed

examples/utils/calibration/find_pole_pair_number/encoder/find_pole_pairs_number/find_pole_pairs_number.ino

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ void setup() {
5656
Serial.println("-\n");
5757

5858
float pp_search_voltage = 4; // maximum power_supply_voltage/2
59-
float pp_search_angle = 6*M_PI; // search electrical angle to turn
59+
float pp_search_angle = 6*_PI; // search electrical angle to turn
6060

6161
// move motor to the electrical angle 0
6262
motor.controller = MotionControlType::angle_openloop;
@@ -90,9 +90,9 @@ void setup() {
9090
Serial.print(F("Estimated PP : "));
9191
Serial.println(pp);
9292
Serial.println(F("PP = Electrical angle / Encoder angle "));
93-
Serial.print(pp_search_angle*180/M_PI);
93+
Serial.print(pp_search_angle*180/_PI);
9494
Serial.print("/");
95-
Serial.print((angle_end-angle_begin)*180/M_PI);
95+
Serial.print((angle_end-angle_begin)*180/_PI);
9696
Serial.print(" = ");
9797
Serial.println((pp_search_angle)/(angle_end-angle_begin));
9898
Serial.println();

examples/utils/calibration/find_pole_pair_number/magnetic_sensor/find_pole_pairs_number/find_pole_pairs_number.ino

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ void setup() {
5555
Serial.println("-\n");
5656

5757
float pp_search_voltage = 4; // maximum power_supply_voltage/2
58-
float pp_search_angle = 6*M_PI; // search electrical angle to turn
58+
float pp_search_angle = 6*_PI; // search electrical angle to turn
5959

6060
// move motor to the electrical angle 0
6161
motor.controller = MotionControlType::angle_openloop;
@@ -90,9 +90,9 @@ void setup() {
9090
Serial.print(F("Estimated PP : "));
9191
Serial.println(pp);
9292
Serial.println(F("PP = Electrical angle / Encoder angle "));
93-
Serial.print(pp_search_angle*180/M_PI);
93+
Serial.print(pp_search_angle*180/_PI);
9494
Serial.print(F("/"));
95-
Serial.print((angle_end-angle_begin)*180/M_PI);
95+
Serial.print((angle_end-angle_begin)*180/_PI);
9696
Serial.print(F(" = "));
9797
Serial.println((pp_search_angle)/(angle_end-angle_begin));
9898
Serial.println();

src/BLDCMotor.cpp

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "BLDCMotor.h"
2+
#include "./communication/SimpleFOCDebug.h"
23

34
// BLDCMotor( int pp , float R)
45
// - pp - pole pair number
@@ -30,10 +31,11 @@ void BLDCMotor::linkDriver(BLDCDriver* _driver) {
3031
void BLDCMotor::init() {
3132
if (!driver || !driver->initialized) {
3233
motor_status = FOCMotorStatus::motor_init_failed;
33-
if(monitor_port) monitor_port->println(F("MOT: Init not possible, driver not initialized"));
34+
SIMPLEFOC_DEBUG("MOT: Init not possible, driver not initialized");
35+
return;
3436
}
3537
motor_status = FOCMotorStatus::motor_initializing;
36-
if(monitor_port) monitor_port->println(F("MOT: Init"));
38+
SIMPLEFOC_DEBUG("MOT: Init");
3739

3840
// sanity check for the voltage limit configuration
3941
if(voltage_limit > driver->voltage_limit) voltage_limit = driver->voltage_limit;
@@ -57,7 +59,7 @@ void BLDCMotor::init() {
5759

5860
_delay(500);
5961
// enable motor
60-
if(monitor_port) monitor_port->println(F("MOT: Enable driver."));
62+
SIMPLEFOC_DEBUG("MOT: Enable driver.");
6163
enable();
6264
_delay(500);
6365
motor_status = FOCMotorStatus::motor_uncalibrated;
@@ -111,24 +113,25 @@ int BLDCMotor::initFOC( float zero_electric_offset, Direction _sensor_direction
111113
// added the shaft_angle update
112114
sensor->update();
113115
shaft_angle = shaftAngle();
114-
}else if(monitor_port) monitor_port->println(F("MOT: No sensor."));
116+
}else
117+
SIMPLEFOC_DEBUG("MOT: No sensor.");
115118

116119
// aligning the current sensor - can be skipped
117120
// checks if driver phases are the same as current sense phases
118121
// and checks the direction of measuremnt.
119122
_delay(500);
120123
if(exit_flag){
121124
if(current_sense) exit_flag *= alignCurrentSense();
122-
else if(monitor_port) monitor_port->println(F("MOT: No current sense."));
125+
else SIMPLEFOC_DEBUG("MOT: No current sense.");
123126
}
124127

125128
if(exit_flag){
126-
if(monitor_port) monitor_port->println(F("MOT: Ready."));
129+
SIMPLEFOC_DEBUG("MOT: Ready.");
127130
motor_status = FOCMotorStatus::motor_ready;
128131
}else{
129-
if(monitor_port) monitor_port->println(F("MOT: Init FOC failed."));
130-
disable();
132+
SIMPLEFOC_DEBUG("MOT: Init FOC failed.");
131133
motor_status = FOCMotorStatus::motor_calib_failed;
134+
disable();
132135
}
133136

134137
return exit_flag;
@@ -138,18 +141,17 @@ int BLDCMotor::initFOC( float zero_electric_offset, Direction _sensor_direction
138141
int BLDCMotor::alignCurrentSense() {
139142
int exit_flag = 1; // success
140143

141-
if(monitor_port) monitor_port->println(F("MOT: Align current sense."));
144+
SIMPLEFOC_DEBUG("MOT: Align current sense.");
142145

143146
// align current sense and the driver
144147
exit_flag = current_sense->driverAlign(voltage_sensor_align);
145148
if(!exit_flag){
146149
// error in current sense - phase either not measured or bad connection
147-
if(monitor_port) monitor_port->println(F("MOT: Align error!"));
150+
SIMPLEFOC_DEBUG("MOT: Align error!");
148151
exit_flag = 0;
149152
}else{
150153
// output the alignment status flag
151-
if(monitor_port) monitor_port->print(F("MOT: Success: "));
152-
if(monitor_port) monitor_port->println(exit_flag);
154+
SIMPLEFOC_DEBUG("MOT: Success: ", exit_flag);
153155
}
154156

155157
return exit_flag > 0;
@@ -158,7 +160,7 @@ int BLDCMotor::alignCurrentSense() {
158160
// Encoder alignment to electrical 0 angle
159161
int BLDCMotor::alignSensor() {
160162
int exit_flag = 1; //success
161-
if(monitor_port) monitor_port->println(F("MOT: Align sensor."));
163+
SIMPLEFOC_DEBUG("MOT: Align sensor.");
162164

163165
// if unknown natural direction
164166
if(!_isset(sensor_direction)){
@@ -189,24 +191,23 @@ int BLDCMotor::alignSensor() {
189191
_delay(200);
190192
// determine the direction the sensor moved
191193
if (mid_angle == end_angle) {
192-
if(monitor_port) monitor_port->println(F("MOT: Failed to notice movement"));
194+
SIMPLEFOC_DEBUG("MOT: Failed to notice movement");
193195
return 0; // failed calibration
194196
} else if (mid_angle < end_angle) {
195-
if(monitor_port) monitor_port->println(F("MOT: sensor_direction==CCW"));
197+
SIMPLEFOC_DEBUG("MOT: sensor_direction==CCW");
196198
sensor_direction = Direction::CCW;
197199
} else{
198-
if(monitor_port) monitor_port->println(F("MOT: sensor_direction==CW"));
200+
SIMPLEFOC_DEBUG("MOT: sensor_direction==CW");
199201
sensor_direction = Direction::CW;
200202
}
201203
// check pole pair number
202-
if(monitor_port) monitor_port->print(F("MOT: PP check: "));
203204
float moved = fabs(mid_angle - end_angle);
204205
if( fabs(moved*pole_pairs - _2PI) > 0.5f ) { // 0.5f is arbitrary number it can be lower or higher!
205-
if(monitor_port) monitor_port->print(F("fail - estimated pp:"));
206-
if(monitor_port) monitor_port->println(_2PI/moved,4);
207-
}else if(monitor_port) monitor_port->println(F("OK!"));
206+
SIMPLEFOC_DEBUG("MOT: PP check: fail - estimated pp: ", _2PI/moved);
207+
} else
208+
SIMPLEFOC_DEBUG("MOT: PP check: OK!");
208209

209-
}else if(monitor_port) monitor_port->println(F("MOT: Skip dir calib."));
210+
} else SIMPLEFOC_DEBUG("MOT: Skip dir calib.");
210211

211212
// zero electric angle not known
212213
if(!_isset(zero_electric_angle)){
@@ -222,13 +223,12 @@ int BLDCMotor::alignSensor() {
222223
//zero_electric_angle = _normalizeAngle(_electricalAngle(sensor_direction*sensor->getAngle(), pole_pairs));
223224
_delay(20);
224225
if(monitor_port){
225-
monitor_port->print(F("MOT: Zero elec. angle: "));
226-
monitor_port->println(zero_electric_angle);
226+
SIMPLEFOC_DEBUG("MOT: Zero elec. angle: ", zero_electric_angle);
227227
}
228228
// stop everything
229229
setPhaseVoltage(0, 0, 0);
230230
_delay(200);
231-
}else if(monitor_port) monitor_port->println(F("MOT: Skip offset calib."));
231+
}else SIMPLEFOC_DEBUG("MOT: Skip offset calib.");
232232
return exit_flag;
233233
}
234234

@@ -237,7 +237,7 @@ int BLDCMotor::alignSensor() {
237237
int BLDCMotor::absoluteZeroSearch() {
238238
// sensor precision: this is all ok, as the search happens near the 0-angle, where the precision
239239
// of float is sufficient.
240-
if(monitor_port) monitor_port->println(F("MOT: Index search..."));
240+
SIMPLEFOC_DEBUG("MOT: Index search...");
241241
// search the absolute zero with small velocity
242242
float limit_vel = velocity_limit;
243243
float limit_volt = voltage_limit;
@@ -257,8 +257,8 @@ int BLDCMotor::absoluteZeroSearch() {
257257
voltage_limit = limit_volt;
258258
// check if the zero found
259259
if(monitor_port){
260-
if(sensor->needsSearch()) monitor_port->println(F("MOT: Error: Not found!"));
261-
else monitor_port->println(F("MOT: Success!"));
260+
if(sensor->needsSearch()) SIMPLEFOC_DEBUG("MOT: Error: Not found!");
261+
else SIMPLEFOC_DEBUG("MOT: Success!");
262262
}
263263
return !sensor->needsSearch();
264264
}
@@ -307,7 +307,7 @@ void BLDCMotor::loopFOC() {
307307
break;
308308
default:
309309
// no torque control selected
310-
if(monitor_port) monitor_port->println(F("MOT: no torque control selected!"));
310+
SIMPLEFOC_DEBUG("MOT: no torque control selected!");
311311
break;
312312
}
313313

src/SimpleFOC.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,5 +114,6 @@ void loop() {
114114
#include "current_sense/GenericCurrentSense.h"
115115
#include "communication/Commander.h"
116116
#include "communication/StepDirListener.h"
117+
#include "communication/SimpleFOCDebug.h"
117118

118119
#endif

src/StepperMotor.cpp

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
#include "StepperMotor.h"
2+
#include "./communication/SimpleFOCDebug.h"
3+
24

35
// StepperMotor(int pp)
46
// - pp - pole pair number
@@ -30,10 +32,11 @@ void StepperMotor::linkDriver(StepperDriver* _driver) {
3032
void StepperMotor::init() {
3133
if (!driver || !driver->initialized) {
3234
motor_status = FOCMotorStatus::motor_init_failed;
33-
if(monitor_port) monitor_port->println(F("MOT: Init not possible, driver not initialized"));
35+
SIMPLEFOC_DEBUG("MOT: Init not possible, driver not initialized");
36+
return;
3437
}
3538
motor_status = FOCMotorStatus::motor_initializing;
36-
if(monitor_port) monitor_port->println(F("MOT: Init"));
39+
SIMPLEFOC_DEBUG("MOT: Init");
3740

3841
// sanity check for the voltage limit configuration
3942
if(voltage_limit > driver->voltage_limit) voltage_limit = driver->voltage_limit;
@@ -51,7 +54,7 @@ void StepperMotor::init() {
5154

5255
_delay(500);
5356
// enable motor
54-
if(monitor_port) monitor_port->println(F("MOT: Enable driver."));
57+
SIMPLEFOC_DEBUG("MOT: Enable driver.");
5558
enable();
5659
_delay(500);
5760

@@ -107,13 +110,13 @@ int StepperMotor::initFOC( float zero_electric_offset, Direction _sensor_direct
107110
// added the shaft_angle update
108111
sensor->update();
109112
shaft_angle = sensor->getAngle();
110-
}else if(monitor_port) monitor_port->println(F("MOT: No sensor."));
113+
}else SIMPLEFOC_DEBUG("MOT: No sensor.");
111114

112115
if(exit_flag){
113-
if(monitor_port) monitor_port->println(F("MOT: Ready."));
116+
SIMPLEFOC_DEBUG("MOT: Ready.");
114117
motor_status = FOCMotorStatus::motor_ready;
115118
}else{
116-
if(monitor_port) monitor_port->println(F("MOT: Init FOC failed."));
119+
SIMPLEFOC_DEBUG("MOT: Init FOC failed.");
117120
motor_status = FOCMotorStatus::motor_calib_failed;
118121
disable();
119122
}
@@ -124,7 +127,7 @@ int StepperMotor::initFOC( float zero_electric_offset, Direction _sensor_direct
124127
// Encoder alignment to electrical 0 angle
125128
int StepperMotor::alignSensor() {
126129
int exit_flag = 1; //success
127-
if(monitor_port) monitor_port->println(F("MOT: Align sensor."));
130+
SIMPLEFOC_DEBUG("MOT: Align sensor.");
128131

129132
// if unknown natural direction
130133
if(!_isset(sensor_direction)){
@@ -155,24 +158,23 @@ int StepperMotor::alignSensor() {
155158
_delay(200);
156159
// determine the direction the sensor moved
157160
if (mid_angle == end_angle) {
158-
if(monitor_port) monitor_port->println(F("MOT: Failed to notice movement"));
161+
SIMPLEFOC_DEBUG("MOT: Failed to notice movement");
159162
return 0; // failed calibration
160163
} else if (mid_angle < end_angle) {
161-
if(monitor_port) monitor_port->println(F("MOT: sensor_direction==CCW"));
164+
SIMPLEFOC_DEBUG("MOT: sensor_direction==CCW");
162165
sensor_direction = Direction::CCW;
163166
} else{
164-
if(monitor_port) monitor_port->println(F("MOT: sensor_direction==CW"));
167+
SIMPLEFOC_DEBUG("MOT: sensor_direction==CW");
165168
sensor_direction = Direction::CW;
166169
}
167170
// check pole pair number
168-
if(monitor_port) monitor_port->print(F("MOT: PP check: "));
169171
float moved = fabs(mid_angle - end_angle);
170172
if( fabs(moved*pole_pairs - _2PI) > 0.5f ) { // 0.5f is arbitrary number it can be lower or higher!
171-
if(monitor_port) monitor_port->print(F("fail - estimated pp:"));
172-
if(monitor_port) monitor_port->println(_2PI/moved,4);
173-
}else if(monitor_port) monitor_port->println(F("OK!"));
173+
SIMPLEFOC_DEBUG("MOT: PP check: fail - estimated pp: ", _2PI/moved);
174+
} else
175+
SIMPLEFOC_DEBUG("MOT: PP check: OK!");
174176

175-
}else if(monitor_port) monitor_port->println(F("MOT: Skip dir calib."));
177+
}else SIMPLEFOC_DEBUG("MOT: Skip dir calib.");
176178

177179
// zero electric angle not known
178180
if(!_isset(zero_electric_angle)){
@@ -187,21 +189,20 @@ int StepperMotor::alignSensor() {
187189
zero_electric_angle = electricalAngle();
188190
_delay(20);
189191
if(monitor_port){
190-
monitor_port->print(F("MOT: Zero elec. angle: "));
191-
monitor_port->println(zero_electric_angle);
192+
SIMPLEFOC_DEBUG("MOT: Zero elec. angle: ", zero_electric_angle);
192193
}
193194
// stop everything
194195
setPhaseVoltage(0, 0, 0);
195196
_delay(200);
196-
}else if(monitor_port) monitor_port->println(F("MOT: Skip offset calib."));
197+
}else SIMPLEFOC_DEBUG("MOT: Skip offset calib.");
197198
return exit_flag;
198199
}
199200

200201
// Encoder alignment the absolute zero angle
201202
// - to the index
202203
int StepperMotor::absoluteZeroSearch() {
203204

204-
if(monitor_port) monitor_port->println(F("MOT: Index search..."));
205+
SIMPLEFOC_DEBUG("MOT: Index search...");
205206
// search the absolute zero with small velocity
206207
float limit_vel = velocity_limit;
207208
float limit_volt = voltage_limit;
@@ -221,8 +222,8 @@ int StepperMotor::absoluteZeroSearch() {
221222
voltage_limit = limit_volt;
222223
// check if the zero found
223224
if(monitor_port){
224-
if(sensor->needsSearch()) monitor_port->println(F("MOT: Error: Not found!"));
225-
else monitor_port->println(F("MOT: Success!"));
225+
if(sensor->needsSearch()) SIMPLEFOC_DEBUG("MOT: Error: Not found!");
226+
else SIMPLEFOC_DEBUG("MOT: Success!");
226227
}
227228
return !sensor->needsSearch();
228229
}

src/common/base_classes/FOCMotor.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "FOCMotor.h"
2+
#include "../../communication/SimpleFOCDebug.h"
23

34
/**
45
* Default constructor - setting all variabels to default values
@@ -80,7 +81,8 @@ float FOCMotor::electricalAngle(){
8081
// function implementing the monitor_port setter
8182
void FOCMotor::useMonitoring(Print &print){
8283
monitor_port = &print; //operate on the address of print
83-
if(monitor_port ) monitor_port->println(F("MOT: Monitor enabled!"));
84+
SimpleFOCDebug::enable(&print);
85+
SIMPLEFOC_DEBUG("MOT: Monitor enabled!");
8486
}
8587

8688
// utility function intended to be used with serial plotter to monitor motor variables

src/communication/Commander.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ class Commander
207207
* - velocity : velocity torque (ex.P10 2.5 or P10 to only chanage the target witout limits)
208208
* - angle : angle velocity torque (ex.P3.5 10 2.5 or P3.5 to only chanage the target witout limits)
209209
*/
210-
void target(FOCMotor* motor, char* user_cmd, char* separator = " ");
210+
void target(FOCMotor* motor, char* user_cmd, char* separator = (char *)" ");
211211

212212
/**
213213
* FOC motor (StepperMotor and BLDCMotor) motion control interfaces
@@ -237,7 +237,7 @@ class Commander
237237
* - velocity (open and closed loop) : velocity torque (ex.M10 2.5 or M10 to only chanage the target witout limits)
238238
* - angle (open and closed loop) : angle velocity torque (ex.M3.5 10 2.5 or M3.5 to only chanage the target witout limits)
239239
*/
240-
void motion(FOCMotor* motor, char* user_cmd, char* separator = " ");
240+
void motion(FOCMotor* motor, char* user_cmd, char* separator = (char *)" ");
241241

242242
private:
243243
// Subscribed command callback variables

0 commit comments

Comments
 (0)