Skip to content

Instantly share code, notes, and snippets.

View jaeandersson's full-sized avatar

Joel Andersson jaeandersson

  • Madison, Wisconsin
View GitHub Profile
@jaeandersson
jaeandersson / gist:5531420
Created May 7, 2013 09:32
modifications of examples/cplusplus/ipopt_nl.cpp
/*
* This file is part of CasADi.
*
* CasADi -- A symbolic framework for dynamic optimization.
* Copyright (C) 2010 by Joel Andersson, Moritz Diehl, K.U.Leuven. All rights reserved.
*
* CasADi is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
@jaeandersson
jaeandersson / gist:8555820
Created January 22, 2014 09:22
Get diagonal entries of the Hessian in CasADi
#include <iostream>
#include <fstream>
#include <ctime>
#include <iomanip>
#include <symbolic/casadi.hpp>
#include <symbolic/stl_vector_tools.hpp>
using namespace CasADi;
using namespace std;
@jaeandersson
jaeandersson / Circle.m
Last active August 29, 2015 13:58
(Incomplete) Matlab interface generated from https://github.com/jaeandersson/swig/tree/matlab
classdef Circle < Shape
methods
function self = Circle(varargin)
self@Shape('_swigCreate',uint64(0),false);
if nargin==3 && ischar(varargin{1}) && strcmp(varargin{1},'_swigCreate')
self.swigCPtr = varargin{2};
self.swigOwn = varargin{3};
else
% How to get working on C side? Commented out, replaed by hack below
%self.swigCPtr = example_wrap('new_Circle',varargin{:});
@jaeandersson
jaeandersson / qpsolve.py
Last active August 4, 2024 04:29
Solve QP using qpOASES and CasADi from Python
import numpy as NP
import casadi as C
def qpsolve(H,g,lbx,ubx,A=NP.zeros((0,0)),lba=NP.zeros(0),uba=NP.zeros(0)):
# Convert to CasADi types
H = C.DMatrix(H)
g = C.DMatrix(g)
lbx = C.DMatrix(lbx)
ubx = C.DMatrix(ubx)
A = C.DMatrix(A)
A = A.reshape((A.size1(),H.size1())) # Make sure matching dimensions
@jaeandersson
jaeandersson / e5_unfinished.py
Created August 6, 2014 02:20
Incomplete implementation of a dynamic programming for a 2-state system
from pylab import *
# End time
T = 10.
# Number of control intervals
N = 20
# Number of Runge-Kutta 4 steps per interval and step size
NK = 20
@jaeandersson
jaeandersson / direct_single_shooting.py
Created August 6, 2014 22:45
Direct single shooting with CasADi
from casadi import *
from numpy import *
import matplotlib.pyplot as plt
N = 20 # Control discretization
T = 10.0 # End time
# Declare variables (use scalar graph)
u = SX.sym("u") # control
x = SX.sym("x",2) # states
@jaeandersson
jaeandersson / direct_multiple_shooting.py
Created August 7, 2014 12:08
Direct multiple shooting with CasADi
from casadi import *
from numpy import *
import matplotlib.pyplot as plt
N = 20 # Control discretization
T = 10.0 # End time
# Declare variables (use scalar graph)
u = SX.sym("u") # control
x = SX.sym("x",2) # states
@jaeandersson
jaeandersson / solution_exercise4.py
Last active August 29, 2015 14:06
Solution, exercise 4
#import casadi
import numpy
from casadi import *
# Initial and final position
px0 = 0.0; py0 = 1.5
pxF = 20.0; pyF = 0.0
# Time horizon and discretization
T = 3.0
@jaeandersson
jaeandersson / quadcopter.py
Last active August 29, 2015 14:06
Quadcopter model by Joris Gillis
from casadi import *
from casadi.tools import *
import numpy
from numpy import cos,sin, vstack, hstack, multiply
class Quadcopter:
"""
Quadcopter model
@jaeandersson
jaeandersson / solution_exercise8.py
Created September 24, 2014 09:40
Solution, Exercise 8 (first part)
import numpy as NP
from casadi import *
# Choose collocation points
d = 4 # Degree
tau_root = collocationPoints(d,"legendre")
# Calculate coefficients
C = DMatrix.nan(d+1,d+1) # For the collocation equation
D = DMatrix.nan(d+1) # For the continuity equation