Sending Data from the Jetson Orin - Carleton-SRL/SPOT GitHub Wiki

Simulink

On the Simulink side, set up a subsystem with the following components. Note, these components are UDP Receive, Demux, Mux, and Cast to Double.

image

In the UDP Send block, there are (4) parameters to set:

  • Local IP Port: Set this to the port number that matches whatever you choose for the sending side of the communication pipeline (see next section).
  • Data Type: For this example, we will set this to single.
  • Data Size: In this example we will be receiving (4) data points, so this parameter can be set to 4.
  • Sample Time: Set this to match your diagram rate -- so when using the main SPOT sofware for example, this would be the baseRate. In this example we will set it to 0.05 seconds.

image

Optionally, in this example the singles are then converted to doubles using the Simulink Cast to Double block. This may not be required depending on your use case.

Jetson Orin

On the Orin computer, adding the code to send the data is quite straightforward. Below is a sample script that can be used to send data from a Linux computer to a remote computer over UDP. In this sample, the IP address is set to 127.0.0.1 -- this sample will only send data to the same computer that is running the code. This is useful for debugging, as you can run code to receive this data (in Python or Simulink) on the same computer that is sending the data, which will make finding problems easier. To use this code to send data to a remote computer, simply change the IP address.

import socket
import struct
import time
import math

sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
server_address = ('127.0.0.1', 13761)

while True:

    time_now = time.time()

    try:

        data = bytearray(struct.pack("ffff", math.sin(time_now), math.cos(time_now), math.tan(time_now), time_now))
        sock.sendto(data, server_address)
        print("Data sent!")

    except Exception as e:
        print(e)
        break

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. The sample Python script and a corresponding Simulink diagram to receive the data can be downloaded here:

Download Here

This code sample does not require a virtual environment, so you can simply place this script somewhere on the Jetson. Then, from the terminal (either through SSH or directly from the Jetson desktop), navigate to the folder with the script. Then run:

python3 simple_UDP_send.py