lti

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2019 License: MIT Imports: 2 Imported by: 8

README

Linear and time-invariant systems in Golang

License GoDoc goreportcard

go get github.com/konimarti/lti

  • Work in Progress

  • State-space representation and estimation of linear, time-invariant systems for control theory in Golang

     x'(t) = A * x(t) + B * u(t)
    

    and

     y(t)  = C * x(t) + D * u(t)
    

Usage

	// define time-continuous linear system
	system, err := lti.NewSystem(
		...
	)

	// check system properties
	fmt.Println("Observable=", system.MustObservable())
	fmt.Println("Controllable=", system.MustControllable())

	// define initial state (x) and control (u) vectors
	...

	// get derivative vector for new state
	fmt.Println(system.Derivative(x, u))

	// get output vector for new state
	fmt.Println(system.Response(x, u))

	// discretize LTI system and propagate state by time step dt
	discrete, err := system.Discretize(dt)

	fmt.Println("x(k+1)=", discrete.Predict(x, u))
}
Example

See example here.

More information

For additional materials on state-space models for control theory, check out the following links:

  • A practical guide to state-space control here
  • State-space model impelmentation for Arduinos here

Credits

This software package has been developed for and is in production at Kalkfabrik Netstal.

Documentation

Overview

Package lti implements a general state-space representation of a linear system. A state-space representation can be expressed in a matrix form as

x'(t) = A * x(t) + B * u(t) and y(t) = C * x(t) + D * u(t)

where x(t) represents the state and u(t) the control input vectors and the matrices are A: System matrix, B: Control matrix, C: Output matrix and D: Feedforward matrix

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IdealDiscretization

func IdealDiscretization(A *mat.Dense, dt float64, M *mat.Dense) (*mat.Dense, error)

IdealDiscretization returns a discretized matrix Md = exp(A*t) * M. If M is nil, then it just returns exp(A*t).

func RealDiscretization

func RealDiscretization(A *mat.Dense, dt float64, M *mat.Dense) (*mat.Dense, error)

RealDiscretization returns a discretized matrix Md = Int_0^T exp(A*t) * M dt.

Types

type Covariance

type Covariance struct {
	Md *mat.Dense
}

Covariance contains a discretized matrix to predict the next covariance matrix according to p(k+1) = Md * p(k) * Md^T

func NewCovariance

func NewCovariance(md *mat.Dense) *Covariance

NewCovariance creates a new covariance struct which needs to be initialized with a discretizied matrix Md

func (*Covariance) Predict

func (c *Covariance) Predict(p *mat.Dense, noise *mat.Dense) *mat.Dense

Predict propagates the covariance p(k) to p(k+1) according to p(k+1) = Md * p(k) * Md^T; additionally noise is added if not nil

type Discrete

type Discrete struct {
	Ad *mat.Dense
	Bd *mat.Dense
	C  *mat.Dense
	D  *mat.Dense
}

Discrete represents a discrete LTI system.

The parameters are:

A_d: Discretized Ssystem matrix
B_d: Discretized Control matrix

func NewDiscrete

func NewDiscrete(A, B, C, D *mat.Dense, dt float64) (*Discrete, error)

NewDiscrete returns a Discrete struct

func (*Discrete) Controllable

func (d *Discrete) Controllable() (bool, error)

Controllable checks the controllability of the LTI system.

func (*Discrete) Observable

func (d *Discrete) Observable() (bool, error)

Observable checks the observability of the LTI system.

func (*Discrete) Predict

func (d *Discrete) Predict(x *mat.VecDense, u *mat.VecDense) *mat.VecDense

Predict predicts x(k+1) = A_discretized * x(k) + B_discretized * u(k)

func (*Discrete) Response

func (d *Discrete) Response(x *mat.VecDense, u *mat.VecDense) *mat.VecDense

Response returns the output vector y(t) = C * x(t) + D * u(t)

type DiscreteLTI

type DiscreteLTI interface {
	LTI
	Predict(x, u *mat.VecDense) *mat.VecDense
}

DiscreteLTI represents a discretized LTI system

type LTI

type LTI interface {
	Observable() (bool, error)
	Controllable() (bool, error)
	Response(x, u *mat.VecDense) *mat.VecDense
}

LTI represents a general time-continuous state-space LTI system

type System

type System struct {
	A *mat.Dense
	B *mat.Dense
	C *mat.Dense
	D *mat.Dense
}

System represents the state equations of time-continuous, linear systems

The parameters are:

A: System matrix
B: Control matrix
C: Output matrix
D: Feedforward matrix

func NewSystem

func NewSystem(A, B, C, D *mat.Dense) (*System, error)

NewSystem returns a System struct and checks the matrix dimensions

func (*System) Controllable

func (s *System) Controllable() (bool, error)

Controllable checks the controllability of the LTI system.

func (*System) Derivative

func (s *System) Derivative(x, u *mat.VecDense) *mat.VecDense

Derivative returns the derivative vetor x'(t) = A * x(t) + B * u(t)

func (*System) Discretize

func (s *System) Discretize(dt float64) (*Discrete, error)

Discretize discretizes the time-continuous LTI into an explicit time-discrete LTI system

func (*System) MustControllable

func (s *System) MustControllable() bool

MustControllable checks the controllability and panics when error occurs

func (*System) MustObservable

func (s *System) MustObservable() bool

MustObservable checks the observability of the LTI system. and panics when error occurs

func (*System) Observable

func (s *System) Observable() (bool, error)

Observable checks the observability of the LTI system.

func (*System) Response

func (s *System) Response(x *mat.VecDense, u *mat.VecDense) *mat.VecDense

Response returns the output vector y(t) = C * x(t) + D * u(t)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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