Skip to content

Commit 8ff4630

Browse files
committed
FIX read sensor after the openloop check
1 parent c9ff03e commit 8ff4630

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

src/BLDCMotor.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -247,14 +247,13 @@ int BLDCMotor::absoluteZeroSearch() {
247247
// Iterative function looping FOC algorithm, setting Uq on the Motor
248248
// The faster it can be run the better
249249
void BLDCMotor::loopFOC() {
250-
250+
// if open-loop do nothing
251+
if( controller==MotionControlType::angle_openloop || controller==MotionControlType::velocity_openloop ) return;
251252
// shaft angle
252253
shaft_angle = shaftAngle(); // read value even if motor is disabled to keep the monitoring updated
253254

254255
// if disabled do nothing
255256
if(!enabled) return;
256-
// if open-loop do nothing
257-
if( controller==MotionControlType::angle_openloop || controller==MotionControlType::velocity_openloop ) return;
258257

259258
// electrical angle - need shaftAngle to be called first
260259
electrical_angle = electricalAngle();

src/StepperMotor.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -216,13 +216,14 @@ int StepperMotor::absoluteZeroSearch() {
216216
// Iterative function looping FOC algorithm, setting Uq on the Motor
217217
// The faster it can be run the better
218218
void StepperMotor::loopFOC() {
219-
// if disabled do nothing
220-
if(!enabled) return;
221219
// if open-loop do nothing
222220
if( controller==MotionControlType::angle_openloop || controller==MotionControlType::velocity_openloop ) return;
223-
224221
// shaft angle
225222
shaft_angle = shaftAngle();
223+
224+
// if disabled do nothing
225+
if(!enabled) return;
226+
226227
electrical_angle = electricalAngle();
227228

228229
// set the phase voltage - FOC heart function :)
@@ -235,15 +236,15 @@ void StepperMotor::loopFOC() {
235236
// - needs to be called iteratively it is asynchronous function
236237
// - if target is not set it uses motor.target value
237238
void StepperMotor::move(float new_target) {
239+
// get angular velocity
240+
shaft_velocity = shaftVelocity();
238241
// if disabled do nothing
239242
if(!enabled) return;
240243
// downsampling (optional)
241244
if(motion_cnt++ < motion_downsample) return;
242245
motion_cnt = 0;
243246
// set internal target variable
244247
if(_isset(new_target) ) target = new_target;
245-
// get angular velocity
246-
shaft_velocity = shaftVelocity();
247248
// choose control loop
248249
switch (controller) {
249250
case MotionControlType::torque:

0 commit comments

Comments
 (0)