Documentation ¶
Overview ¶
Package control package for feedback loop controls This is an Experimental package
Index ¶
- Constants
- func UpdateConstantBlock(ctx context.Context, name string, constVal float64, loop *Loop) error
- func UpdateTrapzBlock(ctx context.Context, name string, maxVel float64, dependsOn []string, ...) error
- type Block
- type BlockConfig
- type Config
- type Control
- type Controllable
- type Loop
- func (l *Loop) BlockList(ctx context.Context) ([]string, error)
- func (l *Loop) ConfigAt(ctx context.Context, name string) (BlockConfig, error)
- func (l *Loop) ConfigsAtType(ctx context.Context, bType string) []BlockConfig
- func (l *Loop) Frequency(ctx context.Context) (float64, error)
- func (l *Loop) GetConfig(ctx context.Context) Config
- func (l *Loop) GetTuning(ctx context.Context) bool
- func (l *Loop) MonitorTuning(ctx context.Context)
- func (l *Loop) OutputAt(ctx context.Context, name string) ([]*Signal, error)
- func (l *Loop) Pause()
- func (l *Loop) Resume()
- func (l *Loop) Running() bool
- func (l *Loop) SetConfigAt(ctx context.Context, name string, config BlockConfig) error
- func (l *Loop) Start() error
- func (l *Loop) Stop()
- type Options
- type PIDConfig
- type PIDLoop
- type Signal
Constants ¶
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
UpdateConstantBlock creates and sets a control config constant 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 (*Loop) BlockList ¶ added in v0.0.8
BlockList returns the list of blocks in a control loop error when the list is empty.
func (*Loop) ConfigAt ¶ added in v0.0.8
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) MonitorTuning ¶ added in v0.21.0
MonitorTuning waits for tuning to start, and then returns once it's done.
func (*Loop) OutputAt ¶ added in v0.0.8
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) SetConfigAt ¶ added in v0.0.8
SetConfigAt returns the Configl at the block name, error when the block doesn't exist.
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
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
StartControlLoop starts a PID control loop.
func (*PIDLoop) TunePIDLoop ¶ added in v0.22.0
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 ¶
GetSignalValueAt returns the value of the signal at an index, threadsafe.
func (*Signal) SetSignalValueAt ¶
SetSignalValueAt set the value of a signal at an index, threadsafe.