single

package
v0.2.35 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 17, 2023 License: AGPL-3.0 Imports: 14 Imported by: 0

Documentation

Overview

Package single implements a single-wire odometer, such as LM393, as an encoder. This allows the attached motor to determine its relative position. This class of encoders requires a single digital interrupt pin.

This encoder must be connected to a motor (or another component that supports encoders and reports the direction it is moving) in order to record readings. The motor indicates in which direction it is spinning, thus indicating if the encoder should increment or decrement reading value.

Resetting a position must set the position to an int64. A floating point input will be rounded.

Sample configuration:

{
	"pins" : {
		"i": 10
	},
	"board": "pi"
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewSingleEncoder

func NewSingleEncoder(
	ctx context.Context,
	deps registry.Dependencies,
	rawConfig config.Component,
	logger golog.Logger,
) (encoder.Encoder, error)

NewSingleEncoder creates a new Encoder.

Types

type AttrConfig

type AttrConfig struct {
	Pins      Pin    `json:"pins"`
	BoardName string `json:"board"`
}

AttrConfig describes the configuration of a single encoder.

func (*AttrConfig) Validate

func (cfg *AttrConfig) Validate(path string) ([]string, error)

Validate ensures all parts of the config are valid.

type DirectionAware

type DirectionAware interface {
	DirectionMoving() int64
}

DirectionAware lets you ask what direction something is moving. Only used for Encoder 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 struct {
	generic.Unimplemented

	I board.DigitalInterrupt

	CancelCtx context.Context
	// contains filtered or unexported fields
}

Encoder keeps track of a motor position using a rotary encoder.s.

func (*Encoder) AttachDirectionalAwareness

func (e *Encoder) AttachDirectionalAwareness(da DirectionAware)

AttachDirectionalAwareness to pre-created encoder.

func (*Encoder) Close

func (e *Encoder) Close() error

Close shuts down the Encoder.

func (*Encoder) GetPosition

func (e *Encoder) GetPosition(
	ctx context.Context,
	positionType *encoder.PositionType,
	extra map[string]interface{},
) (float64, encoder.PositionType, error)

GetPosition returns the current position in terms of ticks or degrees, and whether it is a relative or absolute position.

func (*Encoder) GetProperties

func (e *Encoder) GetProperties(ctx context.Context, extra map[string]interface{}) (map[encoder.Feature]bool, error)

GetProperties returns a list of all the position types that are supported by a given encoder.

func (*Encoder) ResetPosition

func (e *Encoder) ResetPosition(ctx context.Context, extra map[string]interface{}) error

ResetPosition sets the current position of the motor (adjusted by a given offset).

func (*Encoder) Start

func (e *Encoder) Start(ctx context.Context)

Start starts the Encoder background thread.

type Pin

type Pin struct {
	I string `json:"i"`
}

Pin describes the configuration of Pins for a Single encoder.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL