Programmatically add Actors to sim3d world in Simulink

14 Ansichten (letzte 30 Tage)
Alyssa
Alyssa am 30 Aug. 2024
Kommentiert: Alyssa am 4 Sep. 2024
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.

Akzeptierte Antwort

Nishan Nekoo
Nishan Nekoo am 30 Aug. 2024
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
  3 Kommentare

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by