/* * * This file is part of GRAMPC. * * GRAMPC - a gradient-based MPC software for real-time applications * * Copyright (C) 2014 by Bartosz Kaepernick, Knut Graichen, Tilman Utz * Developed at the Institute of Measurement, Control, and * Microtechnology, University of Ulm. All rights reserved. * * GRAMPC 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. * * GRAMPC is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with GRAMPC. If not, see <http://www.gnu.org/licenses/>. * *//* * * File: probfct.c * Authors: Bartosz Kaepernick, Knut Graichen, Tilman Utz * Date: February 2014 * Version: v1.0 * * Problem function for grampc toolbox. * * * This probfct file describes the dynamics, the cost function and the corresponding * derivatives of an overhead crane with 6 states and 2 controls. For a more * detailed model, for instance, see * * B. Käpernick and K. Graichen, "Model Predictive Control of an Overhead Crane * Using Constraint Substitution", Proceedings of the American Control Conference, * Washington D.C. (USA), 2013. * * * This probfct file provides an interface to GRAMPC. The underlying * optimal control problem (OCP) of the model predictive control (MPC) formulation * has the following structure * _T * / * min J(u,xk) = V(T,x(T)) + / L(t,x(t),u(t)) dt * u(.) _/ * 0 * . * s.t. x(t) = f(tk+t,x(t),u(t)), x(0) = xk * * Ul <= u(t) <= Uu, t in [0,T] * * with states x(t), constrained controls u(t) and the fixed prediction horizon T. * The functions V(t,x), L(t,x,u) and f(t,x,u) denote the terminal and integral * cost and the systems dynamics. Note that no terminal conditions for the states * are included in the problem formulation. * * The necessary optimality conditions can then be derived by means of the * Hamiltonian * * The function interfaces below have the following meaning (adj denotes the costates): * * sysfct: f(t,x,u) * * sysjacxadj: df(t,x,u)/dx' * adj * * sysjacuadj: df(t,x,u)/du' * adj * * sysjacx: df(t,x,u)/dx * * sysjacu: df(t,x,u)/du * * icostfct: L(t,x,u) * * icostjacx: dL(t,x,u)/dx * * icostjacu: dL(t,x,u)/du * * fcostfct: V(t,x) * * fcostjacx: dV(t,x)/dx * */#include"probfct.h"#define a11 -111.815132314573#define a12 1059.45323629074#define a21 -662.453528997459#define a22 -88.4173297966401#define b1 3727.17107715244#define b2 2947.24432655467#define w -130861.114561555voidsysdim(typeInt*Nx,typeInt*Nu){*Nx=2;// Number of states*Nu=2;// Number of control inputs}voidsysfct(typeRNum*out,typeRNumt,typeRNum*x,typeRNum*u,typeRNum*pSys){out[0]=a11*x[0]+a12*x[1]+b1*u[0];// f0 := x0'= a11*x0 + a12*x1 + b1*u0out[1]=a21*x[0]+a22*x[1]+b2*u[1]+w;// f1 := x1'= a21*x0 + a22*x1 + b2*u1 + w}voidsysjacxadj(typeRNum*out,typeRNumt,typeRNum*x,typeRNum*adj,typeRNum*u,typeRNum*pSys){out[0]=a11*adj[0]+a21*adj[1];// (df0/dx0)*adj0 + (df1/dx0)*adj1out[1]=a12*adj[0]+a22*adj[1];// (df0/dx1)*adj0 + (df1/dx1)*adj1}voidsysjacuadj(typeRNum*out,typeRNumt,typeRNum*x,typeRNum*adj,typeRNum*u,typeRNum*pSys){out[0]=b1*adj[0];// (df0/du0)*adj0 + (df1/du0)*adj1out[1]=b2*adj[1];// (df0/du1)*adj0 + (df1/du1)*adj1}/* * Matrix must be entered rowwise, i.e. A=[a11,a12;a21,a22] becomes * out[0]=a11; out[1]=a12; out[2]=a21; out[3]=a22; * Note that Matlab/Fortran does it columnwise ! */voidsysjacx(typeRNum*out,typeRNumt,typeRNum*x,typeRNum*u,typeRNum*pSys){out[0]=a11;// df0/dx0out[1]=a21;// df1/dx0out[2]=a12;// df0/dx1out[3]=a22;// df1/dx1}/* * Matrix must be entered rowwise, i.e. A=[a11,a12;a21,a22] becomes * out[0]=a11; out[1]=a12; out[2]=a21; out[3]=a22; * Note that Matlab/Fortran does it columnwise ! */voidsysjacu(typeRNum*out,typeRNumt,typeRNum*x,typeRNum*u,typeRNum*pSys){out[0]=b1;// df0/du0out[1]=0.0;// df1/du0out[2]=0.0;// df0/du1out[3]=b2;// df1/du1}voidfcostfct(typeRNum*out,typeRNumt,typeRNum*x,typeRNum*xdes,typeRNum*pCost){// V = (Delta x )^T * P * (Delta x)out[0]=(x[0]-xdes[0])*(x[0]-xdes[0])*pCost[0]// = (Delta x0)^2 * P0+(x[1]-xdes[1])*(x[1]-xdes[1])*pCost[1];// + (Delta x1)^2 * P1}voidfcostjacx(typeRNum*out,typeRNumt,typeRNum*x,typeRNum*xdes,typeRNum*pCost){out[0]=2*(x[0]-xdes[0])*pCost[0];// dV/d(Delta x0)out[1]=2*(x[1]-xdes[1])*pCost[1];// dV/d(Delta x1)}voidicostfct(typeRNum*out,typeRNumt,typeRNum*x,typeRNum*u,typeRNum*xdes,typeRNum*udes,typeRNum*pCost){// L = (Delta x )^T * Q * (Delta x) + (Delta u)^T * R * (Delta u)out[0]=(x[0]-xdes[0])*(x[0]-xdes[0])*pCost[2]// = (Delta x0)^2 * Q0+(x[1]-xdes[1])*(x[1]-xdes[1])*pCost[3]// + (Delta x1)^2 * Q1+(u[0]-udes[0])*(u[0]-udes[0])*pCost[4]// + (Delta x1)^2 * R0+(u[1]-udes[1])*(u[1]-udes[1])*pCost[5];// + (Delta x1)^2 * R1}voidicostjacx(typeRNum*out,typeRNumt,typeRNum*x,typeRNum*u,typeRNum*xdes,typeRNum*udes,typeRNum*pCost){out[0]=2*(x[0]-xdes[0])*pCost[2];// dL/d(Delta x0)out[1]=2*(x[1]-xdes[1])*pCost[3];// dL/d(Delta x1)}voidicostjacu(typeRNum*out,typeRNumt,typeRNum*x,typeRNum*u,typeRNum*xdes,typeRNum*udes,typeRNum*pCost){out[0]=2*(u[0]-udes[0])*pCost[4];// dL/d(Delta u0)out[1]=2*(u[1]-udes[1])*pCost[5];// dL/d(Delta u1)}
After compiling when it comes to the simulation I get a fatal error.
Can anyone help me?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello,
I tried to run the following code:
startMPC.m
probfct_test.c
After compiling when it comes to the simulation I get a fatal error.
Can anyone help me?
Hello,
Nhor must be greater than 1.
Best regards
Last edit: Tobias Englert 2017-12-02
Oh no! Thank you very much!