embedded optimization for resource constrained platforms...

25
Embedded Optimization for Resource Constrained Platforms Collaborative Project FP7-248940 Seventh Framework Programme ICT-2009.3.4 - Embedded Systems Design Deliverable : D7.3 Documentation for platform modules and release to EMBOCON website Research leading to these results has received funding from the European Community Seventh Framework Programme, Grant Agreement Number 248940 Written by M. Vukov, A. Suardi Reviewed by C. Schoppmeyer Delivery Date August 28, 2013 Work Package WP7: Integration of Embedded Optimization Modules for the Open Platform Dissemination Level Public (PU)

Upload: others

Post on 13-Sep-2020

19 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Embedded Optimization for Resource Constrained Platforms ...grk1855.tu-dortmund.de/cms/Medienpool/forschungsumgebung/...Embedded Optimization for Resource Constrained Platforms Collaborative

Embedded Optimization forResource Constrained Platforms

Collaborative Project FP7-248940Seventh Framework Programme

ICT-2009.3.4 - Embedded Systems Design

Deliverable : D7.3

Documentation for platform modules and release to EMBOCONwebsite

Research leading to these results has received funding from the European CommunitySeventh Framework Programme, Grant Agreement Number 248940Written by M. Vukov, A. Suardi

Reviewed by C. Schoppmeyer

Delivery Date August 28, 2013

Work Package WP7: Integration of Embedded Optimization Modules for theOpen Platform

Dissemination Level Public (PU)

Page 2: Embedded Optimization for Resource Constrained Platforms ...grk1855.tu-dortmund.de/cms/Medienpool/forschungsumgebung/...Embedded Optimization for Resource Constrained Platforms Collaborative

EMBOCON: FP7-ICT-248940 August 28, 2013

Contents

1 Executive Summary 3

2 Documentation of the Interfaces 4

3 Documentation of the Supervisor 4

4 Documentation of the GEMS 44.1 Setting up the simulation for sGEMS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54.2 Setting up the simulation for GEMS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5

5 Documentation of the platform modules 55.1 ACADO Code Generation Tool . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6

5.1.1 Crane and Kite Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65.1.2 Implementing your own problem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6

5.2 qpOASES . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75.2.1 Crane Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75.2.2 Implementing your own problem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7

5.3 FORCES . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85.4 MPT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85.5 Instructions for interfacing an FPGA-based control system with GEMS/sGEMS . . . . . . . . 8

5.5.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105.5.2 XPS: building the interface framework module and interfacing it with the controller

module . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115.5.3 Building the interface framework module . . . . . . . . . . . . . . . . . . . . . . . . 115.5.4 Interfacing the interface framework module with the controller module . . . . . . . . 125.5.5 SDK: building the embedded software application . . . . . . . . . . . . . . . . . . . 155.5.6 Running the embedded software application on the FPGA . . . . . . . . . . . . . . . 205.5.7 Interfacing with FPGA . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 225.5.8 How to port the provided example interface framework to any other applications . . . 22

5.6 Combined Module CasADi and Ipopt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 235.7 Third Party Module - SUNDIALS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23

Bibliography 25

D.7.3: Documentation for platform modules and release to EMBOCON website Page 2 of 25

Page 3: Embedded Optimization for Resource Constrained Platforms ...grk1855.tu-dortmund.de/cms/Medienpool/forschungsumgebung/...Embedded Optimization for Resource Constrained Platforms Collaborative

EMBOCON: FP7-ICT-248940 August 28, 2013

1 Executive Summary

The deliverable reports the documentation and the release of the documentation for the set of standardizedsoftware interface, the supervisor, GEMS and the platform modules. All documentation is released on theofficial EMBOCON website.

The documentation of the set of software interfaces and the supervisor are provided as (final) specification.The documentation of GEMS and the platform modules are provided as user guide in form of examples, whichshould lead users to an efficient use of all platform components.

The documentation for the interfaces, the supervisor, GEMS, and the released platform modules are released onthe following parts of the EMBOCON websites: http://www.embocon.org/index.php/Category:Interfaces, http://www.embocon.org/index.php/Supervisor spec, and http://www.embocon.org/index.php/Category:GEMS.

The software source codes including all examples are uploaded to the following GitHub repositories: https://github.com/EMBOCONcs/EMBOCON Interfaces and https://github.com/EMBOCONcs/GEMS, as reportedin the Deliverable 7.2.

D.7.3: Documentation for platform modules and release to EMBOCON website Page 3 of 25

Page 4: Embedded Optimization for Resource Constrained Platforms ...grk1855.tu-dortmund.de/cms/Medienpool/forschungsumgebung/...Embedded Optimization for Resource Constrained Platforms Collaborative

EMBOCON: FP7-ICT-248940 August 28, 2013

2 Documentation of the Interfaces

The EMBOCON Software Platform offers a set of standardized software interfaces. The set of software inter-faces includes the ModelInterface, the OptimizerInterface, the ObserverInterface and the SimluationApplica-tionInterface. The interfaces form the basis for the interaction between the different modules of the softwareplatform. These interfaces specify sets of callable functions for the different modules to trigger computationroutines in the corresponding modules. The set of specified functions of an interface includes standard func-tions which have to be impemented by the module and optional functions which are used in special problemclasses or for debugging purpose. The input and output parameters of the interace functions define the datacontent and the data structures which are exchanged when calling a function.

The set of standardized software interfaces is documented in the final specification of the EMBOCON platformin deliverable D2.3. The final specification includes a detailed documentation of all function call specificationsof all interfaces. The deliverable D2.3 also includes the licensing information regarding the interfaces.

The final interface specification of the EMBOCON platform is released (published) on the following EMBO-CON website: http://www.embocon.org/index.php/Category:Interfaces.

3 Documentation of the Supervisor

The supervisor of the EMBOCON software platform forms the communication manager between an optimizer,an observer and an application or simulation environment of the optimization routine. The supervisor is re-sponsible for the initialization and freeing of the different elements and for triggering the functions calls ofthe elements in the right order. The supervisor others logging of data like controls, states etc. and measurescomputation times for all function calls. The measured timings together with the logged data can be used fortesting, validation and performance evaluation of numerical algorithms.

The supervisor is documented in the final specification of the EMBOCON platform in deliverable D2.3. Thefinal specification includes a documentation of the basic computation cycle of the supervisor. The deliverableD2.3 also includes the licensing information regarding the supervisor.

The final supervisor specification of the EMBOCON platform is released (published) on the following EMBO-CON website: http://www.embocon.org/index.php/Supervisor spec.

4 Documentation of the GEMS

GEMS is designed to be a minimal-footprint implementation of the EMBOCON Supervisor Specification ofthe EMBOCON open software platform. The GEMS was implemented within the EMBOCON project offeringthe full support of the entire set of EMBOCON Standard Interfaces of the EMBOCON platform as well asmeasuring function call computation times and logging of all data.

The architecture of GEMS includes the four supported interfaces and the data which is exchanged. The GEMSimplementation supports all standard function call definitions of the interfaces and some of the optional functioncall definitions.

The implementation language of GEMS is a combination of C and C++. The interfaces are linked as sharedlibaries under the Linux operating system. The source code is released as open-source under the MIT licenseusing the GitHub repository system. GEMS is contained as a single project for the Eclipse IDE.

D.7.3: Documentation for platform modules and release to EMBOCON website Page 4 of 25

Page 5: Embedded Optimization for Resource Constrained Platforms ...grk1855.tu-dortmund.de/cms/Medienpool/forschungsumgebung/...Embedded Optimization for Resource Constrained Platforms Collaborative

EMBOCON: FP7-ICT-248940 August 28, 2013

The GEMS is used together with the state-of-the-art numerical algorithms developed within the project to showthe applicability and exibility of the software platform as well as the performance of the optimization packageson selected applications across different target sectors.

4.1 Setting up the simulation for sGEMS

A simulation run using the MATLAB-based sGEMS for the crane and the kite model can be executed by thefollowing steps:

1.a Download an optimizer out of one of the released modules from the EMBOCON website: http://www.embocon.org/index.php/Category:GEMS.

1.b If you wish to use a different optimizer, change the ”makeOptStep” function in file ”optimizer.c”.

2. Re-mex the files. You can do this by typing ”mexfiles”.

3. In the beginning of the ”initialize.m” script you can set xref to whatever you desire.

4. In the file ”craneData.m” you can set the initial state of the model.

5. Preform the simulation.

4.2 Setting up the simulation for GEMS

A simulation or execution run using GEMS can be executed by the following steps:

1. Download/ checkout and compile GEMS for the software repository from: https://github.com/EMBOCONcs/GEMS.

2. Download an example or create a ModelInterface implementation and compile to shared library.

3. Download an example or create a ObserverInterface implementation and compile to shared library.

4. Download an example or create a OptimizerInterface implementation and compile to shared library.

5. Download an example or create a SimulationApplicationInterface implementation and compile to sharedlibrary.

6. Start the simulation via GEMS using the command line interface and the compiled shared libraries.

A detailed documentation of the final specification of GEMS can be found in Deliverable D2.3. The documen-tation also includes license information.

The GEMS documentation is released to the following EMBOCON website: http://www.embocon.org/index.php/Category:GEMS.

5 Documentation of the platform modules

To guide the user how to use the platform module, all modules are documented and released for selectedbenchmark examples, the crane example and the kite example. The examples are documented within thedeliverables of work package 8.

D.7.3: Documentation for platform modules and release to EMBOCON website Page 5 of 25

