Skip to content

Commit 8809922

Browse files
committed
removed pp requirement + current_limit used in open loop
1 parent 271a0b6 commit 8809922

File tree

2 files changed

+29
-13
lines changed

2 files changed

+29
-13
lines changed

src/BLDCMotor.cpp

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,6 @@ int BLDCMotor::alignSensor() {
186186
if( fabs(moved*pole_pairs - _2PI) > 0.5 ) { // 0.5 is arbitrary number it can be lower or higher!
187187
if(monitor_port) monitor_port->print(F("fail - estimated pp:"));
188188
if(monitor_port) monitor_port->println(_2PI/moved,4);
189-
return 0; // failed calibration
190189
}else if(monitor_port) monitor_port->println(F("OK!"));
191190

192191
}else if(monitor_port) monitor_port->println(F("MOT: Skip dir calib."));
@@ -216,16 +215,22 @@ int BLDCMotor::absoluteZeroSearch() {
216215

217216
if(monitor_port) monitor_port->println(F("MOT: Index search..."));
218217
// search the absolute zero with small velocity
219-
float limit = velocity_limit;
218+
float limit_vel = velocity_limit;
219+
float limit_volt = voltage_limit;
220220
velocity_limit = velocity_index_search;
221+
voltage_limit = voltage_sensor_align;
221222
shaft_angle = 0;
222223
while(sensor->needsSearch() && shaft_angle < _2PI){
223224
angleOpenloop(1.5*_2PI);
225+
// call important for some sensors not to loose count
226+
// not needed for the search
227+
sensor->getAngle();
224228
}
225229
// disable motor
226230
setPhaseVoltage(0, 0, 0);
227231
// reinit the limits
228-
velocity_limit = limit;
232+
velocity_limit = limit_vel;
233+
voltage_limit = limit_volt;
229234
// check if the zero found
230235
if(monitor_port){
231236
if(sensor->needsSearch()) monitor_port->println(F("MOT: Error: Not found!"));
@@ -337,15 +342,13 @@ void BLDCMotor::move(float new_target) {
337342
case MotionControlType::velocity_openloop:
338343
// velocity control in open loop
339344
shaft_velocity_sp = target;
340-
velocityOpenloop(shaft_velocity_sp);
341-
voltage.q = voltage_limit;
345+
voltage.q = velocityOpenloop(shaft_velocity_sp); // returns the voltage that is set to the motor
342346
voltage.d = 0;
343347
break;
344348
case MotionControlType::angle_openloop:
345349
// angle control in open loop
346350
shaft_angle_sp = target;
347-
angleOpenloop(shaft_angle_sp);
348-
voltage.q = voltage_limit;
351+
voltage.q = angleOpenloop(shaft_angle_sp); // returns the voltage that is set to the motor
349352
voltage.d = 0;
350353
break;
351354
}
@@ -553,7 +556,7 @@ void BLDCMotor::setPhaseVoltage(float Uq, float Ud, float angle_el) {
553556
// Function (iterative) generating open loop movement for target velocity
554557
// - target_velocity - rad/s
555558
// it uses voltage_limit variable
556-
void BLDCMotor::velocityOpenloop(float target_velocity){
559+
float BLDCMotor::velocityOpenloop(float target_velocity){
557560
// get current timestamp
558561
unsigned long now_us = _micros();
559562
// calculate the sample time from last call
@@ -565,18 +568,24 @@ void BLDCMotor::velocityOpenloop(float target_velocity){
565568
shaft_angle = _normalizeAngle(shaft_angle + target_velocity*Ts);
566569
// for display purposes
567570
shaft_velocity = target_velocity;
571+
572+
// use voltage limit or current limit
573+
float Uq = voltage_limit;
574+
if(_isset(phase_resistance)) Uq = current_limit*phase_resistance;
568575

569576
// set the maximal allowed voltage (voltage_limit) with the necessary angle
570-
setPhaseVoltage(voltage_limit, 0, _electricalAngle(shaft_angle, pole_pairs));
577+
setPhaseVoltage(Uq, 0, _electricalAngle(shaft_angle, pole_pairs));
571578

572579
// save timestamp for next call
573580
open_loop_timestamp = now_us;
581+
582+
return Uq;
574583
}
575584

576585
// Function (iterative) generating open loop movement towards the target angle
577586
// - target_angle - rad
578587
// it uses voltage_limit and velocity_limit variables
579-
void BLDCMotor::angleOpenloop(float target_angle){
588+
float BLDCMotor::angleOpenloop(float target_angle){
580589
// get current timestamp
581590
unsigned long now_us = _micros();
582591
// calculate the sample time from last call
@@ -593,9 +602,16 @@ void BLDCMotor::angleOpenloop(float target_angle){
593602
shaft_angle = target_angle;
594603
shaft_velocity = 0;
595604
}
605+
606+
607+
// use voltage limit or current limit
608+
float Uq = voltage_limit;
609+
if(_isset(phase_resistance)) Uq = current_limit*phase_resistance;
596610
// set the maximal allowed voltage (voltage_limit) with the necessary angle
597-
setPhaseVoltage(voltage_limit, 0, _electricalAngle(shaft_angle, pole_pairs));
611+
setPhaseVoltage(Uq, 0, _electricalAngle(shaft_angle, pole_pairs));
598612

599613
// save timestamp for next call
600614
open_loop_timestamp = now_us;
615+
616+
return Uq;
601617
}

src/BLDCMotor.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,14 @@ class BLDCMotor: public FOCMotor
9696
*
9797
* @param target_velocity - rad/s
9898
*/
99-
void velocityOpenloop(float target_velocity);
99+
float velocityOpenloop(float target_velocity);
100100
/**
101101
* Function (iterative) generating open loop movement towards the target angle
102102
* it uses voltage_limit and velocity_limit variables
103103
*
104104
* @param target_angle - rad
105105
*/
106-
void angleOpenloop(float target_angle);
106+
float angleOpenloop(float target_angle);
107107
// open loop variables
108108
long open_loop_timestamp;
109109
};

0 commit comments

Comments
 (0)