Achieve Time Synchronization between different computers - ashBabu/Utilities GitHub Wiki
ROS 2 Multi‑Machine Recording Guide
Time Synchronisation using Chrony (Critical for Accurate Timestamps)
Install chrony on both machines
sudo apt update && sudo apt install chrony -y
Configure the NUC as the time server
Edit the configuration file on the NUC:
sudo nano /etc/chrony/chrony.conf
Ensure the following line is present (adjust the subnet to yours):
allow 192.168.1.0/24
It should also sync with public NTP servers (usually already present):
pool 2.ubuntu.pool.ntp.org iburst
Restart chrony on the NUC:
sudo systemctl restart chrony
Configure the Pi as a client
Edit the configuration file on the Raspberry Pi:
sudo nano /etc/chrony/chrony.conf
Comment out or remove any existing pool lines, and add:
server <NUC_IP_ADDRESS> iburst
Restart chrony on the Pi:
sudo systemctl restart chrony
Verify synchronisation
On the Pi, run:
chronyc tracking
Look for the Last offset value – the closer to zero (e.g., within microseconds), the better your clocks are aligned.
(Raspberry Pi 5 → Intel NUC)
This guide walks you through the necessary steps to record ROS 2 topics from your Raspberry Pi on your Intel NUC, with time‑synchronized timestamps.
1. Network Prerequisites
- Both machines must be on the same local subnet (e.g., both connected to the same router via Ethernet or Wi‑Fi).
- Find the IP address of each machine:
ip addr# or ifconfig
Verify connectivity from the NUC to the Pi:
ping <Raspberry_Pi_IP>
If you get replies, the network layer is working.
Set a Common ROS_DOMAIN_ID
Both machines must use the same number (0–101).
On both the Pi and the NUC, run in every terminal before launching any ROS node:
echo "export ROS_DOMAIN_ID=42" >> ~/.bashrc
source ~/.bashrc
Verify the setting on both:
echo $ROS_DOMAIN_ID The output must be identical.
Important: Ensure ROS_LOCALHOST_ONLY is not set to 1. If it is, clear it with:
unset ROS_LOCALHOST_ONLY
Firewall Configuration
ROS 2 uses UDP multicast for discovery. Temporarily disable the firewall for testing, or (preferred) allow UDP traffic from your local subnet:
sudo ufw allow in proto udp from 192.168.1.0/24 (Replace 192.168.1.0/24 with your actual subnet.)
Verify ROS 2 Communication
Use the built‑in demo nodes to confirm that the two machines can talk.
On the Raspberry Pi (publisher):
source /opt/ros/<your-ros2-distro>/setup.bash
export ROS_DOMAIN_ID=42
ros2 run demo_nodes_cpp talker
On the NUC (subscriber):
source /opt/ros/<your-ros2-distro>/setup.bash
export ROS_DOMAIN_ID=42
ros2 run demo_nodes_cpp listener
If the NUC receives Hello World messages, the communication is successful.
Record Topics on the NUC
Now you can record the topics published by the Pi directly on the NUC.
- List available topics (from the Pi):
ros2 topic list
- Record specific topics, e.g. /scan and /camera/image:
ros2 bag record /scan /camera/image
- Record all topics:
ros2 bag record -a