Sending Data from the Jetson TX2 - Carleton-SRCL/SPOT GitHub Wiki

Receiving data from the Jetson TX2 (typically located on the RED platform) is not included by default in SPOT 4.0.0-RC.4. However, the process is fairly straightforward.

Simulink

On the Simulink side, all that is required is a single NVIDIA UDP Receive block, as well as the Byte Unpack block.

image

Users can set any port they want, so long as it matches the port on the sending-side of the communication pipeline. Data on the sending side will be encoded to ensure the transfer of data remains fast. As such, the recommended data type is uint8. In the data size parameter, assuming the data being unpacked are singles, each data of type single contains 4 bytes. Thus, if we are receiving 5 data of type single (as will be the case in this example), the data size parameter must be set to 20. Lastly, the sample time can be set to the rate of the diagram. When using the SPOT diagram, this would be baseRate.

In the Byte Unpack block, users must set the output port dimensions and the output port data types. For this example where we want to convert 20 bytes of uint8 into our 5 singles, we will set the following:

  1. Output Port Dimensions: {[1],[1],[1],[1],[1]}
  2. Output Port Data Types: {'single','single','single','single','single'}

Optionally, in this example the singles are then converted to doubles using the Simulink Data Type Conversion block.

Jetson TX2

On the TX2 board, adding the code to send the data from the ZED is simple. The Python code is as follows - NOTE that this code is assuming that RED is receiving the data. If you want to send the data to another platform, change the IP address in the socket creation line to match the IP of the device sending the data:

# Import the relevant packages
import socket
import struct

# Create the socket and assign the server address.
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
server_address = ('192.168.1.110', 30172)

# Enter some kind of loop, for example to capture and process frames
while True:

    # [.... Other code goes here ]

    try:

        # Encode the data as a byte string
        data = bytearray(struct.pack("fffff", x, y, yaw, float(output[3]), float(end-start)))

        # Send the data
        sock.sendto(data, server_address)

    except:
        print("Failed to Send Packet")

# On program end, be sure to close the socket
sock.close()

To add more data to send, simply add another 'f' to the data structure, and then add the data (ensuring it is a float) to the end of the struct.pack() function call. Be sure to also update the UDP receive and byte unpacking code in the Simulink diagram.