Drake
 All Classes Files Functions Variables
DynamicalSystem Class Reference

An interface class for a state-space dynamical system with a single (vector) input u, a single (vector) output y, and a single (vector) state x composed of a combination of continuous time and discrete time variables. More...

Inheritance diagram for DynamicalSystem:
Collaboration diagram for DynamicalSystem:

Public Member Functions

virtual function getNumContStates (obj)
 Returns the scalar number of continuous state variables, aka xc. More...
 
virtual function getNumDiscStates (obj)
 Returns the scalar number of discrete state variables, aka xd. More...
 
virtual function getNumInputs (obj)
 Returns the scalar length of the single input vector, aka u. More...
 
virtual function getNumOutputs (obj)
 Returns the scalar length of the single output vector, aka y. More...
 
virtual function getSampleTime (obj)
 Returns a simulink compatible sample time for the system. More...
 
virtual function getModel (obj)
 Returns a SimulinkModelHandle to a simulink model which implements the system. More...
 
virtual function getInitialState (obj)
 Returns a (possibly random) state vector which is a feasible initial condition for the system. More...
 
virtual function dynamics (obj, t, x, u)
 Implements the differential equation governing the dynamics of the continuous state variables. More...
 
virtual function update (obj, t, x, u)
 Implements the difference equation governing the dynamics of the discrete state variables. More...
 
virtual function output (obj, t, x, u)
 Implements the output function. More...
 
function DynamicalSystem ()
 
function inInputFrame (sys, frame)
 Ensures that sys has the specified input frame, by searching for and cascading a coordinate transformation to the existing input if necessary. More...
 
function inStateFrame (sys, frame)
 Ensures that sys has the specified state frame. More...
 
function inOutputFrame (sys, frame)
 Ensures that sys has the specified output frame, by searching for and cascading a coordinate transformation to the existing output if necessary. More...
 
function cascade (sys1, sys2)
 Creates a new system with the output of system 1 connected to the input of system 2. More...
 
function feedback (sys1, sys2)
 Creates a new systems with sys1 and sys2 in a feedback interconnect (with sys1 on the forward path, and sys2 on the return path). More...
 
function parallel (sys1, sys2)
 Creates a new system that takes the inputs to both sys1 and sys2 as a single input (which is "demux"ed and passed independently to the two systems), and outputs the "mux"ed output of the two systems. More...
 
function sampledData (sys, tsin, tsout)
 Creates a new system which is a sampled data (e.g. More...
 
function resolveConstraints (obj, x0, v, constraints)
 attempts to find a x which satisfies the constraints, using x0 as the initial guess. More...
 
function addStateConstraintsToProgram (obj, prog, indices)
 adds state constraints and unilateral constriants to the program on the specified indices. More...
 
function getNumStates (obj)
 Returns the total number of states (discrete + continuous) in the system. More...
 
function getInputSampleTimes (obj)
 Returns the sample time of the input See getSampleTime for more details about sample times. More...
 
function getOutputSampleTimes (obj)
 Returns the sample time of the output See getSampleTime for more details about sample times. More...
 
function isDT (obj)
 Returns true if the system has no states, or has states and only one sample time [a b], with a>0. More...
 
function isCT (obj)
 Returns true if the system has only one sample time [a b], with a==0. More...
 
function isInheritedTime (obj)
 Returns true if the system has only one sample time [a b], with b==-1. More...
 
function isTI (obj)
 Returns true if the system is time-invariant. More...
 
function setTIFlag (obj, bval)
 Sets the time invariant flag. More...
 
function getInputFrame (obj)
 Access the CoordinateFrame object that defines the input to this system. More...
 
function setInputFrame (obj, fr)
 Set the CoordinateFrame object that defines the input of this system. More...
 
function getStateFrame (obj)
 Access the CoordinateFrame object that defines the state of this system. More...
 
function setStateFrame (obj, fr)
 Set the CoordinateFrame object that defines the state of this system. More...
 
function getOutputFrame (obj)
 Access the CoordinateFrame object that defines the output to this system. More...
 
function setOutputFrame (obj, fr)
 Set the CoordinateFrame object that defines the output of this system. More...
 
function getNumStateConstraints (obj)
 Returns the scalar number of state constraints (of the form phi(x)=0) More...
 
function stateConstraints (obj, x)
 defines state equality constraints in the form phi(x)=0 More...
 
function unilateralConstraints (obj, x)
 defines state unilateral constraints in the form phi(x)>=0 More...
 
function getNumUnilateralConstraints (obj)
 Returns the scalar number of state constraints (of the form phi(x)>=0) More...
 
function setSimulinkParam (obj, varargin)
 Sets parameters of the simulink model Syntax setSimulinkParam(obj,param_name,param_value[,param_name,param_value,]) % Se. More...
 
function linearize (obj, t0, x0, u0)
 Linearize the system about an operating point (continuous time) More...
 
function dlinearize (obj, ts, t0, x0, u0)
 Linearize the system about an operating point (discrete time) More...
 
function setParams (obj, p)
 This default setParams method attempts to set class properties of the system according to the coordinate names in the parameter frame. More...
 
function getParams (obj)
 This default getParams method attempts to get class properties of the system according to the coordinate names in the parameter frame. More...
 
function getNumParams (obj)
 
function setParamFrame (obj, fr)
 Set the CoordinateFrame object which describes any system parameters. More...
 
function getParamFrame (obj)
 Returns the CoordinateFrame object which describes any system parameters. More...
 
function setParamLimits (obj, pmin, pmax)
 Set lower and upper bounds on the system parameters. More...
 
function getParamLimits (obj)
 Returns the current lower and upper bounds on the system parameters. More...
 
function parameterEstimation (obj, data, options)
 Estimate parameter values from input-output data. More...
 
function runLCM (obj, x0, options)
 Runs the system as an lcm node. More...
 
function simulate (obj, tspan, x0, options)
 Simulates the dynamical system (using the simulink solvers) More...
 
function tiHinf (obj, x0, u0, Q, R, Bw, gamma)
 Suboptimal state-feedback H-infinity controller for LTI system with bound gamma. More...
 
function tilqr (obj, x0, u0, Q, R, options)
 Computes an LQR controller to stabilize the system around (x0,u0) More...
 
function tilyap (obj, x0, Q)
 Linearizes the system about the state x0 and returns a candidate LyapunovFunction generated by solving the quadratic Lyapunov equation. More...
 
function tvlyap (obj, xtraj, Q, Qf)
 Linearizes the system about the state trajectory xtraj and returns a candidate LyapunovFunction generated by integrating backwards the quadratic differential Lyapunov equation. More...
 

Public Attributes

Property warning_manager
 

Protected Member Functions

function stateIndicesForCombination (sys1, sys2)
 Helper method to figure out the indices of the discrete and continuous states after sys1 and sys2 have been combined into a single system. More...
 
function stateVectorToStructure (obj, xv, mdl)
 Converts the vector state xv to the structure xs for simulink state. More...
 
function stateStructureToVector (obj, xs)
 Converts the simulink state structure representation back to the vector state. More...
 

Detailed Description

An interface class for a state-space dynamical system with a single (vector) input u, a single (vector) output y, and a single (vector) state x composed of a combination of continuous time and discrete time variables.

Constructor & Destructor Documentation

function DynamicalSystem ( )
Return values
sys

Member Function Documentation

function addStateConstraintsToProgram ( obj  ,
prog  ,
indices   
)

adds state constraints and unilateral constriants to the program on the specified indices.

derived classes can overload this method to add additional constraints.

Parameters
proga NonlinearProgram class
indicesthe indices of the state variables in the program
Default: 1:nX
Return values
prog
function cascade ( sys1  ,
sys2   
)

Creates a new system with the output of system 1 connected to the input of system 2.

The input coordinate frame of system 2 must match the output coordinate frame of system 1, or system 1's output frame must know how to transform between the frames.

Parameters
sys1the first DynamicalSystem
sys2the second DynamicalSystem
Return values
newsysthe new DynamicalSystem
function dlinearize ( obj  ,
ts  ,
t0  ,
x0  ,
u0   
)

Linearize the system about an operating point (discrete time)

Parameters
tssample time for linearization
t0nominal scalar time
x0nomimal vector of discrete+continuous state
u0nominal vector input
Return values
A,B,C,D,xn0,y0linear dynamics such that x[n+1]=Ax[n]+Bu[n]+xn0, y[n]=C*x[n]+Du[n]+y0
virtual function dynamics ( obj  ,
,
,
 
)
virtual

Implements the differential equation governing the dynamics of the continuous state variables.

Parameters
ttime (scalar)
xstate vector, containing discrete and continuous states
uinput vector
Return values
xcdotderivative vector of ONLY the continuous states

Reimplemented in HybridDrakeSystem, Reduction, PolytopicSystem, CascadeSystem, FeedbackSystem, MIMODrakeSystem, StochasticDrakeSystem, RobustDrakeSystem, DrakeSystem, Manipulator, Trajectory, StochasticPolynomialSystem, ObserverErrorSystem, SecondOrderSystem, Visualizer, FunctionHandleSystem, and PolynomialSystem.

function feedback ( sys1  ,
sys2   
)

Creates a new systems with sys1 and sys2 in a feedback interconnect (with sys1 on the forward path, and sys2 on the return path).

the input of the new system gets added into the input of sys1 the output of sys1 will be the output of the new system.

Return values
newsys
virtual function getInitialState ( obj  )
virtual

Returns a (possibly random) state vector which is a feasible initial condition for the system.

Return values
x0initial state vector, containing discrete and continuous states

Reimplemented in RigidBodyManipulator, HybridDrakeSystem, TimeSteppingRigidBodyManipulator, Reduction, CascadeSystem, SimulinkModel, FeedbackSystem, PolytopicSystem, MarkovDecisionProcess, DrakeSystem, TransverseLinearControl, Observer, HybridRigidBodyMode, Trajectory, Visualizer, and LinearGaussianDT.

function getInputFrame ( obj  )

Access the CoordinateFrame object that defines the input to this system.

Return values
fr
function getInputSampleTimes ( obj  )

Returns the sample time of the input See getSampleTime for more details about sample times.

Return values
ts
virtual function getModel ( obj  )
virtual

Returns a SimulinkModelHandle to a simulink model which implements the system.

Reimplemented in DrakeSystem, Reduction, StochasticDrakeSystem, RobustDrakeSystem, and SimulinkModel.

virtual function getNumContStates ( obj  )
virtual

Returns the scalar number of continuous state variables, aka xc.

Reimplemented in DrakeSystem, Reduction, and SimulinkModel.

virtual function getNumDiscStates ( obj  )
virtual

Returns the scalar number of discrete state variables, aka xd.

Reimplemented in DrakeSystem, Reduction, and SimulinkModel.

virtual function getNumInputs ( obj  )
virtual

Returns the scalar length of the single input vector, aka u.

Reimplemented in DrakeSystem, Reduction, and SimulinkModel.

virtual function getNumOutputs ( obj  )
virtual

Returns the scalar length of the single output vector, aka y.

Reimplemented in DrakeSystem, Reduction, and SimulinkModel.

function getNumParams ( obj  )
Return values
n
function getNumStateConstraints ( obj  )

Returns the scalar number of state constraints (of the form phi(x)=0)

Return values
n
function getNumStates ( obj  )

Returns the total number of states (discrete + continuous) in the system.

Return values
n
function getNumUnilateralConstraints ( obj  )

Returns the scalar number of state constraints (of the form phi(x)>=0)

Return values
n
function getOutputFrame ( obj  )

Access the CoordinateFrame object that defines the output to this system.

Return values
fr
function getOutputSampleTimes ( obj  )

Returns the sample time of the output See getSampleTime for more details about sample times.

Return values
ts
function getParamFrame ( obj  )

Returns the CoordinateFrame object which describes any system parameters.

Return values
fr
function getParamLimits ( obj  )

Returns the current lower and upper bounds on the system parameters.

Return values
pmin
pmax
function getParams ( obj  )

This default getParams method attempts to get class properties of the system according to the coordinate names in the parameter frame.

Return values
p
virtual function getSampleTime ( obj  )
virtual
function getStateFrame ( obj  )

Access the CoordinateFrame object that defines the state of this system.

Return values
fr
function inInputFrame ( sys  ,
frame   
)

Ensures that sys has the specified input frame, by searching for and cascading a coordinate transformation to the existing input if necessary.

Return values
sys
function inOutputFrame ( sys  ,
frame   
)

Ensures that sys has the specified output frame, by searching for and cascading a coordinate transformation to the existing output if necessary.

Return values
sys
function inStateFrame ( sys  ,
frame   
)

Ensures that sys has the specified state frame.

Return values
sys
function isCT ( obj  )

Returns true if the system has only one sample time [a b], with a==0.

Return values
tf
function isDT ( obj  )

Returns true if the system has no states, or has states and only one sample time [a b], with a>0.

Return values
tf
function isInheritedTime ( obj  )

Returns true if the system has only one sample time [a b], with b==-1.

Return values
tf
function isTI ( obj  )

Returns true if the system is time-invariant.

Return values
tf
function linearize ( obj  ,
t0  ,
x0  ,
u0   
)

Linearize the system about an operating point (continuous time)

Parameters
t0nominal scalar time
x0nomimal vector of discrete+continuous state
u0nominal vector input
Return values
A,B,C,D,xdot0,y0linear dynamics such that xdot=Ax+Bu+xdot0, y=C*x+Du+y0
function parallel ( sys1  ,
sys2   
)

Creates a new system that takes the inputs to both sys1 and sys2 as a single input (which is "demux"ed and passed independently to the two systems), and outputs the "mux"ed output of the two systems.

Return values
newsys
function parameterEstimation ( obj  ,
data  ,
options   
)

Estimate parameter values from input-output data.

Parameters
dataan instance of iddata (see 'help iddata' for more info)
Return values
phat
function resolveConstraints ( obj  ,
x0  ,
,
constraints   
)

attempts to find a x which satisfies the constraints, using x0 as the initial guess.

Parameters
x0initial guess for state satisfying constraints
v(optional) a visualizer that should be called while the solver is doing it's thing
constraints(optional) additional constraints to pass to the solver
Return values
x
success
prog
function runLCM ( obj  ,
x0  ,
options   
)

Runs the system as an lcm node.

Parameters
x0initial conditions. Use [] for the default initial conditions.
Options:
tspan  a 1x2 vector defining the start and end time of the simulation. default [0,inf]
timekeeper  the full name (system/block) of a simulink block that maintains the simulation time (e.g. by sleeping). set to '' to have no timekeeper.
Default: 'drake/realtime'
realtime_factor 
Default: 1 (only guaranteed to work for drake/realtime timekeeper)
input_sample_time  sets the sample time of all lcm inputs. can be any valid simulink sample time (e.g. [-1 0] for inherited).
Default: .005
output_sample_time  sets the publishing rate of any lcm outputs. can be any valid simulink sample time (e.g. set to [-1 0] for inherited.)
Default: .005
function sampledData ( sys  ,
tsin  ,
tsout   
)

Creates a new system which is a sampled data (e.g.

discretized in time) version of the original system. This is accomplished by adding rate transition blocks to the inputs and outputs.

Parameters
tsinthe sample times of the input
tsoutthe sample times of the output
Return values
newsysthe new, sampled-data system See getSampleTime for more details about sample times.
function setInputFrame ( obj  ,
fr   
)

Set the CoordinateFrame object that defines the input of this system.

Parameters
frCoordinateFrame object which must have the correct dimension
Return values
obj
function setOutputFrame ( obj  ,
fr   
)

Set the CoordinateFrame object that defines the output of this system.

Parameters
frCoordinateFrame object which must have the correct dimension
Return values
obj
function setParamFrame ( obj  ,
fr   
)

Set the CoordinateFrame object which describes any system parameters.

Return values
obj
function setParamLimits ( obj  ,
pmin  ,
pmax   
)

Set lower and upper bounds on the system parameters.

Return values
obj
function setParams ( obj  ,
 
)

This default setParams method attempts to set class properties of the system according to the coordinate names in the parameter frame.

Return values
obj
function setSimulinkParam ( obj  ,
varargin   
)

Sets parameters of the simulink model Syntax setSimulinkParam(obj,param_name,param_value[,param_name,param_value,]) % Se.

Parameters
param_namethe string parameter name
param_valuethe string representing the parameter value
Return values
objthe DynamicalSystem object with the updated parameters

Try 'doc set_param' in matlab to see the simulink model and block parameters. Note that this supports many of the same parameter values that you would send to odeset.

function setStateFrame ( obj  ,
fr   
)

Set the CoordinateFrame object that defines the state of this system.

Parameters
frCoordinateFrame object which must have the correct dimension
Return values
obj
function setTIFlag ( obj  ,
bval   
)

Sets the time invariant flag.

Set TI=true if you know the system is time-invariant. It simplifies many things.

Return values
obj
function simulate ( obj  ,
tspan  ,
x0  ,
options   
)

Simulates the dynamical system (using the simulink solvers)

Parameters
tspana 1x2 vector of the form [t0 tf]
x0a vector of length(getNumStates) which contains the initial state (
Default: calls getInitialState())
Options:
OutputOption  'RefineOutputTimes' | 'AdditionalOutputTimes' | 'SpecifiedOutputTimes' For variable step solver only
OutputTimes  to generate output in the time sequence options.OutputTimes
capture_lcm_channels  a string containing the regular expression of the channels to subscribe to (e.g. '.*' for all).
Default: '' -> don't record lcm
gui_control_interface  set to true to bring up a figure with play/stop buttons
Default: false
lcm_control_interface  channel on which to listen for lcmt_simulation_control messages.
Default: '' – which means no lcm interface
MaxDataPoints  integer N to limit output to the last N data points. useful for running very long simulations.
Return values
ytraj
xtraj
lcmlog
function stateConstraints ( obj  ,
 
)

defines state equality constraints in the form phi(x)=0

Return values
con
function stateIndicesForCombination ( sys1  ,
sys2   
)
protected

Helper method to figure out the indices of the discrete and continuous states after sys1 and sys2 have been combined into a single system.

Return values
sys1ind
sys2ind
function stateStructureToVector ( obj  ,
xs   
)
protected

Converts the simulink state structure representation back to the vector state.

Parameters
xsthe state (in simulink structure format)
Return values
xv
function stateVectorToStructure ( obj  ,
xv  ,
mdl   
)
protected

Converts the vector state xv to the structure xs for simulink state.

Parameters
xvthe state (in vector form)
mdloptional - pass in a model (default: getModel(obj))
Return values
xs
function tiHinf ( obj  ,
x0  ,
u0  ,
,
,
Bw  ,
gamma   
)

Suboptimal state-feedback H-infinity controller for LTI system with bound gamma.

For continuous systems, the design is based on the dynamics xdot = A*x + B*u + Bw*w where w is unit-covariance Gaussian white noise.

The resulting controller is the result of min_u max_w ^inf (x^T Q x + u^T R u - w^T w) dt

Parameters
x0linearize the dynamics of obj around this operating point (state)
u0linearize the dynamics of obj around this operating point (input)
Qpos def matrix that describes the cost on state
Rpos def matrix that describes the cost on input
Bwthe disturbance input matrix &param gamma gain on disturbance cost
Return values
ltisys
Vcandidate
function tilqr ( obj  ,
x0  ,
u0  ,
,
,
options   
)

Computes an LQR controller to stabilize the system around (x0,u0)

Linearizes the system around the nominal point then calls lqr (if the input and output sample times of the model are continuous) otherwise calls dlinearize/dlqr.

The system must be time-invariant.

Parameters
x0the nominal/goal state (a Point)
u0the nominal input (a Point)
Q,Rdescribe the LQR cost function dt (x'*Q*x + u'*R*u)
Options:
angle_flag  boolean vector the same size as x which causes the resulting controller to wrap around 2pi for the dimensions where angle_flag is true.
Default: false
N  adds the off-diagonal terms to the cost function
  • dt (2*x'*N*u).
    Default: N=0
Qy  adds terms to the cost function specified via the output
  • dt ( y'*Qy*y ).
    Default: Qy=0
Return values
ltisysa system which implements the control u=-K*x
Vcandidatean msspoly representation of the cost-to-go function x'*S*x
function tilyap ( obj  ,
x0  ,
 
)

Linearizes the system about the state x0 and returns a candidate LyapunovFunction generated by solving the quadratic Lyapunov equation.

Return values
Van msspoly representation of the quadratic Lyapunov candidate
function tvlyap ( obj  ,
xtraj  ,
,
Qf   
)

Linearizes the system about the state trajectory xtraj and returns a candidate LyapunovFunction generated by integrating backwards the quadratic differential Lyapunov equation.

Return values
Van msspoly representation of the time-varying quadratic Lyapunov candidate
function unilateralConstraints ( obj  ,
 
)

defines state unilateral constraints in the form phi(x)>=0

Return values
con
virtual function update ( obj  ,
,
,
 
)
virtual

Implements the difference equation governing the dynamics of the discrete state variables.

Parameters
ttime (scalar)
xstate vector, containing discrete and continuous states
uinput vector
Return values
xdnnew value (e.g. xd[n+1])for ONLY the discrete states in the state vector

Reimplemented in HybridDrakeSystem, TimeSteppingRigidBodyManipulator, Reduction, PolytopicSystem, SpotPolynomialSystem, PolynomialTrajectorySystem, StochasticDrakeSystem, CascadeSystem, MIMODrakeSystem, RobustDrakeSystem, HybridRigidBodyMode, DrakeSystem, LuenbergerObserver, AffineSystem, FeedbackSystem, ObserverErrorSystem, Trajectory, StochasticPolynomialSystem, Visualizer, and FunctionHandleSystem.

Member Data Documentation

Property warning_manager

The documentation for this class was generated from the following file: