gpio

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2022 License: AGPL-3.0 Imports: 19 Imported by: 0

Documentation

Overview

Package gpio implements a GPIO based motor.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewEncodedMotor

func NewEncodedMotor(
	config config.Component,
	motorConfig motor.Config,
	realMotor motor.Motor,
	encoder encoder.Encoder,
	logger golog.Logger,
) (motor.LocalMotor, error)

NewEncodedMotor creates a new motor that supports an arbitrary source of encoder information.

func NewMotor

func NewMotor(b board.Board, mc motor.Config, logger golog.Logger) (motor.Motor, error)

NewMotor constructs a new GPIO based motor on the given board using the given configuration.

func SetRPMSleepDebug

func SetRPMSleepDebug(dur time.Duration, debug bool) func()

SetRPMSleepDebug is for testing only.

func WrapMotorWithEncoder

func WrapMotorWithEncoder(
	ctx context.Context,
	e encoder.Encoder,
	c config.Component,
	mc motor.Config,
	m motor.Motor,
	logger golog.Logger,
) (motor.Motor, error)

WrapMotorWithEncoder takes a motor and adds an encoder onto it in order to understand its odometry.

Types

type EncodedMotor

type EncodedMotor struct {
	generic.Unimplemented
	// contains filtered or unexported fields
}

EncodedMotor is a motor that utilizes an encoder to track its position.

func (*EncodedMotor) Close

func (m *EncodedMotor) Close()

Close cleanly shuts down the motor.

func (*EncodedMotor) DirectionMoving

func (m *EncodedMotor) DirectionMoving() int64

DirectionMoving returns the direction we are currently mpving in, with 1 representing forward and -1 representing backwards.

func (*EncodedMotor) GetFeatures

func (m *EncodedMotor) GetFeatures(ctx context.Context, extra map[string]interface{}) (map[motor.Feature]bool, error)

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

func (*EncodedMotor) GetPosition

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

GetPosition returns the position of the motor.

func (*EncodedMotor) GoFor

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

GoFor instructs the motor to go in a given direction at the given RPM for a number of given revolutions. Both the RPM and the revolutions can be assigned negative values to move in a backwards direction. Note: if both are negative the motor will spin in the forward direction.

func (*EncodedMotor) GoTillStop

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

GoTillStop moves until physically stopped (though with a ten second timeout) or stopFunc() returns true.

func (*EncodedMotor) GoTo

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

GoTo instructs the motor to go to a specific position (provided in revolutions from home/zero), at a specific speed. Regardless of the directionality of the RPM this function will move the motor towards the specified target.

func (*EncodedMotor) IsMoving

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

IsMoving returns if the motor is moving or not.

func (*EncodedMotor) IsPowered

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

IsPowered returns if the motor is on or not.

func (*EncodedMotor) IsRegulated

func (m *EncodedMotor) IsRegulated() bool

IsRegulated returns if the motor is currently regulated or not.

func (*EncodedMotor) RPMMonitorCalls

func (m *EncodedMotor) RPMMonitorCalls() int64

RPMMonitorCalls returns the number of calls RPM monitor has made.

func (*EncodedMotor) RPMMonitorStart

func (m *EncodedMotor) RPMMonitorStart()

RPMMonitorStart starts the RPM monitor.

func (*EncodedMotor) ResetZeroPosition

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

ResetZeroPosition sets the current position of the motor specified by the request (adjusted by a given offset) to be its new zero position.

func (*EncodedMotor) SetPower

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

SetPower sets the power of the motor to the given percentage value between 0 and 1.

func (*EncodedMotor) SetRegulated

func (m *EncodedMotor) SetRegulated(b bool)

SetRegulated sets if the motor should be regulated.

func (*EncodedMotor) Stop

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

Stop turns the power to the motor off immediately, without any gradual step down.

type EncodedMotorState

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

EncodedMotorState is the core, non-statistical state for the motor. Multiple values should be updated atomically at the same time.

type Motor

type Motor struct {
	Board                    board.Board
	A, B, Direction, PWM, En board.GPIOPin
	EnablePinLow             board.GPIOPin
	EnablePinHigh            board.GPIOPin

	generic.Unimplemented
	// contains filtered or unexported fields
}

A Motor is a GPIO based Motor that resides on a GPIO Board.

func (*Motor) GetFeatures

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

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

func (*Motor) GetPosition

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

GetPosition always returns 0.

func (*Motor) GoFor

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

GoFor moves an inputted number of revolutions at the given rpm, no encoder is present for this so power is determined via a linear relationship with the maxRPM and the distance traveled is a time based estimation based on desired RPM.

func (*Motor) GoTillStop

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

GoTillStop is not supported.

func (*Motor) GoTo

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

GoTo is not supported.

func (*Motor) IsMoving

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

IsMoving returns if the motor is currently on or off.

func (*Motor) IsPowered

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

IsPowered returns if the motor is currently on or off.

func (*Motor) ResetZeroPosition

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

ResetZeroPosition is not supported.

func (*Motor) SetPower

func (m *Motor) SetPower(ctx context.Context, powerPct float64, extra map[string]interface{}) error
SetPower instructs the motor to operate at an rpm, where the sign of the rpm

indicates direction.

func (*Motor) Stop

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

Stop turns the power to the motor off immediately, without any gradual step down, by setting the appropriate pins to low states.

Jump to

Keyboard shortcuts

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