Programmatically add Actors to sim3d world in Simulink
조회 수: 19 (최근 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.
댓글 수: 0
채택된 답변
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
댓글 수: 4
iyanuoluwa Adeoye
대략 3시간 전
just a follow up question related to the query above, i am trying to implement a means to reset all of the postions of the actors in my 3Dworld, the world has been created via the 3d actor block and scene configuration within simulink. i have programmed it so that when a certain actor is clicked, it inititates a call back 'OnClick' which pass out to function in my matlab script only the handle of the actor which was clicked, i am then able to programmatically interact with the actor properties via the handle. However what i want to do is once that actor is clicked, i want to interact with more than just one but i want to reset the position of the clicked actor and all of the other actors in the scene, but i have not been able to find a way to obtain the handles or communicate with all of the other actors.
so basically how can i obtain the handles of all of the actors in the scene to communicate with them when a call back is intitate, "Onclick" or even "onHit".
thanks for the help in advance.
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!