Skip to content

Commit 1fa9a76

Browse files
Gabriele Navadiegoferigo
Gabriele Nava
andauthored
Update autogeneration (#92)
* Add driver.cpp.in template * Update clang-format * Update main CMakeLists.txt to use the driver.cpp.in template * Minor edit in RegisteMdl.cmake * Update CreateAutogeneratedCodeTargets.cmake.in template * fix block names for autogen * fixed also the model without Gazebo for autogen * modified installation path of +wbc library * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * models exported to 2017b Co-authored-by: Diego Ferigo <diego.ferigo@iit.it>
1 parent 12ab05e commit 1fa9a76

23 files changed

+1569
-1392
lines changed

.clang-format

+5-1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ IncludeCategories:
6464
Priority: 2
6565
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
6666
Priority: 3
67+
- Regex: '^"rtwtypes'
68+
Priority: -1
69+
- Regex: '^"tmwtypes'
70+
Priority: -1
6771
- Regex: '.*'
6872
Priority: 1
6973
IncludeIsMainRegex: '(Test)?$'
@@ -89,7 +93,7 @@ PenaltyExcessCharacter: 1000000
8993
PenaltyReturnTypeOnItsOwnLine: 60
9094
PointerAlignment: Left
9195
ReflowComments: true
92-
SortIncludes: false
96+
SortIncludes: true
9397
SortUsingDeclarations: true
9498
SpaceAfterCStyleCast: true
9599
SpaceAfterTemplateKeyword: true

CMakeLists.txt

+15-11
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,16 @@ project(whole-body-controllers)
77
option(WBC_EXPORT_AUTOGENERATED "Enable the target to export code generated with Simulink Coder" OFF)
88
option(WBC_INSTALL_ALL_HOME_POS "Installation of all available home positions" ON)
99

10-
# ======================
11-
# Install home positions
12-
# ======================
10+
# ======================================
11+
# Install home positions and WBC library
12+
# ======================================
1313

1414
find_package(YARP REQUIRED)
1515
yarp_configure_external_installation(wbc)
1616

1717
add_subdirectory(utilities)
18+
add_subdirectory(library)
19+
add_subdirectory(config)
1820

1921
# ======================
2022
# Autogeneration routine
@@ -51,8 +53,7 @@ file(WRITE "${CMAKE_BINARY_DIR}/autogenerated/CMakeLists.txt" "# Exported contro
5153
# Find clang-format
5254
find_program(ClangFormat_EXECUTABLE
5355
DOC "Path to the clang-format executable."
54-
NAMES clang-format clang-format-7.0 clang-format-6.0 clang-format-5.0 clang-format-4.0
55-
)
56+
NAMES clang-format clang-format-9 clang-format-8 clang-format-7 clang-format-6.0 clang-format-5.0 clang-format-4.0)
5657
configure_file(${CMAKE_SOURCE_DIR}/.clang-format ${CMAKE_BINARY_DIR}/.clang-format COPYONLY)
5758

5859
# Copy only h and cpp files
@@ -62,17 +63,21 @@ foreach(SOURCEDIR ${AUTOGENERATED_FOLDERS})
6263
file(APPEND "${CMAKE_BINARY_DIR}/autogenerated/CMakeLists.txt" "add_subdirectory(${MDLDIRNAME})\n")
6364
file(MAKE_DIRECTORY "${MDLDESTDIR}")
6465
string(REGEX MATCH "[^_]*" MDL_NAME ${MDLDIRNAME}) # Remove _gtw_rtw
66+
# Create the CMakeLists.txt of the model
6567
configure_file(
6668
"${CMAKE_SOURCE_DIR}/cmake/CreateAutogeneratedCodeTargets.cmake.in"
6769
"${MDLDESTDIR}/CMakeLists.txt"
68-
@ONLY
69-
)
70+
@ONLY)
71+
# Copy the main file
72+
configure_file(
73+
"${PROJECT_SOURCE_DIR}/src/driver.cpp.in"
74+
"${MDLDESTDIR}/driver.cpp"
75+
@ONLY)
7076
# Copy sources to the build directory
7177
add_custom_command(TARGET copy-autogenerated-models
7278
PRE_BUILD
7379
COMMAND ${CMAKE_COMMAND} -E copy "${SOURCEDIR}/*.h" "${SOURCEDIR}/*.cpp" "${SOURCEDIR}/defines.txt" "${MDLDESTDIR}"
74-
COMMENT "Copying ${MDLDIRNAME} to the build folder."
75-
)
80+
COMMENT "Copying ${MDLDIRNAME} to the build folder.")
7681
# Apply clang-format style
7782
if(NOT ${ClangFormat_EXECUTABLE} STREQUAL "ClangFormat_EXECUTABLE-NOTFOUND")
7883
add_custom_command(TARGET copy-autogenerated-models
@@ -86,5 +91,4 @@ endforeach()
8691
add_custom_command(TARGET copy-autogenerated-models
8792
POST_BUILD
8893
COMMAND ${CMAKE_COMMAND} -E copy_directory "${CMAKE_BINARY_DIR}/autogenerated" "${AUTOGENERATED_WBC_SOURCE_DIR}/autogenerated"
89-
COMMENT "Copying generated files to ${AUTOGENERATED_WBC_SOURCE_DIR}/autogenerated"
90-
)
94+
COMMENT "Copying generated files to ${AUTOGENERATED_WBC_SOURCE_DIR}/autogenerated")

