Documentation ¶
Overview ¶
Package encoder implements the encoder component
Index ¶
- Constants
- Variables
- func DependencyTypeError(name string, actual interface{}) error
- func Named(name string) resource.Name
- func NamesFromRobot(r robot.Robot) []string
- func NewUnimplementedInterfaceError(actual interface{}) error
- func ValidateIntegerOffset(offset float64) error
- func WrapWithReconfigurable(r interface{}, name resource.Name) (resource.Reconfigurable, error)
- type AS5048
- type AS5048Config
- type DirectionAware
- type Encoder
- type I2CAttrConfig
- type IncrementalConfig
- type IncrementalEncoder
- func (e *IncrementalEncoder) Close() error
- func (e *IncrementalEncoder) RawPosition() int64
- func (e *IncrementalEncoder) Reset(ctx context.Context, offset float64, extra map[string]interface{}) error
- func (e *IncrementalEncoder) Start(ctx context.Context)
- func (e *IncrementalEncoder) TicksCount(ctx context.Context, extra map[string]interface{}) (float64, error)
- type IncrementalPins
- type SingleEncoder
- func (e *SingleEncoder) AttachDirectionalAwareness(da DirectionAware)
- func (e *SingleEncoder) Close() error
- func (e *SingleEncoder) Reset(ctx context.Context, offset float64, extra map[string]interface{}) error
- func (e *SingleEncoder) Start(ctx context.Context)
- func (e *SingleEncoder) TicksCount(ctx context.Context, extra map[string]interface{}) (float64, error)
- type SingleWireConfig
- type SingleWirePin
- type Ticks
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 DependencyTypeError ¶
DependencyTypeError is used when a resource doesn't implement the expected interface.
func NamesFromRobot ¶
NamesFromRobot is a helper for getting all encoder names from the given Robot.
func NewUnimplementedInterfaceError ¶
func NewUnimplementedInterfaceError(actual interface{}) error
NewUnimplementedInterfaceError is used when there is a failed interface check.
func ValidateIntegerOffset ¶ added in v0.2.11
ValidateIntegerOffset returns an error if a non-integral value for offset is passed to Reset for an incremental encoder (these encoders count based on square-wave pulses and so cannot be supplied an offset that is not an integer).
func WrapWithReconfigurable ¶
func WrapWithReconfigurable(r interface{}, name resource.Name) (resource.Reconfigurable, error)
WrapWithReconfigurable converts a regular Encoder implementation to a reconfigurableEncoder. If encoder is already a reconfigurableEncoder, then nothing is done.
Types ¶
type AS5048 ¶ added in v0.2.11
type AS5048 struct { generic.Unimplemented // contains filtered or unexported fields }
AS5048 is a struct representing an instance of a hardware unit in AM5's AS5048 series of Hall-effect encoders.
func (*AS5048) Close ¶ added in v0.2.11
func (enc *AS5048) Close()
Close stops the position loop of the encoder when the component is closed.
func (*AS5048) Reset ¶ added in v0.2.11
func (enc *AS5048) Reset( ctx context.Context, offset float64, extra map[string]interface{}, ) error
Reset sets the current position measured by the encoder to be considered its new zero position. If the offset provided is not 0.0, it also sets the positionOffset attribute and adjusts all future recorded positions by that offset (until the function is called again).
func (*AS5048) TicksCount ¶ added in v0.2.11
func (enc *AS5048) TicksCount( ctx context.Context, extra map[string]interface{}, ) (float64, error)
TicksCount returns the total number of rotations detected by the encoder (rather than a number of pulse state transitions) because this encoder is absolute and not incremental. As a result a user MUST set ticks_per_rotation on the config of the corresponding motor to 1. Any other value will result in completely incorrect position measurements by the motor.
type AS5048Config ¶ added in v0.2.11
type AS5048Config struct { BoardName string `json:"board"` // We include connection type here in anticipation for // future SPI support ConnectionType string `json:"connection_type"` *I2CAttrConfig `json:"i2c_attributes,omitempty"` }
AS5048Config contains the connection information for configuring an AS5048 encoder.
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 { // TicksCount returns number of ticks since last zeroing TicksCount(ctx context.Context, extra map[string]interface{}) (float64, 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 float64, 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 I2CAttrConfig ¶ added in v0.2.13
I2CAttrConfig stores the configuration information for I2C connection.
func (*I2CAttrConfig) ValidateI2C ¶ added in v0.2.13
func (cfg *I2CAttrConfig) ValidateI2C(path string) error
ValidateI2C ensures all parts of the config are valid.
type IncrementalConfig ¶
type IncrementalConfig struct { Pins IncrementalPins `json:"pins"` BoardName string `json:"board"` }
IncrementalConfig describes the configuration of a quadrature encoder.
type IncrementalEncoder ¶
type IncrementalEncoder struct {
A, B board.DigitalInterrupt
CancelCtx context.Context
generic.Unimplemented
// contains filtered or unexported fields
}
IncrementalEncoder keeps track of a motor position using a rotary incremental encoder.
func NewIncrementalEncoder ¶
func NewIncrementalEncoder( ctx context.Context, deps registry.Dependencies, cfg config.Component, logger golog.Logger, ) (*IncrementalEncoder, error)
NewIncrementalEncoder creates a new IncrementalEncoder.
func (*IncrementalEncoder) Close ¶
func (e *IncrementalEncoder) Close() error
Close shuts down the IncrementalEncoder.
func (*IncrementalEncoder) RawPosition ¶
func (e *IncrementalEncoder) RawPosition() int64
RawPosition returns the raw position of the encoder.
func (*IncrementalEncoder) Reset ¶
func (e *IncrementalEncoder) Reset(ctx context.Context, offset float64, 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 (*IncrementalEncoder) Start ¶
func (e *IncrementalEncoder) Start(ctx context.Context)
Start starts the IncrementalEncoder background thread.
func (*IncrementalEncoder) TicksCount ¶
func (e *IncrementalEncoder) TicksCount(ctx context.Context, extra map[string]interface{}) (float64, error)
TicksCount returns number of ticks since last zeroing.
type IncrementalPins ¶
IncrementalPins describes the configuration of Pins for a quadrature 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 encoder.
func NewSingleEncoder ¶
func NewSingleEncoder( ctx context.Context, deps registry.Dependencies, cfg 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) Reset ¶
func (e *SingleEncoder) Reset(ctx context.Context, offset float64, 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.
func (*SingleEncoder) TicksCount ¶
func (e *SingleEncoder) TicksCount(ctx context.Context, extra map[string]interface{}) (float64, error)
TicksCount returns the current position.
type SingleWireConfig ¶
type SingleWireConfig struct { Pins SingleWirePin `json:"pins"` BoardName string `json:"board"` }
SingleWireConfig describes the configuration of a single encoder.
type SingleWirePin ¶
type SingleWirePin struct {
I string `json:"i"`
}
SingleWirePin describes the configuration of Pins for a Single encoder.