Documentation
¶
Overview ¶
Package board defines the interfaces that typically live on a single-board computer such as a Raspberry Pi.
Besides the board itself, some other interfaces it defines are analog readers and digital interrupts.
Package board contains a gRPC based board client.
Package board contains a gRPC based Board service server.
Index ¶
- Constants
- Variables
- func CreateStatus(ctx context.Context, b Board, extra map[string]interface{}) (*commonpb.BoardStatus, error)
- func Named(name string) resource.Name
- func NamesFromRobot(r robot.Robot) []string
- func NewAnalogCollector(resource interface{}, params data.CollectorParams) (data.Collector, error)
- func NewGPIOCollector(resource interface{}, params data.CollectorParams) (data.Collector, error)
- func NewRPCServiceServer(coll resource.APIResourceCollection[Board]) interface{}
- type AnalogReader
- type AnalogReaderConfig
- type AnalogSmoother
- type BasicDigitalInterrupt
- func (i *BasicDigitalInterrupt) AddCallback(c chan Tick)
- func (i *BasicDigitalInterrupt) AddPostProcessor(pp PostProcessor)
- func (i *BasicDigitalInterrupt) Close(ctx context.Context) error
- func (i *BasicDigitalInterrupt) Config(ctx context.Context) (DigitalInterruptConfig, error)
- func (i *BasicDigitalInterrupt) Reconfigure(conf DigitalInterruptConfig) error
- func (i *BasicDigitalInterrupt) RemoveCallback(c chan Tick)
- func (i *BasicDigitalInterrupt) Tick(ctx context.Context, high bool, nanoseconds uint64) error
- func (i *BasicDigitalInterrupt) Ticks(ctx context.Context, num int, now uint64) error
- func (i *BasicDigitalInterrupt) Value(ctx context.Context, extra map[string]interface{}) (int64, error)
- type Board
- type DigitalInterrupt
- type DigitalInterruptConfig
- type GPIOPin
- type I2CConfig
- type PostProcessor
- type ReconfigurableDigitalInterrupt
- type SPIConfig
- type ServoDigitalInterrupt
- func (i *ServoDigitalInterrupt) AddCallback(c chan Tick)
- func (i *ServoDigitalInterrupt) AddPostProcessor(pp PostProcessor)
- func (i *ServoDigitalInterrupt) Close(ctx context.Context) error
- func (i *ServoDigitalInterrupt) Config(ctx context.Context) (DigitalInterruptConfig, error)
- func (i *ServoDigitalInterrupt) Reconfigure(conf DigitalInterruptConfig) error
- func (i *ServoDigitalInterrupt) RemoveCallback(c chan Tick)
- func (i *ServoDigitalInterrupt) Tick(ctx context.Context, high bool, now uint64) error
- func (i *ServoDigitalInterrupt) Value(ctx context.Context, extra map[string]interface{}) (int64, error)
- type Tick
Constants ¶
const ServoRollingAverageWindow = 10
ServoRollingAverageWindow is how many entries to average over for servo ticks.
const SubtypeName = "board"
SubtypeName is a constant that identifies the component resource API string "board".
Variables ¶
var API = resource.APINamespaceRDK.WithComponentType(SubtypeName)
API is a variable that identifies the component resource API.
Functions ¶
func CreateStatus ¶
func CreateStatus(ctx context.Context, b Board, extra map[string]interface{}) (*commonpb.BoardStatus, error)
CreateStatus constructs a new up to date status from the given board. The operation can take time and be expensive, so it can be cancelled by the given context.
func NamesFromRobot ¶
NamesFromRobot is a helper for getting all board names from the given Robot.
func NewAnalogCollector ¶ added in v0.13.0
func NewAnalogCollector(resource interface{}, params data.CollectorParams) (data.Collector, error)
NewAnalogCollector returns a collector to register an analog reading method. If one is already registered with the same MethodMetadata it will panic.
func NewGPIOCollector ¶ added in v0.13.0
func NewGPIOCollector(resource interface{}, params data.CollectorParams) (data.Collector, error)
NewGPIOCollector returns a collector to register a gpio get method. If one is already registered with the same MethodMetadata it will panic.
func NewRPCServiceServer ¶ added in v0.2.36
func NewRPCServiceServer(coll resource.APIResourceCollection[Board]) interface{}
NewRPCServiceServer constructs an board gRPC service server. It is intentionally untyped to prevent use outside of tests.
Types ¶
type AnalogReader ¶
type AnalogReader interface { // Read reads off the current value. Read(ctx context.Context, extra map[string]interface{}) (int, error) Close(ctx context.Context) error }
An AnalogReader represents an analog pin reader that resides on a board.
type AnalogReaderConfig ¶ added in v0.11.0
type AnalogReaderConfig struct { Name string `json:"name"` Pin string `json:"pin"` AverageOverMillis int `json:"average_over_ms,omitempty"` SamplesPerSecond int `json:"samples_per_sec,omitempty"` }
AnalogReaderConfig describes the configuration of an analog reader on a board.
func (*AnalogReaderConfig) Validate ¶ added in v0.11.0
func (config *AnalogReaderConfig) Validate(path string) error
Validate ensures all parts of the config are valid.
type AnalogSmoother ¶
type AnalogSmoother struct { Raw AnalogReader AverageOverMillis int SamplesPerSecond int // contains filtered or unexported fields }
An AnalogSmoother smooths the readings out from an underlying reader.
func SmoothAnalogReader ¶
func SmoothAnalogReader(r AnalogReader, c AnalogReaderConfig, logger logging.Logger) *AnalogSmoother
SmoothAnalogReader wraps the given reader in a smoother.
func (*AnalogSmoother) Close ¶
func (as *AnalogSmoother) Close(ctx context.Context) error
Close stops the smoothing routine.
func (*AnalogSmoother) Start ¶
func (as *AnalogSmoother) Start(ctx context.Context)
Start begins the smoothing routine that reads from the underlying analog reader.
type BasicDigitalInterrupt ¶
type BasicDigitalInterrupt struct {
// contains filtered or unexported fields
}
A BasicDigitalInterrupt records how many ticks/interrupts happen and can report when they happen to interested callbacks.
func (*BasicDigitalInterrupt) AddCallback ¶
func (i *BasicDigitalInterrupt) AddCallback(c chan Tick)
AddCallback adds a listener for interrupts.
func (*BasicDigitalInterrupt) AddPostProcessor ¶
func (i *BasicDigitalInterrupt) AddPostProcessor(pp PostProcessor)
AddPostProcessor sets the post processor that will modify the value that Value returns.
func (*BasicDigitalInterrupt) Close ¶ added in v0.2.36
func (i *BasicDigitalInterrupt) Close(ctx context.Context) error
Close does nothing.
func (*BasicDigitalInterrupt) Config ¶
func (i *BasicDigitalInterrupt) Config(ctx context.Context) (DigitalInterruptConfig, error)
Config returns the config used to create this interrupt.
func (*BasicDigitalInterrupt) Reconfigure ¶ added in v0.2.36
func (i *BasicDigitalInterrupt) Reconfigure(conf DigitalInterruptConfig) error
Reconfigure reconfigures this digital interrupt with a new formula.
func (*BasicDigitalInterrupt) RemoveCallback ¶
func (i *BasicDigitalInterrupt) RemoveCallback(c chan Tick)
RemoveCallback removes a listener for interrupts.
func (*BasicDigitalInterrupt) Tick ¶
Tick records an interrupt and notifies any interested callbacks. See comment on the DigitalInterrupt interface for caveats.
type Board ¶
type Board interface { resource.Resource // AnalogReaderByName returns an analog reader by name. AnalogReaderByName(name string) (AnalogReader, bool) // DigitalInterruptByName returns a digital interrupt by name. DigitalInterruptByName(name string) (DigitalInterrupt, bool) // GPIOPinByName returns a GPIOPin by name. GPIOPinByName(name string) (GPIOPin, error) // AnalogReaderNames returns the names of all known analog readers. AnalogReaderNames() []string // DigitalInterruptNames returns the names of all known digital interrupts. DigitalInterruptNames() []string // Status returns the current status of the board. Usually you // should use the CreateStatus helper instead of directly calling // this. Status(ctx context.Context, extra map[string]interface{}) (*commonpb.BoardStatus, error) // SetPowerMode sets the board to the given power mode. If // provided, the board will exit the given power mode after // the specified duration. SetPowerMode(ctx context.Context, mode pb.PowerMode, duration *time.Duration) error // WriteAnalog writes an analog value to a pin on the board. WriteAnalog(ctx context.Context, pin string, value int32, extra map[string]interface{}) error }
A Board represents a physical general purpose board that contains various components such as analog readers, and digital interrupts.
func FromDependencies ¶
func FromDependencies(deps resource.Dependencies, name string) (Board, error)
FromDependencies is a helper for getting the named board from a collection of dependencies.
type DigitalInterrupt ¶
type DigitalInterrupt interface { // Value returns the current value of the interrupt which is // based on the type of interrupt. Value(ctx context.Context, extra map[string]interface{}) (int64, error) // Tick is to be called either manually if the interrupt is a proxy to some real // hardware interrupt or for tests. // nanoseconds is from an arbitrary point in time, but always increasing and always needs // to be accurate. Tick(ctx context.Context, high bool, nanoseconds uint64) error // AddCallback adds a callback to be sent a low/high value to when a tick // happens. AddCallback(c chan Tick) // AddPostProcessor adds a post processor that should be used to modify // what is returned by Value. AddPostProcessor(pp PostProcessor) // RemoveCallback removes a listener for interrupts RemoveCallback(c chan Tick) Close(ctx context.Context) error }
A DigitalInterrupt represents a configured interrupt on the board that when interrupted, calls the added callbacks. Post processors can also be added to modify what Value ultimately returns.
type DigitalInterruptConfig ¶
type DigitalInterruptConfig struct { Name string `json:"name"` Pin string `json:"pin"` Type string `json:"type,omitempty"` // e.g. basic, servo Formula string `json:"formula,omitempty"` }
DigitalInterruptConfig describes the configuration of digital interrupt for a board.
func (*DigitalInterruptConfig) Validate ¶
func (config *DigitalInterruptConfig) Validate(path string) error
Validate ensures all parts of the config are valid.
type GPIOPin ¶
type GPIOPin interface { // Set sets the pin to either low or high. Set(ctx context.Context, high bool, extra map[string]interface{}) error // Get gets the high/low state of the pin. Get(ctx context.Context, extra map[string]interface{}) (bool, error) // PWM gets the pin's given duty cycle. PWM(ctx context.Context, extra map[string]interface{}) (float64, error) // SetPWM sets the pin to the given duty cycle. SetPWM(ctx context.Context, dutyCyclePct float64, extra map[string]interface{}) error // PWMFreq gets the PWM frequency of the pin. PWMFreq(ctx context.Context, extra map[string]interface{}) (uint, error) // SetPWMFreq sets the given pin to the given PWM frequency. For Raspberry Pis, // 0 will use a default PWM frequency of 800. SetPWMFreq(ctx context.Context, freqHz uint, extra map[string]interface{}) error }
A GPIOPin represents an individual GPIO pin on a board.
type PostProcessor ¶
A PostProcessor takes a raw input and transforms it into a new value. Multiple post processors can be stacked on each other. This is currently only used in DigitalInterrupt readings.
type ReconfigurableDigitalInterrupt ¶ added in v0.2.36
type ReconfigurableDigitalInterrupt interface { DigitalInterrupt Reconfigure(cfg DigitalInterruptConfig) error }
A ReconfigurableDigitalInterrupt is a simple reconfigurable digital interrupt that expects reconfiguration within the same type.
func CreateDigitalInterrupt ¶
func CreateDigitalInterrupt(cfg DigitalInterruptConfig) (ReconfigurableDigitalInterrupt, error)
CreateDigitalInterrupt is a factory method for creating a specific DigitalInterrupt based on the given config. If no type is specified, a BasicDigitalInterrupt is returned.
type SPIConfig ¶
type SPIConfig struct { Name string `json:"name"` BusSelect string `json:"bus_select"` // "0" or "1" for main/aux in libpigpio }
SPIConfig enumerates a specific, shareable SPI bus.
type ServoDigitalInterrupt ¶
type ServoDigitalInterrupt struct {
// contains filtered or unexported fields
}
A ServoDigitalInterrupt is an interrupt associated with a servo in order to track the amount of time that has passed between low signals (pulse width). Post processors make meaning of these widths.
func (*ServoDigitalInterrupt) AddCallback ¶
func (i *ServoDigitalInterrupt) AddCallback(c chan Tick)
AddCallback currently panics.
func (*ServoDigitalInterrupt) AddPostProcessor ¶
func (i *ServoDigitalInterrupt) AddPostProcessor(pp PostProcessor)
AddPostProcessor sets the post processor that will modify the value that Value returns.
func (*ServoDigitalInterrupt) Close ¶ added in v0.2.36
func (i *ServoDigitalInterrupt) Close(ctx context.Context) error
Close does nothing.
func (*ServoDigitalInterrupt) Config ¶
func (i *ServoDigitalInterrupt) Config(ctx context.Context) (DigitalInterruptConfig, error)
Config returns the config the interrupt was created with.
func (*ServoDigitalInterrupt) Reconfigure ¶ added in v0.2.36
func (i *ServoDigitalInterrupt) Reconfigure(conf DigitalInterruptConfig) error
Reconfigure reconfigures this digital interrupt with a new formula.
func (*ServoDigitalInterrupt) RemoveCallback ¶
func (i *ServoDigitalInterrupt) RemoveCallback(c chan Tick)
RemoveCallback currently panics.
type Tick ¶ added in v0.2.19
Tick represents a signal received by an interrupt pin. This signal is communicated via registered channel to the various drivers. Depending on board implementation there may be a wraparound in timestamp values past 4294967295000 nanoseconds (~72 minutes) if the value was originally in microseconds as a 32-bit integer. The timestamp in nanoseconds of the tick SHOULD ONLY BE USED FOR CALCULATING THE TIME ELAPSED BETWEEN CONSECUTIVE TICKS AND NOT AS AN ABSOLUTE TIMESTAMP.
Source Files
¶
Directories
¶
Path | Synopsis |
---|---|
Package beaglebone implements a beaglebone based board.
|
Package beaglebone implements a beaglebone based board. |
Package customlinux implements a board running Linux.
|
Package customlinux implements a board running Linux. |
Package fake implements a fake board.
|
Package fake implements a fake board. |
Package genericlinux implements a Linux-based board making heavy use of sysfs (https://en.wikipedia.org/wiki/Sysfs).
|
Package genericlinux implements a Linux-based board making heavy use of sysfs (https://en.wikipedia.org/wiki/Sysfs). |
buses
Package buses is for I2C and SPI boards that run Linux.
|
Package buses is for I2C and SPI boards that run Linux. |
hat
|
|
pca9685
Package pca9685 implements a PCA9685 HAT.
|
Package pca9685 implements a PCA9685 HAT. |
Package jetson implements a jetson-based board.
|
Package jetson implements a jetson-based board. |
Package mcp3008helper is shared code for hooking an MCP3008 ADC up to a board.
|
Package mcp3008helper is shared code for hooking an MCP3008 ADC up to a board. |
Package numato is for numato IO boards.
|
Package numato is for numato IO boards. |
Package pi implements a Board and its related interfaces for a Raspberry Pi.
|
Package pi implements a Board and its related interfaces for a Raspberry Pi. |
common
Package picommon contains shared information for supported and non-supported pi boards.
|
Package picommon contains shared information for supported and non-supported pi boards. |
Package register registers all relevant Boards and also API specific functions
|
Package register registers all relevant Boards and also API specific functions |
Package ti implements a ti based board.
|
Package ti implements a ti based board. |
Package upboard implements an Intel based board.
|
Package upboard implements an Intel based board. |