Page 6: Embedded Optimization for Resource Constrained Platforms ...grk1855.tu-dortmund.de/cms/Medienpool/forschungsumgebung/...Embedded Optimization for Resource Constrained Platforms Collaborative

EMBOCON: FP7-ICT-248940 August 28, 2013

The documentation for all modules of the software platform is released on the EMBOCON website: http://www.embocon.org/index.php/Category:GEMS with detailed information on particular modules on subpages,as described below.

The source codes of all the example are released in the EMBOCON software repository: https://github.com/EMBOCONcs/EMBOCON Interfaces/tree/master/Examples/.

5.1 ACADO Code Generation Tool

The ACADO Code Generation Tool module documentation which is given below is released to the followingEMBOCON website: http://www.embocon.org/index.php/GEMS with ACADO.

5.1.1 Crane and Kite Example

The crane and the kite example of the ACADO Code Generation Tool module can be run by execution thefollowing steps:

1. Checkout the source code for the corresponding example from the EMBOCON software repositories:https://github.com/EMBOCONcs/EMBOCON Interfaces/tree/master/Examples/sGEMS/crane acado, orhttps://github.com/EMBOCONcs/EMBOCON Interfaces/tree/master/Examples/sGEMS/kite acado

2. Open the folder of the source code using MATLAB

3. Compile the source code by typing ”mexfiles” in the MATLAB command prompt

4. Once the build process is finished, run the closed loop simulation using Simulink by opening the filecrane.mdl or kite.mdl and start the simulation run

5.1.2 Implementing your own problem

The process of implementing your own problem is described by modifying the existing crane example. TheNMPC code generator is given the C++ file crane nmpc generator.cpp which can be found in the softwarerepository. In order to compile this file one needs to download, install and configure the ACADO toolkit:

1. Go to the main ACADO toolkit website: http://sourceforge.net/p/acado/wiki/Home/

2. Download and compile the source code following the instruction given on the website.

3. Follow a short procedure on how to setup Linux/OS X environment, as explained on the website.

The generator can be compiled and executed following a simple procedure. In the checkout folder of thesoftware repository, we can build the generator and generate the NMPC code by typing the following sequenceof commands:

mkdir b u i l d

cd b u i l d

cmake . .

make

cd . .

. / c r a n e n m p c g e n e r a t o r

D.7.3: Documentation for platform modules and release to EMBOCON website Page 6 of 25

Page 7: Embedded Optimization for Resource Constrained Platforms ...grk1855.tu-dortmund.de/cms/Medienpool/forschungsumgebung/...Embedded Optimization for Resource Constrained Platforms Collaborative

EMBOCON: FP7-ICT-248940 August 28, 2013

Using the Simulink as a top layer of the application, sGEMS serves as an intermediate layer between Simulinkand the auto-generated NMPC code. The code that couples the sGEMS and the NMPC is encapsulated in thefile ”optimizer.c”. In particular, all calls to the auto-generated code are located in the function ”makeOptStep”.The most important function calls are calls to preparationStep and feedbackStep functions. Those functions areresponsible for computing the NMPC algorithm.

Besides the code located in this function, one needs to make instances of the ACADO specific data structures:

• ACADOvariables, a data structure that contains all user variables,

• ACADOworkspace, a data structure that contains all internal variables,

• Vars, a data structure containing the primal and the dual solutions of the QP solver (qpOASES),

• Params, a data structure containing all parametric data passed by the NMPC to the QP solver.

For more details about the auto-generated NMPC, we are referring to the aforementioned ACADO webpageand the manual that can be found on the website.

5.2 qpOASES

The qpOASES module documentation which is given below is released to the following EMBOCON website:http://www.embocon.org/index.php/GEMS with qpOASES.

5.2.1 Crane Example

The crane example of the qpOASES module can be run by execution the steps below. To formulate the MPCproblem we make use of the ACADO sytax. This permits to even use nonlinear models, which are automaticallylinearized for use with qpOASES.

1. Checkout the source code for the crane example from the EMBOCON software repository: https://github.com/EMBOCONcs/EMBOCON Interfaces/tree/master/Examples/sGEMS/crane qpoases

2. Open the folder of the source code using MATLAB

3. Compile the source code by typing ”mexfiles” in the MATLAB command prompt

4. Once the build process is finished, run the closed loop simulation using Simulink by opening the filecrane.mdl and start the simulation run

5.2.2 Implementing your own problem

The MPC code generator is set up in the C++ file crane mpc generator.cpp which can be found in the checkedout folder of the software repository. Make a copy of this file and change the model section to your modelfollowing the instructions from the ACADO toolkit website here: http://sourceforge.net/p/acado/wiki/Home/

In order to compile this changed file and generate the code to be run with sGEMS the user needs to download,install, and configure the ACADO toolkit. Note that this installation already includes qpOASES 3.0.

