Skip to content

Commit 1bc38c5

Browse files
authored
Fix: SmartServoClass::getPosition return value
This PR fixes the issue arduino-libraries#97.
1 parent 32feff2 commit 1bc38c5

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

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)