Giter VIP home page Giter VIP logo

nosnoc's Introduction

NOSNOC

NOSNOC is an open-source MATLAB software package for NOnSmooth Numerical Optimal Control. The Python package nosnoc_py with similar functionality is available as well.

A detailed overview of the theory and methods behind NOSNOC can be found in the course material of the Summer School on Direct Methods for Optimal Control of Nonsmooth Systems.

General

NOSNOC is a tool for numerically solving optimal control problems with nonsmooth dynamical systems with switches and/or state jumps. It supports:

  1. Automatic discretization via the FESD method - high accuracy and correct sensitivities. Note that classical time-stepping methods only have first-order accuracy and wrong sensitivities even when they appear to be differentiable.

  2. Automatic reformulations of systems with state jumps (e.g. contact problems) via time-freezing into Filippov systems/PSS. (enables high accuracy even for systems with state jumps)

  3. Solving the nonsmooth nonlinear programs via homotopy methods. Enables the use of off-the-shelf solvers like IPOPT and SNOPT.

NOSNOC relies on the recently introduced Finite Elements with Switch Detection (FESD) which enables high accuracy optimal control of systems with switches and jumps. It enables the treatment of a broad class of nonsmooth systems in a unified way.

NOSNOC offers several ways to treat switched systems, piecewise smooth systems, Filippov systems, hybrid systems, rigid body models with impacts and friction in simulation, and optimal control. It discretizes a Dynamic Complementarity System (DCS) with the FESD method and solves the resulting mathematical program with complementarity constraints (MPCCs). The MPCCs are solved in a homotopy loop with a standard solver like IPOPT or SNOPT. The user may directly provide a DCS or define the different modes of a Filippov system and the reformulation is automated.

