Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export MATLABPATH from the setup scripts #160

Merged
merged 2 commits into from
Jan 22, 2019
Merged

Export MATLABPATH from the setup scripts #160

merged 2 commits into from
Jan 22, 2019

Conversation

diegoferigo
Copy link
Member

This PR introduces the possibility of configuring the environment in such a way that if Matlab is executed from the terminal and the setup scripts are used, no manual actions are required.

Note that I only tested the behavior in Ubuntu.

Related to #159 (comment).

@traversaro
Copy link
Member

@gabrielenava @nunoguedelha What do you thinkg about this?

README.md Outdated
#### Start MATLAB from the terminal

You can add the folders by modifying the `startup.m` or the `MATLABPATH` environmental variable [as described in official MATLAB documentation](https://www.mathworks.com/help/matlab/matlab_env/add-folders-to-matlab-search-path-at-startup.html).
In you are using the `setup.sh` script for configuring your environment, `MATLABPATH` is automatically populated with these directories.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
In you are using the `setup.sh` script for configuring your environment, `MATLABPATH` is automatically populated with these directories.
In you are using the `setup.sh` or `setup.bat` script for configuring your environment, `MATLABPATH` is automatically populated with these directories.

@traversaro
Copy link
Member

If I understand correctly, startup_robotology_superbuild.m already had share/WBToolbox/images in it, am I correct?

To use this software, you can simply enable its compilation using the `ROBOTOLOGY_USES_MATLAB` CMake option.
Once this software has been compiled by the superbuild, you just need to add some directories of the robotology-superbuild install (typically `$ROBOTOLOGY_SUPERBUILD_ROOT/build/install`) to [the MATLAB path](https://www.mathworks.com/help/matlab/matlab_env/what-is-the-matlab-search-path.html).
In particular you need to add to the MATLAB path the `$ROBOTOLOGY_SUPERBUILD_INSTALL_PREFIX/mex` directory and all the subdirectories `$ROBOTOLOGY_SUPERBUILD_INSTALL_PREFIX/share/WBToolbox`.

As an example, you could add this line to your MATLAB script that uses the robotology-superbuild matlab software:
#### Start MATLAB from the launcher or the application menu
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this may be misleading. If MATLAB is launched from launcher of the application menu, who is setting the ROBOTOLOGY_SUPERBUILD_INSTALL_PREFIX env var? @gabrielenava @nunoguedelha any opinion?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I personally never used that script, I know that @gabrielenava does use it, let's wait his feedback.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Btw, those instructions were there before, probably they had to be updated.

Copy link
Collaborator

@gabrielenava gabrielenava Jan 18, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually never started Matlab from the launcher. On a new installation, I always run the startup_robotology_superbuild.m. However, note that if one uses the startup_robotology_superbuild.m, it is required to open matlab from the folder where the `pathdef.m file is, otherwise the required folders are not added to the path.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, if I understood, with this PR it will be possible to set the required Matlab path using the setup.sh file instead/ as an alternative to:

  • manually add the required folder to the MATLABPATH;

  • run the startup_robotology_superbuild.m if the WBToolbox is installed through the robotology-superbuild, or the startup.m file if the WBToolbox is external to the superbuild. Note that as I said before, if the user decides to choose this last method it is required to always start matlab from the folder where the pathdef.m file is. This is not necessary (as far as I understood, as I always followed this third option) if the user decides to choose one of the other two options.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we please open new issue if problem exist instead of posting in closed issues? :''(

Sorry, I was confused by the old issue, the problem is discussed in #64 .

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just have a question, if two projects need the pathdef.m, is there any possibility that the second project overrides the file created by the first?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just have a question, if two projects need the pathdef.m, is there any possibility that the second project overrides the file created by the first?

Short answer would be "Yes", but I' not sure what you mean, so here is a short explanation of how pathdef.m is handled...

A pathdef.m file is created or overwritten whenever:

  • you hit "save" in the MATLAB "set path" menu window -> the file is then created or overwritten in the folder defined by the userpath MATLAB function,
  • whenever you execute in MATLAB the command savepath, and providing the target file explicitely: for instance savepath([fileDir, filesep, 'pathdef.m']).

The pathdef.m used is the the one located in the same folder where you launch MATLAB from.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that as far as I know this issue still occurs on Ubuntu 18.04, therefore even running the setup.sh file the user will have to manually address this before being able to use the toolbox properly.

...
then if the user does not run matlab from the folder where the pathdef.m is, he will be able to use WBToolbox but not whole-body-controllers.

I think from the Simulink controllers point that's it.

Just to clarify, the constraint on where we launch MATLAB from is applicable only if we launch MATLAB from the terminal, and that section mentions running a startup.m file and gives a reference to the MATLAB documentation.

WARNING: we are mixing things here. The startup.m file the MATLAB documentation refers to is a special file that doesn't have to be explicitely run by the user, but is loaded at startup under certain conditions (the MATLAB documentation is not clear about this. I documented it in a wiki here and in my comments about launching MATLAB from the terminal). If the file name has that exact syntax and is found by MATLAB, it will be executed at startup.

If some startup file like the one from the superbuild or the one from the WB-toolbox creates a pathdef.m in the folder defined by userpath, then it will always be loaded at startup when MATLAB is launched from the GUI in MacOS (from the launchpad or "Applications" Finder folder).

I don't know how it works on Linux but I assume you can configure the startup folder in the properties of the shortcut you create for MATLAB.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regarding MATLABPATH...
On MacOS: when launching MATLAB application through the GUI (launchepad,...), the usual way to set environment variables (MATLABPATH=<some path>) has no effect. You need to use the command launchctl setenv <variable> <value> as documented in my wiki, adding to the ~/.bash_profile the lines:

export MATLABPATH=<some-path>
launchctl setenv MATLABPATH $MATLABPATH

@diegoferigo
Copy link
Member Author

I updated the instructions, imho we cover too many cases and this might create confusion. However, this would worth a separate discussion.

CMakeLists.txt Outdated
@@ -132,6 +132,7 @@ if(ROBOTOLOGY_ENABLE_DYNAMICS)
endif()
if(ROBOTOLOGY_USES_MATLAB)
if(NOT ROBOTOLOGY_NOT_USE_SIMULINK)
set(ROBOTOLOGY_USES_SIMULINK TRUE)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This logic is quite strange to me, isn't it better to have just a variable called "ROBOTOLOGY_USES_SIMULINK" instead of "ROBOTOLOGY_USES_SIMULINK" and "ROBOTOLOGY_NOT_USE_SIMULINK"?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The rationale for this is described in the readme at https://github.com/robotology/robotology-superbuild/blob/98500f5f57fff4d14044379e0edd4a8f1d3bbd33/README.md#system-dependencies-7 . Basically, based on my limited experience the vast majority of our users have Matlab+Simulink installed on their computer, so we just require them to set ROBOTOLOGY_USES_MATLAB to TRUE to enable both software that requires MATLAB and software that requires Simulink. There are (a few, fortunatly) cases in which the user has matlab but no Simulink: in that case, the user select the additional option ROBOTOLOGY_NOT_USE_SIMULINK (that default to false) to avoid compiling the software that depends on Simulink.
I don't think that adding a ROBOTOLOGY_USES_SIMULINK and requiring all users to set it to ON manually in addition to ROBOTOLOGY_USES_MATLAB would be helpful.

See robotology-legacy/codyco-superbuild#65 (comment) for when the option was added. The r

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gabrielenava I add to Silvio's reply that due to limitations of the cmakeif command that you can find in the scripts, specifying a condition (e.g. cmakeif NOT MYVAR) is not supported. After cmakeif there must be a single cmake variable that can be either TRUE or FALSE. For this reason I had to introduce this extra ROBOTOLOGY_USES_SIMULINK variable.

To use this software, you can simply enable its compilation using the `ROBOTOLOGY_USES_MATLAB` CMake option.
Once this software has been compiled by the superbuild, you just need to add some directories of the robotology-superbuild install (typically `$ROBOTOLOGY_SUPERBUILD_ROOT/build/install`) to [the MATLAB path](https://www.mathworks.com/help/matlab/matlab_env/what-is-the-matlab-search-path.html).
In particular you need to add to the MATLAB path the `$ROBOTOLOGY_SUPERBUILD_INSTALL_PREFIX/mex` directory and all the subdirectories `$ROBOTOLOGY_SUPERBUILD_INSTALL_PREFIX/share/WBToolbox`.

As an example, you could add this line to your MATLAB script that uses the robotology-superbuild matlab software:
#### Start MATLAB from the launcher or the application menu
Copy link
Collaborator

@gabrielenava gabrielenava Jan 18, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually never started Matlab from the launcher. On a new installation, I always run the startup_robotology_superbuild.m. However, note that if one uses the startup_robotology_superbuild.m, it is required to open matlab from the folder where the `pathdef.m file is, otherwise the required folders are not added to the path.

To use this software, you can simply enable its compilation using the `ROBOTOLOGY_USES_MATLAB` CMake option.
Once this software has been compiled by the superbuild, you just need to add some directories of the robotology-superbuild install (typically `$ROBOTOLOGY_SUPERBUILD_ROOT/build/install`) to [the MATLAB path](https://www.mathworks.com/help/matlab/matlab_env/what-is-the-matlab-search-path.html).
In particular you need to add to the MATLAB path the `$ROBOTOLOGY_SUPERBUILD_INSTALL_PREFIX/mex` directory and all the subdirectories `$ROBOTOLOGY_SUPERBUILD_INSTALL_PREFIX/share/WBToolbox`.

As an example, you could add this line to your MATLAB script that uses the robotology-superbuild matlab software:
#### Start MATLAB from the launcher or the application menu
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, if I understood, with this PR it will be possible to set the required Matlab path using the setup.sh file instead/ as an alternative to:

  • manually add the required folder to the MATLABPATH;

  • run the startup_robotology_superbuild.m if the WBToolbox is installed through the robotology-superbuild, or the startup.m file if the WBToolbox is external to the superbuild. Note that as I said before, if the user decides to choose this last method it is required to always start matlab from the folder where the pathdef.m file is. This is not necessary (as far as I understood, as I always followed this third option) if the user decides to choose one of the other two options.

To use this software, you can simply enable its compilation using the `ROBOTOLOGY_USES_MATLAB` CMake option.
Once this software has been compiled by the superbuild, you just need to add some directories of the robotology-superbuild install (typically `$ROBOTOLOGY_SUPERBUILD_ROOT/build/install`) to [the MATLAB path](https://www.mathworks.com/help/matlab/matlab_env/what-is-the-matlab-search-path.html).
In particular you need to add to the MATLAB path the `$ROBOTOLOGY_SUPERBUILD_INSTALL_PREFIX/mex` directory and all the subdirectories `$ROBOTOLOGY_SUPERBUILD_INSTALL_PREFIX/share/WBToolbox`.

As an example, you could add this line to your MATLAB script that uses the robotology-superbuild matlab software:
#### Start MATLAB from the launcher or the application menu
Copy link
Collaborator

@gabrielenava gabrielenava Jan 18, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that as far as I know this issue still occurs on Ubuntu 18.04, therefore even running the setup.sh file the user will have to manually address this before being able to use the toolbox properly.

Also, there are two things that should be properly documented:

  1. again: that if the user choose to run the startup.m or startup_robotology_superbuild.m it is required to always run Matlab from the folder where the pathdef.m is;

  2. I recently decided to convert the whole-body-controllers library in a package that can be pointed by the matlab path and used by any Simulink model in any folder. This implies that the user that wants to use whole-body-controllers also need to follow these instructions. Note that there are 2 possibilities: manually add the library to the matlabpath or run yet-another-one startup.m script. If the user does the following combo:

  • WBToolbox: set the required Matlab path using the setup.sh or manually add the required folders to the MATLABPATH;

  • wbc library: run the startup.m;

then if the user does not run matlab from the folder where the pathdef.m is, he will be able to use WBToolbox but not whole-body-controllers.

I think from the Simulink controllers point that's it.

addpath([getenv('ROBOTOLOGY_SUPERBUILD_INSTALL_PREFIX') '/share/WBToolbox'])
addpath('<ROBOTOLOGY_SUPERBUILD_INSTALL_PREFIX>' '/mex'])
addpath('<ROBOTOLOGY_SUPERBUILD_INSTALL_PREFIX>' '/share/WBToolbox'])
addpath('<ROBOTOLOGY_SUPERBUILD_INSTALL_PREFIX>' '/share/WBToolbox/images'])
~~~
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I reviewed a bit the section, and I think we can just remove this addpath calls in this section (if someone is interested in those, they are already described in the previous section), and just leave the docs on how to run startup_robotology_superbuild.m under "Start MATLAB from the launcher or the application menu". This removes the ambiguity of using ROBOTOLOGY_SUPERBUILD_INSTALL_PREFIX env variable.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I did not realized that you stopped using getenv. Then I think we can go forward with the PR (as soon as @gabrielenava and @nunoguedelha green light it) and do more cleanup in separate PRs.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would consider separately the case where :

  • the <ROBOTOLOGY_SUPERBUILD_INSTALL_PREFIX>/mex folder is required -> always when MATLAB is used and we plan to use MATLAB bindings,
  • the .../share/WBToolbox and .../share/WBToolbox/images folder is required -> always when Simulink is used.

@traversaro
Copy link
Member

@gabrielenava if the usage procedure of whole-body-controllers changed, can you open a separate issue? Thanks.

@traversaro
Copy link
Member

@gabrielenava In general, if you think this PR is an improvements and is not going to create problems, let's approve it. Furthere improvements/bug fix can done in subsequent PRs.

@diegoferigo
Copy link
Member Author

@traversaro Addressed your comments, let me know when I have green light and I will perform an interactive rebase.

@traversaro
Copy link
Member

Thanks @diegoferigo . I would wait for the approval of @gabrielenava and @nunoguedelha .

Copy link
Collaborator

@nunoguedelha nunoguedelha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refer to embedded comments.

#### Start MATLAB from the terminal

You can add the folders by modifying the `startup.m` or the `MATLABPATH` environmental variable [as described in official MATLAB documentation](https://www.mathworks.com/help/matlab/matlab_env/add-folders-to-matlab-search-path-at-startup.html).
If you are using the `setup.sh` or `setup.bat` script for configuring your environment, `MATLABPATH` is automatically populated with these directories.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be specified here that if the setup.sh script is used instead of editing the ~/.bash_profile, the following requirements apply:

  • for the environment variables to be set in any new opened terminal, the line source setup.sh has to be added to the bash_profile,
  • for the MATLABPATH variable to be imported in any future sessions of MATLAB, the MATLAB application has to be run from new terminal, or a terminal where that variable has already been set.

~~~
Anyway we strongly suggest that you add this directories to the MATLAB path in robust way,
for example by modifying the `startup.m` or the `MATLABPATH` enviromental variable [as described in official MATLAB documentation](https://www.mathworks.com/help/matlab/matlab_env/add-folders-to-matlab-search-path-at-startup.html).
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not explained in the MATLAB documentation how the startup.m file is handled by MATLAB at startup. I documented it further in a personal wiki, Matlab Search Path (for now).

In a few words...
A single and only startup.m is processed by MATLAB at startup, and it is the first found by the application, in the following search order:

  • local folder from where Matlab is launched,
  • folder defined by 'userpath',
  • folder defined by 'MATLABPATH' variable.

That order can be fully redefined in a pathdef.m function file, which is loaded only if MATLAB is launched from the same parent folder as the pathdef.m file.

In case the startup.m file is found, the respective defined paths (through addpath statements) are added to the top of the MATLAB path, and this, whatever method we use to launch MATLAB, and whether the pathdef.m file is used or not at startup.

addpath([getenv('ROBOTOLOGY_SUPERBUILD_INSTALL_PREFIX') '/share/WBToolbox'])
addpath('<ROBOTOLOGY_SUPERBUILD_INSTALL_PREFIX>' '/mex'])
addpath('<ROBOTOLOGY_SUPERBUILD_INSTALL_PREFIX>' '/share/WBToolbox'])
addpath('<ROBOTOLOGY_SUPERBUILD_INSTALL_PREFIX>' '/share/WBToolbox/images'])
~~~
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would consider separately the case where :

  • the <ROBOTOLOGY_SUPERBUILD_INSTALL_PREFIX>/mex folder is required -> always when MATLAB is used and we plan to use MATLAB bindings,
  • the .../share/WBToolbox and .../share/WBToolbox/images folder is required -> always when Simulink is used.

