Documentation
¶
Index ¶
- Constants
- type DefaultHandler
- func (h *DefaultHandler) GetAngle() uint16
- func (h *DefaultHandler) IsAngleCentered() bool
- func (h *DefaultHandler) SetAngle(angle uint16) tinygoerrors.ErrorCode
- func (h *DefaultHandler) SetAngleRelativeToCenter(relativeAngle int16) tinygoerrors.ErrorCode
- func (h *DefaultHandler) SetAngleToCenter() tinygoerrors.ErrorCode
- func (h *DefaultHandler) SetAngleToLeft(angle uint16) tinygoerrors.ErrorCode
- func (h *DefaultHandler) SetAngleToRight(angle uint16) tinygoerrors.ErrorCode
- func (h *DefaultHandler) SetDirectionToCenter() tinygoerrors.ErrorCode
- func (h *DefaultHandler) SetDirectionToLeft(angle uint16) tinygoerrors.ErrorCode
- func (h *DefaultHandler) SetDirectionToRight(angle uint16) tinygoerrors.ErrorCode
- type Handler
Constants ¶
const ( // LeftLimitAngle is the angle that represents the left limit position of the servo motors. LeftLimitAngle uint16 = 0 // RightLimitAngle is the angle that represents the right limit position of the servo motors. RightLimitAngle uint16 = 180 )
const ( ErrorCodeServoFailedToConfigurePWM tinygoerrors.ErrorCode = tinygoerrors.ErrorCode(iota + ErrorCodeServoStartNumber) ErrorCodeServoFailedToInitializeServo ErrorCodeServoAngleOutOfRange ErrorCodeServoAngleBelowMinPulseWidth ErrorCodeServoAngleAboveMaxPulseWidth ErrorCodeServoFailedToSetServoAngle ErrorCodeServoNilHandler )
const ( // ErrorCodeServoStartNumber is the starting number for servo-related error codes. ErrorCodeServoStartNumber uint16 = 5230 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DefaultHandler ¶
type DefaultHandler struct {
// contains filtered or unexported fields
}
DefaultHandler is the default implementation of the Servo interface
func NewDefaultHandler ¶
func NewDefaultHandler( pwm tinygodriversservo.PWM, pin machine.Pin, afterSetAngleFunc func(angle uint16), isMovementEnabled func() bool, frequency uint16, minPulseWidth uint16, maxPulseWidth uint16, centerAngle uint16, maxAngle uint16, isDirectionInverted bool, logger tinygologger.Logger, ) (*DefaultHandler, tinygoerrors.ErrorCode)
NewDefaultHandler creates a new instance of DefaultHandler
Parameters:
pwm: The PWM interface to control the servo pin: The pin connected to the servo afterSetAngleFunc: A callback function to be called after setting the angle isMovementEnabled: A function to check if movement is enabled frequency: The frequency of the PWM signal minPulseWidth: The minimum pulse width for the servo motor maxPulseWidth: The maximum pulse width for the servo motor centerAngle: The center angle of the servo motor maxAngle: The maximum angle the servo can move from the center isDirectionInverted: Whether the direction of the servo motor is inverted logger: The logger instance for logging messages
Returns:
An instance of DefaultHandler and an error if any occurred during initialization
func (*DefaultHandler) GetAngle ¶
func (h *DefaultHandler) GetAngle() uint16
GetAngle returns the current angle of the servo motor
Returns:
The current angle of the servo motor
func (*DefaultHandler) IsAngleCentered ¶
func (h *DefaultHandler) IsAngleCentered() bool
IsAngleCentered checks if the servo motor angle is centered
Returns:
True if the servo motor is centered, false otherwise
func (*DefaultHandler) SetAngle ¶
func (h *DefaultHandler) SetAngle(angle uint16) tinygoerrors.ErrorCode
SetAngle sets the angle of the servo motor
Parameters:
angle: The angle to set the servo motor to, must be between 0 and the actuation range
func (*DefaultHandler) SetAngleRelativeToCenter ¶
func (h *DefaultHandler) SetAngleRelativeToCenter(relativeAngle int16) tinygoerrors.ErrorCode
SetAngleRelativeToCenter sets the angle of the servo motor relative to the center position
Parameters:
relativeAngle: The relative angle value between -90 and 90 degrees
Returns:
An error if the relative angle is not within the left and right limits
func (*DefaultHandler) SetAngleToCenter ¶
func (h *DefaultHandler) SetAngleToCenter() tinygoerrors.ErrorCode
SetAngleToCenter centers the servo motor to the middle position
Returns:
An error if the servo motor could not be centered
func (*DefaultHandler) SetAngleToLeft ¶
func (h *DefaultHandler) SetAngleToLeft(angle uint16) tinygoerrors.ErrorCode
SetAngleToLeft sets the servo motor to the left by a specified angle
Parameters:
angle: The angle value to move the servo to the left, must be between 0 and the left limit
Returns:
An error if the angle is not within the left limit
func (*DefaultHandler) SetAngleToRight ¶
func (h *DefaultHandler) SetAngleToRight(angle uint16) tinygoerrors.ErrorCode
SetAngleToRight sets the servo motor to the right by a specified angle
Parameters:
angle: The angle value to move the servo to the right, must be between 0 and the right limit
Returns:
An error if the angle is not within the right limit
func (*DefaultHandler) SetDirectionToCenter ¶
func (h *DefaultHandler) SetDirectionToCenter() tinygoerrors.ErrorCode
SetDirectionToCenter sets the direction to center
func (*DefaultHandler) SetDirectionToLeft ¶
func (h *DefaultHandler) SetDirectionToLeft(angle uint16) tinygoerrors.ErrorCode
SetDirectionToLeft sets the direction to left
Parameters:
angle: The angle value to move the servo to the right, must be between 0 and the right limit
Returns:
An error if the angle is not within the right limit
func (*DefaultHandler) SetDirectionToRight ¶
func (h *DefaultHandler) SetDirectionToRight(angle uint16) tinygoerrors.ErrorCode
SetDirectionToRight sets the direction to right
Parameters:
angle: The angle value to move the servo to the left, must be between 0 and the left limit
Returns:
An error if the angle is not within the left limit
type Handler ¶
type Handler interface {
SetAngle(angle uint16) tinygoerrors.ErrorCode
GetAngle() uint16
SetAngleRelativeToCenter(relativeAngle int16) tinygoerrors.ErrorCode
IsAngleCentered() bool
SetAngleToCenter() tinygoerrors.ErrorCode
SetAngleToRight(angle uint16) tinygoerrors.ErrorCode
SetAngleToLeft(angle uint16) tinygoerrors.ErrorCode
SetDirectionToCenter() tinygoerrors.ErrorCode
SetDirectionToRight(angle uint16) tinygoerrors.ErrorCode
SetDirectionToLeft(angle uint16) tinygoerrors.ErrorCode
}
Handler is the interface to handle servo operations