ev3lib

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2024 License: MIT Imports: 7 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ConfigManager *configManager = &configManager{registeredConfigs: map[string]MenuConfig{}}

Functions

func Clamp

func Clamp[T constraints.Ordered](v, min, max T) T

func LCDIndexToPixel

func LCDIndexToPixel(idx int) (x, y int)

func LCDPixelToIndex

func LCDPixelToIndex(x, y int) int

func Max

func Max[T constraints.Ordered](a, b T) T

func Min

func Min[T constraints.Ordered](a, b T) T

func RunCommand

func RunCommand(c CommandInterface)

RunCommand will run a command in a blocking fashion.

func RunTimedCommand

func RunTimedCommand(c CommandInterface, intervalTime time.Duration)

RunTimedCommand will run a command in a blocking fashion with a target interval time.

Types

type BeaconButton

type BeaconButton int
const (
	LeftUp BeaconButton = iota
	LeftDown
	RightUp
	RightDown
	Beacon
)

type ColorSensor

type ColorSensor struct {
	ColorSensorInterface
}

func NewColorSensorBase

func NewColorSensorBase(c ColorSensorInterface) *ColorSensor

type ColorSensorInterface

type ColorSensorInterface interface {
	Ambient() float64
	Reflection() float64
	GetRGB() (float64, float64, float64)
}

type Command

type Command struct {
	CommandInterface
}

Command provides decorator functions on commands.

func NewCommand

func NewCommand(c CommandInterface) *Command

func NewFuncCommand

func NewFuncCommand(f func()) *Command

NewFuncCommand runs a function once.

func NewIfCommand

func NewIfCommand(runA func() bool, a, b CommandInterface) *Command

NewIfCommand returns a command that will run a command depending on a predicate. If the predicate returns true when the command is initialised, then command a will be run.

func NewParallel

func NewParallel(commands ...CommandInterface) *Command

NewParallel will run several commands at the same time waiting for all commands to complete.

func NewParallelRace

func NewParallelRace(commands ...CommandInterface) *Command

NewParallelRace will run several commands at the same time. It will finish when the first command finishes and will interrupt the rest.

func NewPrintCommand

func NewPrintCommand(text string) *Command

NewPrintCommand prints out some text.

func NewPrintlnCommand

func NewPrintlnCommand(text string) *Command

func NewSequence

func NewSequence(commands ...CommandInterface) *Command

NewSequence will run several commands one after another.

func NewWaitCommand

func NewWaitCommand(time time.Duration) *Command

NewWaitCommand waits for a time duration.

func (*Command) OnlyIf

func (c *Command) OnlyIf(pred func() bool) *Command

OnlyIf will run a command only if a predicate returns true.

func (*Command) RaceWith

func (c *Command) RaceWith(cc ...CommandInterface) *Command

func (*Command) Repeatedly

func (c *Command) Repeatedly() *Command

Repeatedly will run a command forever reinitialising it if it ends.

func (*Command) Then

func (c *Command) Then(cc ...CommandInterface) *Command

func (*Command) Until

func (c *Command) Until(predicate func() bool) *Command

Until will run a command but will interrupt if a predicate is satisfied.

func (*Command) WhenDone

func (c *Command) WhenDone(f func(bool)) *Command

WhenDone will run a command then a function when it's done.

func (*Command) While

func (c *Command) While(cc ...CommandInterface) *Command

func (*Command) WithTimeout

func (c *Command) WithTimeout(dur time.Duration) *Command

WithTimeout adds a timeout to a command specified by `dur`.

type CommandInterface

type CommandInterface interface {
	Init()
	Run()
	End(interrupted bool)
	IsDone() bool
}

CommandInterface defines the interface for all commands to implement.

type ConfigNotFoundError

type ConfigNotFoundError struct {
	// contains filtered or unexported fields
}

func (ConfigNotFoundError) Error

func (c ConfigNotFoundError) Error() string

type DefaultCommand

type DefaultCommand struct{}

DefaultCommand provides a default implementation for all commands.

func (*DefaultCommand) End

func (b *DefaultCommand) End(_ bool)

func (*DefaultCommand) Init

func (b *DefaultCommand) Init()

func (*DefaultCommand) IsDone

func (b *DefaultCommand) IsDone() bool

func (*DefaultCommand) Run

func (b *DefaultCommand) Run()

type EV3Brick

type EV3Brick struct {
	EV3BrickInterface
}

func NewEV3BrickBase

func NewEV3BrickBase(e EV3BrickInterface) *EV3Brick

type EV3BrickInterface

type EV3BrickInterface interface {
	IsButtonPressed(button EV3Button) bool
	IsButtonDown(button EV3Button) bool
	IsButtonReleased(button EV3Button) bool
	IsButtonUp(button EV3Button) bool
	ButtonsPressed() []EV3Button

	SetLight(color EV3Color)

	Beep(frequency, duration float64)

	PlayNotes(notes []EV3Note, tempo float64)

	SetVolume(volume float64)

	ClearScreen()

	DrawText(x, y int, text string)

	PrintScreen(text ...string)

	DrawPixel(x, y int, black bool)

	Voltage() float64

	Current() float64
}

type EV3Button

