Documentation ¶
Overview ¶
Package encoder implements the encoder component
Index ¶
- Constants
- Variables
- func Named(name string) resource.Name
- func NamesFromRobot(r robot.Robot) []string
- func WrapWithReconfigurable(r interface{}) (resource.Reconfigurable, error)
- type DirectionAware
- type Encoder
- type HallConfig
- type HallEncoder
- func (e *HallEncoder) Close() error
- func (e *HallEncoder) GetTicksCount(ctx context.Context, extra map[string]interface{}) (int64, error)
- func (e *HallEncoder) RawPosition() int64
- func (e *HallEncoder) Reset(ctx context.Context, offset int64, extra map[string]interface{}) error
- func (e *HallEncoder) Start(ctx context.Context)
- type HallPins
- type SingleConfig
- type SingleEncoder
- func (e *SingleEncoder) AttachDirectionalAwareness(da DirectionAware)
- func (e *SingleEncoder) Close() error
- func (e *SingleEncoder) GetTicksCount(ctx context.Context, extra map[string]interface{}) (int64, error)
- func (e *SingleEncoder) Reset(ctx context.Context, offset int64, extra map[string]interface{}) error
- func (e *SingleEncoder) Start(ctx context.Context)
- type SinglePins
Constants ¶
const SubtypeName = resource.SubtypeName("encoder")
SubtypeName is a constant that identifies the component resource subtype string "encoder".
Variables ¶
var Subtype = resource.NewSubtype( resource.ResourceNamespaceRDK, resource.ResourceTypeComponent, SubtypeName, )
Subtype is a constant that identifies the component resource subtype.
Functions ¶
func NamesFromRobot ¶
NamesFromRobot is a helper for getting all encoder names from the given Robot.
func WrapWithReconfigurable ¶
func WrapWithReconfigurable(r interface{}) (resource.Reconfigurable, error)
WrapWithReconfigurable converts a regular Encoder implementation to a reconfigurableEncoder. If encoder is already a reconfigurableEncoder, then nothing is done.
Types ¶
type DirectionAware ¶
type DirectionAware interface {
DirectionMoving() int64
}
DirectionAware lets you ask what direction something is moving. Only used for SingleEncoder for now, unclear future. DirectionMoving returns -1 if the motor is currently turning backwards, 1 if forwards and 0 if off.
type Encoder ¶
type Encoder interface { // GetTicksCount returns number of ticks since last zeroing GetTicksCount(ctx context.Context, extra map[string]interface{}) (int64, error) // Reset sets the current position of the motor (adjusted by a given offset) // to be its new zero position. Reset(ctx context.Context, offset int64, extra map[string]interface{}) error generic.Generic }
A Encoder turns a position into a signal.
func FromDependencies ¶
func FromDependencies(deps registry.Dependencies, name string) (Encoder, error)
FromDependencies is a helper for getting the named encoder from a collection of dependencies.
type HallConfig ¶
HallConfig describes the configuration of a Hall encoder.
type HallEncoder ¶
type HallEncoder struct {
A, B board.DigitalInterrupt
CancelCtx context.Context
generic.Unimplemented
// contains filtered or unexported fields
}
HallEncoder keeps track of a motor position using a rotary hall encoder.
func NewHallEncoder ¶
func NewHallEncoder(ctx context.Context, deps registry.Dependencies, config config.Component, logger golog.Logger) (*HallEncoder, error)
NewHallEncoder creates a new HallEncoder.
func (*HallEncoder) GetTicksCount ¶
func (e *HallEncoder) GetTicksCount(ctx context.Context, extra map[string]interface{}) (int64, error)
GetTicksCount returns number of ticks since last zeroing.
func (*HallEncoder) RawPosition ¶
func (e *HallEncoder) RawPosition() int64
RawPosition returns the raw position of the encoder.
func (*HallEncoder) Reset ¶
Reset sets the current position of the motor (adjusted by a given offset) to be its new zero position..
func (*HallEncoder) Start ¶
func (e *HallEncoder) Start(ctx context.Context)
Start starts the HallEncoder background thread.
type SingleConfig ¶
type SingleConfig struct { Pins SinglePins `json:"pins"` BoardName string `json:"board"` }
SingleConfig describes the configuration of a single encoder.
type SingleEncoder ¶
type SingleEncoder struct { generic.Unimplemented I board.DigitalInterrupt CancelCtx context.Context // contains filtered or unexported fields }
SingleEncoder keeps track of a motor position using a rotary hall encoder.
func NewSingleEncoder ¶
func NewSingleEncoder( ctx context.Context, deps registry.Dependencies, config config.Component, logger golog.Logger, ) (*SingleEncoder, error)
NewSingleEncoder creates a new SingleEncoder.
func (*SingleEncoder) AttachDirectionalAwareness ¶
func (e *SingleEncoder) AttachDirectionalAwareness(da DirectionAware)
AttachDirectionalAwareness to pre-created encoder.
func (*SingleEncoder) Close ¶
func (e *SingleEncoder) Close() error
Close shuts down the SingleEncoder.
func (*SingleEncoder) GetTicksCount ¶
func (e *SingleEncoder) GetTicksCount(ctx context.Context, extra map[string]interface{}) (int64, error)
GetTicksCount returns the current position.
func (*SingleEncoder) Reset ¶
func (e *SingleEncoder) Reset(ctx context.Context, offset int64, extra map[string]interface{}) error
Reset sets the current position of the motor (adjusted by a given offset) to be its new zero position.
func (*SingleEncoder) Start ¶
func (e *SingleEncoder) Start(ctx context.Context)
Start starts the SingleEncoder background thread.
type SinglePins ¶
type SinglePins struct {
I string `json:"i"`
}
SinglePins describes the configuration of Pins for a Single encoder.