Skip to main content

TICSync Code Snippet

Overview

These code samples show how to use the Client SDK to create time synchronized recordings between multiple Project Aria glasses using TICSync.

  • ticsync_recording.py - create TICSync time synchronized recordings with the option to set:
    • Which device is server, which are clients
    • What recording profile each device uses
  • ticsync_cleanup.py - Stop recording (if necessary) and return glasses to their normal recording state
  • ticsync_file_manager.py - list and download recordings made with shared session ids

This page goes through examples using each of the scripts, followed by a ticsync_recording.py code walkthrough.

Running the sample

Example 1: Create TICSync time synchronized recordings, download them and visualize the data

For an end to end guide from how to create TICSync recordings to how to consume the data, go to Time Synchronized Recordings with Multiple Aria Glasses. This guide uses ticsync_recording.py in its simplest form, where the user does not need to set the server/client details or individual recording profiles.

Example 2: Create TICSync time synchronized recordings with granular control over details.

For TICSync to work, all devices need to be on the one Wi-Fi network and a leader device needs to create a synchronized time reference. By default, ticsync.py will select one device to be the Server device (Wi-Fi hotspot and leader device) and all the other devices will be client devices. You can, however, manually configure which device is the server or alter the script to use different Wi-Fi hotspots or leader devices.

Make the recording

  1. Plug all glasses into your computer
  2. Go to the TICSync sample code directory
cd ~/projectaria_client_sdk_samples/ticsync
  1. Get the serial number for all connected devices by running aria device --list
  2. Use the Client SDK to run ticsync.py to:
    1. Set one pair of glasses to be the server (Wi-Fi hotspot and using Fast DDS to be the leader device)
    2. Set the other glasses to be client devices connecting to the server
    3. Set what recording profiles will be used
    4. Start recording with TICSync protocols

In this example, three devices will be making a time synchronized recording and each uses a different recording profile.

python -m ticsync_recording --server <server_serial> profile4 --client <client1_serial> profile16 --client <client2_serial> profile24
Some recording profiles won't work

Recording profiles 0, 2, 10, 19, 25 and 27 have wifiScanModeActive enabled, so they can't be used to create TICSync recordings.

  1. In the command line you’ll see:
    1. Server device has started a Wi-Fi hotspot and Client devices have joined the hotspot
    2. All devices have started recording
      • You should also have visual confirmation from the recording LED on each of the glasses
    3. Script prompting that it is waiting for devices to be ready for time synchronized data collection.
    4. Script prompting that devices are ready for time synchronized data collection.
  2. Unplug the glasses (if you wish) and record your activity
    • It may take ~40 seconds for the ticsync algorithm to reach stabilization between all devices. The TICSync Jupyter notebook tutorial includes how to assess how long it takes for your specific setup and recording profile.
  3. Stop recording:
    • Press the Capture button on the top right of the Aria glasses and then return glasses to their normal state by plugging them in and using ‘ticsync_cleanup’
    • Plug the glasses back into your computer and use ticsync_cleanup

Run cleanup based on number of devices plugged in:

python -m ticsync_cleanup --total_num_devices 3

Run clean up by specifying devices:

python -m ticsync_cleanup --server <server_serial> --clients <client_serial1> <client_serial2>

Example output:

-------- Plug in all devices to your computer again for TicSync cleanup --------
-------- Then press Enter to start TicSync cleanup --------
[('1WM281623D3490', 'Aria'), ('1WM391623D5689', 'Aria'), ('1WM999999D0000', 'Aria')]
[AriaSdk:DeviceControllerImpl][INFO]: Connecting to device 1WM281623D3490 over USB
[AriaSdk:DeviceControllerImpl][INFO]: Connecting to device 1WM391623D5689 over USB
[AriaSdk:DeviceControllerImpl][INFO]: Connecting to device 1WM999999D0000 over USB
Detected server serial 1WM281623D3490
Detected client serials ['1WM391623D5689', '1WM999999D0000']
[AriaSdk:DeviceControllerImpl][INFO]: Connecting to device 1WM391623D5689 over USB
[AriaSdk:DeviceControllerImpl][INFO]: Connecting to device 1WM999999D0000 over USB
[AriaSdk:DeviceControllerImpl][INFO]: Connecting to device 1WM281623D3490 over USB
-------- All devices reconnected, please keep all devices plugged in. Performing cleanup --------
DDS RPC enabled, disabling it
-------- Successfully performed cleanup. Exiting --------

Example 3: Examine and download recordings

ticsync_file_manager enables you to view recordings on your Aria glasses that contain TICSync data as well as download the server and client files at the same time.

  1. Plug all Aria glasses into your computer.
  2. List VRS recordings grouped by shared session ID. The list is in descending order by date.
python -m ticsync_file_manager --list

Depending on how many client devices were used during recordings, there will be 1 or more client devices information listed per server device:

2024-05-23 21:17:19 Shared Session ID: 7dfe4d16-6f54-47bf-859e-6ee4043234d3 Server Serial: 1WM391623D5689 Server Recording UUID: d8b717ce-ef48-40cd-bcc8-56cd9fe14319
Client Serial: 1WM999999D0000 Client Recording UUID: 63334502-6125-498e-8f2e-86567c4cfc0e
Client Serial: 1WM222222S0000 Client Recording UUID: c0fae751-4ad5-4e95-a21d-f9060edc1112

2024-05-23 21:14:58 Shared Session ID: 4b5e2587-de1a-42f9-a17c-60bd96a8658c Server Serial: 1WM391623D5689 Server Recording UUID: 1204bcb6-71ea-42b9-bfbb-62e11f5c620a
Client Serial: 1WM999999D0000 Client Recording UUID: 012e5c7f-c904-4d6f-822e-0b26aedb7684

...

Using the shared session ID, you can download all the time synchronized recordings for that session, rather than needing to pull individual records. Making a copy of the all the details associated with a shared session ID will be helpful when consuming the data

Download the recordings

Get the Shared Session ID for the recordings you want to download from ticsync_file_manager --list. Download recordings for that Shared Session ID to a specified output directory:

python -m ticsync_file_manager --download 7dfe4d16-6f54-47bf-859e-6ee4043234d3 --output_dir ticsync_vrs

In this example, the server and client recordings with the shared session ID 7dfe4d16-6f54-47bf-859e-6ee4043234d3 will be downloaded to a newly created ticsync_vrs folder.

ticsync_recording.py code walkthrough

1. Retrieve serial number and profile names for server and client devices

A helper function get_device_serial_and_profile_names enables the specified script options to be parsed. If the total number of devices were specified, then it tries to detect the requested number of devices and returns the list. If the device serials and profile names were specified explicitly instead, it simply returns those values.

[server_serial_and_profile_name, client_serial_and_profile_names] = (
get_device_serial_and_profile_names(args, device_client)
)

2. Set up the server device

Use a DeviceClient instance that was configured by a DeviceClientConfig with the server device serial. Connect to the server device.

server_serial = server_serial_and_profile_name[0]
server_profile_name = server_serial_and_profile_name[1]
# Set up the server device
device_client_config.device_serial = server_serial
device_client.set_client_config(device_client_config)
# Connect to server device
server_device = device_client.connect()

3. Set up hotspot on the server device

Retrieve the WifiManager instance from the server device’s Device instance and set up a hotspot on the server device.

# Retrieve wifi_manager of the server device
server_wifi_manager = server_device.wifi_manager
# Switch the server device to hotspot mode with a random password
server_wifi_manager.set_device_hotspot_status(
True, WIFI_HOTSPOT_5GHZ, args.hotspot_country_code
)

4. Set up the DDS RPC on the server device

Use the server device’s Device instance to enable RPC over DDS. If already enabled, retrieve a new DDS RPC session ID.

if server_device.dds_rpc_enabled_status.state == aria.DdsRpcState.Off:
print("DDS RPC is not enabled, enabling it")
server_device.set_dds_rpc_enabled(True, aria.StreamingInterface.WifiSoftAp)
else:
# Retrieve a new DDS RPC session ID
session_id = server_device.dds_rpc_new_session_id()
print("Retrieved a new DDS RPC session ID", session_id)
# Retrieve the server device hotspot status. Will be used to connect the client devices to
# the server device hotspot
server_wifi_hotspot_status = server_wifi_manager.device_hotspot_status

5. Retrieve the recording manager of the server device

Configure server device’s RecordingManager by using a RecordingConfig instance with the specified profile and the time sync mode TicSyncServer.

# Retrieve recording_manager of the server device
server_recording_manager = server_device.recording_manager
# Set time sync mode to TicSyncServer using custom recording config
recording_config = aria.RecordingConfig()
recording_config.profile_name = server_profile_name
recording_config.time_sync_mode = aria.TimeSyncMode.TicSyncServer
server_recording_manager.recording_config = recording_config

6. Set up the client devices

Reuse the existing DeviceClient instance by resetting the DeviceClientConfig with each client device serial. Connect to the client device.

client_devices = {}
client_recording_managers = {}
# Set up the client devices
for [serial, profile_name] in client_serial_and_profile_names:
# Reuse the existing DeviceClient instance by setting a new client config
device_client_config.device_serial = serial
device_client.set_client_config(device_client_config)
# Connect to client device
device = device_client.connect()

7. Connect client devices to the server device hotspot**

Retrieve the WifiManager instance from the client device’s Device instance and connect to the hotspot that was set up on the server device in step 4.

wifi_manager = device.wifi_manager
# Connect client device to server device hotspot
wifi_status = wifi_manager.wifi_status
# Check if the client device is already connected to the server device hotspot
if (
wifi_status.enabled is False
or wifi_status.network.ssid != server_wifi_hotspot_status.ssid
):
# If not, connect client device to server device hotspot
wifi_manager.connect_wifi(
server_wifi_hotspot_status.ssid,
server_wifi_hotspot_status.passphrase,
aria.WifiAuthentication.Wpa,
False, # hidden
"", # username
True, # disable_other_network
True, # skip_internet_check
)
# Set keep Wi-Fi on as true for the client devices
# This keeps the client devices connected to the server Wi-Fi hotspot even when they are disconnected from USB
wifi_manager.keep_wifi_on(True)

8. Start recording on the server device*

# Start recording on the server device
print(f"Starting to record the server device {server_serial} using {profile_name}")
server_recording_manager.start_recording()
# Get recording state of the server device
server_recording_state = server_recording_manager.recording_state
print(f"Recording state of server device {server_serial}: {server_recording_state}")

9. Start recording on the client devices

# Start recording on the client devices
for manager in client_recording_managers.values():
manager.start_recording()

10. Wait for devices to be ready for data collection

Use RecordingManager’s TicSync status field to query whether the client devices are ready for data collection.

# Wait for for ticsync convergence
def _is_stable(recording_manager):
status = recording_manager.tic_sync_status
return status.synchronization_stability == aria.SynchronizationStability.Stable

print(
"-------- Waiting for devices to be ready for time synchronized data collection, this will take around 45 seconds. --------\n"
"-------- Please keep all devices plugged in. ---------"
)
while not all(
_is_stable(manager) for manager in client_recording_managers.values()
):
time.sleep(5)

print(
"-------- All devices are ready for data collection. You can safely unplug all your glasses from USB ---------"
)

Once you’ve finished recording, make sure you run ticsync_cleanup.py with all the glasses plugged in to return them to their normal state. Go to “Time Synchronized Recordings with Multiple Aria Glasses” for more information about downloading and consuming the data.