Interfacing Simulink and Gazebo
조회 수: 2 (최근 30일)
이전 댓글 표시
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::client::setup();
gazebo::transport::init("127.0.0.1", 11345);
gazebo::transport::run();
gazebo::transport::NodePtr node(new gazebo::transport::Node());
node->Init("default");
// 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";
//anglepub->WaitForConnection();
//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.
댓글 수: 0
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Gazebo Co-Simulation에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!