Hello,
Since rosmessage is not supported for code generation, you may have to use the Simulink infrastructure to make your life easy. Long story short: Pass a second blank message also as an input to your main MATLAB function. Then pass this dummy message as an input to your sub function. Sub functions don't require mention of ROS message/any data type. They will take in whatever you pass them. So here is an example.
Suppose you have 2 messages.
- A GeoPoint message
- A WayPoint message that is constructed from the above GeoPoint message in a sub function
First let's use 2 blank message blocks. 1 for each of the above message. In a real application, the GeoPoint message could come from a Subscriber.
Inside the MATLAB function block you could do the following:
function y = fcn(inputMsg,toConstructMsg)
y = twoTimes(inputMsg,toConstructMsg);
end
function y1 = twoTimes(u1,u2)
y1 = u2;
y1.Position.Latitude = 2*(u1.Latitude);
y1.Position.Longitude = 2*(u1.Longitude);
y1.Position.Altitude = 2*(u1.Altitude);
end
Attached is the example. Runs in MATLAB R2016a.