1. Go to the main ACADO toolkit website: http://sourceforge.net/p/acado/wiki/Home/

2. Download and compile the source code following the instruction given on the website.

D.7.3: Documentation for platform modules and release to EMBOCON website Page 7 of 25

Page 8: Embedded Optimization for Resource Constrained Platforms ...grk1855.tu-dortmund.de/cms/Medienpool/forschungsumgebung/...Embedded Optimization for Resource Constrained Platforms Collaborative

EMBOCON: FP7-ICT-248940 August 28, 2013

3. Follow a short procedure on how to setup Linux/OS X environment, as explained on the website.

The generator can be compiled and executed following a simple procedure. After navigating to the folder on thechecked out software repository, we can build the generator and generate the MPC code by typing the followingsequence of commands:

mkdir b u i l d

cd b u i l d

cmake . .

make

cd . .

. / c r a n e m p c g e n e r a t o r

These commands generate a tailored C code solver in the folder crane mpc export. This solver can be compiledfor usage through the sGEMS Simulink frontend by calling the command ”mexfiles” in the MATLAB prompt.

5.3 FORCES

We describe how to run the crane test problem. The function generated by FORCES that is used to solvethe MPC takes 3 arguments. These arguments will briefly be explained now, for further information it isrecommended to consult the FORCES website: http://www.forces.ethz.ch/

• params: This is a struct containing the parameters that you have defined. In this example it contains thecosts ”H” and ”f” of for stages 1 to N-1 and cost ”H N” and ”f N” as the terminal cost on stage N. It alsocontains a parameter ”z1” which contains the initial state.

• output: A struct containing the outputs that you have asked FORCES to return. In this case it is the input”u1” that must be applied to the system.

• info: Struct containing information about the algorithm and the problem

The FORCES module documentation is released to the following EMBOCON website: http://www.embocon.org/index.php/GEMS with FORCES.

Detailed installation instruction for FORCES can be found in deliverable D7.4.

5.4 MPT

Detailed installation instruction for MPT can be found in deliverable D7.4.

5.5 Instructions for interfacing an FPGA-based control system with GEMS/sGEMS

The aim of this text is to describe step by step how to build an interface for an FPGA-based controller with theGeneric EMBOCON Minimal Supervisor (GEMS) [3].

As example, the FPGA source code of the interface as well a MPC controller implementation (Fast Gradient)for controlling the crane experimental setup is available into the git tree folder [4]. Details of its directory listingare reported in Table 1.

D.7.3: Documentation for platform modules and release to EMBOCON website Page 8 of 25

Page 9: Embedded Optimization for Resource Constrained Platforms ...grk1855.tu-dortmund.de/cms/Medienpool/forschungsumgebung/...Embedded Optimization for Resource Constrained Platforms Collaborative

EMBOCON: FP7-ICT-248940 August 28, 2013

The example files provided are compatible with Xilinx evaluation module ML506 [7], Xilinx software ISEV14.6 [9] and MATLAB R2012b [6]. However, the instructions reported below remain valid for any firmwareversions any Xilinx evaluation module which supports an Ethernet connection.

Table 1: Directory listing

Main directory GEMS files for FPGA communication.

XPS FPGA Hardware Xilinx Platform Studio (XPS) [2] project used to build the interface frameworkmodule and interfacing it with the controller module.

XPS Controller Source VHDL code of the controller module. It implements the Fast Gradientalgorithm used for controlling the crane setup using fixed-point arithmetic (18bits words length, 8 bits fraction length).

SDK FPGA Software Software Development Kit (SDK) [2] project used to design embedded soft-ware application which runs upon the soft processor. Include also the sourcecode for UDP echo server to bridge communication to controller module forthe for controlling the crane setup.

Crane Standalone Standalone Matlab-based interface to the FPGA (it does not requires GEMS)

Documentation This documentation source code.

s

D.7.3: Documentation for platform modules and release to EMBOCON website Page 9 of 25

Page 10: Embedded Optimization for Resource Constrained Platforms ...grk1855.tu-dortmund.de/cms/Medienpool/forschungsumgebung/...Embedded Optimization for Resource Constrained Platforms Collaborative

EMBOCON: FP7-ICT-248940 August 28, 2013

5.5.1 Introduction

The FPGA-based control system is interfaced with GEMS via an UDP/IP packets based communication in-frastructure. Every time GEMS’ optimizer function (MAKEOPTSTEP) is called, a sequence of data embeddedin the payload of a UDP packet is transmitted over Ethernet to the FPGA. Once the FPGA has completed itscomputation it returns the control action embedded in another UDP packet.

The figure below

GEMS

Matlab

Desktop/Laptop computer

Ethernet

PHY

UDP/IP

100 Mbit / 1 Gbit

Ethernet

ML506

FPGA

ControllerEthernet

MAC

AXI4-Lite

bus

Soft/Hard

processor

UDP

