encoder

package
v0.43.0 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2024 License: AGPL-3.0 Imports: 13 Imported by: 0

Documentation

Overview

Package encoder implements the encoder component. For more information, see the encoder component docs.

Index

Constants

View Source
const SubtypeName = "encoder"

SubtypeName is a constant that identifies the component resource API string "encoder".

Variables

View Source
var API = resource.APINamespaceRDK.WithComponentType(SubtypeName)

API is a variable that identifies the component resource API.

Functions

func Named

func Named(name string) resource.Name

Named is a helper for getting the named Encoder's typed resource name.

func NamesFromRobot

func NamesFromRobot(r robot.Robot) []string

NamesFromRobot is a helper for getting all encoder names from the given Robot.

func NewEncodedMotorPositionTypeUnsupportedError added in v0.2.36

func NewEncodedMotorPositionTypeUnsupportedError(props Properties) error

NewEncodedMotorPositionTypeUnsupportedError returns a standard error for when an encoded motor tries to use an encoder that doesn't support Ticks.

func NewPositionTypeUnsupportedError added in v0.2.36

func NewPositionTypeUnsupportedError(positionType PositionType) error

NewPositionTypeUnsupportedError returns a standard error for when an encoder does not support the given PositionType.

func NewRPCServiceServer added in v0.2.36

func NewRPCServiceServer(coll resource.APIResourceCollection[Encoder]) interface{}

NewRPCServiceServer constructs an Encoder gRPC service serviceServer.

func PropertiesToProtoResponse added in v0.6.0

func PropertiesToProtoResponse(
	props Properties,
) (*pb.GetPropertiesResponse, error)

PropertiesToProtoResponse takes a properties struct and converts it to a GetPropertiesResponse.

func ToProtoPositionType added in v0.2.34

func ToProtoPositionType(positionType PositionType) pb.PositionType

ToProtoPositionType takes a map of PositionType-to-int (indicating the PositionType) and converts it to a GetPositionResponse.

Types

type Encoder

type Encoder interface {
	resource.Resource

	// Position returns the current position in terms of ticks or degrees, and whether it is a relative or absolute position.
	Position(ctx context.Context, positionType PositionType, extra map[string]interface{}) (float64, PositionType, error)

	// ResetPosition sets the current position of the motor to be its new zero position.
	ResetPosition(ctx context.Context, extra map[string]interface{}) error

	// Properties returns a list of all the position types that are supported by a given encoder.
	Properties(ctx context.Context, extra map[string]interface{}) (Properties, error)
}

A Encoder turns a position into a signal. For more information, see the encoder component docs.

Position example:

myEncoder, err := encoder.FromRobot(machine, "my_encoder")
if err != nil {
  logger.Fatalf("cannot get encoder: %v", err)
}

// Get the position of the encoder in ticks
position, posType, err := myEncoder.Position(context.Background(), encoder.PositionTypeTicks, nil)

ResetPosition example:

myEncoder, err := encoder.FromRobot(machine, "my_encoder")
if err != nil {
  logger.Fatalf("cannot get encoder: %v", err)
}

err = myEncoder.ResetPosition(context.Background(), nil)

Properties example:

myEncoder, err := encoder.FromRobot(machine, "my_encoder")

// Get whether the encoder returns position in ticks or degrees.
properties, err := myEncoder.Properties(context.Background(), nil)

func FromDependencies

func FromDependencies(deps resource.Dependencies, name string) (Encoder, error)

FromDependencies is a helper for getting the named encoder from a collection of dependencies.

func FromRobot

func FromRobot(r robot.Robot, name string) (Encoder, error)

FromRobot is a helper for getting the named encoder from the given Robot.

func NewClientFromConn added in v0.2.34

func NewClientFromConn(
	ctx context.Context,
	conn rpc.ClientConn,
	remoteName string,
	name resource.Name,
	logger logging.Logger,
) (Encoder, error)

NewClientFromConn constructs a new Client from connection passed in.

type PositionType added in v0.2.34

type PositionType byte

PositionType is an enum representing the encoder's position.

const (
	PositionTypeUnspecified PositionType = iota
	// PositionTypeTicks is for relative encoders
	// that report how far they've gone from a start position.
	PositionTypeTicks
	// PositionTypeDegrees is for absolute encoders
	// that report their position in degrees along the radial axis.
	PositionTypeDegrees
)

Known encoder position types.

func ToEncoderPositionType added in v0.2.34

func ToEncoderPositionType(positionType *pb.PositionType) PositionType

ToEncoderPositionType takes a GetPositionResponse and returns an equivalent PositionType-to-int map.

func (PositionType) String added in v0.2.36

func (t PositionType) String() string

type Properties added in v0.6.0

type Properties struct {
	TicksCountSupported   bool
	AngleDegreesSupported bool
}

Properties holds the properties of the encoder.

func ProtoFeaturesToProperties added in v0.6.0

func ProtoFeaturesToProperties(resp *pb.GetPropertiesResponse) Properties

ProtoFeaturesToProperties takes a GetPropertiesResponse and returns an equivalent Properties struct.

Directories

Path Synopsis
Package ams implements the AMS_AS5048 encoder
Package ams implements the AMS_AS5048 encoder
Package fake implements a fake encoder.
Package fake implements a fake encoder.
Package incremental implements an incremental encoder
Package incremental implements an incremental encoder
Package register registers all relevant MovementSensors
Package register registers all relevant MovementSensors
Package single implements a single-wire odometer, such as LM393, as an encoder.
Package single implements a single-wire odometer, such as LM393, as an encoder.

Jump to

Keyboard shortcuts

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