Skip to content

Commit

Permalink
Static GUI for Simulink and add gearboxes inertia (#42)
Browse files Browse the repository at this point in the history
Static GUI for Simulink and add gearboxes inertia
  • Loading branch information
gabrielenava authored Jan 10, 2019
1 parent 525d7ce commit 88dfec5
Show file tree
Hide file tree
Showing 130 changed files with 10,187 additions and 70,487 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ CMakeLists.txt.user*
# Simulink Code Generation
slprj/

# Simulink slx
*.slxc
*.slx

# Matlab binary .mat files
*.mat

Expand Down
54 changes: 35 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# whole-body-controllers

A collection of Matlab/Simulink whole body controllers for humanoid robots.
Simulink-based whole body controllers for humanoid robots.

## Dependencies

This repository depends upon the following Software/repositories:

- [Matlab/Simulink](https://it.mathworks.com/products/matlab.html), at least version **R2014a** (default: **R2017b**)
- [Matlab/Simulink](https://it.mathworks.com/products/matlab.html), default version **R2017b**
- [WB-Toolbox](https://github.com/robotology/WB-Toolbox)
- [Gazebo Simulator](http://gazebosim.org/), at least version **7.8**
- [Gazebo Simulator](http://gazebosim.org/), default version **9.0**
- [gazebo-yarp-plugins](https://github.com/robotology/gazebo-yarp-plugins)
- [icub-gazebo](https://github.com/robotology/icub-gazebo) and [icub-gazebo-wholebody](https://github.com/robotology-playground/icub-gazebo-wholebody) to access iCub models.
- [codyco-modules](https://github.com/robotology/codyco-modules) (Optional, for using [home positions](https://github.com/robotology/codyco-modules/tree/master/src/modules/torqueBalancing/app/robots) and [wholeBodyDynamics](https://github.com/robotology/codyco-modules/tree/master/src/devices/wholeBodyDynamics) device).
Expand All @@ -17,6 +17,8 @@ This repository depends upon the following Software/repositories:

## Installation and usage

- clone the repository on your pc by running on a terminal `git clone https://github.com/robotology/whole-body-controllers`, or dowload the repository.

- set the environmental variable `YARP_ROBOT_NAME` in the `.bashrc` file to be the name of the robot you want to control. List of supported robot names:

| Robot Names | Associated URDF Model |
Expand All @@ -26,7 +28,15 @@ This repository depends upon the following Software/repositories:
| iCubGazeboV2_5 |[model.urdf](https://github.com/robotology/icub-models/blob/master/iCub/robots/iCubGazeboV2_5/model.urdf)|
| icubGazeboSim |[model.urdf](https://github.com/robotology/yarp-wholebodyinterface/blob/master/app/robots/icubGazeboSim/model.urdf) |

- if all the required dependencies are correctly installed and configured, just clone this repository on your pc. No further actions are required. An alternative is to install this repository through the `robotology-superbuild`. It is required to enable the option `ROBOTOLOGY_ENABLE_DYNAMICS`. **Important:** it is necessary to set the
- to use the Simulink controllers, it is required to add the [matlab-wbc](library/matlab-wbc) folder to the Matlab path. There are two different possible ways to add the folder to the path:
- directly add the folder to the Matlab path;
- run **only once** the [startup.m](config/startup.m) script. In this case, it is required to **always** start matlab from the folder where the `pathdef.m` file is (usually `~/Documents/MATLAB`). For further information see also the [WBToolbox documentation](https://robotology.github.io/wb-toolbox/mkdocs/install/#matlab).

**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 can be found in the [Matlab documentation](https://it.mathworks.com/help/matlab/matlab_oop/scoping-classes-with-packages.html).

## Troubleshooting

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

## Structure of the repo

Expand All @@ -36,46 +46,52 @@ This repository depends upon the following Software/repositories:

- **doc**: guidelines on how to create/use Simulink models for control. [[README]](doc/README.md)

- **legacy**: legacy version of all Simulink models in the repo, written in the lowest supported matlab version (R2014a). [[README]](legacy/README.md)

- **library**: a library of functions/scripts used by the controllers. [[README]](library/README.md)

- **utilities**: Simulink models for debugging sensors on the real robot. [[README]](utilities/README.md)

## Automatic generation of c++ code from Simulink
## Interesting features

There is the possibility to generate c++ code from the Simulink models using [Simulink coder](https://www.mathworks.com/products/simulink-coder.html). The repositiory that contains the generated c++ code for the [momentum-based-yoga](torque-controllers/momentum-based-yoga) controller is named [autogenerated-whole-body-controllers](https://github.com/robotology-playground/autogenerated-whole-body-controllers). Documentation on how to generate the code is available in the repository [wiki](https://github.com/robotology-playground/autogenerated-whole-body-controllers/wiki/How-to-generate-code-from-a-Simulink-model).
### Automatic generation of c++ code from Simulink

There is the possibility to generate c++ code from the Simulink models using [Simulink coder](https://www.mathworks.com/products/simulink-coder.html) (**available only for the [momentum-based-yoga](torque-controllers/momentum-based-yoga)**). The repositiory that contains the generated c++ code is named [autogenerated-whole-body-controllers](https://github.com/robotology-playground/autogenerated-whole-body-controllers). Documentation on how to generate the code is available in the repository [wiki](https://github.com/robotology-playground/autogenerated-whole-body-controllers/wiki/How-to-generate-code-from-a-Simulink-model).

### Static GUI for Simulink

When used for controlling real platforms, heavy Simulink models may violate the user-defined simulation time step, see also [this issue](https://github.com/robotology/wb-toolbox/issues/160). It seems a source of delay is the run-time update of the Simulink interface. For this reason, a [static GUI for running the models](library/matlab-gui) has been developed. **Available only for [momentum-based-yoga](torque-controllers/momentum-based-yoga) and [momentum-based-standup](torque-controllers/momentum-based-standup)**. If you want to run Simulink with the static GUI, just run the [start{$SIM_NAME}WithoutSimulinkGui](torque-controllers/momentum-based-yoga/startYogaWithoutSimulinkGui.m) script.

## Where do I find new features and legacy repos?

##### Available controllers
#### Available controllers

- [impedance-control](https://github.com/robotology/whole-body-controllers/tree/master/torque-controllers/impedance-control)
- [momentum-based-standup](https://github.com/robotology/whole-body-controllers/tree/master/torque-controllers/momentum-based-standup)
- [momentum-based-yoga](https://github.com/robotology/whole-body-controllers/tree/master/torque-controllers/momentum-based-yoga)
- [utilities](https://github.com/robotology/whole-body-controllers/tree/master/utilities)

##### Matlab functions library
#### Matlab functions library

- [matlab library](https://github.com/robotology/whole-body-controllers/tree/master/library/matlab)

##### Active Forks (new features)
#### Active Forks (new features)

- [force-parametrization](https://github.com/ahmadgazar/whole-body-controllers)
- [PhRI-standup](https://github.com/Yeshasvitvs/wholeBodyControllers)
- [exploit friction and walking controller](https://github.com/gabrielenava/whole-body-controllers)

##### Legacy
#### Legacy

Official legacy repositories are: [mex-wholebodymodel](https://github.com/robotology/mex-wholebodymodel) and [WBI-Toolbox-controllers](https://github.com/robotology-playground/WBI-Toolbox-controllers). **Note**: these legacy repos contain undocumented/outdated code, and duplicated or not tested matlab functions. They also contain original code that has been tested on the robot in the past and then never used again, or code that will be ported in the main repository in the future.

- [seesaw controller and integration-based-ikin](https://github.com/gabrielenava/whole-body-controllers/tree/legacy)
- [automatic gain tuning](https://github.com/gabrielenava/mex-wholebodymodel/tree/master/controllers/torqueBalancingGainTuning)
- [elastic joints control](https://github.com/gabrielenava/mex-wholebodymodel/tree/master/controllers/torqueBalancing_JE)
- Walkman control: https://github.com/gabrielenava/mex-wholebodymodel/tree/master/controllers/torqueBalancingWalkman and https://github.com/gabrielenava/WBI-Toolbox-controllers/tree/walkman
- [joint-space control and centroidal transformation](https://github.com/gabrielenava/mex-wholebodymodel/tree/master/controllers/torqueBalancingJointControl)
- [exploit friction and walking controller](https://github.com/robotology-playground/WBI-Toolbox-controllers/tree/whole-body-controllers-legacy/controllers/legacy)
- [seesaw controller and integration-based-ikin](https://github.com/robotology-playground/WBI-Toolbox-controllers/tree/whole-body-controllers-legacy/controllers/legacy)
- [automatic gain tuning](https://github.com/robotology/mex-wholebodymodel/tree/master/controllers/torqueBalancingGainTuning)
- [elastic joints control](https://github.com/robotology/mex-wholebodymodel/tree/master/controllers/torqueBalancing_JE)
- [walkman control](https://github.com/robotology-playground/WBI-Toolbox-controllers/tree/whole-body-controllers-legacy/controllers/legacy/torqueBalancing-walkman) and [walkman control-matlab](https://github.com/robotology/mex-wholebodymodel/tree/master/controllers/torqueBalancingWalkman)
- [joint-space control and centroidal transformation](https://github.com/robotology/mex-wholebodymodel/tree/master/controllers/torqueBalancingJointControl)

#### Associated repositories

- [idyntree-high-level-wrappers](https://github.com/gabrielenava/idyntree-high-level-wrappers)
- [matlab-multi-body-sim](https://github.com/gabrielenava/matlab-multi-body-sim)

### Mantainers

Expand Down
4 changes: 3 additions & 1 deletion config/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

A collection of scripts used for correctly configure the repo.

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

- [startup.m](startup.m): run this script once. Then, the path to the `matlab-wbc` folder will be permanently added to the `pathdef.m` file, which is saved inside the Matlab `userpath`. 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 (in general, `~/Documents/MATLAB`).



Expand Down
78 changes: 17 additions & 61 deletions config/export_WBC.m
Original file line number Diff line number Diff line change
Expand Up @@ -22,37 +22,18 @@
fprintf('\n######################################################\n\n');

% list of all simulink models (in this repo only .mdl are allowed) in the project
mdlList = dir('../**/*.mdl');

% ignore models in the "legacy" folder (if there is any)
cont = 1;

if exist('../legacy','dir')

for j = 1:size(mdlList,1)

parsedString = strsplit(mdlList(j).folder,'/');

if sum(strcmp(parsedString, 'legacy')) <= 0

mdlList_red(cont) = mdlList(j); %#ok<SAGROW>
cont = cont +1;
end
end
else
mdlList_red = mdlList;
end
mdlList = dir('../**/*.mdl');

% matlab version to which export all models
matlabVer = input('Specify the Matlab version to export models (format: R20XXx) ','s');

%% Verify matlab version

% latest version: R2017b
matlabVer_list = {'R2014a','R2014b','R2015a','R2015b','R2016a','R2016b','R2017a','R2017b'};
% latest version: R2018a
matlabVer_list = {'R2014a','R2014b','R2015a','R2015b','R2016a','R2016b','R2017a','R2017b','R2018a'};

% associated Simulink version
simulinkVer_number = {'8.3','8.4','8.5','8.6','8.7','8.8','8.9','9.0'};
simulinkVer_number = {'8.3','8.4','8.5','8.6','8.7','8.8','8.9','9.0','9.1'};

% installed Simulink version
currentSimulinkVer = ver('Simulink');
Expand All @@ -76,70 +57,45 @@

if isempty(currentSimulinkVer)

error('Simulink not found Verify your Simulink version.');
error('Simulink not found. Verify your Simulink version.');

elseif str2double(simulinkVer_number{matlabVer_found}) > str2double(currentSimulinkVer.Version)

error('It is not possible to export models to Simulink versions higher than the one installed on your system.');
end

% ask the user if it is necessary to also create a legacy copy of the
% Simulink models with the oldest Matlab version
exportLegacyVersion = input(['Would you also like to export a legacy copy of all models with Matlab ' matlabVer_list{1}, '? Y/N '],'s');
exportInLegacy = false;

if strcmp(exportLegacyVersion,'y') || strcmp(exportLegacyVersion,'Y')

exportInLegacy = true;

if ~exist('../legacy','dir')
mkdir('../legacy');
end
end

%% Load the Simulink models and export to previous versions
mdlVer_list = {'R2014A_MDL','R2014B_MDL','R2015A_MDL','R2015B_MDL','R2016A_MDL','R2016B_MDL','R2017A_MDL','R2017B_MDL'};
mdlVer_list = {'R2014A_MDL','R2014B_MDL','R2015A_MDL','R2015B_MDL','R2016A_MDL','R2016B_MDL','R2017A_MDL','R2017B_MDL','R2018A_MDL'};

% close all open models (if there is any)
close_system('',0)

for k = 1:length(mdlList_red)
for k = 1:length(mdlList)

fprintf(['\nLOADED MODEL: ' mdlList_red(k).name '\n']);
open_system([mdlList_red(k).folder,'/',mdlList_red(k).name],'loadonly');
fprintf(['\nLOADED MODEL: ' mdlList(k).name '\n']);
open_system([mdlList(k).folder,'/',mdlList(k).name],'loadonly');

% save the model in a temporary copy. Then, export the copy into
% the previous version, by overwriting the original model
fprintf('\n saving a temporary copy of the model \n\n');
save_system([mdlList_red(k).folder,'/',mdlList_red(k).name], [mdlList_red(k).folder,'/',mdlList_red(k).name(1:end-4),'_temp.mdl']);
close_system([mdlList_red(k).folder,'/',mdlList_red(k).name],0);

open_system([mdlList_red(k).folder,'/',mdlList_red(k).name(1:end-4),'_temp.mdl'],'loadonly');
save_system([mdlList(k).folder,'/',mdlList(k).name], [mdlList(k).folder,'/',mdlList(k).name(1:end-4),'_temp.mdl']);
close_system([mdlList(k).folder,'/',mdlList(k).name],0);
open_system([mdlList(k).folder,'/',mdlList(k).name(1:end-4),'_temp.mdl'],'loadonly');

% do not export if simulink models are already at the required version
if str2double(simulinkVer_number{matlabVer_found}) == str2double(currentSimulinkVer.Version)

fprintf('\n model is already at the required version. \n');
else
save_system([mdlList_red(k).folder,'/',mdlList_red(k).name(1:end-4),'_temp.mdl'], [mdlList_red(k).folder,'/',mdlList_red(k).name], 'ExportToVersion', mdlVer_list{matlabVer_found});
end

% save a copy in legacy folder
if exportInLegacy

if str2double(simulinkVer_number{1}) == str2double(currentSimulinkVer.Version)
save_system([mdlList_red(k).folder,'/',mdlList_red(k).name(1:end-4),'_temp.mdl'], ['../legacy/',mdlList_red(k).name(1:end-4),'_legacy.mdl']);
else
save_system([mdlList_red(k).folder,'/',mdlList_red(k).name(1:end-4),'_temp.mdl'], ['../legacy/',mdlList_red(k).name(1:end-4),'_legacy.mdl'], 'ExportToVersion', mdlVer_list{1});
end
save_system([mdlList(k).folder,'/',mdlList(k).name(1:end-4),'_temp.mdl'], [mdlList(k).folder,'/',mdlList(k).name], 'ExportToVersion', mdlVer_list{matlabVer_found});
end

% closing the temporary model
fprintf('\n closing the model \n');
close_system([mdlList_red(k).folder,'/',mdlList_red(k).name(1:end-4),'_temp.mdl']);
close_system([mdlList(k).folder,'/',mdlList(k).name(1:end-4),'_temp.mdl']);

% delete the temporary model
delete([mdlList_red(k).folder,'/',mdlList_red(k).name(1:end-4),'_temp.mdl'])
delete([mdlList(k).folder,'/',mdlList(k).name(1:end-4),'_temp.mdl'])
end

fprintf('\nDone.\n');
fprintf('\nDone.\n');
79 changes: 79 additions & 0 deletions config/startup.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
%% startup.m
%
% Run this script only once to permanently add the matlab-wbc folder to your MATLAB path.

fprintf('\n## whole-body-controllers ##\n');
fprintf('\nAdding "matlab-wbc" to pathdef.m...\n\n');

% path to whole-body-controllers
pathToWBC = pwd;
pathToWBC = pathToWBC(1:end-6);

% path to the matlab-wbc library
pathToLibrary = [pathToWBC, filesep, 'library/matlab-wbc'];

if exist(pathToLibrary, 'dir')

addpath(pathToLibrary);
else
error('Path to the "matlab-wbc" library not found or not correct.')
end

% Path to the Matlab userpath
pathToUserpath = userpath;
pathSeparatorLocation = strfind(pathToUserpath, pathsep);

if isempty(pathToUserpath)

answer = input('Empty userpath. Do you want to reset the userpath? Y/N ','s');

if strcmpi(answer,'Y')

userpath('reset');
disp('Resetting userpath..');
pathToUserpath = userpath;
pathSeparatorLocation = strfind(pathToUserpath, pathsep);
else
error('Please set the userpath before running this script');
end

elseif size(pathSeparatorLocation, 2) > 1

answer = input('Multiple userpath. Do you want to reset the userpath? Y/N ','s');

if strcmpi(answer,'Y')

userpath('reset');
disp('Resetting userpath..');
pathToUserpath = userpath;
pathSeparatorLocation = strfind(pathToUserpath, pathsep);
else
error('Please set a single userpath before running this script');
end
end

% check again the userpath
if isempty(pathToUserpath)

error('userpath is still empty. Please set the userpath before running this script');

elseif size(pathSeparatorLocation, 2) > 1

error('There are still multiple userpath. Please set a single userpath before running this script');
end

if (~isempty(pathSeparatorLocation))

pathToUserpath(pathSeparatorLocation) = [];
end

fprintf('Saving paths to %s\n\n', [pathToUserpath, filesep, 'pathdef.m']);

if (~savepath([pathToUserpath, filesep, 'pathdef.m']))

fprintf(['A file called pathdef.m has been created in your %s folder.\n', ...
'This should be enough to permanently add matlab-wbc to ', ...
'your MATLAB installation.\n'], pathToUserpath);
else
disp('There was an error generating the pathdef.m. Please manually add the matlab-wbc folder to your matlabpath');
end
6 changes: 0 additions & 6 deletions legacy/README.md

This file was deleted.

Loading

0 comments on commit 88dfec5

Please sign in to comment.