server

Interface framework

shows a schematic representation of interface.

On the FPGA side two hardware modules are required: the interface framework and the controller.The interface framework is based on Xilinx MicroBlaze soft core processor [10], upon which a software ap-plication, based on the lwIP UDP server [5], bridges the communication between the Ethernet interface andthe controller. The choice of this interface framework architecture has been driven by the fact it provides somesystem flexibility in comparison to a dedicated custom interface allowing easy portability to other standard in-terfaces, e.g. SpaceWire, CAN bus, etc.. However this flexibility come with a small increase in FPGA resourceusage and communication delayThe controller module is a custom designed circuit implementing the control algorithm. It can be directly codedby hand with a low level Hardware Description Language (HDL), i.e. Verilog or VHDL, or can be coded usingan high level language, i.e using C, and translated into hardware using dedicated software such as Vivado HLS[8].The designed controller module communicates with the processor via an AXI4-Lite bus [1] based on 4 memoryregisters each of 32 bits size.

The remain part of the document is organized as follow: Section 5.5.2 shows how to design the interfaceframework module from scratch and connect to it a custom designed controller module, Section 5.5.5 describeshow to build the embedded software application which runs upon the soft processor, Section 5.5.7 describeshow to communicate with the FPGA and Section 5.5.8 shows how to port the provided example design interfaceto any other application.

D.7.3: Documentation for platform modules and release to EMBOCON website Page 10 of 25

Page 11: Embedded Optimization for Resource Constrained Platforms ...grk1855.tu-dortmund.de/cms/Medienpool/forschungsumgebung/...Embedded Optimization for Resource Constrained Platforms Collaborative

EMBOCON: FP7-ICT-248940 August 28, 2013

5.5.2 XPS: building the interface framework module and interfacing it with the controller module

5.5.3 Building the interface framework module

1. Run Xilinx Platform Studio (XPS) tool suite [2] and create a new project using base system builder

2. Assign a project name and select as interconnect type “AXI System”

3. Choose the development board you have got on available, i.e. ML605, select ”Single MicroBlaze Pro-cessor System” and optimization strategy for “Area” or “Throughput”

D.7.3: Documentation for platform modules and release to EMBOCON website Page 11 of 25

Page 12: Embedded Optimization for Resource Constrained Platforms ...grk1855.tu-dortmund.de/cms/Medienpool/forschungsumgebung/...Embedded Optimization for Resource Constrained Platforms Collaborative

EMBOCON: FP7-ICT-248940 August 28, 2013

4. Increase the Local Memory Size , instruction cache size and data cache size to (e.g.) 64 KB, add the“axi timer” peripheral to the list of included peripherals, and ensure that “axi timer” and “axi ethernetlite”use interrupts. Do NOT remove the “RS232 Uart” and ” DDR3 SDRAM” peripherals. Press “Finish”.

5.5.4 Interfacing the interface framework module with the controller module

5. In the XPS Project, choose ”Project→ Project Options”, and add the “EDK controller” directory to the“Project Peripheral Repository Search Path”.Note that the controller module has to be in the Xilinx pcores or processor IPs [2] format and with aAXI4-Lite bus interface exposing 4 memory registers each of 32 bits size. Their use is summarized inthe Table 2.

D.7.3: Documentation for platform modules and release to EMBOCON website Page 12 of 25

Page 13: Embedded Optimization for Resource Constrained Platforms ...grk1855.tu-dortmund.de/cms/Medienpool/forschungsumgebung/...Embedded Optimization for Resource Constrained Platforms Collaborative

EMBOCON: FP7-ICT-248940 August 28, 2013

Table 2: Controller module registers use

Reg 0 When all the data have been passed to the controller module, the processortells to the controller module to start the computation.

Reg 1 The processor writes the data to pass to the controller module one after another.

Reg 2 The controller module communicates to the processor that the computationhas been completed, thus the processor can start reading back the results of thecomputation.

Reg 3 The processor reads back results of the computation from the controller mod-ule one after an other.

6. Add the controller module from the USER project peripheral repository double clicking on it in the IPcatalog

D.7.3: Documentation for platform modules and release to EMBOCON website Page 13 of 25

Page 14: Embedded Optimization for Resource Constrained Platforms ...grk1855.tu-dortmund.de/cms/Medienpool/forschungsumgebung/...Embedded Optimization for Resource Constrained Platforms Collaborative

EMBOCON: FP7-ICT-248940 August 28, 2013

7. Change “C NUM MEM” to “0”, and “C NUM REG” to “4” and press OK.

8. Let the XPS connect this to “microblaze 0”.

Now the FPGA circuit architecture has been built, it has to be compiled to generate the FPGA configuration(bitstream)

9. In the XPS Project, choose ”Project → Export hardware design to SDK” and select ”Export & launchSDK”. Wait a long time (also a few hours).

