trajoptlib.legacy package

Module contents

trajoptlib.legacy.probFun

alias of pyoptsolver.pyoptsolvercpp.OptProblem

trajoptlib.legacy.solver

alias of pyoptsolver.pyoptsolvercpp.SnoptSolver

trajoptlib.legacy.snoptConfig

alias of pyoptsolver.pyoptsolvercpp.SnoptConfig

trajoptlib.legacy.ipSolver

alias of pyoptsolver.pyoptsolvercpp.IpoptSolver

trajoptlib.legacy.ipOption

alias of pyoptsolver.pyoptsolvercpp.IpoptConfig

trajoptlib.legacy.trajOptProblem

alias of trajoptlib.trajOptProblem.OptProblem

trajoptlib.legacy.system

alias of trajoptlib.trajOptBase.System

trajoptlib.legacy.daeSystem

alias of trajoptlib.trajOptBase.DaeSystem

trajoptlib.legacy.baseFun

alias of trajoptlib.trajOptBase.BaseFun

trajoptlib.legacy.addX

alias of trajoptlib.trajOptBase.AddX

trajoptlib.legacy.lqrObj

alias of trajoptlib.trajOptBase.LqrObj

trajoptlib.legacy.linearPointObj

alias of trajoptlib.trajOptBase.LinearPointObj

trajoptlib.legacy.nonLinearObj

alias of trajoptlib.trajOptBase.NonLinearObj

trajoptlib.legacy.nonLinearPointObj

alias of trajoptlib.trajOptBase.NonLinearPointObj

trajoptlib.legacy.linearObj

alias of trajoptlib.trajOptBase.LinearObj

trajoptlib.legacy.nonLinearPointConstr

alias of trajoptlib.trajOptBase.NonLinearPointConstr

trajoptlib.legacy.nonLinearConstr

alias of trajoptlib.trajOptBase.NonLinearConstr

trajoptlib.legacy.linearPointConstr

alias of trajoptlib.trajOptBase.LinearPointConstr

trajoptlib.legacy.linearConstr

alias of trajoptlib.trajOptBase.LinearConstr

trajoptlib.legacy.trajOptProblem

alias of trajoptlib.trajOptProblem.OptProblem

trajoptlib.legacy.trajOptCollocProblem

alias of trajoptlib.trajOptCollocationProblem.OptProblem

class trajoptlib.legacy.NonLinearConnectConstr(phase1, phase2, nc, lb=None, ub=None, nG=None, index1=-1, index2=0, addx_index=None)[source]

Bases: object

Class for defining point constraint function.

Currentmodule:
__callg__(x1, x2, F, G, row, col, rec, needg, addx=None)[source]

Call and evaluate the constraint function. x1 and x2 are points in phase 1 and phase 2.

I return them together in G, row, col since it might be derived from sympy so thay are together. But, human derived formulas love the previous one better

find_time_gradient(x1, x2, addx=None)[source]

Find where the gradients are w.r.t time.

class trajoptlib.legacy.LinearConnectConstr(phase1, phase2, a1, a2, lb=None, ub=None, index1=-1, index2=0, adda=None, addx_index=None)[source]

Bases: object

Class for defining linear constraint functions.

Currentmodule:
find_time_gradient()[source]

For a matrix, find column 0 indice.

class trajoptlib.legacy.TrajOptMultiPhaseCollocProblem(probs, addx=None, process_args={})[source]

Bases: pyoptsolver.pyoptsolvercpp.OptProblem

A class for definition of trajectory optimization problem using collocation constraints with support for phase transition.

The support of multiple phase is implemented by calling functions defined in trajOptCollocProblem since I do not want to reinvent the wheels. I can conveniently add support for other constraints that connects two phases.

Currentmodule:
add_addx_constr(constr)[source]

Add a linear or nonlinear constraint associated with addx.

Parameters:constr – a point constraint.
add_addx_obj(obj)[source]

Add an objective evaluated at addx to the problem.

Parameters:obj – a point objective object
add_connect_constr(constr)[source]

Add a linear constraint that connects two phases.

Parameters:constr – a connect constraint object.
add_connect_linear_constr(constr)[source]

Add a linear connection constraint to the problem.

Parameters:constr – a LinearConnectConstr object.
add_connect_nonlinear_constr(constr)[source]

Add a nonlinear connect constraint to the problem.

Parameters:constr – a NonLinearConnectConstr object.
add_constr(constr)[source]

Add a constraint to the problem.

Parameters:constr – a general constraint function object.
add_nonlinear_constr(constr)[source]

Add a general nonlinear constraint to the problem.

Parameters:constr – a nonLinearConstr object.
add_nonlinear_obj(obj)[source]

Add a nonlinear objective to the problem.

Parameters:obj – a nonLinearObj object.
add_obj(obj)[source]

Add a objective function to the problem.

Parameters:obj – a general objective function object.
change_connect_time_constr_bound(num, xl, xu)[source]

Change the connect time constraint if other specification are required.

guess_gen_from_phase_sol(phase_sols, addX=[])[source]

Generate an initial guess for the multi-phase problem by concatenating solutions from single phases.