README.md

+19-16
Original file line numberDiff line numberDiff line change
@@ -12,29 +12,37 @@ The repository contains `Simulink-based whole-body controllers` developed to con
1212

1313
- The controllers stored in this repository are an **overview** of the possibile control frameworks that can be implemented using the `robotology` software infrastructure. Also, the repository contains a [library](library/README.md) of configuration and utility Matlab functions to design simulations with [Gazebo](http://gazebosim.org/) simulator and on the real robot iCub.
1414

15-
- The robot dynamics and kinematics is computed run-time by means of [WBToolbox](https://github.com/robotology/wb-toolbox), a Simulink libary that wraps [iDyntree](https://github.com/robotology/idyntree). For more information on iDyntree library, see also this [README](https://github.com/robotology/idyntree/blob/master/README.md).
15+
- The robot dynamics and kinematics is computed run-time by means of [WBToolbox](https://github.com/robotology/wb-toolbox), a Simulink library that wraps [iDyntree](https://github.com/robotology/idyntree). For more information on iDyntree library, see also this [README](https://github.com/robotology/idyntree/blob/master/README.md).
1616

1717
- The Simulink models implement different control strategies both for fixed-base and for floating-base robots. They space from `momentum-based` torque control to `inverse-kinematics-based` position control. Have a look at the [controllers](controllers/README.md) folder for more details.
1818

1919
## Dependencies
2020

2121
This repository depends upon the following Software:
2222

23+
- [CMake](https://cmake.org/), at least version **3.5**.
2324
- [Matlab/Simulink](https://it.mathworks.com/products/matlab.html), default version **R2017b**.
2425
- [WB-Toolbox](https://github.com/robotology/WB-Toolbox) and [blockfactory](https://github.com/robotology/blockfactory).
2526
- [Gazebo Simulator](http://gazebosim.org/), default version **9.0**.
2627
- [gazebo-yarp-plugins](https://github.com/robotology/gazebo-yarp-plugins).
2728
- [icub-gazebo](https://github.com/robotology/icub-gazebo), [icub-gazebo-wholebody](https://github.com/robotology-playground/icub-gazebo-wholebody) and [icub-models](https://github.com/robotology/icub-models) to access iCub models.
28-
- [codyco-modules](https://github.com/robotology/codyco-modules) (**Optional**, for using [wholeBodyDynamics](https://github.com/robotology/codyco-modules/tree/master/src/devices/wholeBodyDynamics) device).
29+
- [whole-body-estimators](https://github.com/robotology/whole-body-estimators) (**Optional**, for using [wholeBodyDynamics](https://github.com/robotology/whole-body-estimators/tree/master/devices/wholeBodyDynamics) device).
2930
- [YARP](https://github.com/robotology/yarp) and [icub-main](https://github.com/robotology/icub-main).
3031

3132
## Installation and usage
3233

3334
The repository is usually tested and developed on **Ubuntu** and **macOS** operating systems. Some functionalities may not work properly on **Windows**.
3435

35-
**NOTE:** it is suggested to install `whole-body-controllers` and most of its dependencies (namely, `YARP`, `icub-main`, `codyco-modules`,`icub-gazebo`,`icub-gazebo-wholebody`, `icub-models`, `gazebo-yarp-plugins`, `blockfactory` and `WB-Toolbox` and their dependencies) using the [robotology-superbuild](https://github.com/robotology/robotology-superbuild) (enable `ROBOTOLOGY_USES_GAZEBO`, `ROBOTOLOGY_ENABLE_DYNAMICS`, `ROBOTOLOGY_USES_MATLAB` options).
36+
- **NOTE:** it is suggested to install `whole-body-controllers` and most of its dependencies (namely, `YARP`, `icub-main`, `whole-body-estimators`,`icub-gazebo`,`icub-gazebo-wholebody`, `icub-models`, `gazebo-yarp-plugins`, `blockfactory` and `WB-Toolbox` and their dependencies) using the [robotology-superbuild](https://github.com/robotology/robotology-superbuild) (enable `ROBOTOLOGY_USES_GAZEBO`, `ROBOTOLOGY_ENABLE_DYNAMICS`, `ROBOTOLOGY_USES_MATLAB` options).
3637

37-
- Otherwise, after intalling all the dependencies, **clone the repository** on your pc by running on a terminal `git clone https://github.com/robotology/whole-body-controllers`, or download the repository.
38+
- Otherwise, after installing all the dependencies, **clone the repository** on your pc by running on a terminal `git clone https://github.com/robotology/whole-body-controllers`, or download the repository. Then (on Ubuntu), open a terminal from the folder where you downloaded whole-body-controllers and run:
39+
40+
```
41+
mkdir build
42+
cd build
43+
ccmake ..
44+
```
45+
in the GUI that it will open, set the `CMAKE_PREFIX_PATH` as your desired installation folder. Then, run `make install`.
3846

3947
- Set the environmental variable `YARP_ROBOT_NAME` in your `.bashrc` file (or equivalent) to be the name of the robot you want to control. List of supported robot names:
4048

@@ -45,26 +53,21 @@ The repository is usually tested and developed on **Ubuntu** and **macOS** opera
4553
| iCubGazeboV2_5|[model.urdf](https://github.com/robotology/icub-models/blob/master/iCub/robots/iCubGazeboV2_5/model.urdf)|
4654
| icubGazeboSim |[model.urdf](https://github.com/robotology/yarp-wholebodyinterface/blob/master/app/robots/icubGazeboSim/model.urdf) |
4755

48-
- **IMPORTANT!** to use the WBC Simulink controllers, it is **required** to add the [matlab-wbc](library/matlab-wbc) folder to the Matlab path. There are two possible ways to add the folder to the path:
56+
- **IMPORTANT!** to use the WBC Simulink controllers, it is **required** to add the **installed** [+wbc](library/matlab-wbc/+wbc) folder to the Matlab path. There are two possible ways to add the folder to the Matlab path:
4957

50-
- `manually` and `permanently` add the folder to the Matlab path;
51-
- run **only once** the [startup_WBC.m](config/startup_WBC.m) script. In this case, path is **not** permanently added to Matlab, and it is required to **always** start Matlab from the folder where your `pathdef.m` file is (usually `~/Documents/MATLAB`). To facilitate the reaching of the WBC working folder from the folder containing the `pathdef.m`, a `goToWholeBodyController.m` script will be automatically created in that folder. Run it to jump to the WBC folder. For further information see also the [WBToolbox documentation](https://robotology.github.io/wb-toolbox/mkdocs/install/#matlab). **WARNING**: if the repository is installed through the `robotology-superbuild`, **DO NOT** run the `startup_WBC.m` file but instead run the [startup_robotology_superbuild.m](https://github.com/robotology/robotology-superbuild/blob/master/cmake/template/startup_robotology_superbuild.m.in) file that comes along with robotology-superbuild installation. The result will be the same.
52-
- **Note**: to use any function inside the package [matlab-wbc/+wbc](library/matlab-wbc/+wbc), add the `wbc` prefix to the function name when the function is invoked, i.e. `[outputs] = wbc.myFunction(inputs)`. More information on packages can be found in the [Matlab documentation](https://it.mathworks.com/help/matlab/matlab_oop/scoping-classes-with-packages.html).
58+
**1a.** `manually` and `permanently` add the folder to the Matlab path;
5359

54-
- There are some functionalities of the repo such as the [automatic generation of c++ code from Simulink](https://github.com/robotology/whole-body-controllers#automatic-generation-of-c-code-from-simulink) that require to compile and install the repository using `cmake`. To do so (on Ubuntu), open a terminal from the folder where you installed whole-body-controllers and run:
60+
**1b.** run **only once** the [startup_WBC.m](config/startup_WBC.m.in) script, which is installed in your `${BUILD}` folder. In this case, path is **not** permanently added to Matlab, and it is required to **always** start Matlab from the folder where your `pathdef.m` file is (usually `~/Documents/MATLAB`). To facilitate the reaching of the WBC working folder from the folder containing the `pathdef.m`, a `goToWholeBodyController.m` script can be [automatically created](config/createGoToWBC.m) in that folder. Run it to jump to the WBC folder. For further information on the installation procedure see also the [WBToolbox documentation](https://robotology.github.io/wb-toolbox/mkdocs/install/#matlab).
61+
**WARNING**: if the repository is installed through the `robotology-superbuild`, **DO NOT** run the `startup_WBC.m` file but instead run the [startup_robotology_superbuild](https://github.com/robotology/robotology-superbuild/blob/master/cmake/template/startup_robotology_superbuild.m.in) file that comes along with robotology-superbuild installation.
62+
- **Note**: to use any function inside the package [matlab-wbc/+wbc](library/matlab-wbc/+wbc), add the `wbc` prefix to the function name when the function is invoked, i.e. `[outputs] = wbc.myFunction(inputs)`. More information on packages can be found in the [Matlab documentation](https://it.mathworks.com/help/matlab/matlab_oop/scoping-classes-with-packages.html).
5563

56-
```
57-
mkdir build
58-
cd build
59-
ccmake ..
60-
```
61-
then in the GUI that it will open, set the `CMAKE_PREFIX_PATH` as your desired installation folder. Then, run `make install`.
64+
- There are some functionalities of the repo such as the [automatic generation of c++ code from Simulink](https://github.com/robotology/whole-body-controllers#automatic-generation-of-c-code-from-simulink) that require to enable not-default cmake options. Check the available options by running `ccmake .` in your `build` directory.
6265

6366
## Troubleshooting
6467

6568
Please refer to the [WBToolbox troubleshooting documentation](https://robotology.github.io/wb-toolbox/mkdocs/troubleshooting/).
6669

67-
## Structure of the repo
70+
## Relevant folders of the repo
6871

6972
- **config**: a collection of scripts to correctly configure this repo. [[README]](config/README.md)
7073

+18-11
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,29 @@
1+
# Copyright (C) 2019 Istituto Italiano di Tecnologia (IIT). All rights reserved.
2+
# This software may be modified and distributed under the terms of the
3+
# GNU Lesser General Public License v2.1 or any later version.
4+
5+
find_package(BlockFactory COMPONENTS SimulinkCoder REQUIRED)
6+
7+
# ===============================================
18
# Generate a library from the autogenerated class
29
# ===============================================
310

4-
set(MDL_NAME @MDL_NAME@)
5-
add_generated_code_lib(MODELNAME ${MDL_NAME})
11+
include(TargetFromGeneratedCode)
12+
set(SIMULINK_MODEL_NAME "@MDL_NAME@")
613

14+
# This macro creates a target named as the mdl file for the autogenerated class
15+
target_from_generated_code(
16+
MODELNAME ${SIMULINK_MODEL_NAME}
17+
SOURCE_FOLDER ${CMAKE_CURRENT_SOURCE_DIR})
18+
19+
# ================================
720
# Test executable with custom main
821
# ================================
922

1023
# Set the target name for the custom driver
11-
set(CODER_MAIN "CoderMain_${MDL_NAME}")
12-
13-
configure_file(
14-
"${PROJECT_SOURCE_DIR}/src/driver.cpp.in"
15-
"${CMAKE_CURRENT_BINARY_DIR}/driver.cpp"
16-
@ONLY)
24+
set(CODER_MAIN "Run${SIMULINK_MODEL_NAME}")
1725

1826
add_executable(${CODER_MAIN}
19-
"${CMAKE_CURRENT_BINARY_DIR}/driver.cpp"
20-
)
27+
"${CMAKE_CURRENT_SOURCE_DIR}/driver.cpp")
2128

22-
target_link_libraries(${CODER_MAIN} PUBLIC ${MDL_NAME}_LIB)
29+
target_link_libraries(${CODER_MAIN} PUBLIC ${SIMULINK_MODEL_NAME})

cmake/RegisterMdl.cmake

+4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ function(initialize_mdl_set)
44
# PARSE ARGUMENTS
55
# ===============
66

7+
set(_options)
78
set(_oneValueArgs NAME)
9+
set(_multiValueArgs)
810

911
cmake_parse_arguments(PREFIX
1012
"${_options}"
@@ -31,7 +33,9 @@ function(register_mdl)
3133
# PARSE ARGUMENTS
3234
# ===============
3335

36+
set(_options)
3437
set(_oneValueArgs MODELNAME)
38+
set(_multiValueArgs)
3539

3640
cmake_parse_arguments(PREFIX
3741
"${_options}"

config/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/startup_WBC.m.in ${CMAKE_BINARY_DIR}/startup_WBC.m)

config/README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,6 @@ A collection of scripts used for configuring the repo.
44

55
- [export_WBC.m](export_WBC.m): run this script. Then, digit the Matlab version in which you want to export the Simulink models. All models in the repo will be exported to that version. By default, Simulnk models in this repo are written using Matlab 2017b. **Remember: you cannot export a model in a Matlab version newer than the one you are using**!
66

7-
- [startup_WBC.m](startup_WBC.m): run this script. Then, the path to the `matlab-wbc` folder will be **permanently** added to your `pathdef.m` file, which will be saved inside the Matlab `userpath`. **WARNING**! In order to have the `matlab-wbc` folder inside the Matlab path, it is **required** to start Matlab from the folder where the `pathdef.m` file is (i.e., from the folder that the `userpath` is pointing, usually `~/Documents/MATLAB`).
7+
- [startup_WBC.m.in](startup_WBC.m.in): **DO NOT** run this script, but run its installation inside the procjet `${BUILD}` folder. Then, the path to the `+wbc` folder will be **permanently** added to your `pathdef.m` file, which will be saved inside the Matlab `userpath`. **WARNING**! In order to have the `+wbc` folder inside the Matlab path, it is **required** to start Matlab from the folder where the `pathdef.m` file is (i.e., from the folder that the `userpath` is pointing, usually `~/Documents/MATLAB`).
8+
9+
- [createGoToWBC.m](createGoToWBC.m): run this script. A file named 'goToWholeBodyControllers.m' will be created in the folder pointed by your `userpath`, to facilitate the reaching of WBC source folder when Matlab is started from the `userpath` folder.

config/startup_WBC.m config/createGoToWBC.m

+4-35
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,10 @@
1-
%% startup_WBC.m
1+
%% createGoToWBC.m
22
%
3-
% Run this script once to permanently add the matlab-wbc library to your MATLAB path.
3+
% Run this script once create the goToWholeBodyControllers.m script in your userpath.
44

55
clc
66
fprintf('\n## whole-body-controllers ##\n');
7-
fprintf('\nAdding "matlab-wbc" library to your pathdef.m...\n\n');
8-
9-
% path to whole-body-controllers
10-
pathToWBC = pwd;
11-
pathToWBC = pathToWBC(1:end-6);
12-
13-
% path to the matlab-wbc library
14-
pathToLibrary = [pathToWBC, filesep, 'library/matlab-wbc'];
15-
16-
if exist(pathToLibrary, 'dir')
17-
18-
addpath(pathToLibrary);
19-
else
20-
error('Path to the "matlab-wbc" library not found or not correct.')
21-
end
7+
fprintf('\nCreating "goToWholeBodyControllers.m" in your userpath...\n\n');
228

239
% Path to the Matlab userpath
2410
pathToUserpath = userpath;
@@ -63,22 +49,6 @@
6349
error('There are still multiple userpath. Please set a single userpath before running this script');
6450
end
6551

66-
if (~isempty(pathSeparatorLocation))
67-
68-
pathToUserpath(pathSeparatorLocation) = [];
69-
end
70-
71-
fprintf('Saving paths to %s\n\n', [pathToUserpath, filesep, 'pathdef.m']);
72-
73-
if (~savepath([pathToUserpath, filesep, 'pathdef.m']))
74-
75-
fprintf(['A file called pathdef.m has been created in your %s folder.\n', ...
76-
'This should be enough to permanently add matlab-wbc to ', ...
77-
'your MATLAB installation.\n'], pathToUserpath);
78-
else
79-
disp('There was an error generating the pathdef.m. Please manually add the matlab-wbc folder to your matlabpath');
80-
end
81-
8252
% save a script named "goToWholeBodyControllers" inside the pathdef folder,
8353
% to facilitate the user to reach the WBC working folder
8454

@@ -100,8 +70,7 @@
10070
fclose(fid);
10171

10272
fprintf('\n')
103-
fprintf(['A file called goToWholeBodyControllers.m has also been created in your %s folder.\n', ...
73+
fprintf(['A file called goToWholeBodyControllers.m has been created in your %s folder.\n', ...
10474
'This will help to quickly reach the WBC-project folder after ', ...
10575
'Matlab is launched.\n'], pathToUserpath);
10676
end
107-

0 commit comments

Comments
 (0)