How to combine more than 2 entities to 1 entity by Composite Entity Creator?
조회 수: 3 (최근 30일)
이전 댓글 표시
Hello,
I want to simulate a situation where I put several identical items onto pallets, treating each loaded pallet as one item. I'm aware of the entity batch creator, but it requires a fixed capacity. For instance, I have 36 items, and a pallet can hold 30 items. So, I'd like to group 30 items (30 entities) into one pallet (1 entity), and the remaining 6 items (6 entities) into another pallet (1 entity).
I tried using the Composite Entity Creator by sending 30 entities together and then 6 entities, but it only combined 2 entities into 1. Ultimately, I ended up with 18 entities.
If anyone could offer guidance or share a resource for me to learn more, I'd really appreciate it. Please let me know if my explanation is unclear or if you need more information to understand better.
Thank you, Chi
댓글 수: 2
채택된 답변
Ayush
2023년 9월 15일
Hi Chi,
I understand that you combine more than 2 entities into 1 entity by using the Composite Entity Creator. I have also understood the provided Simulink model and your purpose of using the Composite Entity Creator therein.
Here are some possible workarounds:
1. Using the Composite Entity Creator: To use this block for the desired use case you would need to change the block parameter “Number of Input Ports” to dynamically control the number of entity inputs to combine into a single entity. Since each input port of the Composite Entity Creator block would take the output of each Entity Generator Block.
This can be done programmatically using “add_block”, “add_line” and “delete_block” functions iteratively based on the size of the entity store as per your example model provided. Please refer to the below documentations to know more about the “add_block”, “add_line” and “delete_block” functions respectively:
- https://www.mathworks.com/help/simulink/slref/add_block.html#d126e367511
- https://www.mathworks.com/help/simulink/slref/add_line.html
- https://www.mathworks.com/help/simulink/slref/delete_block.html
Here is code snippet for reference:
model = 'example1'; % Name of the Simulink model
% You would need to iteratively generate and connect the blocks % and delete it too once one pallet ends to start the next one.
% Add the required amount of Entity Generator blocks
add_block('sldelib/Entity Generator', [model, '/EntityBlock'], 'Position', [100, 100, 200, 200]);
add_block('sldelib/Entity Generator', [model, '/EntityBlock2'], 'Position', [150, 150, 200, 200]);
add_block('sldelib/Entity Generator', [model, '/EntityBlock3'], 'Position', [50, 50, 200, 200]);
% Add the Composite Entity Creator block and set its Number of % Input Ports parameter to the same number of blocks created % for the Entity Generator Block
add_block('sldelib/Composite Entity Creator', [model, '/CompositeEntityCreator'], 'Position', [300, 100, 400, 200]);
set_param("example1/CompositeEntityCreator","NumberInputPorts","3")
% Connect the Entity Generator block output to the Composite % Entity Creator input corresponding to the input port number
add_line(model, 'EntityBlock/1', 'CompositeEntityCreator/1');
add_line(model, 'EntityBlock2/1', 'CompositeEntityCreator/2');
add_line(model, 'EntityBlock3/1', 'CompositeEntityCreator/3');
2. Using the Entity Batch Creator: You can also use this block to create a single entity having similar properties by modifying the block parameter “Number of entities in batch” programmatically by adding a “MATLAB function” block in your model.
It takes the desired batch size (pallet size) and the entity store as an input and then sets the parameter of the “Entity Batch Creator” block using the “set_param” function and outputs the entity to create a batch of the desired size. Please refer to the below documentations to know more about the “MATLAB Function” block and the “set_param” function respectively:
- https://www.mathworks.com/help/simulink/slref/matlabfunction.html
- https://www.mathworks.com/help/simulink/slref/set_param.html
Here is code snippet for reference:
% Inside the MATLAB function block
load_system("example1.slx")
set_param("example1/Entity Batch Creator", "NumberOfEntitiesInBatch", "30")
% rest of the code
Hope it helps,
Regards,
Ayush Misra
댓글 수: 2
추가 답변 (0개)
참고 항목
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!