question

Malcolm L3 avatar image
0 Likes"
Malcolm L3 asked Jason Lightfoot commented

How to utilize Data from SQL database in 3D model

Good evening guys,

Making use of data imported from SQL database and exporting of data extracted in models

To give some context about the 3D model: I am trying to replicate a pick and sort production line with traffic light system to indicate the status of the system. Right now I would require help in the area of utilizing the data imported from SQL database for my 3D model so that the simulation of the 3D Model will be more realistic when simulated.

Based on the below fsm model that I have attached, I am able to import data from SQL server into global table form example global table 1,2,3. For global table 1 and 3, it's supposed to have data but I cleared it in my database. So for convenience's sake, I had replicated certain datas from there and wrote it under PCBquantity. For the given data under PCBquantity global table, I would like to know how to make use of those data like schedule data/time to sync to my 3D model upon running the model, set the quantity of the object (over here is the PCB) produced in each of the source. Right now I'm using real-time (based on computer time) upon running the 3D Model in the OnRunStart script and for my source ( on exit I have limited the number of object output) which isn't what I want. I want my 3D model to be able to make use of the data imported from SQL server on the global table and be able to export statistical data (such as numbers of sorted blue/red PCB/ duration of each cycle of the robotic arm when pick -> placed -> original position) into SQL server be it in table and column form or others. Can any1 kindly help me with this? I have drafted this 3D Model a few months back. To clarify I am a novice in this area and I am not very good with coding, as for those script-wise codes I found online samples of it, so please do not tell me to write any script code by myself. So sorry about this, please do help. Thankyou!

For future work: I will have to try to sync to PLC emulation/e-schedular etc.

Making use of SQL data and exporting statistical data into SQL.fsm

FlexSim 20.0.8
sql queriesplc emulationflexsim 20.0.8datetimerealtime
· 1
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Malcolm L3 avatar image Malcolm L3 commented ·

Would be of great help if anyone can give me advise or help me out! I wanna know is it possible when I click " Run" the simulation

Based on Runstart I am able to program to sync the start of the simulation to my computer time. However I am looking to either

1) Do the above ^ and upon taking in data from the global table i.e production schedule ( 10/02/2021 3.15pm [10 mins later from when run the simulation model]), the assigned task [ PCB delivered and sorted out based on the given model above] will carry out 10mins from when I run the simulation.

2) Or when I run the simulation model, it will be able to sync it to the production schedule date and time and immediately start the task given.

Thankyou in advance!

0 Likes 0 ·

1 Answer

·
Steven Hamoen avatar image
0 Likes"
Steven Hamoen answered Jason Lightfoot commented

@Malcolm L3 If you don't want to program (which a big disadvantage if you are going into PLC emulation and or scheduling) I would say try out process flow. I looked at your model but there is no processflow model and with processflow you can create logic without scripting. I'm still not exactly sure what it is you want but if you want something to happen at a certain moment in time you have to create events at that time. So if you want that at the time mentioned in the Pcbquantity table you want to create a certain number of products you have to create an event for that. I attached a sample with processflow source, maybe this will give you some pointers.

UsingSQL_TAL.fsm


usingsql-tal.fsm (2.4 MiB)
· 9
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Malcolm L3 avatar image Malcolm L3 commented ·

Good evening Steven,

Thanks for the input

My teammates will be handling the coding part for PLC and E-schedular, for now I just have to make use of the relevant data imported from SQL. For instance, I would like to run the 3D model in a way that it will make use of the data such as schedule date and time taken under Pcbquantity table. When I run the 3D Model based on the computer time, the model should start only when the run time (based on my computer time) hits the schedule date and time. Is this possible without process flow (I don't want it to start immediately)?

If process flow is the only way to do the above, do I have to reconstruct the whole model in process flow? I'm not good at using process flow to cater it in a way that my 3D Model will continue to work in this way

Update: I have managed to make use of the data "Quantity" under Pcbquantity table by utilising script for the source in 3D MODEL. Attached is the updated file.


Making use of SQL data and exporting statistical data into SQL -v3.fsm

0 Likes 0 ·
Steven Hamoen avatar image Steven Hamoen commented ·

@Malcolm L3 So if your model starttime (so the actual real time) is say 8:15 in the morning and the first job on the Pcbquantity table is 10:27 what should the model do? Wait till it becomes actually 10:27 or runs as fast as it can to this time to start executing something?

In both case you have to schedule an even for (10:27 - 8:15) 132 minutes ( 7920 seconds) in the future. In the first situation you have to put the runspeed at 1 which means it will actually follow the realtime. Otherwise you can set it at high speed and at the start it will jump to the next event being the 10:27 event. (For runspeed information look here)

In process flow I would create a token at start and let that token calculate the time difference and send it to a delay activity with that delay time.

If you want to do in 3D, there is a "model on reset trigger" that you can use to find the first time and calculate the difference. Then there are many ways to start your process. You can open the output of a source, you can create a flowitem, you can start a token.

Concerning Process Flow, no you don't have to rebuild your model. Process Flow and 3D goes together smoothly. The only thing you shouldn't do, is do your logic in both paradigms. But for small bits of logic and if you don't want to program, process flow is perfect. The sooner you start with it the better. I work with FlexSim for more than 18 years and since Process Flow came around we have not build a model that wasn't controlled by Process Flow


0 Likes 0 ·
Malcolm L3 avatar image Malcolm L3 Steven Hamoen commented ·

Good evening steven,


Hi steven, the information you fed sounds really great. It is what I wanted - Model wait till it becomes actually scheduled time and it starts running.

For the first case using process flow, can you show me how to do it? I'm a complete Idiot at it.. not even knowing the basics.

Regarding to do it in 3D, how do I do what u said? Calculate the difference etc, is there any code snippet? And after for this method, it sounded like I have to use process flow too (since token are involve).

Would really appreciate if you can show me how to do it with beginning of the actions from the source itself based on my current model. Thankyou in advance sir!

0 Likes 0 ·
Joerg Vogel avatar image Joerg Vogel Malcolm L3 commented ·

Process Flow is just a graphical substitute for a larger scale of own written source code. It visualizes some typical source code structures by graphical activity blocks.

You can still do the same in 3D model logic. But it is necessary you write source code. You can do this in process flow or in a trigger of an object.

You can try to replace process flow by a supporting 3D sub model, which processes a flow item in a processor for 1 minute, releasing the item into a queue and then send the item to the processor again. Each time the item leaves the processor, you check in an On Exit Trigger if the real time matches with the simulation time in your model. If the condition become true, then you are resuming a previously stopped source of your main 3D model process. This source object was stopped at model run start or on reset.

Alternatively you stop the main process model source on reset, compute a delay time, send a delayed message to another object in your model. The object receives this delayed message and you let resume the source by the On Message trigger of this object.

There are some more methodes to accomplish your task. Please think about them yourself. FlexSim is a tool, which imitates the reality, but it is never real. You can attach as many objects and logical sub structures in a model to support your main task as you like. But you must be creative to get the best out of this tool. If you restrict yourself by denying the use of features you must find other ways to replace them. But I can tell you at some point, you will write source code yourself.

0 Likes 0 ·
Show more comments

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.