D.7.3: Documentation for platform modules and release to EMBOCON website Page 14 of 25

Page 15: Embedded Optimization for Resource Constrained Platforms ...grk1855.tu-dortmund.de/cms/Medienpool/forschungsumgebung/...Embedded Optimization for Resource Constrained Platforms Collaborative

EMBOCON: FP7-ICT-248940 August 28, 2013

5.5.5 SDK: building the embedded software application

The system requires an embedded application to be run on the Xilinx MicroBlaze soft-core to act as a serverapplication, which listens on the Ethernet port of the ML605 evaluation board and brings the data to the con-troller module.The application source code is available in the ”SDK FPGA Software\controller server 0\src\echo.c” and”SDK FPGA Software\controller server 0\src\main.c” files.

1. In the workspace launcher select the destination folder that is called workspace by SDK

D.7.3: Documentation for platform modules and release to EMBOCON website Page 15 of 25

Page 16: Embedded Optimization for Resource Constrained Platforms ...grk1855.tu-dortmund.de/cms/Medienpool/forschungsumgebung/...Embedded Optimization for Resource Constrained Platforms Collaborative

EMBOCON: FP7-ICT-248940 August 28, 2013

2. In the workspace create a “New Application Project” (File→ New→ Project→ Xilinx→ New Appli-cation Project).

Named “controller server 0”.

D.7.3: Documentation for platform modules and release to EMBOCON website Page 16 of 25

Page 17: Embedded Optimization for Resource Constrained Platforms ...grk1855.tu-dortmund.de/cms/Medienpool/forschungsumgebung/...Embedded Optimization for Resource Constrained Platforms Collaborative

EMBOCON: FP7-ICT-248940 August 28, 2013

Use the “lwIP Echo Server” template project.

D.7.3: Documentation for platform modules and release to EMBOCON website Page 17 of 25

Page 18: Embedded Optimization for Resource Constrained Platforms ...grk1855.tu-dortmund.de/cms/Medienpool/forschungsumgebung/...Embedded Optimization for Resource Constrained Platforms Collaborative

EMBOCON: FP7-ICT-248940 August 28, 2013

3. Copy “echo.c” and “main.c” from ”SDK FPGA Software\controller server 0\src”’ folder into the project,replacing those automatically generated by the Xilinx SDK.

4. In the workspace run Xilinx Tools→ Repositories

Add the drivers for the controller module core drivers path (”EDK Controller\mycores) to the local driverrepository search path.

D.7.3: Documentation for platform modules and release to EMBOCON website Page 18 of 25

Page 19: Embedded Optimization for Resource Constrained Platforms ...grk1855.tu-dortmund.de/cms/Medienpool/forschungsumgebung/...Embedded Optimization for Resource Constrained Platforms Collaborative

EMBOCON: FP7-ICT-248940 August 28, 2013

5. In the workspace run Xilinx Tools→ Board Support Package Settings→ controller server 0 bsp.

Change the drivers for “controller 0” from “generic” to “controller”.

D.7.3: Documentation for platform modules and release to EMBOCON website Page 19 of 25

Page 20: Embedded Optimization for Resource Constrained Platforms ...grk1855.tu-dortmund.de/cms/Medienpool/forschungsumgebung/...Embedded Optimization for Resource Constrained Platforms Collaborative

EMBOCON: FP7-ICT-248940 August 28, 2013

6. The SDK project should now build without errors.

5.5.6 Running the embedded software application on the FPGA

7. Making sure that the Xilinx evaluation module (ML605) is connected via the UART and JTAG USBcables, run Xilinx Tools→ Program FPGA.

8. Start the software component running on the MicroBlaze.

D.7.3: Documentation for platform modules and release to EMBOCON website Page 20 of 25

Page 21: Embedded Optimization for Resource Constrained Platforms ...grk1855.tu-dortmund.de/cms/Medienpool/forschungsumgebung/...Embedded Optimization for Resource Constrained Platforms Collaborative

EMBOCON: FP7-ICT-248940 August 28, 2013

Now the FPGA is programmed and ready to compute a new the control action every time it receives data fromGEMS via the Ethernet interface.

Remarks

1. It is possible to monitor the status of the UDP server that is running on the FPGA by connecting a serialterminal to the serial port connected to the UART on the ML605.Set the Baud Rate to 9600, Parity to None and Data Bits to 8.

2.

D.7.3: Documentation for platform modules and release to EMBOCON website Page 21 of 25

Page 22: Embedded Optimization for Resource Constrained Platforms ...grk1855.tu-dortmund.de/cms/Medienpool/forschungsumgebung/...Embedded Optimization for Resource Constrained Platforms Collaborative

EMBOCON: FP7-ICT-248940 August 28, 2013

5.5.7 Interfacing with FPGA

