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

Revision history [back]

click to hide/show revision 1
initial version

I'd also wanted ROS in Simulink. My understanding looking at the early ROS for Matlab package was that it really wasn't designed for that. Subscribed messages come in as an aysnchonous callback; and that is not how simulink works. And I think the ROS/Matlab integration is all Java based on the ros-java bridge, and Simulink is really based around a C++ integration paradigm. They are really two different products kind of bound togther in my opinion.

Having worked a little with simulink SFunctions, I think you'd need to do a fair bit of work, but I have done essentially this kind of integration to make ROS messages accessible from a game engine (which works similarly to simulink in that you are processing things based on ticks/frames, both are really simulators at the end of the day.)

1) write a C++ function using the core roscpp library that monitors/subscribes to the topic but polls the message queue and retrieves the message on every call. You are basically looking to pop a message of the queue with every simulated time-tick/call on your function from simulink simulation your are running. ROS will keep a message queue for you of incoming messages that you can access. 2) wrap this function in the appropriate simulink wrapping (I believe the terminology is a SFunction, but it is been awhile) and make the outputs your new Simulink block a straight transfer from the message fields of the ROS message that you are interested in. 3) do this trick with every kind of message you are interested in.

To be fair, I know this is a fair amount of work; you'd need to understand a little simulink integration and the ros core libraries, and you will need to work in C++ which not everyone prefers. But it is not a ton of code and is certainly doable.

As an alternative, it may very well be possible to use the ros matlab bridge to capture the messages and push into in some form of global data structure in matlab, and simulink may be able to access and pop things off that data structure from within a block. I do know you can access matlab language functions from within a block, in fact, I think there is a type of simulink block that is, actually, just a matlab function you write. So if that function can pop off a message from this global queue, that may be all you need.

So that may be a simpler avenue. But I have always tended toward the C++ route. So I am not certain as to how you'd do the above.