Skip to content

Commit 32ba3a1

Browse files
authored
Merge pull request #126 from robotology/nunoguedelha-patch-1
- Update README (after #122) - Converted floating-base-balancing-torque-control-with-simulator into a package +floatingBaseBalancingTorqueControlWithSimulator - Added the package installation through CMake.
2 parents c217f05 + 82b2173 commit 32ba3a1

25 files changed

+439
-346
lines changed

CMakeLists.txt

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ option(WBC_EXPORT_AUTOGENERATED "Enable the target to export code generated with
88
option(WBC_INSTALL_ALL_HOME_POS "Installation of all available home positions" ON)
99

1010
# ======================================
11-
# Install home positions and WBC library
11+
# Install home positions and WBC library
1212
# ======================================
1313

1414
find_package(YARP REQUIRED)
@@ -18,12 +18,26 @@ add_subdirectory(utilities)
1818
add_subdirectory(library)
1919
add_subdirectory(config)
2020

21+
# Install the example controller model (YOGA+matlab-simulator)
22+
set(FLOATING_BASE_BALANCING_TORQCTRL_INSTALL_MATLAB_FILESDIR ${CMAKE_INSTALL_PREFIX}/mex/+wbc/examples CACHE
23+
STRING "Location (relative to the install prefix) in which the Matlab .m files and simulink .mdl models are installed.")
24+
set(M_FILES_DIR ${whole-body-controllers_SOURCE_DIR}/controllers/+floatingBaseBalancingTorqueControlWithSimulator)
25+
26+
install(
27+
DIRECTORY ${M_FILES_DIR}
28+
DESTINATION ${FLOATING_BASE_BALANCING_TORQCTRL_INSTALL_MATLAB_FILESDIR}
29+
USE_SOURCE_PERMISSIONS
30+
FILES_MATCHING
31+
PATTERN "*.m"
32+
PATTERN "*.jpeg"
33+
PATTERN "*.mdl")
34+
2135
# ======================
22-
# Autogeneration routine
36+
# Autogeneration routine
2337
# ======================
2438

2539
if(NOT WBC_EXPORT_AUTOGENERATED)
26-
# Fake installation.
40+
# Fake installation.
2741
install(CODE "MESSAGE(\"Disabled exporting of autogenerated c++ code from Simulink.\")")
2842
return()
2943
endif()

README.md

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
The repository contains `Simulink-based whole-body controllers` developed to control the [iCub](http://www.icub.org/) humanoid robot. It can be imagined as a **starting point** and a **support** repository for a user that intends to develop a new Simulink controller (not necessarily for the iCub robot) in within the framework of the [robotology](https://github.com/robotology) organization. It is worth noting that:
1313

14-
- 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.
14+
- 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. With the dependency [matlab-whole-body-simulator](https://github.com/dic-iit/matlab-whole-body-simulator) installed, you can also design simulations with a full MATLAB/Simulink simulator and robot visualizer, accessible through the Simulink Library Browser entry `Matlab Whole-body Simulator` (refer to this [README](controllers/floating-base-balancing-torque-control-with-simulator/README.md)).
1515

1616
- 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).
1717

@@ -24,6 +24,7 @@ This repository depends upon the following Software:
2424
- [CMake](https://cmake.org/), at least version **3.5**.
2525
- [Matlab/Simulink](https://it.mathworks.com/products/matlab.html), default version **R2019b**.
2626
- [WB-Toolbox](https://github.com/robotology/WB-Toolbox) and [blockfactory](https://github.com/robotology/blockfactory).
27+
- [matlab-whole-body-simulator](https://github.com/dic-iit/matlab-whole-body-simulator), at least version **2.0.0**.
2728
- [Gazebo Simulator](http://gazebosim.org/), default version **9.0**.
2829
- [gazebo-yarp-plugins](https://github.com/robotology/gazebo-yarp-plugins).
2930
- [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.
@@ -34,7 +35,7 @@ This repository depends upon the following Software:
3435

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

37-
- 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_ENABLE_DYNAMICS` option). **Warning**: the superbuild can download and compile the repository also without having Matlab, Simulink and Gazebo installed in the PC, but the functionalities of the repo will be considerably reduced! To access all the features of the repo, install all the [dependencies](https://github.com/robotology/whole-body-controllers/blob/master/README.md#dependencies). Also, in the superbuild you have to enable the `ROBOTOLOGY_USES_GAZEBO` and `ROBOTOLOGY_USES_MATLAB` options.
38+
- 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`, `matlab-whole-body-simulator`, `blockfactory` and `WB-Toolbox` and their dependencies) using the [robotology-superbuild](https://github.com/robotology/robotology-superbuild) (enable `ROBOTOLOGY_ENABLE_DYNAMICS` option). **Warning**: the superbuild can download and compile the repository also without having Matlab, Simulink and Gazebo installed in the PC, but the functionalities of the repo will be considerably reduced! To access all the features of the repo, install all the [dependencies](https://github.com/robotology/whole-body-controllers/blob/master/README.md#dependencies). Also, in the superbuild you have to enable the `ROBOTOLOGY_USES_GAZEBO` and `ROBOTOLOGY_USES_MATLAB` options.
3839

3940
- 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:
4041

@@ -54,14 +55,16 @@ The repository is usually tested and developed on **Ubuntu** and **macOS** opera
5455
| iCubGazeboV2_5|[model.urdf](https://github.com/robotology/icub-models/blob/master/iCub/robots/iCubGazeboV2_5/model.urdf)|
5556
| icubGazeboSim |[model.urdf](https://github.com/robotology/yarp-wholebodyinterface/blob/master/app/robots/icubGazeboSim/model.urdf) |
5657

57-
- **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:
58+
- **IMPORTANT!** to use the WBC Simulink controllers, it is **required** to add the **installed** `+wbc` and `+wbc/simulink` folders (copied from [+wbc](library/matlab-wbc/+wbc)) to the Matlab path. There are two possible ways to add the folder to the Matlab path:
5859

59-
**1a.** `manually` and `permanently` add the folder to the Matlab path;
60+
**1a.** `manually` and `permanently` add the parent folder of the installed `+wbc` (`${CMAKE_INSTALL_PREFIX}/mex`), and its sub-folder `+wbc/simulink` to the Matlab path;
6061

6162
**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).
6263
**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.
6364
- **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).
64-
65+
66+
- The folder `${CMAKE_INSTALL_PREFIX}/mex` having been already added to the Matlab path, there are no other requirements for using the simulation library from `matla-whole-body-simulator`.
67+
6568
- 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.
6669

6770
## Troubleshooting
@@ -85,8 +88,8 @@ Please refer to the [WBToolbox troubleshooting documentation](https://robotology
8588
- [fixed-base-joints-torque-control](controllers/fixed-base-joints-torque-control/README.md)
8689
- [floating-base-balancing-position-control](controllers/floating-base-balancing-position-control/README.md)
8790
- [floating-base-balancing-torque-control](controllers/floating-base-balancing-torque-control/README.md)
91+
- [floating-base-balancing-torque-control-with-simulator](controllers/floating-base-balancing-torque-control-with-simulator/README.md)
8892
- [floating-base-jerk-control](controllers/floating-base-jerk-control/README.md)
89-
- [simulink-balancing-simulator](controllers/simulink-balancing-simulator/README.md)
9093

9194
### Matlab functions library
9295

@@ -119,6 +122,9 @@ Official legacy repositories are: [mex-wholebodymodel](https://github.com/roboto
119122
- [joint-space control and centroidal transformation](https://github.com/robotology/mex-wholebodymodel/tree/master/controllers/torqueBalancingJointControl)
120123
- [stand-up control 4 contacts](https://github.com/robotology-legacy/WBI-Toolbox-controllers/tree/master/controllers/torqueBalancingStandup_4Contacts)
121124

125+
You can also find other legacy controllers/simultors in this repository **whole-body-controllers** in specific commits:
126+
- [simulink-balancing-simulator@c217f051](https://github.com/robotology/whole-body-controllers/tree/c217f051b16da32c8acc607182524239b3a7d8fb/controllers/simulink-balancing-simulator).
127+
122128
## Citing this work
123129

124130
If you are using this code for your research activity and you're willing to cite it, you may add the following references to your bibliography:
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
## Module description
2+
3+
This module implements the same torque controller described in [floating-base-balancing-torque-control](../floating-base-balancing-torque-control/README.md), the block **"MOMENTUM BASED TORQUE CONTROL"**, but instead of controlling the real iCub robot or the model on Gazebo, it is integrated with the robot simulator from [matlab-whole-body-simulator](https://github.com/dic-iit/matlab-whole-body-simulator).
4+
5+
<img src="/doc/pics/torqueControlwithSimu_w_SampleRates.png" width="1800">
6+
7+
In the above diagram, signals and blocks sampling times are identified by colors
8+
- red: 1 ms
9+
- pink: constant
10+
- green: 10 ms
11+
12+
More precisely:
13+
- The controller **"MOMENTUM BASED TORQUE CONTROL"** feeds the joint torques to the robot dynamics simulator **"Robot Simulator"** through a memory block for avoiding algebraic loops.
14+
- The **"Robot Simulator"** simulates the robot dynamics, handling the contacts of the feet with the ground. This sub-system provides the inputs required by the controller:
15+
- joint positions
16+
- joint velocities
17+
- joint accelerations
18+
- left foot wrench
19+
- right foot wrench
20+
- IMU measurements
21+
- The **"Robot Visualizer"** allows to visualize the robot. It avoids using Gazebo as a visualizer. As a result, the overall procedure for running the simulation is simpler (no need to run Yarp nor Gazebo, nor synchronize them with Matlab).
22+
23+
<img src="/doc/pics/robotSimulator_w_SampleRates.png" width="1800">
24+
25+
The **"Robot Simulator"** has its own **"Config"** block, for a robot configuration specific to the simulation, and is composed of three other blocks:
26+
- The **"RobotDynWithContacts"**, actual simulator core, simulates the robot dynamics and provides all the robot kinematic and dynamic quantities.
27+
- The **"IMU"** emulates the sensor outputs from the floating base state and linear acceleration.
28+
- The **"Friction Model"** block implements a simple viscous friction model, function of the joints velocities and desired torques.
29+
30+
"RobotDynWithContacts", "IMU" and "RobotVisualizer" blocks are library blocks imported from [`matlab-whole-body-simulator`](https://github.com/dic-iit/matlab-whole-body-simulator). Their parameters are set through their respective masks. For further details on the "RobotDynWithContacts" configuration, refer to https://github.com/dic-iit/matlab-whole-body-simulator/blob/master/README.md.
31+
32+
### Compatibility
33+
34+
The folder contains the Simulink model `torqueControlBalancingWithSimu.mdl`, which is generated by using Matlab R2020b.
35+
36+
### Supported robots
37+
38+
Currently, the only supported robot model is `iCubGazeboV2_5` which has the proper inertia tuning (for the very small and light links within the shoulders, hips, etc).
39+
40+
## Module details
41+
42+
### How to run the demo
43+
44+
You don't need any module external module running outside of Matlab.
45+
46+
For running the simulation from the source module (for developpers wishing to perform any modification), follow the few steps below:
47+
1. Set the `YARP_ROBOT_NAME` environment variable to the desired model. The default and only currently supported model is `iCubGazeboV2_5`. There is no direct link with Gazebo. This model is suitable for the `matlab-whole-body-simulator` because of the modified inertia of the intermediate small and light links within the 3-DoF joints (shoulder pitch-roll-yaw, hip pitch-roll-yaw, etc), tuned for stabilising the dynamics of the simulation.
48+
```
49+
> setenv(`YARP_ROBOT_NAME`,`iCubGazeboV2_5`)
50+
```
51+
52+
2. Verify that the target robot model is available. You can check if the controller is targeting the correct robot model by typing on the Matlab command line:
53+
```
54+
system('yarp resource --find model.urdf')
55+
```
56+
57+
then, check that the path and the model name are correct.
58+
59+
3. Change the working directory to the [parent folder of the controller model](./).
60+
4. Open the Simulink model `torqueControlBalancingWithSimu.mdl`.
61+
5. Run the model.
62+
63+
For running the simulation from the installed module (e.g. in case of a user, without any experience in simulation nor control, just trying the simulator for the first time), skip steps 3. and 4. and execute instead:
64+
- still in Matlab, and from any location except from [whole-body-controllers/controllers](../) (for avoiding file naming collision with [this folder](./)), open the model directly from the Matlab command line:
65+
```
66+
>> floatingBaseBalancingTorqueControlWithSimulator.torqueControlBalancingWithSimu
67+
```
68+
69+
### Configuration file
70+
71+
At start, the module calls the initialization file `initTorqueControlBalancingWithSimu.m`. Once opened, this file contains some configuration variables. Please follow the instruction inside the script to properly configure your simulation.
72+
73+
### Robot and demo specific configurations
74+
75+
The gains and references for a specific robot (specified by the variable `YARP_ROBOT_NAME`) or a specific demo can be found in the folder `app/robots/YARP_ROBOT_NAME`.
Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,11 @@
2121
clearvars -except sl_synch_handles simulinkStaticGUI
2222
clc
2323

24+
% Get the parent folder of the running *.mdl model
25+
MODEL_PATH = fileparts(which(bdroot));
26+
2427
% Add path to local source code
25-
addpath('./src/')
28+
addpath(strcat(MODEL_PATH,'/src/'));
2629

2730
%% GENERAL SIMULATION INFO
2831
%
@@ -73,12 +76,14 @@
7376
switch(getenv('YARP_ROBOT_NAME'))
7477
case 'iCubGazeboV2_5'
7578
otherwise
76-
error(['Unsupported robot model. Supported models are listed below:',repmat('\n- %s',[1 numel(supportedMmodels)])],supportedMmodels{:});
79+
warning(['Unsupported robot model. Supported models are listed below:',repmat('\n- %s',[1 numel(supportedMmodels)])],supportedMmodels{:});
80+
setenv('YARP_ROBOT_NAME','iCubGazeboV2_5');
81+
warning('Setting the default model iCubGazeboV2_5.');
7782
end
78-
run(strcat('app/robots/',getenv('YARP_ROBOT_NAME'),'/configRobot.m'));
79-
run(strcat('app/robots/',getenv('YARP_ROBOT_NAME'),'/configStateMachine.m'));
80-
run(strcat('app/robots/',getenv('YARP_ROBOT_NAME'),'/gainsAndReferences.m'));
81-
run(strcat('app/robots/',getenv('YARP_ROBOT_NAME'),'/configRobotSim.m'));
83+
run(strcat(MODEL_PATH,'/app/robots/',getenv('YARP_ROBOT_NAME'),'/configRobot.m'));
84+
run(strcat(MODEL_PATH,'/app/robots/',getenv('YARP_ROBOT_NAME'),'/configStateMachine.m'));
85+
run(strcat(MODEL_PATH,'/app/robots/',getenv('YARP_ROBOT_NAME'),'/gainsAndReferences.m'));
86+
run(strcat(MODEL_PATH,'/app/robots/',getenv('YARP_ROBOT_NAME'),'/configRobotSim.m'));
8287
run('initVisualizer');
8388

8489
% Deactivate/activate the internal coordinator

0 commit comments

Comments
 (0)