Code Monkey home page Code Monkey logo

predictivecontrol's Introduction

Predictive Control in Python

This package implements Predictive Control techniques in Python2.7. Currently it supports only Model-Predictive Control (MPC), for SISO and MIMO systems, although a class for Economic MPC has been added (not tested!).

Dependencies

Installation

Install the package directly from PyPI:

pip install predictivecontrol

Or clone the repository and install locally:

pip -e <path_to_repository>

Usage

Simply import the class of controller wanted and instantiate it with valid state-space model matrices (i.e., A, B and C). Optional arguments include sampling time (T), prediction (Np) and control horizons (Nc), actuation limits (umin, umax, dumin, dumax), and whether the provided state-space model should be discretized (discretize).

You may also posteriorly set the prediction and control horizons, the actuation limits, the references and output weights for your control system.

Then use the run() method to update the controller output based on the last sensed or estimated states.

import numpy as np
from predictivecontrol import MPC

# Define your state-space matrices, i.e. A, B, C

# Instantiate controller
mpc = MPC(A,B,C)

# Set prediction and control horizons
mpc.set_predict_horizon(10)
mpc.set_control_horizon(4)

# Set control restrictions (currently variation and amplitude)
mpc.umin, mpc.umax = np.array([0]), np.array([100])     # Considering a SISO system
mpc.dumin, mpc.dumax = np.array([-0.5]), np.array([0.5])

# Set setpoints and output weights
mpc.set_reference(np.array([10]))
mpc.set_output_weights(np.array([1]))

mpc.run()

Examples

This package currently contains 4 examples:

  • Voltage control in a simulated First-order RC Lowpass filter;
  • Motor shaft angular velocity control in a simulated DC Motor;
  • Angular velocity control in 3-DoF rotating rigid body (3-input-3-output MIMO);
  • Toy mock MIMO systems, modelled from arbitrary transfer matrices;

You can run the examples with:

python <example>.py

If you want to plot the results, you must install the matplotlib package:

pip install matplotlib

The plotted results you will see are (for DC motor example):

States' plot from DC Motor example Inputs' plot from DC Motor example Outputs' plot from DC Motor example

To-Do

  • Test MPC with a different model [DONE]
  • Extend MPC to support MIMO systems [DONE]
  • Test MPC with MIMO systems [DONE]
  • Test E-MPC SISO and MIMO
  • Account for external disturbances in MPC SISO and MIMO
  • Account for external disturbances in E-MPC SISO and MIMO

Credits

Code inspired by Prof. Dr. Aurelio Salton's MPC matlab example.

Collaborators

predictivecontrol's People

Contributors

rgmaidana avatar

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.