To use this software, you can simply enable its compilation using the `ROBOTOLOGY_USES_MATLAB` CMake option.
Once this software has been compiled by the superbuild, you just need to add some directories of the robotology-superbuild install (typically `$ROBOTOLOGY_SUPERBUILD_ROOT/build/install`) to [the MATLAB path](https://www.mathworks.com/help/matlab/matlab_env/what-is-the-matlab-search-path.html).
In particular you need to add to the MATLAB path the `$ROBOTOLOGY_SUPERBUILD_INSTALL_PREFIX/mex` directory and all the subdirectories `$ROBOTOLOGY_SUPERBUILD_INSTALL_PREFIX/share/WBToolbox`.

As an example, you could add this line to your MATLAB script that uses the robotology-superbuild matlab software:
#### Start MATLAB from the launcher or the application menu
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just have a question, if two projects need the pathdef.m, is there any possibility that the second project overrides the file created by the first?

Short answer would be "Yes", but I' not sure what you mean, so here is a short explanation of how pathdef.m is handled...

A pathdef.m file is created or overwritten whenever:

  • you hit "save" in the MATLAB "set path" menu window -> the file is then created or overwritten in the folder defined by the userpath MATLAB function,
  • whenever you execute in MATLAB the command savepath, and providing the target file explicitely: for instance savepath([fileDir, filesep, 'pathdef.m']).

The pathdef.m used is the the one located in the same folder where you launch MATLAB from.

~~~
Anyway we strongly suggest that you add this directories to the MATLAB path in robust way,
for example by modifying the `startup.m` or the `MATLABPATH` enviromental variable [as described in official MATLAB documentation](https://www.mathworks.com/help/matlab/matlab_env/add-folders-to-matlab-search-path-at-startup.html).

Another way is to run (only once) the script `startup_robotology_superbuild.m` in the `$ROBOTOLOGY_SUPERBUILD_ROOT/build` folder. This should be enough to permanently add the required paths for all the toolbox that use MATLAB.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note:
The pathdef.m is saved in the path userpath. In MacOS, when the application launched from the launchpad, the startup folder is defined by userpath also. For this reason it is necessary that the userpath value has not been changed since the moment when startup_robotology_superbuild.m script was run in a previous MATLAB session. But it's unlikely that it happens unless the user knows what he's doing...

To use this software, you can simply enable its compilation using the `ROBOTOLOGY_USES_MATLAB` CMake option.
Once this software has been compiled by the superbuild, you just need to add some directories of the robotology-superbuild install (typically `$ROBOTOLOGY_SUPERBUILD_ROOT/build/install`) to [the MATLAB path](https://www.mathworks.com/help/matlab/matlab_env/what-is-the-matlab-search-path.html).
In particular you need to add to the MATLAB path the `$ROBOTOLOGY_SUPERBUILD_INSTALL_PREFIX/mex` directory and all the subdirectories `$ROBOTOLOGY_SUPERBUILD_INSTALL_PREFIX/share/WBToolbox`.

As an example, you could add this line to your MATLAB script that uses the robotology-superbuild matlab software:
#### Start MATLAB from the launcher or the application menu
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that as far as I know this issue still occurs on Ubuntu 18.04, therefore even running the setup.sh file the user will have to manually address this before being able to use the toolbox properly.

...
then if the user does not run matlab from the folder where the pathdef.m is, he will be able to use WBToolbox but not whole-body-controllers.

I think from the Simulink controllers point that's it.

Just to clarify, the constraint on where we launch MATLAB from is applicable only if we launch MATLAB from the terminal, and that section mentions running a startup.m file and gives a reference to the MATLAB documentation.

WARNING: we are mixing things here. The startup.m file the MATLAB documentation refers to is a special file that doesn't have to be explicitely run by the user, but is loaded at startup under certain conditions (the MATLAB documentation is not clear about this. I documented it in a wiki here and in my comments about launching MATLAB from the terminal). If the file name has that exact syntax and is found by MATLAB, it will be executed at startup.

If some startup file like the one from the superbuild or the one from the WB-toolbox creates a pathdef.m in the folder defined by userpath, then it will always be loaded at startup when MATLAB is launched from the GUI in MacOS (from the launchpad or "Applications" Finder folder).

I don't know how it works on Linux but I assume you can configure the startup folder in the properties of the shortcut you create for MATLAB.


@cmakeif ROBOTOLOGY_USES_MATLAB
rem Configure the Matlab
set "MATLABPATH=%MATLABPATH%;%ROBOTOLOGY_SUPERBUILD_INSTALL_PREFIX%/mex;%ROBOTOLOGY_SUPERBUILD_INSTALL_PREFIX%/share/WBToolbox;%ROBOTOLOGY_SUPERBUILD_INSTALL_PREFIX%/share/WBToolbox/images"
Copy link
Collaborator

@nunoguedelha nunoguedelha Jan 20, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the System Dependencies section we have:

Note: tipically we assume that a user that selects the ROBOTOLOGY_USES_MATLAB also has Simulink installed in his computer.
If this is not the case, you can enable the advanced CMake option ROBOTOLOGY_NOT_USE_SIMULINK to compile all the subprojects that depend on MATLAB, but disable the subprojecs that depend on Simulink (i.e. the
wb-toolbox Simulink Library) if you have enabled the ROBOTOLOGY_ENABLE_DYNAMICS CMake options.

So why in the robotology-superbuild/CMakeLists.txt is the WB-Toolbox downloaded and compiled outside the ROBOTOLOGY_USES_MATLAB option flag. Shouldn't it be in the if(ROBOTOLOGY_USES_MATLAB)...if(NOT ROBOTOLOGY_NOT_USE_SIMULINK) section, along with the whole-body-controllers?

...and MATLABPATH content should reflect that.

#### Start MATLAB from the terminal

You can add the folders by modifying the `startup.m` or the `MATLABPATH` environmental variable [as described in official MATLAB documentation](https://www.mathworks.com/help/matlab/matlab_env/add-folders-to-matlab-search-path-at-startup.html).
If you are using the `setup.sh` or `setup.bat` script for configuring your environment, `MATLABPATH` is automatically populated with these directories.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bottom line, the best would be to:

  • either use a startup.m file located in userpath (it's actually the most portable and systematic solution), either the environment variable we set in the ~/.bashrc or ~/.bash_profile in a way it is visible for MATLAB launched from terminal or launchpad(*).
  • append to the file or the variable, through the setup.sh, whatever path dependencies are needed.

I think that for the sake of simplicity, a common chosen method (valid for both ways of launching MATLAB) should be "enforced" and the remaining methods presented as options.

(*) for MacOS, launchctl does the deal. I have no idea how it works on Linux or Windows.

@traversaro
Copy link
Member

I think @nunoguedelha and @gabrielenava raise super-interesting points, that for the large part actually applies to the README before this PR. As several of this modifications are probably not necessary once we do a general cleanup of the Matlab part of the README (see for example all the section commented in #160 (comment)) I would be inclined to go forward and merge this PR, and then incorporate all the feedback in the cleanup of the Matlab section of the README. What do you think @nunoguedelha @gabrielenava ?

@gabrielenava
Copy link
Collaborator

@gabrielenava In general, if you think this PR is an improvements and is not going to create problems, let's approve it. Furthere improvements/bug fix can done in subsequent PRs.

I agree. Concerning the startup.m that is necessary to use whole-body-controllers, at the moment it is documented in the whole-body-controllers README. We can decide to change/improve this workflow in a separate issue.

@gabrielenava
Copy link
Collaborator

I think @nunoguedelha and @gabrielenava raise super-interesting points, that for the large part actually applies to the README before this PR. As several of this modifications are probably not necessary once we do a general cleanup of the Matlab part of the README (see for example all the section commented in #160 (comment)) I would be inclined to go forward and merge this PR, and then incorporate all the feedback in the cleanup of the Matlab section of the README. What do you think @nunoguedelha @gabrielenava ?

Perfect timing :-)

@diegoferigo
Copy link
Member Author

@traversaro I agree, let's discuss what is the best approach in another issue. From what I understood, also thanks to @nunoguedelha and @gabrielenava comments, there is no optimal solution. All of them have some drawback.

I define optimal solution the one that meets the following features:

  • It works for both cases: launching matlab from the terminal and from the launcher
  • It is compatible to be extended if another of our project needs to add other resources to the path (e.g. if it creates a file that can be overridden by the same process of another repo it's a no-go)
  • If the user already uses the method for their own projects, it should integrate with it without breaking anything

@traversaro
Copy link
Member

As discussed with @nunoguedelha f2f, we can merge this in its current form. @diegoferigo do you want to cleanup the commits? Otherwise I can merge in its current form.

Using the .m script is useful especially when Matlab is executed the desktop file. Instead, when it is opened from the command line, exporting this env var is enough.
@diegoferigo
Copy link
Member Author

I squashed what I had to squash, ready to go 👍

@traversaro traversaro merged commit 23ec981 into robotology:master Jan 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants