Interfacing Simulink and Gazebo

1 view (last 30 days)
Glen on 9 Dec 2016
Edited: Glen on 9 Dec 2016
I'd like to encapsulate a gazebo simulation as an S-function in Simulink. I've written an S-function that should configure itself and publish a gazebo topic message. When this code is compiled as "regular" C+ and run from the command line, it works. But when I copy it into an S-function, compile it with mex, and try to use it in Simulink, it doesn't - for some reason, it sees a small subset of all of the gazebo topics the master knows about.
The pertinent code is:
static void mdlStart(SimStruct *S)
std::string _master_host;
unsigned int _master_port;
std::list<std::string> topics_list;
gazebo::transport::init("", 11345);
gazebo::transport::NodePtr node(new gazebo::transport::Node());
// This topic will let us issue gazebo single-step commands
step_cmd = node->Advertise<gazebo::msgs::WorldControl>("/gazebo/default/world_control");
//std::cout << "Waiting for connection\n";
//std::cout << "Got connection\n";
gazebo::transport::get_master_uri(_master_host, _master_port);
std::cout << "Host: " << _master_host << " port: " << _master_port << "\n";
topics_list = gazebo::transport::getAdvertisedTopics("");
for(std::list<std::string>::iterator topic=topics_list.begin(); topic!=topics_list.end(); topic++) {
std::cout << (*topic) << "\n";
Oddly, it does see some of the topics from the master, just not all of them (and not the ones I need). Also, if I uncomment the "WaitForConnection" line, Simulink hangs at that line.
Yes, I know I could buy the Robotics Toolbox and do this through ROS, but for my particular use case I need finer-grained control over gazebo than the ROS interface provides, so I need to be able to talk directly to a gazebo plugin that I'm writing.
My suspicion is that the environment S-functions run in is in some way nonstandard, but I can't find any documentation about it.

Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!