Rosanswers logo

Dear All,

I'm am still writing a C++ simulink file, i got communication up and running via ROSTOPICS(see this link).

However, due to the nature of my simulator/research i want to time simulink to run the same speed (x times real time). I've tried timers and other ros stuff, they just do not suffice (not accurate enough mostly). This is needed for causality.

Hence I'm trying to run/start gazebo myself from within my C++ simulink file, to be able to aces the simulator directly. And i was successful, but for some reason it is not running correctly any more(it was last week)!! Compilation is runs fine, but at runtime i get an error.

Right now I'm getting the following error in matlab:

/home/erik/ros/simulator_gazebo/gazebo/build/gazebo/server/rendering  /OgreAdaptor.cc:457 : Exception: unable to find rendering system

The error occurs after the following piece of code(basically the same as gazeboros.cpp).

/*Starting the Gazebo Simulator with all the neccesary paths*/
    gazebo::Simulator::Instance()->SetCreateOgreLog( optOgreLog );
    gazebo::Simulator::Instance()->SetGuiEnabled( optGuiEnabled );
    gazebo::Simulator::Instance()->SetRenderEngineEnabled( optRenderEngineEnabled );
  std::string ogre_package_name("ogre"); 
  std::string ogre_package_path = std::string("/home/s041723/ros/visualization_common/ogre/ogre/lib/OGRE");
  std::cerr << ogre_package_path << std::endl;


  // set gazebo media paths by adding all packages that exports "gazebo_media_path" for gazebo
  std::vector<std::string> gazebo_media_paths;
  for (std::vector<std::string>::iterator iter=gazebo_media_paths.begin(); iter != gazebo_media_paths.end(); iter++)
    ROS_DEBUG("med path %s",iter->c_str());

  // set gazebo plugins paths by adding all packages that exports "plugin" for gazebo
  std::vector<std::string> plugin_paths;
  for (std::vector<std::string>::iterator iter=plugin_paths.begin(); iter != plugin_paths.end(); iter++)
    ROS_DEBUG("plugin path %s",(*iter).c_str());

  // set .gazeborc path to something else, so we don't pick up default ~/.gazeborc
  std::string gazeborc = ros::package::getPath("gazebo")+"/.do_not_use_gazeborc";
            gazebo::Simulator::Instance()->LoadWorldFile(std::string("physics_setup.world"), optServerId);

    catch (gazebo::GazeboError e)
            std::cerr << "Error Loading Gazebo" << std::endl;
            std::cerr << e << std::endl;
           // return -1;

It crashes as soon as i call loadworldfile.

The weird thing is, i do not get this error when i compile and run the same outside of matlab. Which works perfectly fine.

Here is a piece of the stacktrace from the matlab error.

   Stack Trace (from fault):