type EV3Button int
const (
	Back EV3Button = iota
	Left
	Middle
	Right
	Up
	Down
)

type EV3Color

type EV3Color struct {
	// contains filtered or unexported fields
}

func NewColor

func NewColor(r, g, b float64) EV3Color

type EV3Note

type EV3Note string

type EV3Port

type EV3Port string
const (
	IN1 EV3Port = "ev3-ports:in1"
	IN2 EV3Port = "ev3-ports:in2"
	IN3 EV3Port = "ev3-ports:in3"
	IN4 EV3Port = "ev3-ports:in4"

	OUTA EV3Port = "ev3-ports:outA"
	OUTB EV3Port = "ev3-ports:outB"
	OUTC EV3Port = "ev3-ports:outC"
	OUTD EV3Port = "ev3-ports:outD"
)

type GyroSensor

type GyroSensor struct {
	GyroSensorInterface
}

func NewGyroSensorBase

func NewGyroSensorBase(g GyroSensorInterface) *GyroSensor

type GyroSensorInterface

type GyroSensorInterface interface {
	Rate() float64
	Angle() float64
	AngleRate() (float64, float64)
	ResetAngle(angle float64)
	Calibrate()
}

type InfraredSensor

type InfraredSensor struct {
	InfraredSensorInterface
}

func NewInfraredSensorBase

func NewInfraredSensorBase(i InfraredSensorInterface) *InfraredSensor

type InfraredSensorInterface

type InfraredSensorInterface interface {
	Distance() float64
	Buttons(channel int) []BeaconButton
}
type MainMenu struct {
	// contains filtered or unexported fields
}

func NewMainMenu

func NewMainMenu(i MainMenuInterface, m *Menu) *MainMenu
func (m *MainMenu) Start()
type MainMenuInterface interface {
	Exit() bool

	RunSelected() bool
	CancelRun() bool

	NextCommand() bool
	PreviousCommand() bool

	SetCommand() (bool, int)

	NextPage() bool
	PreviousPage() bool

	SetPage() (bool, int)

	Display(menu *Menu, command, page int, running bool)
}
type Menu struct {
	Pages []*MenuPage
}

func NewCommandMenu

func NewCommandMenu() *Menu
func (c *Menu) AddPage(name string) *MenuPage
type MenuConfig interface {
	GetCommandPages() Menu
}
type MenuPage struct {
	Name     string
	Commands []NamedCommand
	// contains filtered or unexported fields
}
func (c *MenuPage) Add()
func (c *MenuPage) AddCommand(name string, command *Command) *MenuPage

type Motor

type Motor struct {
	MotorInterface
}

func NewMotorBase

func NewMotorBase(m MotorInterface) *Motor

func (*Motor) RunToAbsPos

func (m *Motor) RunToAbsPos(pos float64, tolerance float64, pid PIDController) *Command

func (*Motor) RunToRelPos

func (m *Motor) RunToRelPos(pos float64, tolerance float64, pid PIDController) *Command

func (*Motor) SetCommand

func (m *Motor) SetCommand(power float64) *Command

type MotorInterface

type MotorInterface interface {
	CountPerRot() int
	State() MotorState

	Inverted() bool
	SetInverted(inverted bool)

	Scale() float64
	SetScale(scale float64)
	Position() float64
	ResetPosition(pos float64)
	Speed() float64

	Set(power float64)
	Stop()

	StopAction() MotorStopAction
	SetStopAction(s MotorStopAction)
}

type MotorState

type MotorState int
const (
	Running MotorState = 1 << iota
	Ramping
	Holding
	Overloaded
	Stalled
)

type MotorStopAction

type MotorStopAction string
const (
	Coast MotorStopAction = "coast"
	Brake MotorStopAction = "brake"
	Hold  MotorStopAction = "hold"
)

type NamedCommand

type NamedCommand struct {
	Name string
	*Command
}

type PIDController

type PIDController struct {
	// contains filtered or unexported fields
}

func NewPIDController

func NewPIDController(kp, ki, kd float64) *PIDController

func (*PIDController) Get

func (p *PIDController) Get(current, setPoint float64) float64

func (*PIDController) Kd

func (p *PIDController) Kd() float64

func (*PIDController) Ki

func (p *PIDController) Ki() float64

func (*PIDController) Kp

func (p *PIDController) Kp() float64

func (*PIDController) PID

func (p *PIDController) PID() (float64, float64, float64)

func (*PIDController) SetKd

func (p *PIDController) SetKd(kd float64)

func (*PIDController) SetKi

func (p *PIDController) SetKi(ki float64)

func (*PIDController) SetKp

func (p *PIDController) SetKp(kp float64)

func (*PIDController) SetPID

func (p *PIDController) SetPID(kp, ki, kd float64)

type TouchSensor

type TouchSensor struct {
	TouchSensorInterface
}

func NewTouchSensorBase

func NewTouchSensorBase(t TouchSensorInterface) *TouchSensor

type TouchSensorInterface

type TouchSensorInterface interface {
	IsPressed() bool
}

type UltrasonicSensor

type UltrasonicSensor struct {
	UltrasonicSensorInterface
}

type UltrasonicSensorInterface

type UltrasonicSensorInterface interface {
	Distance() float64
	DistanceSilent() float64
	Presence() bool
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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