fake

package
v0.29.0-rc0 Latest Latest
Warning

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

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

Documentation

Overview

Package fake implements a fake motor.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewMotor added in v0.18.0

func NewMotor(ctx context.Context, deps resource.Dependencies, conf resource.Config, logger logging.Logger) (motor.Motor, error)

NewMotor creates a new fake motor.

Types

type Config

type Config struct {
	Pins             PinConfig `json:"pins,omitempty"`
	BoardName        string    `json:"board,omitempty"`
	MinPowerPct      float64   `json:"min_power_pct,omitempty"`
	MaxPowerPct      float64   `json:"max_power_pct,omitempty"`
	PWMFreq          uint      `json:"pwm_freq,omitempty"`
	Encoder          string    `json:"encoder,omitempty"`
	MaxRPM           float64   `json:"max_rpm,omitempty"`
	TicksPerRotation int       `json:"ticks_per_rotation,omitempty"`
	DirectionFlip    bool      `json:"direction_flip,omitempty"`
}

Config describes the configuration of a motor.

func (*Config) Validate added in v0.1.6

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

Validate ensures all parts of the config are valid.

type Motor

type Motor struct {
	resource.Named
	resource.TriviallyCloseable

	Board             string
	PWM               board.GPIOPin
	PositionReporting bool
	Encoder           fake.Encoder
	MaxRPM            float64
	DirFlip           bool
	TicksPerRotation  int

	OpMgr  *operation.SingleOperationManager
	Logger logging.Logger
	// contains filtered or unexported fields
}

A Motor allows setting and reading a set power percentage and direction.

func (*Motor) Direction

func (m *Motor) Direction() int

Direction returns the set direction.

func (*Motor) GoFor

func (m *Motor) GoFor(ctx context.Context, rpm, revolutions float64, extra map[string]interface{}) error

GoFor sets the given direction and an arbitrary power percentage. If rpm is 0, the motor should immediately move to the final position.

func (*Motor) GoTo

func (m *Motor) GoTo(ctx context.Context, rpm, pos float64, extra map[string]interface{}) error

GoTo sets the given direction and an arbitrary power percentage for now.

func (*Motor) IsMoving

func (m *Motor) IsMoving(ctx context.Context) (bool, error)

IsMoving returns if the motor is pretending to be moving or not.

func (*Motor) IsPowered

func (m *Motor) IsPowered(ctx context.Context, extra map[string]interface{}) (bool, float64, error)

IsPowered returns if the motor is pretending to be on or not, and its power level.

func (*Motor) Position

func (m *Motor) Position(ctx context.Context, extra map[string]interface{}) (float64, error)

Position returns motor position in rotations.

func (*Motor) PowerPct

func (m *Motor) PowerPct() float64

PowerPct returns the set power percentage.

func (*Motor) Properties

func (m *Motor) Properties(ctx context.Context, extra map[string]interface{}) (motor.Properties, error)

Properties returns the status of whether the motor supports certain optional properties.

func (*Motor) Reconfigure added in v0.2.36

func (m *Motor) Reconfigure(ctx context.Context, deps resource.Dependencies, conf resource.Config) error

Reconfigure atomically reconfigures this motor in place based on the new config.

func (*Motor) ResetZeroPosition

func (m *Motor) ResetZeroPosition(ctx context.Context, offset float64, extra map[string]interface{}) error

ResetZeroPosition resets the zero position.

func (*Motor) SetPower

func (m *Motor) SetPower(ctx context.Context, powerPct float64, extra map[string]interface{}) error

SetPower sets the given power percentage.

func (*Motor) SetRPM added in v0.29.0

func (m *Motor) SetRPM(ctx context.Context, rpm float64, extra map[string]interface{}) error

SetRPM instructs the motor to move at the specified RPM indefinitely.

func (*Motor) Stop

func (m *Motor) Stop(ctx context.Context, extra map[string]interface{}) error

Stop has the motor pretend to be off.

type PinConfig

type PinConfig struct {
	Direction string `json:"dir"`
	PWM       string `json:"pwm"`
}

PinConfig defines the mapping of where motor are wired.

Jump to

Keyboard shortcuts

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