Skip to content

Commit 3c9371e

Browse files
authored
Merge pull request #99 from metanav/patch-1
Fix: SmartServoClass::getPosition return value
2 parents 32feff2 + e1e6612 commit 3c9371e

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

Diff for: src/lib/motors/SmartServo.cpp

+12-1
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,18 @@ float SmartServoClass::getPosition(uint8_t const id)
235235
return -1.0f;
236236

237237
mbed::ScopedLock<rtos::Mutex> lock(_mtx);
238-
return positionToAngle(readWordCmd(id, REG(SmartServoRegister::POSITION_H)));
238+
int position = readWordCmd(id, REG(SmartServoRegister::POSITION_H));
239+
240+
// retry one more time
241+
if (position < 0) {
242+
delay(1);
243+
position = readWordCmd(id, REG(SmartServoRegister::POSITION_H));
244+
}
245+
246+
if (position < 0)
247+
return -1.0f;
248+
249+
return positionToAngle(position);
239250
}
240251

241252
void SmartServoClass::center(uint8_t const id, uint16_t const position)

0 commit comments

Comments
 (0)