GEMS invokes the controller running on the FPGA by calling the function UDPCLIENT COMBINED availablein the library ”UDPclient int32 library.c”.Every time it is called, the controller’s current state XCURR is encapsulated into an UDP/IP packet and sent tothe FPGA. The function returns UCURR, the control action.

It should be noticed that the supported communication data formats are the floating-point single precision andany fixed-point precision up to 32 bits word length. The data format should be chosen according to arithmeticused for the FPGA implemented controller.When a fixed-point precision is selected, the transmitted data is scaled by a factor of 2 f raction length and receiveddata is scaled by 2− f raction length where f raction length is the fixed-point number fraction length.

Remark

A Matlab-based standalone interface is also provided with the FPGA for the crane application in the folderCRANE STANDALONE.A user guide called ”readme.txt” can be found in the same directory.

5.5.8 How to port the provided example interface framework to any other applications

The provided example files have been tailored to control the crane experimental setup with the Fast Gradientalgorithm. To reuse the interface framework with any other controller and application type, the following stepsshould be taken::

• Controller module design should be made according Section 5.5.2 - point 5.

• The following changes to the embedded application(”SDK FPGA Software\controller server 0\src\echo.c”), which runs on the embedded microprocessor,have to be done:

– #define NINPUTS 17set the number of data inputs the controller module requires

– #define NOUTPUTS 2set the number of data outputs the controller module requires

• The following changes to c-based application (”FPGAcontroller library.h”), which runs on the desk-top/laptop computer, have to be done:

– #define N INPUTS 17set the number of data inputs the controller module requires

– #define N OUTPUTS 2set the number of data oputputs the controller module requires

– #define FLOAT FIX 1set according to the controller module arithmetic: 0 if floating-point single precision, 1 if fixed-point(up to 32 bits word length)

– #define SCALE INT32 8set the number the fraction length number of bits if fixed-point arithmetic is used

D.7.3: Documentation for platform modules and release to EMBOCON website Page 22 of 25

Page 23: Embedded Optimization for Resource Constrained Platforms ...grk1855.tu-dortmund.de/cms/Medienpool/forschungsumgebung/...Embedded Optimization for Resource Constrained Platforms Collaborative

EMBOCON: FP7-ICT-248940 August 28, 2013

5.6 Combined Module CasADi and Ipopt