With NOSNOC one can simulate and solve optimal control problems subject to different kinds of nonsmooth systems, by declaring the dcs_mode:

  1. settings.dcs_mode = 'Stewart' - for treating Filippov systems via Stewart's reformulation
  2. settings.dcs_mode = 'Step' - for treating nonsmooth systems via set valued step functions (covers also all Filippov systems that are treated with Stewart's).
  3. settings.dcs_mode = 'CLS' - for rigid bodies with friction and impact (also called complementarity Lagrangian systems (CLS)) - uses FESD tailored to CLS.
  4. settings.time_freezing = 1 - and using for the dcs_mode = Step, the CLS is reformulated into an equivalent Filippov system and treated with FESD.

Installation

NOSNOC requires CasADi version 3.5.5 and Matlab version R2021b or later.

Installation for MATLAB

  1. Install CasADi and make sure it is added to your MATLAB path. For CasADi installation instructions follow visit: https://web.casadi.org/get/

  2. Clone this repository

git clone --recursive https://github.com/nurkanovic/nosnoc.git
  1. Open the NOSNOC folder in Matlab and run the install_nosnoc script
>> install_nosnoc

Note that IPOPT is shipped with CasADi. More information including detailed documentation can be found on its homepage

Installation for python

Go to the nosnoc_py repository and clone it.

Afterward,

  1. Setup virtual environment:
virtualenv env --python=python3
  1. Source environment:
source env/bin/activate
  1. Install
pip install -e .

Using NOSNOC

The interface of NOSNOC is based on the symbolic modeling framework CasADi. User inputs should be given as CasADi expressions.

To get started we recommend you look into our example libraries for MATLAB or python.

Literature - theory and algorithms

FESD

Finite Elements with Switch Detection for Direct Optimal Control of Nonsmooth Systems
A.Nurkanović, M. Sperl, S. Albrecht, M. Diehl
arXiv preprint 2022

@article{Nurkanovic2022,
  title={Finite elements with switch detection for direct optimal control of nonsmooth systems},
  author={Nurkanovi{\'c}, Armin and Sperl, Mario and Albrecht, Sebastian and Diehl, Moritz},
  journal={arXiv preprint arXiv:2205.05337},
  year={2022}
}

Time - Freezing

A Time-Freezing Approach for Numerical Optimal Control of Nonsmooth Differential Equations with State Jumps
A. Nurkanović, T. Sartor, S. Albrecht, M. Diehl
IEEE Control Systems Letters 2021

The Time-Freezing Reformulation for Numerical Optimal Control of Complementarity Lagrangian Systems with State Jumps
A. Nurkanović, S. Albrecht, B. Brogliato, M. Diehl
Automatica 2023 (accepted for publication)

Continuous Optimization for Control of Hybrid Systems with Hysteresis via Time-Freezing
A.Nurkanović , M. Diehl
IEEE Control Systems Letters 2022

Literature - Software

NOSNOC

NOSNOC: A Software Package for Numerical Optimal Control of Nonsmooth Systems
A.Nurkanović , M. Diehl
IEEE Control Systems Letters 2022

@article{Nurkanovic2022,
  title={NOSNOC: A software package for numerical optimal control of nonsmooth systems},
  author={Nurkanovi{\'c}, Armin and Diehl, Moritz},
  journal={IEEE Control Systems Letters},
  volume={6},
  pages={3110--3115},
  year={2022},
  publisher={IEEE}
}

CasADi

CasADi - A software framework for nonlinear optimization and optimal control
J.A.E. Andersson, J. Gillis, G. Horn, J.B. Rawlings, M. Diehl
Mathematical Programming Computation, 2019

IPOPT

On the implementation of an interior-point filter line-search algorithm for large-scale nonlinear programming
A. Wächter, L. T. Biegler Mathematical programming, 2006

Contact

Feel free to contact one of the main developers directly: Armin Nurkanović, [email protected] Anton Pozharskiy [email protected] Jonathan Frey [email protected] If you have questions, remarks, or comments, you are strongly encouraged to report them by creating a new issue on this Github page. Success stories and source code contributions are very welcome.

nosnoc's People

Contributors

apozharski avatar freyjo avatar nurkanovic avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

nosnoc's Issues

Create a new README

New README should contain a clearer explanation of the steps that NOSNOC uses to solve an OCP/simulate a system.

Rleaxed and slacked constraints in nosnoc

Currently, we support ell_1 relaxation of some terminal constraints

  1. the terminal constraints of the ocp
  2. some of the FESD/time-freezing terminal constraints to meet a certain final numerical/physical time.

I would still steer the relaxation of these constraints with appropriate separate options, as we have them now.

In addition to this, it would be nice to be able to relax other constraints (e.g. using vdx internally to define according variables and constraints). In particular it would be nice to relax:

  1. Path constraints
  2. Dynamics constraints (maybe to separate even between the differential and algebraic part of the dynamics)

Choices for relaxing:

  1. ell 2 (every constraint gets a separate slack), maybe we can have upper bounds on slacks to avoid unbounded problems
  2. ell1 (every constraint gets a separate slack)
  3. ell_inf (every constraint group gets one slack)

Choice for penalty parameter:

  1. fixed value (separate parameter for every constraint group, by groups i mean: path, dynamics, terminal, terminal_algoritmic (nice and instructive names are a plus))
  2. use rho = 1/sigma - we should decide if we can mix fixed values and homotopy penalities. one one hand it gives a lot of flexibility, on the other hand too many choices might be confusing.

Clean up and document results

Currently the results struct has lots of noise in it with possibly empty entries. Remove these and document what we store in the results.

This may be irrelevant if we use vdx.

The main_throwing_ball.m example is not working, the setting is wrong?

clear all
clc
close all
import casadi.*
%% model parameters
e = 0.2; u_max = 9; beta = 0.0; mu=0;
%% NOSNOC settings
problem_options = NosnocProblemOptions();
solver_options = NosnocSolverOptions(); %% Optionally call this function to have an overview of all options.

problem_options.n_s = 3;
solver_options.mpcc_mode = 'Scholtes_ineq';
solver_options.homotopy_update_rule = 'superlinear';
% problem_options.step_equilibration = 'direct_homotopy';
problem_options.use_fesd = 1;
problem_options.time_freezing = 1;

problem_options.local_speed_of_time_variable = 1;
problem_options.stagewise_clock_constraint = 0;
problem_options.nonsmooth_switching_fun = 0;
problem_options.pss_lift_step_functions = 0;

problem_options.no_initial_impacts = 0;
% solver
solver_options.opts_casadi_nlp.ipopt.max_iter = 1e5;
solver_options.opts_casadi_nlp.ipopt.tol = 1e-7;
solver_options.opts_casadi_nlp.ipopt.acceptable_tol = 1e-5;
solver_options.use_previous_solution_as_initial_guess = 0;
solver_options.N_homotopy = 6;
solver_options.print_level = 3;
solver_options.comp_tol = 1e-6;
solver_options.elastic_scholtes = 1;
%% model parameters
g=9.81;
q_target = [4;0.5];

%% solver
model = NosnocModel();
model.mu_f = mu;

problem_options.T = 4;
problem_options.N_stages = 20;
problem_options.N_finite_elements = 3;
% model equations
q = SX.sym('q',2);
v = SX.sym('v',2);
u = SX.sym('u',2);

model.lbx = [0;-0.001;0;-inf]; model.ubx = [4;inf;inf;inf];
model.x0 = [0;0.5;0;0];
model.x = [q;v]; model.u = u; model.e = e ;
model.f_c = q(2)-0;
model.f_v = [u-[0;g]-betavsqrt(v(1)^2^2+v(2)^2+1e-3)];
model.J_tangent = [1; 0];
model.dims.n_dim_contact = 2;

% Objective and constraints
model.f_q = u'u; model.f_q_T = 100v'*v;
model.g_path = u'*u-u_max^2;
model.g_terminal = q-[q_target];

mpcc = NosnocMPCC(problem_options, model);
solver = NosnocSolver(mpcc, solver_options);
[results,stats] = solver.solve();

Support for MPVCs via mpccsol

By introducing a slack variable, MPVCs are equivalent to MPCCs. This can always be done manually, but it would be maybe useful to automate this step if the user indicates that the given problem is a mpvc (or we automatically recognize it by looking at the bounds of G and H) and transform into an mpcc.
maybe it makes sense to rename everything that is mpcc into mpec.

Can nosnoc determine the state transition borders (gap functions)?

Hi,
Thanks for the nice tool and quite interesting research papers.

I am not sure how to formulate one hybrid dynamics problem in order to solve it with Nosnoc. In simple terms, it is as follows:

master; % integer, influences the speed capabilities by switching the profiles 
u; % continuous control

if master==0
    f = profile_0; % define dynamics profile 0
elseif master==1
    f = profile_1; % define dynamics profile 1 
end

% goal: achieve *maximum speed*. 
% Determine best `u` (continuous control) and `master` (profile sequence e.g. profile_0, profile_1, profile_0)

I have checked examples, but I start to think you might not be dealing with these cases. I saw that you are defining the gap function. However, in this case the gap function should be kinda determined by the algorithm and it might be changing in time as well.

Would really appreciate feedback.

Best,

Add option `relax_terminal_physical_time` for time_freezing problems

We have this for the plain numerical time, to make an ell_1 relaxation of the terminal time constraint.
It would be nice to have the same also for physical time constraints (maybe even also for the stagewise constraints - but to be discussed).

I want also to test with this the ease of use of vdx, once we migrated to it.

Simplify index tracking

Currently indexes are tracked independently at different levels and must be handled somewhat manually.
Several things need to be done to make maintenance of NOSNOC easier:

  • Remove FiniteElement and ControlStage classes
  • Use a smarter index tracking utility to avoid pre-definition, etc. Something similar to CasADi "structures" in casadi.tools

Clock state for integration grid and block band structure in FESD

Currently, we have for every FE an h.
Alternatively, we can define a clock state t, and have a "control variable" h_n to determine the length of a finite element.
We simply integrate the clock state as t_{n+1} = t_n + h_n; and enforce a "terminal" constraint
t_N = T_final instead of sum_n h_n = T_final
The intermediate variables t_n help eliminate sum_n h_n = T_final, which kills the block banded structure.

nosnoc mpc class

As we will have a new integration and OCP class after the refactoring, it would be nice to add afterwards an mpc loop that solves a sequence of OCPs.

This will also have some options, e.g. how to initialize? To use an early homotopy iterate or the solution of the previous step?
For having the new x0, use the same integrator (e..g., just shift ocp solution) or simulate with a different nosnoc integrator (e.g. higher order, more intermediate FEs).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.