Skip to content

Code Structure

Philipp Foehn edited this page May 14, 2018 · 1 revision

The whole MPC is based on ACADO (http://acado.github.io/). ACADO's C++ interface is used to describe the quadrotor model and parameters for transcription into a quadratic program, which is then solved with qpOASES (https://projects.coin-or.org/qpOASES). To compile and run, none of these dependencies are needed, since the generated code is already included in this repository. To modify the model and solver options, please install ACADO from http://acado.github.io/install_linux.html.

The code is organized as follows:

Solver mpc_solver

The auto-generated model, transcription, and solver is built as a library called mpc_solver. This library consist of purely auto-generated code with nomenclature, code-style and structure as used in ACADO.

Wrapper mpc_wrapper

To wrap this into a standard interface, the library mpc_wrapper is used. ACADO uses arrays with column-major format to store matrices, since this is rather inconvenient, mpc_wrapper provides interfaces using Eigen objects by mapping the arrays.

  • It is written to be compatible even with changing model descriptions in the mpc_solver.
  • It should prevent the most common runtime errors caused by the user by doing some initialization and checks with hardcoded parameters, which are overwritten in normal usage.

Controller mpc_controller

To provide not only a solver, but a full controller, mpc_controller is a library based on the previous mpc_solver and mpc_wrapper, providing all funcitonality to implement a controller with minimal effort. It provides two main execution modes:

  • Embedded: The mpc_controller can be included in any oder controller class or copilot by generating an object with the default constructor "MPC::MpcController controller();". It still registers node-handles to publish the predicted trajectory after each control cycle, but does nothing more. It only provides the interfaces of ControllerBase as in the LargeAngleController but without a specific class for parameters.

  • Standalone (not yet provided): The mpc_controller object can be passed node-handles or creates its own, registers multiple subscribers and publishers to get a state estimate as well as the control goals (pose or trajectory) and registers a timer to run a control loop. It works as a full standalone controller which can be used with the oneliner: MPC::MpcController<double> controller(ros::NodeHandle(), ros::NodeHandle("~")); as in test/control_node.cpp and launch/mpc_controller.launch.

Directories

  • The main source code for the ROS node is contained in include and src.
  • The launch file to start the ROS node is located in launch, whereas the corresponding parameter file(s) are stored in parameters in the .yaml file format.
  • model contains the MPC-description quadrotor_model_thrustrates.cpp which uses ACADO to generate the code in model/quadrotor_mpc_codegen.
  • externals contains the qpOASES solver used by the MPC.
Clone this wiki locally