You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
ServoImpl#getPosition incorrectly reversing a scaled servo. #1470
In ServoImpl#getPosition,reverse is called on the unscaled position in getPosition. While in ServoImpl#setPosition, reverse is called on scaled values. This means Servo#getPosition return incorrect values for reversed scaled servos.
Example
Let's say we have a reversed servo scaled from 0 to 0.5 instead of from 0 to 1:
Setting:
setPosition(0.5) -> sets an actual position of 0.25 for the servo.
I think the issue is actually in the setting. and it should be like this:
Setting:
setPosition(0.5) -> SHOULD set an actual position of 0.75 for the servo.
Getting:
ServoController#getServoPosition returns 0.75 (line 178)
reverse reverses the value from 0.75 to 0.25 (line 179)
Range.scale scales the value from 0.25 to 0.5 (line 180)
Range.clip does nothing
Thanks for the quick response. I believe both approaches will have the same effect, however, changing setPosition would break current servos.
Since right now, setPosition(0.5) sets 0.25, but if it's changed to set 0.75, then it will break more current contraptions and people would have to recalibrate their servos. Changing getPosition will break less stuff, but both approaches will fix the issue.
Activity
kevinthegreat1 commentedon Mar 2, 2025
I know you guys don't accept prs, but I'd be happy to submit one if needed.
alan412 commentedon Mar 2, 2025
Thank you for this catch. I have put it as an issue on our internal repo. We'll likely fix it for the off-season release.
alan412 commentedon Mar 2, 2025
Also @kevinthegreat1 , all of the detail was very helpful!!
alan412 commentedon Mar 2, 2025
I think the issue is actually in the setting. and it should be like this:
Setting:
setPosition(0.5) -> SHOULD set an actual position of 0.75 for the servo.
Getting:
ServoController#getServoPosition returns 0.75 (line 178)
reverse reverses the value from 0.75 to 0.25 (line 179)
Range.scale scales the value from 0.25 to 0.5 (line 180)
Range.clip does nothing
@kevinthegreat1 - agree?
kevinthegreat1 commentedon Mar 2, 2025
Thanks for the quick response. I believe both approaches will have the same effect, however, changing
setPositionwould break current servos.Since right now,
setPosition(0.5)sets 0.25, but if it's changed to set 0.75, then it will break more current contraptions and people would have to recalibrate their servos. ChanginggetPositionwill break less stuff, but both approaches will fix the issue.