Programmatically add Actors to sim3d world in Simulink

39 次查看(过去 30 天)
Hi everyone,
My language might be a bit non-technical, but I will try to explain myself clearly. I have a project in which I am trying to simulate a drone in a 3D environment. I would like to build that environment programmatically in Matlab, but run the simulation in Simulink (because there are various nice function blocks for camera sims, etc in Simulink). I would like to be able to Add and Remove Actors from the environment using Matlab functions or based on some struct/cell array/object list in Matlab. This is proving to be quite a challenge.
Unfortunately, it doesn't seem that I can create a 3D world object outside of Simulink that interfaces nicely with the aforementioned blocks (they require the inclusion of a '3D Scene Configuration' block in the same model, and I think it is this block that creates the sim3d world object).
I am now hoping that I can somehow get the name or handle of the world created by this scene config block and pass it to a Matlab function block, in which I can add the 3D actors. However, I have no idea how to find the handle or name. I've tried combing through the Model Explorer. Is there some version of "findObj" that works in Simulink?
Does anyone have a better suggestion? I'm sure this is a problem faced by many before me, and it is possible that my approach is not the best way.

采纳的回答

Nishan Nekoo
Nishan Nekoo 2024-8-30
Hi Alyssa,
There are a few different approaches you can take here and I think this example could be very relevant for you: https://www.mathworks.com/help/sl3d/automate-virtual-assembly-line.html
" I would like to build that environment programmatically in Matlab, but run the simulation in Simulink"
The example above uses the Simulation 3D Actor block (labelled "Prepare World") to load in a .m file that contains several 3D Actors. This is how an environment built programmatically in MATLAB can be loaded into Simulink. Note that the .m file should not contain any notion of a sim3d.World. An alternative is to create a .mat file instead. This can be done by creating a world programmatically in MATLAB then while the simulation is running, right click in the Simulation 3D Viewer window and click "Save as MAT file".
"I would like to be able to Add and Remove Actors from the environment using Matlab functions or based on some struct/cell array/object list in Matlab"
If you use a .mat file instead of a .m file in the first step above, you can use the Simulation 3D Actor block and the "Inputs" tab to create input ports for any of the properties of the Actors that you added programmatically. This includes the "Hidden" property which you can use to effectively add or remove an actor from the environment.
I think this should help you get started, but please feel free to respond if you have any additional questions.
Nishan
  12 个评论
iyanuoluwa Adeoye
iyanuoluwa Adeoye about 6 hours 前
The function works :), the name of the world is the name of the simulink model within which the the simulink actor blocks have been saved so in my case "Static_MiniRig_Model", after getting the handle i was able to easily access the actor properties just by following the relationships.
worldH= sim3d.World.getWorld("Static_MiniRig_Model");
worldH.Actors.Heatgun.Translation = [0 -9 0];
i have not tried anything extravagent apart from simple translations so i cant say how robust this method of interaction is, but its has given me the correct translation results so far. i'm sure knowing function will come in handy down the line, will it be further developed and properly documented in future releases?
thanks for the help.
Nishan Nekoo
Nishan Nekoo about 3 hours 前
Ah that's good to know that it takes on the name of the Simulink model, thanks for letting me know :)
We'll consider documenting the function and workflow in a future release but I can't say for sure whether we will or when it will happen!
Nishan

请先登录,再进行评论。

更多回答(0 个)

Community Treasure Hunt

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

Start Hunting!

Translated by