Clock Messages

Time synchronization types for multi-node and multi-process systems.

# simplified
from horus import Clock, TimeReference

Clock

Timestamp message for clock distribution across nodes.

Constructor

# simplified
clock = Clock(clock_ns=0, realtime_ns=0, sim_speed=1.0, paused=False, source=0, timestamp_ns=0)

Fields

FieldTypeDescription
clock_nsintClock time in nanoseconds
realtime_nsintReal (wall) time in nanoseconds
sim_speedfloatSimulation speed multiplier (1.0 = real-time)
pausedboolWhether the clock is paused
sourceintClock source: 0 = wall, 1 = sim, 2 = replay
timestamp_nsintMessage timestamp in nanoseconds

Static Methods

MethodReturnsDescription
Clock.wall_clock()ClockCreate a wall clock (real time)
Clock.sim_time(sim_ns, speed)ClockCreate a simulation clock with given time and speed multiplier
Clock.replay_time(replay_ns, speed)ClockCreate a replay clock with given time and speed multiplier

Methods

MethodReturnsDescription
elapsed_since(earlier)intElapsed time in nanoseconds since another clock reading
is_paused()boolCheck if the clock is paused

Example

# simplified
# Wall clock
clock = Clock.wall_clock()

# Simulation clock at 2x speed
sim = Clock.sim_time(sim_ns=1_000_000_000, speed=2.0)

# Check elapsed time
elapsed = clock.elapsed_since(sim)

# Replay clock
replay = Clock.replay_time(replay_ns=500_000_000, speed=1.0)
print(replay.paused)  # False

TimeReference

External time reference for synchronization (GPS, NTP, PTP).

Constructor

# simplified
tref = TimeReference(time_ref_ns=0, source="", offset_ns=0, timestamp_ns=0)

Fields

FieldTypeDescription
time_ref_nsintExternal reference time in nanoseconds
sourcestrTime source name (e.g. "gps", "ntp", "ptp")
offset_nsintSigned offset in nanoseconds (local_time - reference_time)
timestamp_nsintMessage timestamp in nanoseconds

Methods

MethodReturnsDescription
correct_timestamp(local_ns)intCorrect a local timestamp using this reference's offset

Example

# simplified
tref = TimeReference(time_ref_ns=1_000_000_000, source="gps", offset_ns=-500)
corrected = tref.correct_timestamp(local_ns=1_000_000_500)

See Also