Skip to content

SmartServoClass::getPosition returns wrong value #97

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
metanav opened this issue Feb 21, 2023 · 0 comments
Closed

SmartServoClass::getPosition returns wrong value #97

metanav opened this issue Feb 21, 2023 · 0 comments
Labels
conclusion: resolved Issue was resolved topic: code Related to content of the project itself type: imperfection Perceived defect in any part of project

Comments

@metanav
Copy link
Contributor

metanav commented Feb 21, 2023

The SmartServoClass::getPosition method always returns 5160.88 when readWordCmd returns -1. The positionToAngle method converts -1 to 65535. Consequently, this sets limited_runtime_sec to a large value of around 5000/angular_velocity seconds. This is a bug!

float SmartServoClass::getPosition(uint8_t const id)
{
  if (!isValidId(id))
    return -1.0f;

  mbed::ScopedLock<rtos::Mutex> lock(_mtx);
  return positionToAngle(readWordCmd(id, REG(SmartServoRegister::POSITION_H)));
}
int SmartServoClass::readWordCmd(uint8_t const id, uint8_t const address) {
  if (readBuffer(id,address,2) == 0) {
    return (_rxBuf[5]<<8)|_rxBuf[6];
  }
  return -1;
}
inline float  positionToAngle(uint16_t const position) {
   return (MAX_ANGLE*position)/MAX_POSITION; 
}

@metanav metanav changed the title SmartServoClass::getPosition return wrong value SmartServoClass::getPosition returns wrong value Feb 21, 2023
@per1234 per1234 added type: imperfection Perceived defect in any part of project topic: code Related to content of the project itself labels Feb 21, 2023
metanav added a commit to metanav/Arduino_Braccio_plusplus that referenced this issue Feb 22, 2023
@metanav metanav closed this as completed Feb 22, 2023
@per1234 per1234 added the conclusion: resolved Issue was resolved label Feb 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
conclusion: resolved Issue was resolved topic: code Related to content of the project itself type: imperfection Perceived defect in any part of project
Projects
None yet
Development

No branches or pull requests

2 participants