File tree Expand file tree Collapse file tree 1 file changed +5
-5
lines changed Expand file tree Collapse file tree 1 file changed +5
-5
lines changed Original file line number Diff line number Diff line change @@ -179,6 +179,11 @@ func (h *DefaultHandler) GetAngle() uint16 {
179179//
180180// angle: The angle to set the servo motor to, must be between 0 and the actuation range
181181func (h * DefaultHandler ) SetAngle (angle uint16 ) tinygoerrors.ErrorCode {
182+ // Check if the direction is inverted
183+ if h .isDirectionInverted {
184+ angle = h .actuationRange - angle
185+ }
186+
182187 // Check if the angle is within the valid range
183188 if angle < h .centerAngle - h .leftLimitAngle || angle > h .centerAngle + h .rightLimitAngle {
184189 return ErrorCodeServoAngleOutOfRange
@@ -189,11 +194,6 @@ func (h *DefaultHandler) SetAngle(angle uint16) tinygoerrors.ErrorCode {
189194 return tinygoerrors .ErrorCodeNil
190195 }
191196
192- // Check if the direction is inverted
193- if h .isDirectionInverted {
194- angle = h .rightLimitAngle - (angle - h .leftLimitAngle )
195- }
196-
197197 // Update the current angle
198198 h .angle = angle
199199
You can’t perform that action at this time.
0 commit comments