ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Enrique Fernandez's profile - activity

2013-05-03 05:35:48 -0500 answered a question MATLAB MRC Engine and ROS

Hi Javier

Unfortunately, I wasn't able to solve the problem and didn't even consider recompiling ROS. Because the way I was using my MATLAB code was pretty simple and I didn't have enough time to make things right, I ended up using the typical "hack" of making two programs: a standard C++ ROS node with no dependencies to the MATLAB code or MCR and another C++ program (not a ROS node) that linked to the MCR and the MATLAB shared library.

The C++ ROS node wrote the arguments needed for the MATLAB code as input files in a common folder and then called the C++ program that linked with the MCR. That same program then wrote the output to a common folder that was, at the end, read and parsed by the ROS node.

One final detail that I had to change is that the MCR installation was asking me to change my LD_LIBRARY_PATH, which was raising problems everywhere else in my system (OpenRAVE for example). Therefore, I wrote a simple bash script that just changed the LD_LIBRARY_PATH just before calling the program that linked to the MCR

echo Modifying LD_LIBRARY_PATH
old_lib_path=$LD_LIBRARY_PATH
export LD_LIBRARY_PATH=/usr/local/MATLAB/MATLAB_Compiler_Runtime/v80/runtime/glnxa64:/usr/local/MATLAB/MATLAB_Compiler_Runtime/v80/bin/glnxa64:/usr/local/MATLAB/MATLAB_Compiler_Runtime/v80/sys/os/glnxa64:/usr/local/MATLAB/MATLAB_Compiler_Runtime/v80/sys/java/jre/glnxa64/jre/lib/amd64/native_threads:/usr/local/MATLAB/MATLAB_Compiler_Runtime/v80/sys/java/jre/glnxa64/jre/lib/amd64/server:/usr/local/MATLAB/MATLAB_Compiler_Runtime/v80/sys/java/jre/glnxa64/jre/lib/amd64:$LD_LIBRARY_PATH
export XAPPLRESDIR=/usr/local/MATLAB/MATLAB_Compiler_Runtime/v80/X11/app-defaults
echo LD_LIBRARY_PATH changed to $LD_LIBRARY_PATH

bin/PFTExpertNode
export LD_LIBRARY_PATH=$old_lib_path

As you can see, this is a really bad hack, but, because my application was simple enough, it was good enough for my needs.

2013-05-02 17:43:38 -0500 received badge  Famous Question (source)
2013-04-13 02:09:41 -0500 received badge  Notable Question (source)
2013-03-27 09:34:31 -0500 received badge  Popular Question (source)
2013-03-27 06:30:37 -0500 received badge  Student (source)
2013-03-27 05:20:50 -0500 commented answer CMake with compiled matlab code

Hi!Did this work?I want to do the same but my program crashes during runtime when calling mclInitializeApplication(NULL,0).I'm using MATLAB R2012b and fuerte. Any help would be immensely welcome as I'm really struggling with this http://answers.ros.org/question/59302/matlab-mrc-engine-and-ros/

2013-03-27 05:12:21 -0500 commented answer ROS/Matlab Simulink communication

Hi rado0x54 Are you using a shared C++ library? I'm trying to create a ROS C++ node that uses (and links) to a shared C++ MATLAB R2012b Library compiled with mcc, but I'm having issues.Are there any more specific instructions for compiling ROS fuerte with MATLAB's boost headers and binaries?Thanks!

2013-03-27 05:10:30 -0500 commented question MATLAB MRC Engine and ROS

Thanks a lot for your help jbohren. I've updated my question now.

2013-03-27 05:09:54 -0500 received badge  Editor (source)
2013-03-26 16:02:59 -0500 asked a question MATLAB MRC Engine and ROS

Hi All

First of all, sorry, if this question has been asked already. I've indeed come across several questions that seem very related, but since the errors I'm getting are not the same I figured I'd just ask. This (question/57991/use-matlab-code-within-ros/) is very related but it doesn't completely ask the same question. This one (/question/33326/matlab-engine-and-ros-library-incompatible/) is also relevant, but the error reported is different from mine.

I'm using fuerte under Ubuntu 12.04 Precise and I would like to call some MATLAB functions that I have converted to MATLAB C++ Shared Libraries using MATLAB's mcc compiler (MATLAB R2012b in Ubuntu 12.04).

If I don't use ROS, but just a simple C++ example with CMake, everything works perfectly, and I'm able to call the MATLAB functions without problems.

However, when I try to do the same from a C++ ROS node, my node crashes with an strange error just after I try to execute the following line:

if (!mclInitializeApplication(NULL,0))

I get the error:

matlabLibServer: malloc.c:2451: sYSMALLOc: Assertion `(old_top == (((mbinptr) (((char *) &((av)->bins[((1) - 1) * 2])) - __builtin_offsetof (struct malloc_chunk, fd)))) && old_size == 0) || ((unsigned long) (old_size) >= (unsigned long)((((__builtin_offsetof (struct malloc_chunk, fd_nextsize))+((2 * (sizeof(size_t))) - 1)) & ~((2 * (sizeof(size_t))) - 1))) && ((old_top)->size & 0x1) && ((unsigned long)old_end & pagemask) == 0)' failed.

Aborted (core dumped)

The CMakeLists that I use is:

# Add MATLAB MCR include directories and lib directories
include_directories (${PROJECT_SOURCE_DIR}/lib /usr/local/MATLAB/MATLAB_Compiler_Runtime/v80/extern/include/cpp /usr/local/MATLAB/MATLAB_Compiler_Runtime/v80/extern/include)

# Add library directories for the libvigenere library and the MCR libraries
link_directories (${PROJECT_SOURCE_DIR}/lib /usr/local/MATLAB/MATLAB_Compiler_Runtime/v80/runtime/glnxa64)

#uncomment if you have defined messages
rosbuild_genmsg()
#uncomment if you have defined services
rosbuild_gensrv()

#common commands for building c++ executables and libraries
#rosbuild_add_library(${PROJECT_NAME} src/example.cpp)
#target_link_libraries(${PROJECT_NAME} another_library)
#rosbuild_add_boost_directories()
#rosbuild_link_boost(${PROJECT_NAME} thread)
#rosbuild_add_executable(example examples/example.cpp)
#target_link_libraries(example ${PROJECT_NAME})

rosbuild_add_executable(matlabLibServer src/matlabLibServer.cpp)
rosbuild_add_executable(matlabLibClient src/matlabLibClient.cpp)


#Link with vigenere and with the MCR
target_link_libraries (matlabLibServer libvigenere.so mwmclmcrrt)

Note however, that compiling and linking work perfectly.

Is there anyway to link to MATLAB Shared C++ libraries while using ROS at the same time? What I would like is to implement a ROS service that basically calls a MATLAB function with some arguments and then I get the output back (a couple of double arrays). This service would be called rarely but the MATLAB routine takes quite a while to complete (1-3 sec). I would like to avoid using other third party projects such as rosbridge or IPC-MATLAB bridge if possible..

Finally, if I was able to use MATLAB coder to completely generate C code for my current MATLAB functions instead of converting them to MATLAB MCR Shared Libraries, would my problem be solved? Has anybody had success with that?

Thanks a lot for your help.

UPDATE:

This gets interesting. So if I use the same source file, but I comment all the ROS parts (ros::init ... (more)