Topic outline

  • General

    TEMPO Summer School, July 17-21, 2017

    Hardware Implementation of Embedded Optimisation tempo logo



    The aim of this intensive five-days summer schools is to give hands-on experience in implementation of model predictive controllers (MPC) on embedded hardware like field-programmable gateway arrays (FPGAs), programmable logic controllers (PLCs), and Arduino microcontrollers. The course is recommended for both industrial and academic researchers as well as for master and PhD students of engineering, computer science, mathematics, and physics.


    Faculty of Chemical and Food Technology, Slovak University of Technology in Bratislava, Radlinskeho 9.

    2nd floor, block A, Slovak Chemical Library, conference room

  • PLC

    The PLC module will introduce participants to logic-based programming of PLCs and show how simple controllers can be implemented using basic building blocks. Moreover, in this module students will learn how to implement simple optimisation-based control strategies. The module will feature hands-on labs devoted to implementation of an intelligent, optimisation-based thermostat for residential buildings that can run on industrial-grade hardware.

  • FPGA

    The FPGA module will give participants hands-on experience in implementing a model predictive controller on a FPGA. The course will include an introduction to hardware description languages, such as VHDL, and the student will implement simple circuits, such as counters, on an FPGA using high level synthesis tools from Xilinx. By the end of the course, the student should be able to implement matrix-vector multiplications within a quadratic programming solver and perform Processor-in-the-Loop tests of a predictive controller.
  • Arduino

    The Arduino module will be a practical, hands-on introduction to programming embedded devices. Participants will learn fundamental ideas and concepts about the intertwined world of microcontroller programming and electronics via the popular Arduino prototyping system. Besides the basics, the module will also offer a particular focus on control-engineering related use of microcontrollers, detailing sensor and actuator interfacing and reliable real-time sampling.

    • Part I: Arduino basics - Computers and MCUs, Arduino hardware and IDE, serial communication, analog inputs, PWM outputs
    • Part II: Data acquisition and sampling with the Arduino - Sampling, data acquisition and experimental system identification
    • Part III: Closed loop control with the Arduino - Tracking by integrator-augmentation, LQ control, execution timing, real-time constraint violation
    • Part IV: - Introduction to muAO-MPC, code generation via Python, hardware deployment to the Arduino

  • Projects

    This section lists some possible projects for the summer school. Feel free to suggest your own project! To choose a project, fill out the Project Selection Form. You can view the project allocations here.

    Participants are encouraged to work in small teams (up to 4 persons) and to share responsibilities. Keep in mind that you will need to present the results of your project by means of nice slides, so don't forget to account for this factor in your time management (unless you want to do this off-site during the evening/night).

    You will have 10 minutes on Friday, July 21 to present the main results. Note that there are only 20 presentation slots available. It's up to the team members to decide who will deliver the presentation (you can also share). The schedule of individual presentations can be found here.

      PLC Projects

      1. Flexy control using a Siemens Simatic S7-200 PLC (max 4 teams)
        In this project you will learn how to connect analog inputs/outputs to a PLC and how to configure the input/output ports, will implement a control logic (on/off, PI, LQR) using ladder diagrams or function block diagrams, and will create graphical user interfaces to visualize the closed-loop performance. Four PLC stations will be available. The PLCs are installed in room no. 640 on the 6th floor of the building, block C. The project will be supervised by Richard Valo. For technical information, consult the S7-200 user's guide:

      2. Explicit MPC for the building temperature control example implemented in FBD on Loxone
        In this project you will learn how to synthesize an explicit MPC controller off-line by solving a parametric optimization problem, translate it into a binary search tree for a simple implementation, and implement the tree in FBD in the Loxone Config environment. Various extensions are possible: considering set-point tracking instead of disturbance rejection, adding integral action, incorporation of measured disturbances, etc. The responsible person is Michal Kvasnica. Supporting files: empc_regulation1.mempc_regulation2.mempc_tracking.m,

      3. Loxone showcase
        This is a free-form project where you implement your favorite non-trivial control logic in Loxone together with a mathematical model of a plant of your choice.

      FPGA Projects

      All FPGA projects will be supervised by Deepak Ingole and Harsh Shukla.

      1. FPGA Implementation of Explicit MPC  with Sequential Search Algorithm
        The objective of this project is to implement explicit MPC using sequential search point location algorithm on FPGA to control specific control application. You can construct explicit MPC in Multi-Parametric Toolbox (MPT) and export C code of sequential search algorithm which can be used in Vivado/ PRTOIP.   You can compare nominal implementation with parallelized implementation.

      2. FPGA Implementation of Hybrid MPC
        The objective of this project is to develop first order optimization method for hybrid MPC which can be employed in the closed-loop control of control application of your choice.  Your objective can be to increase speed and reduce resources.  

      3. FPGA Implementation of Explicit MPC  with Binary Search Tree Algorithm
        The objective of this project is to implement explicit MPC using binary search tree point location algorithm on FPGA to control specific control application. You can construct explicit MPC in Multi-Parametric Toolbox (MPT) and export C code of binary search tree algorithm which can be used in Vivado/ PRTOIP.   You can compare nominal implementation with parallelized implementation. 

      4. FPGA Implementation of PID Controller 
        One can implement classical PID controller on FPGA to control output(s) of your model/system of your choice. You can implement PID algorithm in serial as well as parallel fashion and compare resources of both the implementation. You can use VHDL/Verilog or C/C++ programming languages to develop PID. 

      5. Design and Implementation of a Real-time Traffic Light Control System
        In this project, a real-time traffic light control system algorithm is designed on FPGA using VHDL/Verilog/C/C++ code. The developed code is first modeled and simulated and then downloaded to FPGA board to verify its functioning.

      6. Floating Point Fused Add-Subtract and Fused Dot-Product Units
        This project aims to perform simultaneous floating point multiplication and add-subtract operations by implementing Floating Point Fused Add-Subtract and Fused Dot-Product Units in parallel. These units are simulated using Xilink Vivado/PROTOIP software.

      7. FPGA Implementation of LQR Controller
        Implement a LQR algorithm on FPGA using VHDL/Verilog or C/C++ programming languages. You can use model/system of your choice to control its state(s)/output(s). You can first design LQR in MATLAB and use same Q, R, and P values directly in HDL code.  

      8. FPGA Implementation of First-Order Optimization Algorithm
        The objective of this project is to implement first order optimization method like ADMM, Accelerated proximal gradient method, etc. You can develop your own algorithm or export it from any available solver.

      9. FPGA Implementation of Linear Solver
        The goal of this project is to implement linear solver (Ax=b) using matrix decomposition and forward/backward substitution approach. You will need to develop matrix decomposition algorithm like QR, LU or Cholesky decomposition. You can test implemented linear solver for different examples. 

      Arduino Projects

      This section presents possible Arduino-related project ideas you may work on. Team up with a mate and select a project idea that you will work on Thursday. May the odds be ever in your favor.

      1. A better Flexy model
        Identify a better model for the Flexy device using your Arduino and MATLAB. Would a higher order model capture higher order dynamics? Could you include nonlinearities in your model? Would a different identification experiment, using e.g. pseudo-random binary signals (PRBS) yield better results? You should repeat identification experiments and verify the improved model with measurement data.

      2. Explicit Flexy
        Design and deploy an explicit (multi-parametric) model predictive controller to govern the position of the flex sensor on the Flexy device. You may use the Multi-Parametric Toolbox to design and generate the C-source code for the controller. Hint: You will need to force large matrices to be stored in ROM instead of RAM by the PROGMEM directive. Do not forget to read them back in your program, the MCU knows only the address of the array, not its location (look for the PROGMEM documentation).

      3. Flexy in Simulink
        Design a feedback controller of your choice (I recommend LQ) in Simulink and deploy it directly to hardware. After installing the Arduino Hardware Support Package for Simulink, you will be able to deploy your block schemes directly to the Arduino. 

      4. Explore μAO-MPC!
        The workshop modules did not allow us to fully explore μAO-MPC. Your task is to repeat the code generation procedure introduced during the workshop yourself! You will need a Python interpreter, then you will need to install μAO-MPC. The μAO-MPC library is also dependent on several other libraries. Repeat the code generation procedure and experiment with the various features of the software!

      5. Re-design Flexy
        Your task is to analyze the hardware design of the Flexy device and suggest incremental changes. How could you make this didactic tool even better? Here are some suggestions: Plot the output of the ADC connected to the flex sensor and test the range of output values (ADC levels). What portion of the ADC resolution does the flex sensor circuitry cover? How could this be improved? Yet another idea can be to power the Arduino from the 12 V external adapter, instead of the USB port of the computer. How could you do this? 

      6. Your own MPC problem on Arduino
        Similar to your computer, the Arduino can be used to run just simulation studies without controlling hardware, the serial interface is of much help in these cases. Your task would be to attempt to design and deploy your very own MPC problem to the Arduino MCU and test it in simulation. The advantage compared to a test in MATLAB is of course, that you will learn about timing and memory properties and may run into additional difficulties because of finite and limited numerical precision. You can use any method to design and deploy your MPC controller, but stick to fairly low-order linear problems.

      7. Kalman filters
        A state-feedback controller is useless without a proper observer. Study the design and deployment of Kalman filters to the Arduino. Even though we have not assumed a state observer for the Flexy problem, you may design and include one - the advantage could be robustness to noise. You may also choose to design and deploy a Kalman filter for a different process then the Flexy, in this case you may choose to evaluate your results in simulation that is running on the Arduino.

      8. Arduino and MATLAB
        Simulink is not the only way you can control your Arduino from your computer. Explore the possibilities offered by MATLAB scripts in controlling your Arduino. You will have to install the Arduino Hardware Support Package. The Arduino is working alongside your computer thus, strictly speaking, real-time sampling is not possible. You can still experiment to extract measurement data, control inputs and outputs directly from the command line. Could you devise a closed-loop controller (in pseudo-real time) running directly in MATLAB and controlling the Flexy?

      9. Timing is everything!
        Your job will be to bypass the Timer1 (TimerOne) library entirely and deploy your very own sampling framework by manipulating the registers of the MCU. Reliable sampling in digital control is a fundamental requirement and learning about hardware timers, counters and interrupts is of utmost importance when working with microcontrollers. Your friend for this adventure is the data specification sheet for the microcontroller in the Arduino UNO, look for "atmega 328 datasheet", which will yield a hefty document. Look into "Timers" to start.

      10. Frugal programming
        Not thinking about the memory footprint and type of your variable is a luxury that you can only afford in MATLAB. In a microcontroller, you must squeeze the last available bit from your program to save valuable memory space. Also, you must think about removing any unnecessary operations to reduce execution time. Your task will be to take a closed-loop control framework we have covered during the workshop and attempt to remove any superfluous parts. Your measure of success is listed in the output of the Arduino IDE reporting on memory footprint, but you may also attempt to shorten execution time (especially with MPC). You may measure the execution time by an oscilloscope, ask Martin Kalúz for one.

      11. Ditch the Arduino IDE
        The Arduino IDE was designed to be as simple as possible, but it is not the only way to program your Arduino. There are several tools available online, that may help you to get the most out of your Arduino board. Test and compare these tools and see if you find anything suiting your taste. A starting point could be Atmel Studio, that is a professional tool made by the company manufacturing the chip itself (free software). Another very common IDE that is used for a plethora of other hardware is Eclipse. Other possibilities include an extension for Microsoft Visual Studio, compiling and deploying your program from command line and many other possibilities. There is even an IDE for Android devices!

      12. Improve the Flexy library
        As you know by now, the Flexy is meant for control systems engineering education. Its library currently contains a PID control example. Your task in this project will be to augment the library with your very own didactic and educational examples. Want to demonstrate system identification? Show why using on-off control is a bad idea? Create an LQ control example? This is your chance. Be sure to have an educational spirit on your mind and stay consistent with the naming convention of the library.

      13. Line Following Robots Contest (max 4 teams)
        In this project, you will program a small line following robot to compete in time-trial racing on a circuit. Each robot has two separately operated wheels to control its speed and direction. The robot can detect a line via 5 IR sensors and can detect an obstacle in front of it using an ultrasonic sensor.

        Each team will get one robot equipped with an Arduino Uno board. The main goal is to program the robot to follow a line in the best possible way and to be also able to cope with the obstacles in the way. The robot with the better control performance will be able to finish the circuit in less time than other robots. The selection of control algorithms is arbitrary. Any type of control strategy can be used (logic, PID, LQR, heuristic, etc.).
        Robot documentation and library can be found on the following wiki page. The project will be supervised by Martin Kalúz.

      14. Inverted Pendulum (max 1 team)
        In this project you will work with a real inverted pendulum. The process can be controlled via an Arduino Mega board. The mathematical model of the pendulum will be provided to you, but if you look for some bigger challenge, you can derive one yourself. Recommended control strategies to implement are PID and LQR (in discrete-time). The project will be supervised by Peter Bakaráč.

      15. A thermo-optical process (max 3 teams)
        In this project, you will control the uDAQ28/LT thermo-optical process. Here, Arduino UNO will be used as a control platform. The project includes wiring, data acquisition, identification, controller design and its validation. The project will be supervised by Martin Kalúz.
        Pinout of analog interface.