question

立洲 avatar image
0 Likes"
立洲 asked Ben Wilson commented

Send a signal to external software when the model starts executing

回到上一個問題,我正在嘗試使用 Flexsim 與物理機械臂進行連接。目前,我想使用 Rest API 方法。我想知道模型運行時如何向機械臂發送信號。

FlexSim 20.0.10
digital twinconnectionrealtimerestapi
· 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.

Ben Wilson avatar image Ben Wilson ♦♦ commented ·

Via Google Translate:

Going back to the previous question, I'm trying to connect with a physical robotic arm using FlexSim. Currently, I want to use Rest API methods. I would like to know how to send a signal to the robotic arm when the model is running.


0 Likes 0 ·
Ben Wilson avatar image
1 Like"
Ben Wilson answered Ben Wilson commented

FlexSim versions 20.1 and greater include an Http API.

For version 20.0 and earlier you'll need to use sendhttprequest (synchronous) or downloadhttprequest (async) application commands.

You can use a model trigger like On Run Start to send a request when the model starts executing.

· 7
5 |100000

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

立洲 avatar image 立洲 commented ·

我可以請你幫我寫一個在 On Run Start 觸發器上的 Rest API 的代碼嗎

0 Likes 0 ·
Ben Wilson avatar image Ben Wilson ♦♦ 立洲 commented ·
0 Likes 0 ·
立洲 avatar image 立洲 Ben Wilson ♦♦ commented ·
@Steven Chen Can you help me, Please.
0 Likes 0 ·
立洲 avatar image 立洲 commented ·

我現在有一個需要執行的 URL 以使物理對象執行操作

http://192.168.168.100:1880/relativeP?info=[50,0,0,0,0,0]&speed=0.5

我應該如何在 Flexsim 中編寫和執行

0 Likes 0 ·
Ben Wilson avatar image Ben Wilson ♦♦ 立洲 commented ·

In version 20.0:

//specify a text node in the tree where the server's response will be written
treenode result = model.find("/Tools").subnodes.assert("response");
result.value="";
//send http request
applicationcommand("sendhttpreqeust", "POST", "192.168.168.100", "/relativeP", "?&info=[50,0,0,0,0,0]&speed=0.5", 0, result);

You could also try keeping your parameters within the URL, rather than using the data param:

applicationcommand("sendhttpreqeust", "POST", "192.168.168.100", "/relativeP?info=[50,0,0,0,0,0]&speed=0.5", "", 0, result);

Please check this answer which explains in detail each parameter, and its comment with more detail on the data param.

2 Likes 2 ·
立洲 avatar image 立洲 Ben Wilson ♦♦ commented ·

@Ben Wilson Thank you for helping me solve some problems

I also want to do an experiment. I want to write a printf (result) in Code and write the printed result to Global Talbe. How to implement

0 Likes 0 ·
Show more comments
Joerg Vogel avatar image
0 Likes"
Joerg Vogel answered

You can realize it with a light detector. You stick sensor on your screen and you connect his electric circuit to an input port of your robot plc. FlexSim sets an area under for your detector accordingly to get a signal for your robot.

You can get to a similar physical result by using a gateway interface to your robot controller BUS like DeviceNet, ModBus, ASi, … Then you would communicate by HTTP and your gateway would set a routed input port in your robot plc.

if you try do it by an internet protocol directly, you have to provide us with much more information, because a standard robot language does not have an interface to communicate over TCP/IP with HTTP. Some robot controller support higher programming languages like java, c#, c++, but this depends on your robot firmware version. Then you can listen on an Ethernet port in your PLC directly.
Some Corporations don’t allow a physical connection of PLCs in manufacturing plants with the World Wide Web called internet. Then you have to check if you are allowed to communicate with a robot over Layer-2 Connection of OSI Model. If you don’t, then you can only get data from one ethernet device to a different Ethernet Network by my first suggested approach. You can replace a screen area by any device that emits any light you can control from FlexSim.

5 |100000

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