Skip to content

[BUG] FaultManager uses simulation time instead of wall clock for fault timestamps #155

@mfaferek93

Description

@mfaferek93

Bug report

Steps to reproduce

When running with use_sim_time: true, fault timestamps (first_occurred, last_occurred) are recorded in simulation time (seconds since sim start) instead of wall clock time.

This causes UI/API consumers to display incorrect timestamps like "1/1/1970 00:02:28" when simulation time is e.g. 148 seconds.

Example API response:

{
  "fault_code": "NAVIGATION_GOAL_ABORTED",
  "first_occurred": 148.041,
  "last_occurred": 220.248
}

UI interprets 148.041 as Unix timestamp → new Date(148.041 * 1000) → **1970-01-01

Expected Behavior

Fault timestamps should use wall clock time (Unix epoch) regardless of use_sim_time setting, as they represent when events occurred in the real world.

Affected Components

  • ros2_medkit_fault_manager
  • src/ros2_medkit_fault_manager/src/fault_storage.cpp - uses now() which returns sim time
  • src/ros2_medkit_fault_manager/src/fault_manager_node.cpp - passes now() to storage

Root Cause

// fault_manager_node.cpp
bool is_new = storage_->report_fault_event(
    request->fault_code,
    request->event_type,
    request->severity,
    request->description,
    request->source_id,
    now());  // <-- This returns sim time when use_sim_time=true

Suggested Fix

Use std::chrono::system_clock::now() for fault timestamps instead of ROS now():

// Option 1: Use system clock directly
#include <chrono>

auto wall_time = std::chrono::system_clock::now();
auto wall_time_sec = std::chrono::duration_cast<std::chrono::nanoseconds>(
    wall_time.time_since_epoch()).count();

// Option 2: Add parameter to choose clock source
bool use_wall_clock_for_faults = declare_parameter("use_wall_clock_for_faults", true);

Impact

  • Faults in simulation have meaningless timestamps
  • Cannot correlate faults with real-world events
  • Logs and debugging are harder

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions