Package tulip :: Package abstract :: Module find_controller
[frames] | no frames]

Module find_controller

Algorithms related to controller synthesis for discretized dynamics.

Primary functions:

Helper functions:

See Also

discretize

Functions
 
assert_cvxopt()
Raise `ImportError` if `cvxopt.solvers` failed to import.
(N x m) numpy 2darray
get_input(x0, ssys, abstraction, start, end, R=None, r=None, Q=None, ord=1, mid_weight=0.0)
Compute continuous control input for discrete transition.
 
get_input_helper(x0, ssys, P1, P3, N, R, r, Q, ord=1, closed_loop=True)
Calculate the sequence u_seq such that:
 
is_seq_inside(x0, u_seq, ssys, P0, P1)
Checks if the plant remains inside P0 for time t = 1, ...
int
find_discrete_state(x0, part)
Return index identifying the discrete state to which the continuous state x0 belongs to.
Variables
  logger = logging.getLogger(__name__)
  __package__ = None
hash(x)
Function Details

get_input(x0, ssys, abstraction, start, end, R=None, r=None, Q=None, ord=1, mid_weight=0.0)

 

Compute continuous control input for discrete transition.

Computes a continuous control input sequence which takes the plant:

  • from state start
  • to state end

These are states of the partition abstraction. The computed control input is such that:

   f(x, u) = |Rx|_{ord} + |Qu|_{ord} + r'x +
             mid_weight * |xc - x(N)|_{ord}

be minimal.

xc is the chebyshev center of the final cell. If no cost parameters are given, then the defaults are:

  • Q = I
  • mid_weight = 3

Notes

  1. The same horizon length as in reachability analysis should be used in order to guarantee feasibility.
  2. If the closed loop algorithm has been used to compute reachability the input needs to be recalculated for each time step (with decreasing horizon length).

    In this case only u(0) should be used as a control signal and u(1) ... u(N-1) discarded.

  3. The "conservative" calculation makes sure that the plant remains inside the convex hull of the starting region during execution, i.e.:
       x(1), x(2) ...  x(N-1) are
       \in conv_hull(starting region).
    

    If the original proposition preserving partition is not convex, then safety cannot be guaranteed.

Parameters:
  • x0 (numpy 1darray) - initial continuous state
  • ssys (LtiSysDyn) - system dynamics
  • abstraction (AbstractPwa) - abstract system dynamics
  • start (int >= 0) - index of the initial state in abstraction.ts
  • end (int >= 0) - index of the end state in abstraction.ts
  • R (size (N*xdim x N*xdim)) - state cost matrix for:
           x = [x(1)' x(2)' .. x(N)']'
       If empty, zero matrix is used.
    
  • r (size (N*xdim x 1)) - cost vector for state trajectory: x = [x(1)' x(2)' .. x(N)']'
  • Q (size (N*udim x N*udim)) - input cost matrix for control input:
           u = [u(0)' u(1)' .. u(N-1)']'
       If empty, identity matrix is used.
    
  • mid_weight - cost weight for |x(N)-xc|_{ord}
  • ord (ord \in {1, 2, np.inf}) - norm used for cost function:
       f(x, u) = |Rx|_{ord} + |Qu|_{ord} + r'x +
             mid_weight *|xc - x(N)|_{ord}
    
Returns: (N x m) numpy 2darray
array A where row k contains the control input: u(k) for k = 0, 1 ... N-1

get_input_helper(x0, ssys, P1, P3, N, R, r, Q, ord=1, closed_loop=True)

 
Calculate the sequence u_seq such that:

  - x(t+1) = A x(t) + B u(t) + K
  - x(k) \in P1 for k = 0,...N
  - x(N) \in P3
  - [u(k); x(k)] \in PU

and minimize:
    |Rx|_{ord} + |Qu|_{ord} + r'x +
    mid_weight * |xc - x(N)|_{ord}

is_seq_inside(x0, u_seq, ssys, P0, P1)

 

Checks if the plant remains inside P0 for time t = 1, ... N-1 and that the plant reaches P1 for time t = N. Used to test a computed input sequence. No disturbance is taken into account.

Parameters:
  • x0 - initial point for execution
  • u_seq - (N x m) array where row k is input for t = k
  • ssys (LtiSysDyn) - dynamics
  • P0 - Polytope where we want x(k) to remain for k = 1, ... N-1
Returns:
True if x(k) \in P0 for k = 1, .. N-1 and x(N) \in P1. False otherwise

find_discrete_state(x0, part)

 

Return index identifying the discrete state to which the continuous state x0 belongs to.

Notes

  1. If there are overlapping partitions (i.e., x0 belongs to more than one discrete state), then return the first discrete state ID
Parameters:
Returns: int
if x0 belongs to some discrete state in part, then return the index of that state

Otherwise return None, i.e., in case x0 does not belong to any discrete state.