robotology / idyntree

Multibody Dynamics Library designed for Free Floating Robots
BSD 3-Clause "New" or "Revised" License
177 stars 67 forks source link

MATLAB bindings: Matlab crash on semantic error #44

Closed raffaello-camoriano closed 3 years ago

raffaello-camoriano commented 9 years ago

@traversaro @DiegoRomeres

I have followed the simple steps outlined in https://github.com/robotology-playground/idyntree#bindings to generate the iDynTree MATLAB bindings.

Then, I have started MATLAB r2014b (UNIX version), and added iDynTree/bindings/matlab/* to the MATLAB path.

Later on, I have tried the two example scripts proposed in https://github.com/robotology-playground/idyntree/blob/master/doc/geometric_classes.md

The outputs were:

1)

Undefined function 'iDynTreeMATLAB_wrap' for input arguments of type 'double'.

Error in iDynTree.Position (line 9)
        tmp = iDynTreeMATLAB_wrap(80,'new_Position',varargin{:}); % FIXME

Error in test1 (line 4)
origin_A_B = iDynTree.Position(1,2,3)

2)

Undefined function 'iDynTreeMATLAB_wrap' for input arguments of type 'double'.

Error in iDynTree.Position (line 9)
        tmp = iDynTreeMATLAB_wrap(80,'new_Position',varargin{:}); % FIXME

Error in test2 (line 9)
origin_A_B = iDynTree.Position(1,2,3)

Long things short: class _iDynTreeMATLABwrap does not seem to be defined.

Note: In folder iDynTree/bindings/matlab there is a file called _iDynTreeMATLABwrap.cxx. I do not know what is it for, but I would expect to also have a MATLAB version of it, which I don't.

Maybe some options for generating the bindings are wrong?

Thanks.

traversaro commented 9 years ago

The iDynTreeMATLAB_wrap.cxx file gets compiled in the iDynTreeMATLAB_wrap.mexa64 file (the extension could change in different architectures/OSs ). This file (and the Matlab classes contained in ) are then installed in ${CMAKE_INSTALL_PREFIX}/mex/. Consequently you should add to your path that directory.. but this is currently lacking from the README, because if you where using the codyco-superbuild you had already instructions on how to add that directory to Matlab path... thanks for spotting this lack!

traversaro commented 9 years ago

I am not a great Matlab user, are this instructions https://github.com/robotology-playground/idyntree/commit/8aca61356e6be1a8fb1a97eb3cc9012727abe67f enough or we need to clarify the necessary steps?

raffaello-camoriano commented 9 years ago

Thanks Silvio,

I have found the mex64 file in the following way:

 'kammo@kammo-Latitude-E5540:~$ sudo find / -name 'iDynTreeMATLAB_wrap.mexa64'
[sudo] password for kammo: 
/home/kammo/Repos/codyco-superbuild/libraries/iDynTree/build/lib/x86_64-linux-gnu/iDynTreeMATLAB_wrap.mexa64

The directory in which it has been placed seems different from the ones you suggested in https://github.com/robotology-playground/idyntree/commit/8aca61356e6be1a8fb1a97eb3cc9012727abe67f

Test 1 works correctly

Test 2 makes matlab crash. The crash dump is reported below


------------------------------------------------------------------------
              abort() detected at Wed Jun 10 17:19:58 2015
------------------------------------------------------------------------

Configuration:
  Crash Decoding     : Disabled
  Current Visual     : None
  Default Encoding   : UTF-8
  GNU C Library      : 2.19 stable
  MATLAB Architecture: glnxa64
  MATLAB Root        : /usr/local/MATLAB/R2014b
  MATLAB Version     : 8.4.0.150421 (R2014b)
  Operating System   : Linux 3.13.0-37-generic #64-Ubuntu SMP Mon Sep 22 21:28:38 UTC 2014 x86_64
  Processor ID       : x86 Family 6 Model 69 Stepping 1, GenuineIntel
  Software OpenGL    : 0
  Virtual Machine    : Java 1.7.0_11-b21 with Oracle Corporation Java HotSpot(TM) 64-Bit Server VM mixed mode
  Window System      : No active display

Fault Count: 1

Abnormal termination:
abort()

Register State (from fault):
  RAX = 0000000000000000  RBX = 00007f9b7c024000
  RCX = ffffffffffffffff  RDX = 0000000000000006
  RSP = 00007f9c0bff9d58  RBP = 00007f9c24c483d0
  RSI = 0000000000001b33  RDI = 0000000000001b02

   R8 = fefefefefefefeff   R9 = fefefefefefefeff
  R10 = 0000000000000008  R11 = 0000000000000202
  R12 = 00007f9b638d2faf  R13 = 00007f9b638d2fc0
  R14 = 00007f9c0bffa8a0  R15 = 00007f9c0bffa8a0

  RIP = 00007f9c24afdcc9  EFL = 0000000000000202

   CS = 0033   FS = 0000   GS = 0000

Stack Trace (from fault):
[  0] 0x00007f9c24afdcc9                    /lib/x86_64-linux-gnu/libc.so.6+00224457 gsignal+00000057
[  1] 0x00007f9c24b010d8                    /lib/x86_64-linux-gnu/libc.so.6+00237784 abort+00000328
[  2] 0x00007f9c24af6b86                    /lib/x86_64-linux-gnu/libc.so.6+00195462
[  3] 0x00007f9c24af6c32                    /lib/x86_64-linux-gnu/libc.so.6+00195634
[  4] 0x00007f9b638c87b9 /home/kammo/Repos/codyco-superbuild/libraries/iDynTree/build/lib/x86_64-linux-gnu/libidyntree-core-exp.so+00440249
[  5] 0x00007f9b638c8003 /home/kammo/Repos/codyco-superbuild/libraries/iDynTree/build/lib/x86_64-linux-gnu/libidyntree-core-exp.so+00438275 _ZN8iDynTree18TransformSemantics15check_transformERKS0_RKNS_17PositionSemanticsE+00000085
[  6] 0x00007f9b638c3f0b /home/kammo/Repos/codyco-superbuild/libraries/iDynTree/build/lib/x86_64-linux-gnu/libidyntree-core-exp.so+00421643 _ZN8iDynTree9Transform9transformERKS0_RKNS_8PositionE+00000073
[  7] 0x00007f9b638c4219 /home/kammo/Repos/codyco-superbuild/libraries/iDynTree/build/lib/x86_64-linux-gnu/libidyntree-core-exp.so+00422425 _ZNK8iDynTree9TransformmlERKNS_8PositionE+00000043
[  8] 0x00007f9b63b1eaa7 /home/kammo/Repos/codyco-superbuild/libraries/iDynTree/build/lib/x86_64-linux-gnu/iDynTreeMATLAB_wrap.mexa64+00232103 _Z30_wrap_Transform_mtimes__SWIG_1iPP11mxArray_tagiS1_+00000437
[  9] 0x00007f9b63b1f2ce /home/kammo/Repos/codyco-superbuild/libraries/iDynTree/build/lib/x86_64-linux-gnu/iDynTreeMATLAB_wrap.mexa64+00234190 _Z22_wrap_Transform_mtimesiPP11mxArray_tagiS1_+00000397
[ 10] 0x00007f9b63b2494f /home/kammo/Repos/codyco-superbuild/libraries/iDynTree/build/lib/x86_64-linux-gnu/iDynTreeMATLAB_wrap.mexa64+00256335 mexFunction+00019025
[ 11] 0x00007f9c1b694c0a     /usr/local/MATLAB/R2014b/bin/glnxa64/libmex.so+00150538 mexRunMexFile+00000090
[ 12] 0x00007f9c1b6915c4     /usr/local/MATLAB/R2014b/bin/glnxa64/libmex.so+00136644
[ 13] 0x00007f9c1b692414     /usr/local/MATLAB/R2014b/bin/glnxa64/libmex.so+00140308
[ 14] 0x00007f9c1a9c9329 /usr/local/MATLAB/R2014b/bin/glnxa64/libmwm_dispatcher.so+00791337 _ZN8Mfh_file11dispatch_fhEiPP11mxArray_tagiS2_+00000697
[ 15] 0x00007f9c198a3b70 /usr/local/MATLAB/R2014b/bin/glnxa64/libmwm_interpreter.so+04053872
[ 16] 0x00007f9c19853e02 /usr/local/MATLAB/R2014b/bin/glnxa64/libmwm_interpreter.so+03726850
[ 17] 0x00007f9c19856022 /usr/local/MATLAB/R2014b/bin/glnxa64/libmwm_interpreter.so+03735586
[ 18] 0x00007f9c1985bf87 /usr/local/MATLAB/R2014b/bin/glnxa64/libmwm_interpreter.so+03760007
[ 19] 0x00007f9c198576ff /usr/local/MATLAB/R2014b/bin/glnxa64/libmwm_interpreter.so+03741439
[ 20] 0x00007f9c19858334 /usr/local/MATLAB/R2014b/bin/glnxa64/libmwm_interpreter.so+03744564
[ 21] 0x00007f9c198cd52e /usr/local/MATLAB/R2014b/bin/glnxa64/libmwm_interpreter.so+04224302
[ 22] 0x00007f9c1a9c9329 /usr/local/MATLAB/R2014b/bin/glnxa64/libmwm_dispatcher.so+00791337 _ZN8Mfh_file11dispatch_fhEiPP11mxArray_tagiS2_+00000697
[ 23] 0x00007f9c1a55e992  /usr/local/MATLAB/R2014b/bin/glnxa64/libmwmcos.so+02304402
[ 24] 0x00007f9c1a605588  /usr/local/MATLAB/R2014b/bin/glnxa64/libmwmcos.so+02987400
[ 25] 0x00007f9c1a974e34 /usr/local/MATLAB/R2014b/bin/glnxa64/libmwm_dispatcher.so+00446004 _ZN13Mfh_MATLAB_fn11dispatch_fhEiPP11mxArray_tagiS2_+00000244
[ 26] 0x00007f9c1a602dd1  /usr/local/MATLAB/R2014b/bin/glnxa64/libmwmcos.so+02977233
[ 27] 0x00007f9c198a3b70 /usr/local/MATLAB/R2014b/bin/glnxa64/libmwm_interpreter.so+04053872
[ 28] 0x00007f9c19853e02 /usr/local/MATLAB/R2014b/bin/glnxa64/libmwm_interpreter.so+03726850
[ 29] 0x00007f9c19856022 /usr/local/MATLAB/R2014b/bin/glnxa64/libmwm_interpreter.so+03735586
[ 30] 0x00007f9c1985bf87 /usr/local/MATLAB/R2014b/bin/glnxa64/libmwm_interpreter.so+03760007
[ 31] 0x00007f9c198576ff /usr/local/MATLAB/R2014b/bin/glnxa64/libmwm_interpreter.so+03741439
[ 32] 0x00007f9c19858334 /usr/local/MATLAB/R2014b/bin/glnxa64/libmwm_interpreter.so+03744564
[ 33] 0x00007f9c198cd52e /usr/local/MATLAB/R2014b/bin/glnxa64/libmwm_interpreter.so+04224302
[ 34] 0x00007f9c1a9c94af /usr/local/MATLAB/R2014b/bin/glnxa64/libmwm_dispatcher.so+00791727 _ZN8Mfh_file11dispatch_fhEiPP11mxArray_tagiS2_+00001087
[ 35] 0x00007f9c198a3b70 /usr/local/MATLAB/R2014b/bin/glnxa64/libmwm_interpreter.so+04053872
[ 36] 0x00007f9c19824293 /usr/local/MATLAB/R2014b/bin/glnxa64/libmwm_interpreter.so+03531411
[ 37] 0x00007f9c198550de /usr/local/MATLAB/R2014b/bin/glnxa64/libmwm_interpreter.so+03731678
[ 38] 0x00007f9c1985bf87 /usr/local/MATLAB/R2014b/bin/glnxa64/libmwm_interpreter.so+03760007
[ 39] 0x00007f9c198576ff /usr/local/MATLAB/R2014b/bin/glnxa64/libmwm_interpreter.so+03741439
[ 40] 0x00007f9c19858334 /usr/local/MATLAB/R2014b/bin/glnxa64/libmwm_interpreter.so+03744564
[ 41] 0x00007f9c198cd52e /usr/local/MATLAB/R2014b/bin/glnxa64/libmwm_interpreter.so+04224302
[ 42] 0x00007f9c1a9c94af /usr/local/MATLAB/R2014b/bin/glnxa64/libmwm_dispatcher.so+00791727 _ZN8Mfh_file11dispatch_fhEiPP11mxArray_tagiS2_+00001087
[ 43] 0x00007f9c1988bff5 /usr/local/MATLAB/R2014b/bin/glnxa64/libmwm_interpreter.so+03956725
[ 44] 0x00007f9c1984d699 /usr/local/MATLAB/R2014b/bin/glnxa64/libmwm_interpreter.so+03700377
[ 45] 0x00007f9c19849a87 /usr/local/MATLAB/R2014b/bin/glnxa64/libmwm_interpreter.so+03684999
[ 46] 0x00007f9c1984a143 /usr/local/MATLAB/R2014b/bin/glnxa64/libmwm_interpreter.so+03686723
[ 47] 0x00007f9c1b8d59dc /usr/local/MATLAB/R2014b/bin/glnxa64/libmwbridge.so+00223708
[ 48] 0x00007f9c1b8d6649 /usr/local/MATLAB/R2014b/bin/glnxa64/libmwbridge.so+00226889 _Z8mnParserv+00000729
[ 49] 0x00007f9c25fe0b7f   /usr/local/MATLAB/R2014b/bin/glnxa64/libmwmcr.so+00772991 _ZN11mcrInstance30mnParser_on_interpreter_threadEv+00000031
[ 50] 0x00007f9c25fc1083   /usr/local/MATLAB/R2014b/bin/glnxa64/libmwmcr.so+00643203
[ 51] 0x00007f9c25fc2d69   /usr/local/MATLAB/R2014b/bin/glnxa64/libmwmcr.so+00650601 _ZN5boost6detail11task_objectIvNS_3_bi6bind_tIvPFvRKNS_8functionIFvvEEEENS2_5list1INS2_5valueIS6_EEEEEEE6do_runEv+00000025
[ 52] 0x00007f9c25fc3737   /usr/local/MATLAB/R2014b/bin/glnxa64/libmwmcr.so+00653111 _ZN5boost6detail9task_baseIvE3runEv+00000071
[ 53] 0x00007f9c25fc3797   /usr/local/MATLAB/R2014b/bin/glnxa64/libmwmcr.so+00653207
[ 54] 0x00007f9c25fbebca   /usr/local/MATLAB/R2014b/bin/glnxa64/libmwmcr.so+00633802
[ 55] 0x00007f9c18c04a46   /usr/local/MATLAB/R2014b/bin/glnxa64/libmwuix.so+00330310
[ 56] 0x00007f9c18becad2   /usr/local/MATLAB/R2014b/bin/glnxa64/libmwuix.so+00232146
[ 57] 0x00007f9c2678100f /usr/local/MATLAB/R2014b/bin/glnxa64/libmwservices.so+02523151
[ 58] 0x00007f9c2678117c /usr/local/MATLAB/R2014b/bin/glnxa64/libmwservices.so+02523516
[ 59] 0x00007f9c2677d07f /usr/local/MATLAB/R2014b/bin/glnxa64/libmwservices.so+02506879
[ 60] 0x00007f9c267824b5 /usr/local/MATLAB/R2014b/bin/glnxa64/libmwservices.so+02528437
[ 61] 0x00007f9c267828e7 /usr/local/MATLAB/R2014b/bin/glnxa64/libmwservices.so+02529511
[ 62] 0x00007f9c26782fc0 /usr/local/MATLAB/R2014b/bin/glnxa64/libmwservices.so+02531264 _Z25svWS_ProcessPendingEventsiib+00000080
[ 63] 0x00007f9c25fbf248   /usr/local/MATLAB/R2014b/bin/glnxa64/libmwmcr.so+00635464
[ 64] 0x00007f9c25fbf564   /usr/local/MATLAB/R2014b/bin/glnxa64/libmwmcr.so+00636260
[ 65] 0x00007f9c25fabcdd   /usr/local/MATLAB/R2014b/bin/glnxa64/libmwmcr.so+00556253
[ 66] 0x00007f9c24e95182              /lib/x86_64-linux-gnu/libpthread.so.0+00033154
[ 67] 0x00007f9c24bc200d                    /lib/x86_64-linux-gnu/libc.so.6+01028109 clone+00000109

This error was detected while a MEX-file was running. If the MEX-file
is not an official MathWorks function, please examine its source code
for errors. Please consult the External Interfaces Guide for information
on debugging MEX-files.

If this problem is reproducible, please submit a Service Request via:
    http://www.mathworks.com/support/contact_us/

A technical support engineer might contact you with further information.

Thank you for your help.
traversaro commented 9 years ago

Mh... that is the one compiled in the build directory... did you run the install command on iDynTree repo, directly from the repo or by doing a make on codyco-superbuild ?

DiegoRomeres commented 9 years ago

I got the same results as Raffaello, Test1 works and Test2 crushes Matlab.

I run the install command directly on the repo.

raffaello-camoriano commented 9 years ago

I have tried both ways.

1) I went to codyco-superbuild/libraries/iDynTree/build, issued a ccmake .. and set the option _IDYNTREE_USESMATLAB = ON. Then I issued a make instruction. I did not issue a sudo make install (since the instructions do not say it) There is no _{CMAKE_INSTALLPREFIX}/mex directory

2) I assumed that SUPERBUILD_BUILD_DIRECTORY means CMAKE_INSTALL_PREFIX I set _CODYCO_USESMATLAB = ON and left _CMAKE_INSTALLPREFIX = /usr/local I issued a make update-all in codyco-superbuild/build I did not issue a sudo make install cmd (since the instructions do not say it) There is no _SUPERBUILD_BUILDDIRECTORY/install/mex directory

DiegoRomeres commented 9 years ago

I tryed both cases as well and the results doesn't change.

Running the code line by line I saw that the error occurs in the last line: O_A_wrong = transform_B_A*O_B;

I guess the problem is related to the method 'Inverse()' of 'iDynTree.Transform' since the previous code worked properly. The error that apperas in the Matlab command Window befor the crash is:

[ERROR] TransformSemantics :: apply : Mismatch between orientationFrame of first operand and coordinateFrame of second operand

traversaro commented 9 years ago

Sorry guys, this is my fault. : )

Basically the error handling procedure is calling an assert(false) if you do something wrong, to exit the program.. but this is not desirable in bindings where if you exit the program you exit the all interpreter! This happens for example in :

The easiest fix is to remove those assert(false), or compile the library in Release.

Notice that this was mentioned in the tutorial: Semantics check will prevent us from doing stupid things (this will result in an error)

DiegoRomeres commented 9 years ago

I tried to run the test example after commenting the assert(false) you indicated us, but the problem is not solved. At a first view I didn't find the correct one to remove, but I will check the file more accurately and I will be back to you later.

DiegoRomeres commented 9 years ago

Commenting this 'assert(false)':

https://github.com/robotology-playground/idyntree/blob/3d87d9b8c2fd3e863eb0cea5e1751ae7f5760059/core-experimental/src/Utils.cpp#L33

Matlab doesn't crash any more in the second test of: https://github.com/robotology-playground/idyntree/blob/master/doc/geometric_classes.md

traversaro commented 9 years ago

@nunoguedelha is working on an improved version of the semantics checking, we will push it soon and it will solve the problem of Matlab crashing on semantic error.

traversaro commented 3 years ago

Semantics was removed in https://github.com/robotology/idyntree/pull/704, so automatically this bug is fixed.