Some optional functions may not be available, depending on your type of license.
UDP Input Overview¶
With the Moticon Science Software it is possible to stream sensor data of external devices (EMG, force plate, etc.) via the UDP protocol directly into a measurement.
The following assumes that your external device sends data over the network to your computer using the UDP protocol. Alternatively, if your external device is directly connected to your computer (e.g. by USB), it is required that an adapter software captures the external data and re-sends it to 'localhost' using UDP.
The following illustration shows both the case of software running on different computers, and the case where data shall be imported from a program running on the same computer. Note that the IP addresses and port numbers are just examples and must be adapted to your system.
Setting up UDP Input¶
Whenever a UDP packet is received, the data contained in the UDP packet will be recorded in the measurement. Oftentimes, you may want to record multiple data channels at a time, e.g. to record several force and torque values of a force measurement device. As an illustrative example, let's assume that you want to record 4 force values and 2 torque values, and that your external device (or adapter software) generates UDP packets containing 4 integer values (Newton) and 2 float values (N*m).
To set up Moticon Science Software for receiving and correctly interpreting these 6-value
UDP packets, go to the 'Connect' tab of the Record Settings and use the
'New' button in the lower part of the UDP Input category. First, set up
an external data channel (e.g. called 'force') with 4 sub-channels with unit 'N'
and data type 'int16' (or a different integer data type, depending on your UDP
packet setup). Then, click on the 'New' button again to set up a channel
'torque' with 2 sub-channels with unit 'Nm' and data type 'float32'.
The resulting order of data channels within the UDP packet will be displayed in the settings dialog (in the above example: 'force force force force torque torque').
To 'Edit' your settings or 'Delete' the entered channels, use the respective buttons. To activate the recording of external UDP data, insert the UDP port number to which the external device (or adapter software) sends the data, and move the toggle box to 'On'.
You can also use the External Data Quick Launch Button in the status bar to
activate the streaming of external sensor data.
External Data Quick Launch Button
Making a Measurement including UDP Data¶
When the toggle box in the UDP input settings has been turned to 'On', any data received on the configured UDP socket will be included as channel in any data capturing. For the data capturing a Live Capture is recommended, but the UDP import also works for Recording. For Recording, however, there are two restrictions: - The data capture will generate two measurements: one of the UDP data (automatically stored in the measurement tree) and one of the sensor insoles data (data download required). Both measurements can be merged afterwards using the 'Merge' functionality. - The UDP data capture will stop as soon as the sensor insoles are disconnected.
If you wish to capture UDP data even without using sensor insoles, you can do so by selecting 'External Sensors' in the dropdown of the 'Connect' button, instead of a regular pair of sensor insoles.
Python Example for UDP Sender¶
An example for a program sending UDP packets to be imported in the Moticon software is given below as Python code (UDP client). If your external system has no UDP software interface, this Python code may serve as a basis for an adapter software.
Extending this code to transfer data from an external measurement system requires additional development effort which is not provided by Moticon.
import socket from argparse import ArgumentParser import random from time import sleep def send_udp(num_values, host, port): sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) while True: sleep(0.5) message = " ".join([str(random.randint(0, 1000)) for _ in range(num_values)]) print "Send message:", message sock.sendto(message, (host, port)) if __name__ == '__main__': parser = ArgumentParser(description="Example UDP sender") parser.add_argument("num_values", nargs="?", type=int, help="number of values to send in each UDP packet", default=5) parser.add_argument("--host", default="192.168.0.10") parser.add_argument("--port", default=8888, type=int) args = parser.parse_args() send_udp(args.num_values, host=args.host, port=args.port)