fake

package
v0.2.27 Latest Latest
Warning

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

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

Documentation

Overview

Package fake implements a fake motor.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Pins             PinConfig `json:"pins"`
	BoardName        string    `json:"board"`
	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:"dir_flip"`
}

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 {
	Name string

	Board             string
	PWM               board.GPIOPin
	PositionReporting bool
	Logger            golog.Logger
	Encoder           *fakeencoder.Encoder
	MaxRPM            float64
	DirFlip           bool

	TicksPerRotation int
	generic.Echo
	// 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) GoTillStop

func (m *Motor) GoTillStop(ctx context.Context, rpm float64, stopFunc func(ctx context.Context) bool) error

GoTillStop always returns an error.

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{}) (map[motor.Feature]bool, error)

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

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) 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