control

package
v0.26.0 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2024 License: AGPL-3.0 Imports: 11 Imported by: 0

Documentation

Overview

Package control package for feedback loop controls This is an Experimental package

Index

Constants

View Source
const (
	BlockNameEndpoint    = "endpoint"
	BlockNameConstant    = "constant"
	BlockNameTrapezoidal = "trapezoidalVelocityProfile"
)

BlockNameEndpoint, BlockNameConstant, and BlockNameTrapezoidal represent the strings needed to update a control loop block.

Variables

This section is empty.

Functions

func UpdateConstantBlock added in v0.23.0

func UpdateConstantBlock(ctx context.Context, name string, constVal float64, loop *Loop) error

UpdateConstantBlock creates and sets a control config constant block.

func UpdateTrapzBlock added in v0.23.0

func UpdateTrapzBlock(ctx context.Context, name string, maxVel float64, dependsOn []string, loop *Loop) error

UpdateTrapzBlock creates and sets a control config trapezoidalVelocityProfile block.

Types

type Block added in v0.0.8

type Block 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 BlockConfig) 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 Block
	Config(ctx context.Context) BlockConfig
}

Block interface for a control block.

type BlockConfig added in v0.0.8

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

BlockConfig configuration of a given block.

func CreateConstantBlock added in v0.22.0

func CreateConstantBlock(ctx context.Context, name string, constVal float64) BlockConfig

CreateConstantBlock returns a new constant block based on the parameters.

func CreateTrapzBlock added in v0.22.0

func CreateTrapzBlock(ctx context.Context, name string, maxVel float64, dependsOn []string) BlockConfig

CreateTrapzBlock returns a new trapezoidalVelocityProfile block based on the parameters.

type Config added in v0.0.8

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

Config configuration of the control loop.

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) (BlockConfig, 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 Controllable

type Controllable interface {
	// SetState set the power and direction of the motor
	SetState(ctx context.Context, state []*Signal) error
	// Position returns the current encoder count value
	State(ctx context.Context) ([]float64, error)
}

Controllable controllable type for a DC motor.

type Loop added in v0.0.8

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

Loop holds the loop config.

func NewLoop added in v0.0.8

func NewLoop(logger logging.Logger, cfg Config, m Controllable) (*Loop, error)

NewLoop construct a new control loop for a specific endpoint.

func (*Loop) BlockList added in v0.0.8

func (l *Loop) BlockList(ctx context.Context) ([]string, error)

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

func (*Loop) ConfigAt added in v0.0.8

func (l *Loop) ConfigAt(ctx context.Context, name string) (BlockConfig, error)

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

func (*Loop) ConfigsAtType added in v0.19.0

func (l *Loop) ConfigsAtType(ctx context.Context, bType string) []BlockConfig

ConfigsAtType returns the Config(s) at the block type, error when the block doesn't exist.

func (*Loop) Frequency added in v0.0.8

func (l *Loop) Frequency(ctx context.Context) (float64, error)

Frequency returns the loop's frequency.

func (*Loop) GetConfig added in v0.0.8

func (l *Loop) GetConfig(ctx context.Context) Config

GetConfig return the control loop config.

func (*Loop) GetTuning added in v0.15.0

func (l *Loop) GetTuning(ctx context.Context) bool

GetTuning returns the current tuning value.

func (*Loop) MonitorTuning added in v0.21.0

func (l *Loop) MonitorTuning(ctx context.Context)

MonitorTuning waits for tuning to start, and then returns once it's done.

func (*Loop) OutputAt added in v0.0.8

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

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

func (*Loop) Pause added in v0.25.0

func (l *Loop) Pause()

Pause sets l.running to false to pause the loop.

func (*Loop) Resume added in v0.25.0

func (l *Loop) Resume()

Resume sets l.running to true to resume the loop.

func (*Loop) Running added in v0.25.0

func (l *Loop) Running() bool

Running returns the value of l.running.

func (*Loop) SetConfigAt added in v0.0.8

func (l *Loop) SetConfigAt(ctx context.Context, name string, config BlockConfig) error

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

func (*Loop) Start added in v0.0.8

func (l *Loop) Start() error

Start starts the loop.

func (*Loop) Stop added in v0.0.8

func (l *Loop) Stop()

Stop stops then loop.

type Options added in v0.22.0

type Options struct {
	// PositionControlUsingTrapz adds a trapezoidalVelocityProfile block to the
	// control config to allow for position control of a component
	PositionControlUsingTrapz bool

	// SensorFeedback2DVelocityControl adds linear and angular blocks to a control
	// config in order to use the sensorcontrolled base component for velocity control
	SensorFeedback2DVelocityControl bool

	// DerivativeType is the type of derivative to be used for the derivative block of a control config
	DerivativeType string

	// UseCustomeConfig is if the necessary config is not created by this setup file
	UseCustomConfig bool

	// CompleteCustomConfig is the custom control config to be used instead of the config
	// created by this setup file
	CompleteCustomConfig Config

	// NeedsAutoTuning is true when all PID values of a PID block are 0 and
	// the control loop needs to be auto-tuned
	NeedsAutoTuning bool

	// LoopFrequency is the frequency at which the control loop should run
	LoopFrequency float64

	// ControllableType is the type of component the control loop will be set up for,
	// currently a base or motor
	ControllableType string
}

Options contains values used for a control loop.

type PIDConfig added in v0.22.0

type PIDConfig struct {
	Type string  `json:"type,omitempty"`
	P    float64 `json:"p"`
	I    float64 `json:"i"`
	D    float64 `json:"d"`
}

PIDConfig is values needed to configure a PID control loop.

func (*PIDConfig) NeedsAutoTuning added in v0.22.0

func (conf *PIDConfig) NeedsAutoTuning() bool

NeedsAutoTuning checks if the PIDConfig values require auto tuning.

type PIDLoop added in v0.22.0

type PIDLoop struct {
	BlockNames   map[string][]string
	PIDVals      []PIDConfig
	ControlConf  Config
	ControlLoop  *Loop
	Options      Options
	Controllable Controllable
	// contains filtered or unexported fields
}

PIDLoop is used for setting up a PID control loop.

func SetupPIDControlConfig added in v0.22.0

func SetupPIDControlConfig(
	pidVals []PIDConfig,
	componentName string,
	options Options,
	c Controllable,
	logger logging.Logger,
) (*PIDLoop, error)

SetupPIDControlConfig creates a control config.

func (*PIDLoop) StartControlLoop added in v0.22.0

func (p *PIDLoop) StartControlLoop() error

StartControlLoop starts a PID control loop.

func (*PIDLoop) TunePIDLoop added in v0.22.0

func (p *PIDLoop) TunePIDLoop(ctx context.Context, cancelFunc context.CancelFunc) error

TunePIDLoop runs the auto-tuning process for a PID control loop.

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