The crane example of the CasADi and Ipopt module (see: https://github.com/casadi/casadi/wiki and https://projects.coin-or.org/Ipopt) can be run by executing the steps below.

1. Checkout the source code for GEMS from the EMBOCON software repository: https://github.com/EMBOCONcs/GEMS

2. Compile GEMS using the ”makefile”

3. Checkout the source code for the ModelInterface dummy implementation for the crane example from theEMBOCON software repository: https://github.com/EMBOCONcs/EMBOCON Interfaces/tree/master/Examples/GEMS/Model CraneExample and compile the shared library using the ”makefile” in the DE-BUG folder

4. Checkout the source code for the ObserverInterface dummy implementation for the crane example fromthe EMBOCON software repository: https://github.com/EMBOCONcs/EMBOCON Interfaces/tree/master/Examples/GEMS/Observer CraneExample and compile the shared library using the ”makefile” in theDEBUG folder

5. Download and install the required dependencies CasADi (download and instruction can be found here:https://github.com/casadi/casadi/wiki) and Ipopt (download and instructions can be found here: https://projects.coin-or.org/Ipopt)

6. Checkout the source code for the OptimizerInterface CasADi and Ipopt implementations for the crane ex-ample from the EMBOCON software repository: https://github.com/EMBOCONcs/EMBOCON Interfaces/tree/master/Examples/GEMS/Optimizer CraneExample CASADI IPOPT and compile the shared libraryusing the ”makefile” in the DEBUG folder.

7. Download and install SUNDIALS from: http://computation.llnl.gov/casc/sundials/main.html

8. Checkout the source code for the SimulationApplicationInterface SUNDIALS implementation for thecrane example from the EMBOCON software repository: https://github.com/EMBOCONcs/EMBOCONInterfaces/tree/master/Examples/GEMS/Simulation CraneExample SUNDIALS and compile the sharedlibrary using the ”makefile” in the DEBUG folder. The SUNDIALS installation from the previous stepis required as dependency.

9. Copy all compiled shared libraries to the LIB folder of GEMS.

10. Copy the additional files in the EXCLUDE folder of the optimizer source code to the GEMS folder(including the EXCLUDE folder structure).

11. Run GEMS using the command line interfaces and the selected libraries for 10 steps as described on theEMBOCON website: http://www.embocon.org/index.php/Category:GEMS and in deliverable D2.3

The CasADi and Ipopt module documentation is released to the following EMBOCON website: http://www.embocon.org/index.php/GEMS with CasADi and Ipopt.

5.7 Third Party Module - SUNDIALS

The crane example of the SUNDIALS module (see: http://computation.llnl.gov/casc/sundials/main.html) canbe run by executing the steps below.

D.7.3: Documentation for platform modules and release to EMBOCON website Page 23 of 25

Page 24: Embedded Optimization for Resource Constrained Platforms ...grk1855.tu-dortmund.de/cms/Medienpool/forschungsumgebung/...Embedded Optimization for Resource Constrained Platforms Collaborative

EMBOCON: FP7-ICT-248940 August 28, 2013

1. Checkout the source code for GEMS from the EMBOCON software repository: https://github.com/EMBOCONcs/GEMS

2. Compile GEMS using the ”makefile”

3. Checkout the source code for the ModelInterface dummy implementation for the crane example from theEMBOCON software repository: https://github.com/EMBOCONcs/EMBOCON Interfaces/tree/master/Examples/GEMS/Model CraneExample and compile the shared library using the ”makefile” in the DE-BUG folder

4. Checkout the source code for the ObserverInterface dummy implementation for the crane example fromthe EMBOCON software repository: https://github.com/EMBOCONcs/EMBOCON Interfaces/tree/master/Examples/GEMS/Observer CraneExample and compile the shared library using the ”makefile” in theDEBUG folder

5. Checkout the source code for one of the OptimizerInterface implementations offered for the crane exam-ple from the EMBOCON software repository:

• FORCES: https://github.com/EMBOCONcs/EMBOCON Interfaces/tree/master/Examples/GEMS/Optimizer CraneExample FORCES

• ACADO: https://github.com/EMBOCONcs/EMBOCON Interfaces/tree/master/Examples/GEMS/OptimizerCraneExample Acado

• CasADi and Ipopt: https://github.com/EMBOCONcs/EMBOCON Interfaces/tree/master/Examples/GEMS/Optimizer CraneExample CASADI IPOPT

And compile the shared library using the ”makefile” in the DEBUG folder. For using the optimizerimplementation based on CasADi and Ipopt, the user is required to install the dependencies CasADi(download and instruction can be found here: https://github.com/casadi/casadi/wiki) and Ipopt (downloadand instructions can be found here: https://projects.coin-or.org/Ipopt) first.

6. Download and install SUNDIALS from: http://computation.llnl.gov/casc/sundials/main.html

7. Checkout the source code for the SimulationApplicationInterface SUNDIALS implementation for thecrane example from the EMBOCON software repository: https://github.com/EMBOCONcs/EMBOCONInterfaces/tree/master/Examples/GEMS/Simulation CraneExample SUNDIALS and compile the sharedlibrary using the ”makefile” in the DEBUG folder. The SUNDIALS installation from the previous stepis required as dependency.

8. Copy all compiled shared libraries to the LIB folder of GEMS. For using the optimizer implementationbased on CasADi and Ipopt, the additional files in the EXCLUDE folder of the optimizer source code arerequired to be copied to the GEMS folder (including the EXCLUDE folder structure).

9. Run GEMS using the command line interfaces and the selected libraries for 10 steps as described on theEMBOCON website: http://www.embocon.org/index.php/Category:GEMS and in deliverable D2.3

The SUNDIALS module documentation is released to the following EMBOCON website: http://www.embocon.org/index.php/GEMS with SUNDIALS.

D.7.3: Documentation for platform modules and release to EMBOCON website Page 24 of 25

Page 25: Embedded Optimization for Resource Constrained Platforms ...grk1855.tu-dortmund.de/cms/Medienpool/forschungsumgebung/...Embedded Optimization for Resource Constrained Platforms Collaborative

EMBOCON: FP7-ICT-248940 August 28, 2013

References

[1] Axi interconnect documentation. www.xilinx.com/products/intellectual-property/axi interconnect.htm.

[2] Embedded system tools reference manual. www.xilinx.com/support/documentation/sw manuals/xilinx14 3/est rm.pdf.

[3] GEMS documentation. www.embocon.org/index.php/Category:GEMS.

[4] Github public repository. www.github.com/EMBOCONcs/EMBOCON Interfaces/tree/master/Examples/sGEMS/crane fpga.

[5] Lightweight ip (lwip) application examples. www.xilinx.com/support/documentation/application notes/xapp1026.pdf.

[6] Matlab documentation. www.mathworks.co.uk/.

[7] ML506 evaluation board documentation. www.xilinx.com/products/boards-and-kits/HW-V5-ML506-UNI-G.htm.

[8] Vivado high-level synthesis documentation. www.xilinx.com/products/design-tools/vivado/integration/esl-design/index.htm.

[9] Xilinx ISE design suite (system edition) documentation. www.xilinx.com/products/design-tools/ise-design-suite/index.htm.

[10] Xilinx microblaze soft processor documentation. www.xilinx.com/tools/microblaze.htm.

D.7.3: Documentation for platform modules and release to EMBOCON website Page 25 of 25