Parameters:phase_sols – list of dict, a list of guess of solutions to each phase
guess_gen_from_phase_traj(X=None, U=None, P=None, t0=None, tf=None, addx=None, tstamp=None, obj=None, addX=None, interp_kind='linear')[source]

Generate a guess from the trajectory in other phases.

The parameters are the same with .. py:classmethod::trajOptCollocation.genGuessFromTraj but a list version.

parse_f(sol)[source]

Use the solution and evaluate on all constraints. Check which are active and analyze why we are not converging.

Parameters:sol – ndarray, the solution we want to analyze
parse_sol(sol)[source]

Given a solution, we parse and return readable data structure.

Parameters:sol – ndarray or result object returned by SNOPT.
Return traj:a dict of keys ‘t’, ‘x’, ‘u’, ‘p’, ‘phases’.
  • ‘t’ is a concatenated time grid (might not be equidistant, but piecewise equidistant
  • ‘x’ ndarray, (*, dimx) is the concatenated state vector of all phases
  • ‘u’ ndarray, (*, dimu) is the concatenated control vector of all phases
  • ‘p’ ndarray, (*, dimp) is the concatenated parameter vector of all phases
  • ‘phases’ list of dictionaries composed of keys ‘t’, ‘x’, ‘u’, ‘p’, ‘addx’ where ‘addx’ is additional optimization variables.
pre_process()[source]

Initialize the instances of probFun now we are ready.

Call this function after the objectives and constraints have been set appropriately. It calculate the space required for SNOPT and allocates sparsity structure if necessary.

random_gen_x()[source]

Generate a random guess to the problem.

trajoptlib.legacy.manifoldConstr

alias of trajoptlib.trajOptManifoldCollocationProblem.ManifoldConstr

trajoptlib.legacy.trajOptManifoldCollocProblem

alias of trajoptlib.trajOptManifoldCollocationProblem.OptProblem

trajoptlib.legacy.systemWrapper

alias of trajoptlib.classBuilder.SystemWrapper

trajoptlib.legacy.daeSystemWrapper

alias of trajoptlib.classBuilder.DaeSystemWrapper

trajoptlib.legacy.nonLinearPointConstrWrapper

alias of trajoptlib.classBuilder.NonLinearPointConstrWrapper

trajoptlib.legacy.blockIndex(i, j, rows, cols, order='C')[source]

For a matrix block, we return the index of row and columns.

For a matrix we choose a block using the upper left corner positioned at (i, j) and size (row, col). Each element of the block has row and col index, they are returned in two arrays. The order controls we use row or column major order

For example, blockIndex(1, 3, 2, 3, ‘C’) returns (array([1, 1, 1, 2, 2, 2]), array([3, 4, 5, 3, 4, 5]))

i: int
the row of the upper left corner
j: int
the column of the upper left corner
rows: int
number of rows of the block
cols: int
number of columns of the block
order: char
(‘C’/’F’) if we return row or column major
class trajoptlib.legacy.GeometricRobot(dim, dimp=0)[source]

Bases: trajoptlib.trajOptBase.DaeSystem

A class that defines a geometric robot, no dynamics involved

dyn(t, x, u, p, y, G, row, col, rec, needg)[source]

Write dynamics function

class trajoptlib.legacy.GeometricRobotSystem(dim, dimp=0, ode='Euler')[source]

Bases: trajoptlib.trajOptBase.System

A class that implements a geometric robot, second order.

dyn(t, x, u, p=None, h=None)[source]

Dynamics function without gradient information.

It has to be overriden.

Parameters:
  • t – float, time when evaluating system dynamics
  • x – np.ndarray, (nx,) state variable
  • u – np.ndarray, (nu,) control variable
  • p – np.ndarray, (np,) additional optimizing variable
  • h – float, used for discretized system. Integration step size
Returns:

either dotx or x_k+1 depends on system type

jac_dyn(t, x, u, p, h=None)[source]

Dynamics function with Jacobian return.

It has to be overriden.

Parameters:x, u, p, h (t,) – see dyn
Returns:y: ndarray, either dotx or x_k+1
Returns:J: ndarray/spmatrix, returning Jacobian of this function evaluation
trajoptlib.legacy.parseX(x, N, dimx, dimu, dimp, uset0, usetf, setfinal=True)

Parse the solution into a dict of time, state, control, parameter.

Parameters:
  • x – ndarray, solution found by SNOPT
  • dimx, dimu, dimp (N,) – discretization of the problem
  • usetf (uset0,) – float/array like, specification of initial and final time
  • setfinal – if we set the final element of u/p the same with second last
Returns:

a dictionary of keys ‘t’, ‘x’, ‘u’, ‘p’

trajoptlib.legacy.showSol(solDict, xsplit=None, usplit=None, psplit=None, show=True)

Plot the parsed solution.

Parameters:
  • solDict – dict, returned from solParse; or a list of such dict. Then they are compared
  • xsplit – if state space is large, this splits it into several images it’s a list of int like (3, 6). None means no split
  • usplit – similar to xsplit, apply for control
  • psplit – similar to xsplit, apply for parameter
trajoptlib.legacy.getInf(n=None)

Return an inf array.

Parameters:n – int, size of the array to return, None means scalar
Returns y:the scalar inf or array of inf