Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:CARLA simulator Carla Timestamp Class

From Leeroopedia
Knowledge Sources
Domains Client Library, Timing, Simulation State
Last Updated 2026-02-15 05:00 GMT

Overview

Timestamp is a lightweight value type that captures the timing information for a single simulation frame, including frame count, elapsed time, delta time, and platform timestamp.

Description

The Timestamp class in the carla::client namespace provides a simple, immutable-style data structure for simulation timing. It is used throughout the CARLA client library to identify frames and measure time.

Data Members

  • frame (std::size_t, default 0) -- Number of frames elapsed since the simulator was launched. Serves as the primary frame identifier.
  • elapsed_seconds (double, default 0.0) -- Simulated seconds elapsed since the beginning of the current episode.
  • delta_seconds (double, default 0.0) -- Simulated seconds elapsed since the previous frame.
  • platform_timestamp (double, default 0.0) -- Real-world time-stamp of the frame in seconds, as given by the operating system.

Constructor

Supports both default construction (all zeros) and parameterized construction: Timestamp(in_frame, in_elapsed_seconds, in_delta_seconds, in_platform_timestamp)

Comparison Operators

  • operator== -- Two timestamps are equal if their frame numbers are equal.
  • operator!= -- Negation of equality.

Stream Output

A std::ostream operator<< in the std namespace outputs the timestamp in the format: Timestamp(frame=N,elapsed_seconds=X,delta_seconds=Y,platform_timestamp=Z)

Usage

Timestamps are embedded in sensor data, world snapshots, and RSS check results. They are the primary mechanism for identifying and ordering simulation frames.

Code Reference

Source Location

  • Repository: CARLA
  • File: LibCarla/source/carla/client/Timestamp.h (72 lines)

Signature

namespace carla {
namespace client {

class Timestamp {
public:
  Timestamp() = default;

  Timestamp(
      std::size_t in_frame,
      double in_elapsed_seconds,
      double in_delta_seconds,
      double in_platform_timestamp);

  std::size_t frame = 0u;
  double elapsed_seconds = 0.0;
  double delta_seconds = 0.0;
  double platform_timestamp = 0.0;

  bool operator==(const Timestamp &rhs) const;
  bool operator!=(const Timestamp &rhs) const;
};

} // namespace client
} // namespace carla

namespace std {
  std::ostream &operator<<(std::ostream &out, const ::carla::client::Timestamp &timestamp);
}

Import

#include "carla/client/Timestamp.h"

I/O Contract

Inputs

Name Type Required Description
in_frame std::size_t No Frame number since simulator launch
in_elapsed_seconds double No Simulated seconds since episode start
in_delta_seconds double No Simulated seconds since previous frame
in_platform_timestamp double No OS-level timestamp in seconds

Outputs

Name Type Description
frame std::size_t Frame counter value
elapsed_seconds double Total elapsed simulation time
delta_seconds double Time step for this frame
platform_timestamp double Real-world OS timestamp

Usage Examples

// Create a timestamp
carla::client::Timestamp ts(42, 3.14, 0.05, 1234567890.0);

// Access fields
std::cout << "Frame: " << ts.frame << std::endl;
std::cout << "Delta: " << ts.delta_seconds << " seconds" << std::endl;

// Compare timestamps
carla::client::Timestamp ts2(42, 3.19, 0.05, 1234567890.05);
assert(ts == ts2);  // Equal because same frame number

// Stream output
std::cout << ts << std::endl;
// Output: Timestamp(frame=42,elapsed_seconds=3.140000,delta_seconds=0.050000,platform_timestamp=1234567890.000000)

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment