@@ -186,7 +186,6 @@ int BLDCMotor::alignSensor() {
186
186
if ( fabs (moved*pole_pairs - _2PI) > 0.5 ) { // 0.5 is arbitrary number it can be lower or higher!
187
187
if (monitor_port) monitor_port->print (F (" fail - estimated pp:" ));
188
188
if (monitor_port) monitor_port->println (_2PI/moved,4 );
189
- return 0 ; // failed calibration
190
189
}else if (monitor_port) monitor_port->println (F (" OK!" ));
191
190
192
191
}else if (monitor_port) monitor_port->println (F (" MOT: Skip dir calib." ));
@@ -216,16 +215,22 @@ int BLDCMotor::absoluteZeroSearch() {
216
215
217
216
if (monitor_port) monitor_port->println (F (" MOT: Index search..." ));
218
217
// search the absolute zero with small velocity
219
- float limit = velocity_limit;
218
+ float limit_vel = velocity_limit;
219
+ float limit_volt = voltage_limit;
220
220
velocity_limit = velocity_index_search;
221
+ voltage_limit = voltage_sensor_align;
221
222
shaft_angle = 0 ;
222
223
while (sensor->needsSearch () && shaft_angle < _2PI){
223
224
angleOpenloop (1.5 *_2PI);
225
+ // call important for some sensors not to loose count
226
+ // not needed for the search
227
+ sensor->getAngle ();
224
228
}
225
229
// disable motor
226
230
setPhaseVoltage (0 , 0 , 0 );
227
231
// reinit the limits
228
- velocity_limit = limit;
232
+ velocity_limit = limit_vel;
233
+ voltage_limit = limit_volt;
229
234
// check if the zero found
230
235
if (monitor_port){
231
236
if (sensor->needsSearch ()) monitor_port->println (F (" MOT: Error: Not found!" ));
@@ -337,15 +342,13 @@ void BLDCMotor::move(float new_target) {
337
342
case MotionControlType::velocity_openloop:
338
343
// velocity control in open loop
339
344
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
342
346
voltage.d = 0 ;
343
347
break ;
344
348
case MotionControlType::angle_openloop:
345
349
// angle control in open loop
346
350
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
349
352
voltage.d = 0 ;
350
353
break ;
351
354
}
@@ -553,7 +556,7 @@ void BLDCMotor::setPhaseVoltage(float Uq, float Ud, float angle_el) {
553
556
// Function (iterative) generating open loop movement for target velocity
554
557
// - target_velocity - rad/s
555
558
// it uses voltage_limit variable
556
- void BLDCMotor::velocityOpenloop (float target_velocity){
559
+ float BLDCMotor::velocityOpenloop (float target_velocity){
557
560
// get current timestamp
558
561
unsigned long now_us = _micros ();
559
562
// calculate the sample time from last call
@@ -565,18 +568,24 @@ void BLDCMotor::velocityOpenloop(float target_velocity){
565
568
shaft_angle = _normalizeAngle (shaft_angle + target_velocity*Ts);
566
569
// for display purposes
567
570
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;
568
575
569
576
// 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));
571
578
572
579
// save timestamp for next call
573
580
open_loop_timestamp = now_us;
581
+
582
+ return Uq;
574
583
}
575
584
576
585
// Function (iterative) generating open loop movement towards the target angle
577
586
// - target_angle - rad
578
587
// it uses voltage_limit and velocity_limit variables
579
- void BLDCMotor::angleOpenloop (float target_angle){
588
+ float BLDCMotor::angleOpenloop (float target_angle){
580
589
// get current timestamp
581
590
unsigned long now_us = _micros ();
582
591
// calculate the sample time from last call
@@ -593,9 +602,16 @@ void BLDCMotor::angleOpenloop(float target_angle){
593
602
shaft_angle = target_angle;
594
603
shaft_velocity = 0 ;
595
604
}
605
+
606
+
607
+ // use voltage limit or current limit
608
+ float Uq = voltage_limit;
609
+ if (_isset (phase_resistance)) Uq = current_limit*phase_resistance;
596
610
// 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));
598
612
599
613
// save timestamp for next call
600
614
open_loop_timestamp = now_us;
615
+
616
+ return Uq;
601
617
}
0 commit comments