Skip to content

Commit ebd4906

Browse files
committed
move the sensor calls to before the enable checks in move and loopFOC
this enables two things: 1. you can still see the sensors change and update in SimpleFOCStudio even if you disable the motor. This is useful to determine sensor accuracy etc. 2. you previously ran the risk of losing track of full rotations if the motor was (e.g. manually) moved while disabled. With this change we always track the sensor values and keep track of all rotations.
1 parent c43f1e3 commit ebd4906

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/BLDCMotor.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -244,13 +244,15 @@ int BLDCMotor::absoluteZeroSearch() {
244244
// Iterative function looping FOC algorithm, setting Uq on the Motor
245245
// The faster it can be run the better
246246
void BLDCMotor::loopFOC() {
247+
248+
// shaft angle
249+
shaft_angle = shaftAngle(); // read value even if motor is disabled to keep the monitoring updated
250+
247251
// if disabled do nothing
248252
if(!enabled) return;
249253
// if open-loop do nothing
250254
if( controller==MotionControlType::angle_openloop || controller==MotionControlType::velocity_openloop ) return;
251255

252-
// shaft angle
253-
shaft_angle = shaftAngle();
254256
// electrical angle - need shaftAngle to be called first
255257
electrical_angle = electricalAngle();
256258

@@ -295,15 +297,17 @@ void BLDCMotor::loopFOC() {
295297
// - needs to be called iteratively it is asynchronous function
296298
// - if target is not set it uses motor.target value
297299
void BLDCMotor::move(float new_target) {
300+
301+
// get angular velocity
302+
shaft_velocity = shaftVelocity(); // read value even if motor is disabled to keep the monitoring updated
303+
298304
// if disabled do nothing
299305
if(!enabled) return;
300306
// downsampling (optional)
301307
if(motion_cnt++ < motion_downsample) return;
302308
motion_cnt = 0;
303309
// set internal target variable
304310
if(_isset(new_target)) target = new_target;
305-
// get angular velocity
306-
shaft_velocity = shaftVelocity();
307311

308312
switch (controller) {
309313
case MotionControlType::torque:

0 commit comments

Comments
 (0)