is-centre / udp-ue4-plugin-win64

A simple UDP communication plugin based on freely available code
MIT License
53 stars 20 forks source link

How to receive data from UE4 to Simulink? #3

Closed master-chief-117-oye closed 4 years ago

master-chief-117-oye commented 4 years ago

Hi,

Thank you for the plugin. I am able to send data from Simulink to UE4 but failed in getting the correct data from UE4 in Simulink.

In Simulink's UDP Receive block, I set all addresses and ports, set Data size as 1 (not sure if it is right, since I only set 1 float number input 'float1' in UE4), and Source Data type is set as uint8.

When I run both UE4 and Simulink, I am able to see some received data in Simulink's display or scope, but that is some jumpy integer number, which is not the float number I set in UE4. I tried to convert the data in Simulink to 'Single', but still no success.

May I know how can I get the correct float number from UE4 to Simulink? Thank you.

extall commented 4 years ago

The way we do it now is we set up a broadcast IP. So, if your subnet is something like 192.168.1.xxx, then try 192.168.1.255 from UE4 side and specify the IP of the other computer on the Simulink side. We have had success with this, somehow MATLAB/Simulink will receive packets from the broadcast. We are actually investigating this further and will come up with a version of the plugin that is pretty much plug-and-play. For now, let me know if this solution works for you.

master-chief-117-oye commented 4 years ago

Thanks for the suggestion. However, I only have 1 PC, both UE4 and Simulink run on that. In UE4 blueprint, I set 'Start UDPSender' 'The IP' 127.0.0.1, 'The Port' 5555. In Simulink's UDP Receive block, I set 'Local address 127.0.0.1', 'Local Port' 5555, 'Remote address' 0.0.0.0 and 'Remote port' 51002, 'Data size' 1 and 'Source Data Type' uint8.

I can receive data from UE4 into Simulink, the problem is that the received number is some weird integer rather than the float number I set in UE4. I followed your Youtube video setting everything up. However, the UDPSender video has no information about how things should be set up in Simulink. That's where I'm confused.

Could you please explain in more details like what blocks should be used in Simulink? Also how everything should be set up if both UE4 and Simulink are running on one computer? Thanks.

extall commented 4 years ago

In that case, it is easy. There were some updates required for the plugin to work in LAN (which it does, but I didn't have time to push them to the repo yet). But for localhost, it's pretty straightforward.

First, make sure you create two separate virtual network cards on the Simulink side (Install new board → Standard devices → UDP Protocol); one for Packet Input block and one for Packet Output block.

Second, use Little Endian byte order in I/O blocks.

Now, as an example, we use the following config for one of our apps:

UE4 → Simulink

[UE4 side] Socket name: sock12 (name doesn't matter) IP: 127.0.0.1 Port 9977

[Simulink side, virtual network card used in Packet Input block] Local port: 9977 IP: 127.0.0.1 Remote port: 9955 (I think this remote port doesn't matter)

[Simulink side, Packet Input block config] Output packet size: 20*4+3 Block output data types: {'20*single', '3*uint8'} - if we want to use single bytes (datatype uint8), we need to specify the full thing; the packet input block in Simulink will have two signal outputs for the two vectors containing different data types, so use a demux block to get individual values.

master-chief-117-oye commented 4 years ago

Thank you very much, following your guide I received data from UE4 into Simulink. For now, I only tried the 'Packet Input' block in Simulink (Packet Output not yet used). In 'Packet Input' block --> 'Install new board', I set 'Remote host IP' 127.0.0.1, 'Local UDP port' 9977 and 'Remote UDP port' 9955. I set some constant single values into 'Make UDP data' in UE4 and they all showed up in Simulink. Very happy!

I tried to add 'Packet Output' block into my same Simulink model, because I would also like to send data from Simulink to UE4 at the same time. In 'Packet Output' block, I did 'install new board', and set 'Remote host IP' 127.0.0.1, 'Local UDP port' 9955 and 'Remote UDP port' 9977. The rest settings in 'Packet Output' block are similar to the 'Packet Input' block. However, Matlab crashes immediately.

I'm totally not familiar with all these communication protocols. Could you let me know how I can correctly set up the 'Packet Output' block as well? So that I can both receive and send data between Simulink and UE4.

Thank you very much!

extall commented 4 years ago

I am tempted to close this issue and redirect this discussion to other channels as this is not an issue related to the project, but rather one with configuring Simulink. So this is my final reply whereby I also close the issue. Please contact me directly with further inquiries.

Looks like you have short-circuited MATLAB's RT network interface by your config above.

Simulink → UE4

[Simulink side] Local port: 9999 IP: 127.0.0.1 Remote port: 9988

You can add the same data types to Packet Output block as above and use a mux block to combine multiple scalar signals into the necessary 20 x float and 3 x uint8 vectors.

[UE4 side] Socket name: sock1 IP: 127.0.0.1 Port: 9988