cyberbotics / webots

Webots Robot Simulator
https://cyberbotics.com
Apache License 2.0
3.21k stars 1.68k forks source link

MATLAB R2019b is not detected by Webots on Windows 10 #1336

Closed wbadry closed 4 years ago

wbadry commented 4 years ago

Describe the Bug MATLAB R2019b is not detected by Webots on Windows 10

Steps to Reproduce

  1. run cmd or PowerShell

  2. type matlab, it should open up MATLAB. 1

  3. Open C:\Program Files\Webots\projects\languages\matlab\worlds\e-puck_matlab.wbt 2020-02-06_17-42-55

  4. See error WARNING: To run Matlab controllers, you need to install Matlab 64-bit and ensure it is available from the DOS CMD.EXE console.

Expected behavior MATLAB controller script is running normally

System

DavidMansolino commented 4 years ago

Maybe link with #681

wbadry commented 4 years ago

Thank you @DavidMansolino for your response. Could you at least try it using a trial version? Thanks

omichel commented 4 years ago

We are currently in discussion with the Mathworks on this topic. We will keep you informed here.

wbadry commented 4 years ago

Thanks Oliver.

sxbug commented 4 years ago

This question is different from #681

681 problem is that as soon as I start the simulation, matlab will be black and stuck。

I have found some faults in launcher.m and allincludes.h , then I modified : the webots made a mistake in the controller directory of MATLAB (it is not Webots\lib\matlab ,it is Webots\lib\controller\matlab). After I modified it, there were other errors. when I change controller to ,and run launcher.m in Matlab 2017b ,the error msg displayed:

launcher The MATLAB "MinGW-w64 C/C++ Compiler" addon is not installed, please install it from: https://fr.mathworks.com/matlabcentral/fileexchange/52848-matlab-support-for-mingw-w64-c-c-compiler Using prototype file: C:\Users\xsun\AppData\Local\Temp\protofile_matlab_2017b_webots_R2020a_rev2.m error use loadlibrary load library "Controller" error The specified module could not be found.

error launcher (line 126) loadlibrary(libname,protofile,'alias','libController');

Reason: Wrong use of loaddefinedlibrary The specified module could not be found.

I thought It's probably the problem with loadlibrary Can you help me? Thanks

DavidMansolino commented 4 years ago

We fixed many issues with Matlab in #1378, we have successfully tested it with the latest version of Matlab (R2019b update 4).

wbadry commented 4 years ago

Hello @DavidMansolino I downloaded the nightly build 6/3/2020. Still having same issue on MATLAB 2019b. 1 I rechecked that MATLAB can run using matlab command from CMD window: 2020-03-09_17-08-07

Environment variables is configured correctly 2020-03-09_17-51-26

I also verified that MinGW-w64 Compiler is installed and working 2020-03-10_0-04-22

I even made a new world to test it based on first tutorials: 2020-03-10_7-49-21

Edit: I opened launcher.m and tried to execute it to check if it works. I modified a single path to MATLAB library, the only problem left is when loading libraries, I get this error:

_Invalid function name '2020c7fd26b7264e6de1de1cde03a7784967f9f8d7cf'.

I couldn't find where this function is created, but I believe it is a naming error as it started with number, not character. So I believe the launcher stucks at loading libraries.

Edit: I figured out that naming has an issue since I use Night build having dates in version number with '/' So I modified the protofile: protofile = strrep(strrep(strrep(['protofile_matlab_' version('-release') '_webots_' WEBOTS_VERSION], '.', '_'), ' ', '_'),'/','_');

However, MATLAB returned that this is an unrecognized function. I don't know the mechanism for naming this function. I guess it is from matlab and webots version but have no idea how it is turned into a function so MATLAB could recognize it

omichel commented 4 years ago

I checked this and I can run the nightly build (6/3/2020) of Webots R2020a-rev2 together with MATLAB R2019b without any problem. The only difference I have with your setup is that my path only include C:\Program Files\MATLAB\R2019b\bin and not C:\Program Files\MATLAB\R2019b\runtime\win64. I tried to add it, but MATLAB still works fine with Webots... Did you install Webots for all users or just for one user? Did you set the WEBOTS_HOME environment variable globally to point to C:\Program Files\Webots or the local user installation folder?

wbadry commented 4 years ago

I will walk you through what I did so maybe a hidden bug is there in the release.

  1. I installed the nightly build (6/3/2020) .
  2. I followed the tutorials using Pyhton with no issues and MATLAB. I named MATLAB controller *EPuckGoForward * and copied the MATLAB script.
  3. When nothing is happening, I went to launcher.m to test it from MATLAB.
  4. Before running it, I checked path and environment variables needed. Note that MATLAB is under "Polyspace" not "MATLAB" WEBOTS_HOME Path 2020-03-10_19-24-40
  5. I started to run launcher with breakpoints to get the variables retrieved from the environment. 2020-03-10_19-28-40

WEBOTS_HOME path is correct 2020-03-10_19-30-33

  1. I ran into the second section getting the version of WEBOTS and changing MATLAB working directory to webots matlab controller library. Since I call the script from MATLAB, test_mode is set to true. 2020-03-10_19-34-10

I think the problem is in the protofile name as I don't think backslash is allowed 2020-03-10_19-42-59 2020-03-10_19-44-56

I don'y know how it runs on your machine. For some reason, MATLAB splits the name after month and that's why it shows that this function is unknown.

sxbug commented 4 years ago

Maybe you not set Environment variables :WEBOTS_CONTROLLER_NAME? WEBOTS_CONTROLLER_NAME=matlab

omichel commented 4 years ago

This patch, to be included in the next nightly build, should fix the protofile issue. But normally, this code shouldn't be executed if you define properly WEBOTS_CONTROLLER_NAME to run your controller as an extern controller. From your description, I understand you cannot run your own MATLAB controller, but can you run the MATLAB example provided in $WEBOTS_HOME/projects/languages/matlab/worlds/e-puck_matlab.wbt?

omichel commented 4 years ago

I tested with MATLAB R2017b and for some reason, it doesn't work. MATLAB R2017b hangs at start-up. However, MATLAB R2019b works nicely.

wbadry commented 4 years ago

This patch, to be included in the next nightly build, should fix the protofile issue. But normally, this code shouldn't be executed if you define properly WEBOTS_CONTROLLER_NAME to run your controller as an extern controller. From your description, I understand you cannot run your own MATLAB controller, but can you run the MATLAB example provided in $WEBOTS_HOME/projects/languages/matlab/worlds/e-puck_matlab.wbt?

I tried nao_matlab example by setting MATLAB as external controller. All variables were set as in document . 2020-03-11_12-40-13

The launcher script is still broken until it is fixed. When I tried to run the MATLAB controller from MATLAB, it reported that libraries are not found. 2020-03-11_12-47-12

Is there any additional setting I should make? Libraries are not found as I believe launcher is supposed to load it in temp directory (or perhaps not)

It would be great if there is a video setting for MATLAB as it might br a missing configuration that was skipped in documentation.

wbadry commented 4 years ago

I tested with MATLAB R2017b and for some reason, it doesn't work. MATLAB R2017b hangs at start-up. However, MATLAB R2019b works nicely.

Hi @omichel Could it be due to folder naming change from MATLAB to Ployspace on R2019b?

wbadry commented 4 years ago

Maybe you not set Environment variables :WEBOTS_CONTROLLER_NAME? WEBOTS_CONTROLLER_NAME=matlab

Even in external mode, the protofile is still broken and maybe that's why the controller script is unable to load controller library files

omichel commented 4 years ago

I don't think that the folder naming change to Ployspace is a problem. However, in your environment variable settings, you should set WEBOTS_CONTROLLER_NAME to nao_matlab and WEBOTS_PROJECT to C:\Program Files\Webots\projects\robots\softbank\nao to run the nao matlab demo. And be sure that Webots is indeed installed for all users in C:\Program Files\Webots and not for a specific user (in C:\Users\MyUsername\AppData\Local\Programs\Webots).

omichel commented 4 years ago

By the way, you should probably set the environment variables from MATLAB as shown here.

wbadry commented 4 years ago

I don't think that the folder naming change to Ployspace is a problem. However, in your environment variable settings, you should set WEBOTS_CONTROLLER_NAME to nao_matlab and WEBOTS_PROJECT to C:\Program Files\Webots\projects\robots\softbank\nao to run the nao matlab demo. And be sure that Webots is indeed installed for all users in C:\Program Files\Webots and not for a specific user (in C:\Users\MyUsername\AppData\Local\Programs\Webots).

Thanks @omichel I was using the example in the languages folder for e-puck as a test. I committed the changes as instructed to check nao example 2020-03-11_13-25-42

The library path needed to be added (MATLAB detected it). However, after I run it, I got the

following error:
Error using calllib
Library was not found

Error in wb_robot_get_device (line 6)
result = calllib('libController', 'wb_robot_get_device', name);

Error in nao_matlab (line 18)
camera = wb_robot_get_device('CameraTop');
wbadry commented 4 years ago

Was the version written correctly or should add nightly build?

omichel commented 4 years ago

The version is correct (it should not include nightly build).

wbadry commented 4 years ago

Does libControllerreside somewhere or it is created in runtime by loadlibrary ?

omichel commented 4 years ago

libController resides in $WEBOTS_HOME\lib\controller and is actually named Controller.dll. It should be in your PATH environment variable as explained here, so that MATLAB can load it.

wbadry commented 4 years ago

I guess the header file is missing to use loadlibrary and then calling the calllib? Path is already as described and webots location is correct 2020-03-11_14-20-24

omichel commented 4 years ago

I don't think the header file is needed. As I said, it works nicely on my machine and also on the machine of @DavidMansolino. I am not sure what is the problem on your machine. I see that C:\cygwin64\bin is in your PATH. This may cause some conflicts. Can you try to remove it and see if it works? Or maybe another folder in your PATH is causing a problem (loading some wrong DLL)?

sxbug commented 4 years ago

Thanks @omichel I want to know whether only the matlab 2017B is not valid?matlab 2019b is too large for me, my free diskspace is not enough.

omichel commented 4 years ago

I tested only MATLAB 2017b and 2019b and it turns out that 2017b doesn't work for me while 2019b works well. I didn't test other versions.

sxbug commented 4 years ago

Thanks @omichel I would wait for you fix this problem.

omichel commented 4 years ago

Sorry, but we do not plan to fix it. I would recommend you to upgrade to a more recent version of MATLAB.

sxbug commented 4 years ago

OK. Thanks

wbadry commented 4 years ago

Hi, Can we at least get a confirmation that MATLAB has no issues from anyone else other than developers? Sometimes, the developer machine has installed files that don't exist on production machine. I would appreciate this.

sxbug commented 4 years ago

So disappointed, I installed matlab '9.7.0.119022 (r2019b)' . But MATLAB R2019b is not detected by Webots on Windows 10 too. There was an error, just like wbadry's.

WARNING: To run Matlab controllers, you need to install Matlab 64-bit and ensure it is available from the DOS CMD.EXE console.

webots :2020b nightly build 13/3/2020

SYSTEM: Operating System: Windows 10 enterprise Chinese Version Graphics Card: NVIDIA GeForce 750 Ti

PATH: D:\Program Files\Polyspace\R2019b\bin;
D:\Program Files\Polyspace\R2019b\polyspace\bin;
D:\Program Files\Polyspace\R2019b\runtime\win64

WEBOTS_HOME=D:\Program Files\Webots WEBOTS_VERSION=2020b WEBOTS_CONTROLLER_NAME=MATLAB MW_MINGW64_LOC=C:\PROGRA~1\mingw-w64\X86_64~1.2-P\mingw64

mex -setup MEX 配置为使用 'MinGW64 Compiler (C)' 以进行 C 语言编译。 要选择不同的语言,请从以下选项中选择一种命令: mex -setup C++ mex -setup FORTRAN

How can I do? Thanks

sxbug commented 4 years ago

only set e-puck controller= extern in CMD window input: matlab -nosplash -nodesktop -minimize -r launcher then can start matlab simulate.

wbadry commented 4 years ago

@sxbug This is fantastic work! I tried this on nao and it works although the launcher script displayed "C++ compiler" is not installed while it is installed and verified using mex -setup in MATLAB

2020-03-14_16-34-19 2020-03-14_16-35-26 2020-03-14_16-42-37

Actually, in an easier way, you can run launcher directly from MATLAB. The issue is I was trying to run the nao_matlab script directly from MATLAB which fails. Using launcher as mentioned is a great solution. Still to be noted that Webots can not directly run MATLAB scripts like python and C files.

To make this thread useful. Let's summarize how to run MATLAB scripted Webots on Windows.

Example folder: C:\Program Files\Webots\projects\robots\softbank\nao or WEBOTS_HOME \projects\robots\softbank\nao

  1. Download and install MinGW-w64 C/C++ compiler from MATLAB Addons

2020-03-14_16-52-39

  1. Look inside the controllers folder. Your MATLAB controller file must match the folder name. In this example, the script name and its containing folder is named nao_matlab

2020-03-14_17-00-27 2020-03-14_17-01-54

  1. Now both worlds and controllers are ready. Time to verify environment variables to match your project settings

3.1 path settings

2020-03-14_17-07-42

3.2 variables settings pay attention to WEBOTS_CONTROLLER_NAME and WEBOTS_VERSION

2020-03-14_17-17-57

  1. Restart your computer

  2. Set nao controller to <extern>

2020-03-14_17-23-04

  1. Open MATLAB and type help launcher

2020-03-14_17-30-58

If MATLAB doesn't recognize launcher, you may need to add C:\Program Files\Webots\lib\controller\matlab or WEBOTS_HOME \Webots\lib\controller\matlab to MATLAB search path.

  1. run Webots project

2020-03-14_17-34-21

  1. from MATLAB command window, type launcher and hit enter

2020-03-14_17-36-05

You should see a message showing the protofile script generated.

And NAO robot should start walking while MATLAB plots feet pressure, accelerometer, camera feedback, and edge detection

2020-03-14_17-38-47

wbadry commented 4 years ago

Thanks, @omichel for being patient with me. Hopefully, we can identify the issue and solve it somehow in the next releases. I would be happy to participate if needed. Thanks to you and @DavidMansolino for being active and responsive to all issues even though it is free.

sxbug commented 4 years ago

If 'mex - setup' checked is OK , it doesn't matter if the warning msg 'mingw-w64 C / C + + compiler addon is not installed' is displayed during simulation. Matlab Simulation is available.

omichel commented 4 years ago

@wbadry: thank you for this detailed report. Can you now launch the MATLAB examples from Webots? To do so, you should remove the following environment variables: WEBOTS_CONTROLLER_NAME, WEBOTS_PROJECT and WEBOTS_VERSION and open the original nao_matlab.wbt, e.g., without the controller set to <extern>.

wbadry commented 4 years ago

@wbadry: thank you for this detailed report. Can you now launch the MATLAB examples from Webots? To do so, you should remove the following environment variables: WEBOTS_CONTROLLER_NAME, WEBOTS_PROJECT and WEBOTS_VERSION and open the original nao_matlab.wbt, e.g., without the controller set to <extern>.

Unfortunately, it is still not working. @sxbug were you able to run MATLAB controller directly from Webots?

sxbug commented 4 years ago

@wbadry Matlab 2019 can't be started directly from webots, or it can only be started in extra mode and from CMD (input : matlab .... -r launcher). But now I can start matlab 2017b directly, just comment out lines 28-32 in launcher. m.

sxbug commented 4 years ago

It's very convenient to use, but there is still a library that hasn't been loaded successfully. What's the problem?

[matlab] (dynamic library) [matlab] Error: remote control initialisation failed [matlab] Error: Cannot load the "C:/Program Files/Webots/projects/robots/gctronic/e-puck/plugins/remote_controls/e-puck_bluetooth/e-puck_bluetooth.dll" remote control library. [matlab] Running Matlab sample Webots controller.

sxbug commented 4 years ago

I can not upload any PICs

omichel commented 4 years ago

You can ignore this e-puck_bluetooth library. It is used only for remote-control of an e-puck robot. It shows up probably because of a DLL conflict in your PATH. I don't have it on my system.

sxbug commented 4 years ago

The DLL file is in this directory ‘D:/Program Files/Webots/projects/robots/gctronic/e-puck/plugins/remote_controls/e-puck_bluetooth/’. I checked it. That is OK Thanks @omichel