tank

package
v0.0.0-...-3122fff Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2020 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	I2cWrite = iota + 1
	I2cRead
	I2cWriteRead
	I2cGet
)

Variables

View Source
var DefaultLedSequence = LedSequence{
	Circle:         true,
	Bounce:         false,
	NumLeds:        15,
	PeakRadius:     4,
	SleepTime:      50 * time.Millisecond,
	PeakTravelTime: 1300 * time.Millisecond,
}
View Source
var DefaultTank = Tank{
	UsbDevice:       "",
	I2cFreq:         uint(400),
	I2cRequestQueue: 20,
	Motors: MainMotors{
		I2cAddr:        pca9685.ADDRESS,
		PwmStart:       pca9685.LED0,
		InvertLeftDir:  false,
		InvertRightDir: false,
	},
	Leds: MainLeds{
		I2cAddr:  pca9685.ADDRESS + 4,
		PwmStart: pca9685.LED0,
		NumLeds:  15,
		PwmOutput: pca9685.PwmOutput{
			ValuesFrom: 0,
			ValuesTo:   0.7,
		},
	},
	Adc: Adc{
		I2cAddr:    ads1115.ADDR_GND,
		BatteryMin: 2.60,
		BatteryMax: 3.24,
	},
}

Functions

This section is empty.

Types

type Adc

type Adc struct {
	BatteryMin float64
	BatteryMax float64

	I2cAddr  byte
	Dummy    bool
	SkipInit bool
	// contains filtered or unexported fields
}

func (*Adc) ConvertVoltageToPercentage

func (a *Adc) ConvertVoltageToPercentage(voltage float64) float64

func (*Adc) GetBatteryPercentage

func (a *Adc) GetBatteryPercentage() (float64, error)

func (*Adc) GetBatteryVoltage

func (a *Adc) GetBatteryVoltage() (float64, error)

func (*Adc) Init

func (a *Adc) Init() error

type I2cRequest

type I2cRequest struct {
	Type        int
	Addr        byte
	DataWrite   []byte
	DataRead    []byte
	GetRegister byte // Only for I2cGet
	GetSize     int  // Only for I2cGet
	Error       error
	// contains filtered or unexported fields
}

func (*I2cRequest) Wait

func (r *I2cRequest) Wait()

type LedGroup

type LedGroup struct {
	Leds *MainLeds
	From byte
	To   byte
}

func (*LedGroup) Set

func (g *LedGroup) Set(val float64) error

type LedSequence

type LedSequence struct {
	Circle         bool
	Bounce         bool
	NumLeds        int
	PeakRadius     int           // Number of LEDs around the brightness peak, that are not dark
	SleepTime      time.Duration // Time resolution for LED updates
	PeakTravelTime time.Duration // Time for one brightness peak to travel all LEDs
}

func (*LedSequence) Run

func (s *LedSequence) Run(numRounds int, callback func(sleepTime time.Duration, values []float64) error) error

type MainLeds

type MainLeds struct {
	I2cAddr  byte
	Dummy    bool
	SkipInit bool
	NumLeds  int

	PwmStart  byte // pca9685.LED0
	PwmOutput pca9685.PwmOutput
	// contains filtered or unexported fields
}

func (*MainLeds) DisableAll

func (m *MainLeds) DisableAll() error

func (*MainLeds) Group

func (m *MainLeds) Group(from, to byte) LedGroup

func (*MainLeds) Groups

func (m *MainLeds) Groups() (red, green, yellow LedGroup)

func (*MainLeds) Init

func (m *MainLeds) Init() error

func (*MainLeds) SetAll

func (m *MainLeds) SetAll(values []float64) error

func (*MainLeds) SetRow

func (m *MainLeds) SetRow(from, to byte, val float64) error

type MainMotors

type MainMotors struct {
	I2cAddr  byte
	Dummy    bool
	SkipInit bool

	InvertRightDir, InvertLeftDir bool

	// Starting from the first PWM output, the order of outputs must be:
	// Right Direction, Right Speed, Left Direction, Left Speed
	PwmStart byte // pca9685.LED0
	// contains filtered or unexported fields
}

func (*MainMotors) ForceSet

func (m *MainMotors) ForceSet(left, right float64) error

func (*MainMotors) Init

func (m *MainMotors) Init() error

func (*MainMotors) Set

func (m *MainMotors) Set(left, right float64) error

Input values in -100..100

type Motor

type Motor interface {
	SetSpeed(val float32)
	GetSpeed() float32
}

type SmoothMotor

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

func (*SmoothMotor) GetSpeed

func (m *SmoothMotor) GetSpeed() float32

func (*SmoothMotor) SetSpeed

func (m *SmoothMotor) SetSpeed(val float32)

type SmoothTank

type SmoothTank struct {
	Tank
	SleepTime      time.Duration
	AccelSlopeTime time.Duration
	DecelSlopeTime time.Duration
	MinSpeed       float64
	// contains filtered or unexported fields
}

func (*SmoothTank) Cleanup

func (a *SmoothTank) Cleanup()

func (*SmoothTank) Left

func (a *SmoothTank) Left() Motor

func (*SmoothTank) RegisterFlags

func (a *SmoothTank) RegisterFlags()

func (*SmoothTank) Right

func (a *SmoothTank) Right() Motor

func (*SmoothTank) Setup

func (a *SmoothTank) Setup() error

type Tank

type Tank struct {
	UsbDevice       string
	I2cFreq         uint
	I2cRequestQueue int
	NoI2cSequencer  bool
	Dummy           bool
	SkipInit        bool

	Motors MainMotors
	Leds   MainLeds
	Adc    Adc
	// contains filtered or unexported fields
}

func (*Tank) Bus

func (t *Tank) Bus() ft260.I2cBus

func (*Tank) Cleanup

func (t *Tank) Cleanup()

func (*Tank) InitI2cPeripherals

func (t *Tank) InitI2cPeripherals() error

func (*Tank) RegisterFlags

func (t *Tank) RegisterFlags()

func (*Tank) Setup

func (t *Tank) Setup() error

Jump to

Keyboard shortcuts

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