control

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: 8 Imported by: 0

Documentation

Overview

Package control package for feedback loop controls

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Control

type Control interface {
	// OutputAt returns the Signal at the block name, error when the block doesn't exist
	OutputAt(ctx context.Context, name string) ([]Signal, error)
	// ConfigAt returns the Configl at the block name, error when the block doesn't exist
	ConfigAt(ctx context.Context, name string) (ControlBlockConfig, error)
	// BlockList returns the list of blocks in a control loop error when the list is empty
	BlockList(ctx context.Context) ([]string, error)
	// Frequency returns the loop's frequency
	Frequency(ctx context.Context) (float64, error)
	// Start starts the loop
	Start() error
	// Stop stops the loop
	Stop()
}

Control control interface can be used to interfact with a control loop to query signals, change config, start/stop the loop etc...

type ControlBlock

type ControlBlock interface {
	// Reset will reset the control block to initial state. Returns an error on failure
	Reset(ctx context.Context) error

	// Next calculate the next output. Takes an array of float64 , a delta time returns True and the output value on success false otherwise
	Next(ctx context.Context, x []Signal, dt time.Duration) ([]Signal, bool)

	// UpdateConfig update the configuration of a pre-existing control block returns an error on failure
	UpdateConfig(ctx context.Context, config ControlBlockConfig) error

	// Output returns the most recent valid value, useful for block aggregating signals
	Output(ctx context.Context) []Signal

	// Config returns the underlying config for a ControlBlock
	Config(ctx context.Context) ControlBlockConfig
}

ControlBlock interface for a control block nolint: revive

type ControlBlockConfig

type ControlBlockConfig struct {
	Name      string              `json:"name"`       // Control Block name
	Type      controlBlockType    `json:"type"`       // Control Block type
	Attribute config.AttributeMap `json:"attributes"` // Internal block configuration
	DependsOn []string            `json:"depends_on"` // List of blocks needed for calling Next
}

ControlBlockConfig configuration of a given block nolint: revive

type ControlConfig

type ControlConfig struct {
	Blocks    []ControlBlockConfig `json:"blocks"`    // Blocks Control Block Config
	Frequency float64              `json:"frequency"` // Frequency loop Frequency
}

ControlConfig configuration of the control loop nolint: revive

type ControlLoop

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

ControlLoop holds the loop config nolint: revive

func NewControlLoop

func NewControlLoop(logger golog.Logger, cfg ControlConfig, m Controllable) (*ControlLoop, error)

NewControlLoop construct a new control loop for a specific endpoint.

func (*ControlLoop) BlockList

func (c *ControlLoop) BlockList(ctx context.Context) ([]string, error)

BlockList returns the list of blocks in a control loop error when the list is empty.

func (*ControlLoop) ConfigAt

func (c *ControlLoop) ConfigAt(ctx context.Context, name string) (ControlBlockConfig, error)

ConfigAt returns the Configl at the block name, error when the block doesn't exist.

func (*ControlLoop) Frequency

func (c *ControlLoop) Frequency(ctx context.Context) (float64, error)

Frequency returns the loop's frequency.

func (*ControlLoop) GetConfig

func (c *ControlLoop) GetConfig(ctx context.Context) ControlConfig

GetConfig return the control loop config.

func (*ControlLoop) OutputAt

func (c *ControlLoop) OutputAt(ctx context.Context, name string) ([]Signal, error)

OutputAt returns the Signal at the block name, error when the block doesn't exist.

func (*ControlLoop) SetConfigAt

func (c *ControlLoop) SetConfigAt(ctx context.Context, name string, config ControlBlockConfig) error

SetConfigAt returns the Configl at the block name, error when the block doesn't exist.

func (*ControlLoop) Start

func (c *ControlLoop) Start() error

Start starts the loop.

func (*ControlLoop) Stop

func (c *ControlLoop) Stop()

Stop stops then loop.

type Controllable

type Controllable interface {
	// SetPower set the power and direction of the motor
	SetPower(ctx context.Context, power float64, extra map[string]interface{}) error
	// GetPosition returns the current encoder count value
	GetPosition(ctx context.Context, extra map[string]interface{}) (float64, error)
}

Controllable controllable type for a DC motor.

type Signal

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

Signal holds any data passed between blocks.

func (*Signal) GetSignalValueAt

func (s *Signal) GetSignalValueAt(i int) float64

GetSignalValueAt returns the value of the signal at an index, threadsafe.

func (*Signal) SetSignalValueAt

func (s *Signal) SetSignalValueAt(i int, val float64)

SetSignalValueAt set the value of a signal at an index, threadsafe.

Jump to

Keyboard shortcuts

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