-
-
Notifications
You must be signed in to change notification settings - Fork 24
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
getCumulativePosition messed up by http.POST #62
Comments
Thanks for the issue, The context: int32_t AS5600::getCumulativePosition()
{
int16_t value = readReg2(AS5600_ANGLE) & 0x0FFF; <<<<<<<<<<< (1)
// whole rotation CW?
// less than half a circle
if ((_lastPosition > 2048) && ( value < (_lastPosition - 2048)))
{
_position = _position + 4096 - _lastPosition + value;
}
// whole rotation CCW?
// less than half a circle
else if ((value > 2048) && ( _lastPosition < (value - 2048)))
{
_position = _position - 4096 - _lastPosition + value;
}
else _position = _position - _lastPosition + value; <<<<<<<<<<< (3)
_lastPosition = value;
return _position;
}
....
uint16_t AS5600::readReg2(uint8_t reg)
{
_error = AS5600_OK;
_wire->beginTransmission(_address);
_wire->write(reg);
if (_wire->endTransmission() != 0)
{
_error = AS5600_ERROR_I2C_READ_2;
return 0; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< (2)
}
uint8_t n = _wire->requestFrom(_address, (uint8_t)2);
if (n != 2)
{
_error = AS5600_ERROR_I2C_READ_3;
return 0; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< (2)
}
uint16_t _data = _wire->read();
_data <<= 8;
_data += _wire->read();
return _data;
}
GetCumulativePosition() does not check if (1) the readReg2() call works or not. No, this is not a feature, so it classifies as a bug ==> need to be fixed. |
GetCumulativePosition() should check _error to catch the incorrect read.
in code this would add one line in the library. int32_t AS5600::getCumulativePosition()
{
int16_t value = readReg2(AS5600_ANGLE) & 0x0FFF;
if (_error != AS5600_OK) return _position;
// whole rotation CW?
// less than half a circle
if ((_lastPosition > 2048) && ( value < (_lastPosition - 2048)))
{
_position = _position + 4096 - _lastPosition + value;
}
// whole rotation CCW?
// less than half a circle
else if ((value > 2048) && ( _lastPosition < (value - 2048)))
{
_position = _position - 4096 - _lastPosition + value;
}
else _position = _position - _lastPosition + value; <<<<<<<<<<< (3)
_lastPosition = value;
return _position;
} |
Can you verify if the proposed patch works for you? |
Hi, thanks for the very quick reply. I tried your fix but it did not help. Best, |
Mmm, Can you add a check for lastError() after your calls to getCumulativePosition() to see if it fails and if so what the error code is. |
I added lastError call . It always return 0. |
So that excludes the scenario above. To be continued. |
FYI, Can you add a print statement in the function to see what values are read from the sensor? int32_t AS5600::getCumulativePosition()
{
int16_t value = readReg2(AS5600_ANGLE) & 0x0FFF;
Serial.println(value); |
Still can't explain the behaviour. Could it be that the wifi signal distorts the sensor? Have you tried to make a plot of raw reads? |
Too fast a conclusion imho, Q1: What data do you send over the HTTP POST? So far I do see problems in the library (except for the read error not handled before). Maybe it is time to post your question on the Arduino forum or so |
Have you read #28 ? |
Created a develop branch + PR for the patch for getCumulativePosition() + some pending things. |
I will try suggestions from #28 and let you know what happens. |
- improve **getCumulativePosition()**, catch I2C error, see #62 - update readme.md (incl reorder future work). - update GitHub actions - minor edits
@ivukotic |
Any new insights? |
@ivukotic |
Hi Rob, |
Good to hear you found a way to work around / solve the issue. Still I can not explain why / what happened that caused the issue in the first place. Thanks |
Hi,
not sure if this is a bug or a feature. I am reading getCumulativePosition from 8 sensors every 100 ms.
After some time, I upload the data using http.POST (ESP Async Web Server). If sensor moved during the upload, getCumulativePosition skips (didn't notice the movement).
Best,
I
The text was updated successfully, but these errors were encountered: