Skip to content

Compile DFE Applications for Webots

Yannick Goumaz edited this page Jul 19, 2023 · 12 revisions

Run DFE Applications with MaxIDE explains how to use MaxIDE to create accelerated functions. In a further step, one may want to combine the C/C++ code of the DFE project with the controller code of a Webots robot.

This page explains the workflow to include .max files and DFE SLiC functions in a Webots controller.

Build shared library

The first step consists in building a shared library from the DFE project.

shared lib folder
  • First, duplicate the CPU folder (the one named your-project-name-CPU) in the left panel of MaxIDE. Name it according to the desired library name.
  • Delete every files and folders, except the Makefile, the Includes, as well as additional data that you may have added yourself.
  • Select the .max files to be compiled in the library by right-clicking on the my_library directory in the left panel and click on Manage MaxFiles, as shown in Select .max files for CPU execution. Be sure to select the DFE files and not the SIM files.
  • Open the Makefile and choose a name for the shared library on line 14:
    EXE := library_name
  • Edit line 15 to correctly generate the .so file (parenthesis are missing around EXE):
    SONAME := lib$(shell echo $(EXE) | tr '[:upper:]' '[:lower:]').so
  • Open a terminal, go to the library directory and build the shared library.
    cd your_workspace_path/my_library
    make create_so
  • The my_library directory now contains all necessary files (see figure on the right).

Copy to Webots project

  • Create a libraries folder at the root of the Webots project (at the same level as the worlds or controllers folders).
  • Copy the my_library folder you created in the last section into this new libraries directory.

Modify the controller Makefile

The next step consists in editing the controller Makefile to include the shared library, as well as the MaxelerOS and SLiC libraries.

  • Open the Makefile located in your controller folder
  • Add the following elements to the INCLUDE and LIBRARIES variables.
    INCLUDE = -I../../libraries/my_library/inc/MAX5C/max -I/opt/maxeler/maxeleros/include -I/opt/Software/maxeler/maxcompiler-2018.3.1/include/slic 
    LIBRARIES = -L../../libraries/my_library/lib/MAX5C -L/opt/Software/maxeler/maxcompiler-2018.3.1/lib -L/opt/maxeler/maxeleros/lib -lslic -lmaxeleros -lm -lpthread -lcurl -llibrary_name 
  • Add a new C flag.
    CFLAGS = -fPIC

Create runtime.ini

When Webots is launched, the path to the shared libraries like libController.so are added to the WEBOTS_LIBRARY_PATH environment variable. To add the new shared library to the path, Webots allows to use a .ini file. Note that if the controller is run as extern, WEBOTS_LIBRARY_PATH is replaced by LD_LIBRARY_PATH.

  • Add a runtime.ini text file to the controller folder and open it.
  • Write the following lines inside and save it.
    [environment variables with paths]
    WEBOTS_LIBRARY_PATH = lib:$(WEBOTS_LIBRARY_PATH):../../libraries/my_library/lib/MAX5C ;for intern controller execution
    LD_LIBRARY_PATH = ../../libraries/cnn_dfe/lib/MAX5C:$(LD_LIBRARY_PATH) ;for extern controller execution

Add max CPU code to controller code and build

You can now merge the CPU code of the DFE application with the one from your Webots controller and build the controller.

make -j 8

Start Webots

The process to start Webots headless on Jumax is explained here.

Clone this wiki locally