[  0] 0xb76bd255     /usr/local/MATLAB/R2011b/bin/glnx86/libmwfl.so+00156245 _ZN2fl4diag15stacktrace_base7captureERKNS0_14thread_contextEj+000169
[  1] 0xb76c0175     /usr/local/MATLAB/R2011b/bin/glnx86/libmwfl.so+00168309
[  2] 0xb76c0569     /usr/local/MATLAB/R2011b/bin/glnx86/libmwfl.so+00169321 _ZN2fl4diag13terminate_logEPKcRKNS0_14thread_contextEb+000181
[  3] 0xb733b93f    /usr/local/MATLAB/R2011b/bin/glnx86/libmwmcr.so+00399679 _ZN2fl4diag13terminate_logEPKcPK8ucontextb+000096
[  4] 0xb7338996    /usr/local/MATLAB/R2011b/bin/glnx86/libmwmcr.so+00387478
[  5] 0xb7339d35    /usr/local/MATLAB/R2011b/bin/glnx86/libmwmcr.so+00392501
[  6] 0xb733a880    /usr/local/MATLAB/R2011b/bin/glnx86/libmwmcr.so+00395392
[  7] 0xb7833410 __kernel_rt_sigreturn+000000
[  8] 0x8b974432 /home/s041723/ros/simulator_gazebo/gazebo/gazebo/lib/libgazebo_rendering.so+00300082 _ZN6gazebo11OgreAdaptor7HasGLSLEv+000082
[  9] 0x8b974585 /home/s041723/ros/simulator_gazebo/gazebo/gazebo/lib/libgazebo_rendering.so+00300421 _ZN6gazebo11OgreAdaptor4FiniEv+000037
[ 10] 0x8baf5894 /home/s041723/ros/simulator_gazebo/gazebo/gazebo/lib/libgazebo_server.so.0.10.0+00796820 _ZN6gazebo9Simulator4FiniEv+000100
[ 11] 0x8da0f4fa /home/erik/Dropbox/Afstuderen/gazebo/matlab/gazebo_cpp.mexglx+00017658
[ 12] 0x8da0f9f6 /home/erik/Dropbox/Afstuderen/gazebo/matlab/gazebo_cpp.mexglx+00018934
[ 13] 0x8da10235 /home/erik/Dropbox/Afstuderen/gazebo/matlab/gazebo_cpp.mexglx+00021045 mexFunction+001649
[ 14] 0xb4e47302      /usr/local/MATLAB/R2011b/bin/glnx86/libmex.so+00041730 mexRunMexFile+000109
[ 15] 0xb4e440bd      /usr/local/MATLAB/R2011b/bin/glnx86/libmex.so+00028861
[ 16] 0xb4e44e12      /usr/local/MATLAB/R2011b/bin/glnx86/libmex.so+00032274
[ 17] 0xb72b7264 /usr/local/MATLAB/R2011b/bin/glnx86/libmwm_dispatcher.so+00451172 _ZN8Mfh_file11dispatch_fhEiPP11mxArray_tagiS2_+000460
[ 18] 0xb728f2f2 /usr/local/MATLAB/R2011b/bin/glnx86/libmwm_dispatcher.so+00287474 _Z17mdDoMatlabFcnCalliPP11mxArray_tagiPPKS_P13Mfh_MATLAB_fn9mpLmgrUse+000151
[ 19] 0x98f37ba2 /usr/local/MATLAB/R2011b/bin/glnx86/libmwsimulink.so+14666658
[ 20] 0x977d0960 /usr/local/MATLAB/R2011b/bin/glnx86/libmwsl_services.so+00317792 _ZN14CMatlabCommand7executeEb11mxErrorMode+000148
[ 21] 0x98f376d0 /usr/local/MATLAB/R2011b/bin/glnx86/libmwsimulink.so+14665424
[ 22] 0x9949ddc6 /usr/local/MATLAB/R2011b/bin/glnx86/libmwsimulink.so+20327878
[ 23] 0x994a0254 /usr/local/MATLAB/R2011b/bin/glnx86/libmwsimulink.so+20337236
[ 24] 0x9948b143 /usr/local/MATLAB/R2011b/bin/glnx86/libmwsimulink.so+20250947

Does anyone have an idea what might cause this? I've tried reinstalling ROS as a whole, setting the ogrePath manually (as it is now) and automatically with ros package. Both yielded the same error inside matlab.

Note Gazebo runs fine and the earlier compiled matlab simulation_name.exe file run fine as well (i'm using an external target).

Note The problem is not machine/driver related for it is the same on two computers.

Note My best guess that it is not taking to this line:


for some reason. Because it does not matter at all what i fill out for this path! Is there another way to set this path? (i tried exporting OGRE_RESOURCE PATH, didnt work).

Originally posted by Erik_S on ROS Answers with karma: 103 on 2012-02-28

Post score: 0

Original comments

Comment by hsu on 2012-02-28:
could it be a permissions issue? Maybe matlab starts some processes as a different user, try chmod 777 /dev/nvidia*?

Comment by Erik_S on 2012-02-29:
The permissions for these files are crw-rw-rw-, so i dont really see an issue there.

Comment by hsu on 2012-02-29:
to clarify, you have a mex-version of gazeboros.cpp?

Comment by Erik_S on 2012-03-01:
Yeah, basically i copied most of the 'main' from gazeboros.cpp into a S-function (C++). Which i mex compile. This file (the cpp S-function) is causing the headache at runtime inside matlab.

Comment by hsu on 2012-03-02:
can you try adding to ogrePaths the path to libOgreMain.so as well, as see if that helps?

Comment by Erik_S on 2012-03-02:
Too bad, that didn't work either. Appreciate the help though!! For some reason in ogreadaptor.cc the line this->root->getAvailableRenderers(); returns empty when compiled in matlab. Maybe matlabs own openGL libs are interfering, allthough i would be strange since they didnt before.


1 Answer 1


Rosanswers logo

hm, might have to dig into OgreRoot.cpp for that one.

Originally posted by hsu with karma: 5780 on 2012-03-02

This answer was ACCEPTED on the original site

Post score: 0


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.