User Datagram Protocol (UDP) is a commonly used communication protocol for the robotic devices at the MLN lab, such as the Lokomat, ARMin, BURT.
UDP is a communication protocol which speeds up transmissions by enabling the transfer of data before an agreement is provided by the receiving party, resulting in a connection that is [source]:
UDP packets come with a header, having 4 fields, each of which is 2 bytes:
This header is the reason you need to specify all this information when setting up a UDP connection. Through selecting the ports we select from which application (port) you want to receive data, as well as to which application (port) we want to send it.
If you want to know how to set up such a Host pc, see here.
We now removed the external PC, also running Unity on the Host-PC. This simplifies the network and works just as well, given the Host-PC is powerful enough to run Unity.
in this new setup, replace all the
25
’s with100
’s for the configuration settings.
Underneath, find a schematic of our network setup, for easy reference/debugging. All information below will be based on this schematic. We won’t talk in terms of client and server, because that’ll depend on from which device we will take our perspective.
When connecting a PC to the LAN network, you’ll need to quickly set some parameters for your IPv4 connection. In Windows:
192.168.1.25
(can also be another, non-used, number after the last .
)24
(for 255.255.255.0
subnet mask)192.168.1.1
Find the xPC UDP blocks under Simulink Library Browser xPC Target/Real-Time UDP/
and the Pack/Unpack blocks under Simulink Library Browser xPC Target/UDP/
Example model underneath:
Network Configuration block (called xpcnwconfig
) is used:
192.168.1.11
(using the new, extra network card for dedicated UDP connection).255.255.255.0
192.168.1.1
Intel 8255x
1
9
Send block (called send
) is used:
uint8
vector)192.168.1.100
25001
25000
-1
Pack block (called xpcbytepacking
) is used:
uint8
{'datatype','other data type', ... }
{'int8'}
to send over an integer value.double, single, int8, uint8, int16, uint16, int32, uint32, boolean
1
Receive block (called receive
) is used:
uint8
vector)192.168.1.100
25000
= 8*nDouble + 4*nSingle + 1*nInt8 + 2*nInt16 + 4*nInt32 + 1*nBool
-1
Unpack block (called xpcbytepacking
) is used:
{'datatype','other data type', ... }
{1,N,...}
1
In this guide, we are sending our data to and from Unity, using a UDP_CSharp
C# Library found here. However, this can be any sort of device connected to the network and communinication over UDP.
TO DO: put link to C# library
192.168.1.100
25001
192.168.1.11
25000
We’ve also set up a UDP connection for the Treadmill.
Here, we can’t use the xPC Real-Time blocks, as they’re not compatible with the network card in the LokoBasis PC (also I8254x). Instead, we use the other UDP blocks, found under under Simulink Library Browser xPC Target/UDP/
. We just need to receive data from here (the treadmill speed), so the example model would look like:
Receive block (called xpcudpbytereceive
) is used:
uint8
vector)192.168.1.100
25000
= 8*nDouble + 4*nSingle + 1*nInt8 + 2*nInt16 + 4*nInt32 + 1*nBool
-1
The Unpack block works the same as for the LokoFree, noted above.
192.168.1.100
25001
192.168.1.20
25000
When the xPC is sending out data over UDP, sometimes (note: not always…) it somehow takes priority over the TCP/IP connection making it unreachable. UDP communication will remain intact (although it will sometimes also crash).
Still don’t understand exactly what triggers this.
This does not happen when data is only received on the xPC.
If you set an end simulation time, the connection will break, until the model stops, at which point you can reconnect to the xPC via TCP/IP. If no end-time has been set, you may not be able to recover your connection, requiring a reboot of the xPC.
We fixed this by adding another NIC to the Lokomat target PC, and configuring UDP communication to run over that.
Lokomat shows error:
Error: Error 8 102 1
Error: --> EADDRINUSE
Error:
---
Error: System Halted
---
Not sure what caused it, but rebooting fixed it.