FERS 0.1.0
The Flexible Extensible Radar Simulator
Loading...
Searching...
No Matches
simulation_state.h
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-only
2//
3// Copyright (c) 2025-present FERS Contributors (see AUTHORS.md).
4//
5// See the GNU GPLv2 LICENSE file in the FERS project root for more information.
6
7/**
8 * @file simulation_state.h
9 * @brief Defines the global state for the event-driven simulation engine.
10 */
11
12#pragma once
13
14#include <cstddef>
15#include <cstdint>
16#include <optional>
17#include <vector>
18
19#include "config.h"
20#include "radar/transmitter.h"
21
22namespace fers_signal
23{
24 class FmcwChirpSignal;
26 class RadarSignal;
27}
28
29namespace core
30{
31 /// Streaming waveform shape cached for a currently active source.
32 enum class StreamingWaveformKind : std::uint8_t
33 {
34 Cw,
37 };
38
39 /// Cached description of an active streaming transmitter segment.
41 {
42 const radar::Transmitter* transmitter = nullptr; ///< Transmitter active during this segment.
43 RealType segment_start = 0.0; ///< Segment start time in seconds.
44 RealType segment_end = 0.0; ///< Segment end time in seconds.
45
46 RealType carrier_freq = 0.0; ///< Cached carrier frequency in hertz.
47 RealType amplitude = 0.0; ///< Cached emitted signal amplitude.
48 StreamingWaveformKind kind = StreamingWaveformKind::Cw; ///< Cached streaming waveform shape.
49 bool is_fmcw = false; ///< Compatibility flag for any FMCW source.
50
51 const fers_signal::FmcwChirpSignal* fmcw = nullptr; ///< Stable pointer to the linear FMCW waveform, if any.
52 const fers_signal::FmcwTriangleSignal* triangle = nullptr; ///< Stable pointer to the triangle waveform, if any.
53 RealType chirp_duration = 0.0; ///< Cached FMCW chirp duration in seconds.
54 RealType chirp_period = 0.0; ///< Cached FMCW chirp period in seconds.
55 RealType chirp_rate = 0.0; ///< Cached FMCW chirp rate in hertz per second.
56 RealType signed_chirp_rate = 0.0; ///< Cached signed FMCW chirp rate in hertz per second.
57 RealType start_freq_off = 0.0; ///< Cached FMCW start frequency offset in hertz.
58 RealType two_pi_f0 = 0.0; ///< Cached two-pi carrier angular frequency factor.
59 RealType s_pi_alpha = 0.0; ///< Cached signed pi-scaled FMCW chirp-rate factor.
60 std::optional<std::size_t> chirp_count; ///< Optional finite chirp count for the segment.
61
62 RealType two_pi_f0_plus_B = 0.0; ///< Triangle down-leg linear coefficient.
63 RealType pi_alpha = 0.0; ///< Triangle up-leg quadratic coefficient.
64 RealType neg_pi_alpha = 0.0; ///< Triangle down-leg quadratic coefficient.
65 RealType mod_phi_up = 0.0; ///< Triangle leg phase increment modulo 2*pi.
66 RealType mod_phi_tri = 0.0; ///< Triangle period phase increment modulo 2*pi.
67 RealType triangle_period = 0.0; ///< Cached full triangle period in seconds.
68 std::optional<std::size_t> triangle_count; ///< Optional finite triangle count for the segment.
69 };
70
71 /// Builds an active-source cache from a streaming transmitter and segment bounds.
73 RealType segment_end);
74
75 /// Builds an active-source cache directly from a waveform for receiver-local LO references.
77 RealType segment_start, RealType segment_end);
78
79 /// Returns the first FMCW chirp start inside the absolute interval, if one exists.
80 [[nodiscard]] std::optional<RealType> firstFmcwChirpStart(const ActiveStreamingSource& source,
82
83 /// Counts FMCW chirps that start inside the absolute interval.
86
87 /// Returns the first FMCW triangle start inside the absolute interval, if one exists.
88 [[nodiscard]] std::optional<RealType> firstFmcwTriangleStart(const ActiveStreamingSource& source,
90
91 /// Counts FMCW triangles that start inside the absolute interval.
94
95 /// Tracks the current FMCW chirp boundary for a streaming path.
97 {
98 bool initialized = false; ///< True after the tracker has been initialized for a path.
99 RealType t_n = 0.0; ///< Current chirp boundary time in seconds.
100 std::size_t n_current = 0; ///< Current zero-based chirp index.
101 bool triangle_initialized = false; ///< True after the triangle tracker has been initialized.
102 std::size_t triangle_leg = 0; ///< Current triangle leg index: 0 for up-leg, 1 for down-leg.
103 std::size_t triangle_index = 0; ///< Current zero-based triangle index.
104 RealType triangle_t_leg = 0.0; ///< Current triangle leg boundary time in seconds.
105 RealType triangle_phi_base = 0.0; ///< Current modular triangle base phase in radians.
106 };
107
108 /// Tracks the current FMCW triangle leg boundary for a streaming path.
110 {
111 bool initialized = false; ///< True after the tracker has been initialized for a path.
112 std::size_t m_current = 0; ///< Current leg index: 0 for up-leg, 1 for down-leg.
113 std::size_t M_current = 0; ///< Current zero-based triangle index.
114 RealType t_leg = 0.0; ///< Current leg boundary time in seconds.
115 RealType phi_base = 0.0; ///< Current modular base phase in radians.
116 };
117
118 /// Tracks the current streaming waveform boundary for a path.
124
125 /// Per-receiver FMCW tracker state for direct and reflected streaming paths.
127 {
128 std::vector<FmcwChirpBoundaryTracker> direct; ///< Trackers for direct paths by source index.
129 std::vector<std::vector<FmcwChirpBoundaryTracker>> reflected; ///< Trackers for reflected paths.
130 std::vector<FmcwChirpBoundaryTracker> dechirp_reference; ///< Trackers for receiver LO source segments.
131 std::size_t active_dechirp_source_index = 0; ///< Monotonic cursor for receiver LO source segments.
132 std::optional<RealType> last_dechirp_time = std::nullopt; ///< Last sample time used by the LO cursor.
133 };
134
135 /**
136 * @struct SimulationState
137 * @brief Holds the dynamic global state of the simulation.
138 *
139 * This includes the master simulation clock and lists of active objects
140 * that are needed for calculations across different event types.
141 */
143 {
144 /// The master simulation clock, advanced by the event loop.
146
147 /// A global list of all currently active streaming transmitters.
148 std::vector<ActiveStreamingSource> active_streaming_transmitters;
149 };
150}
FMCW linear chirp signal implementation.
FMCW symmetric triangular modulation signal implementation.
Class representing a radar signal with associated properties.
Represents a radar transmitter system.
Definition transmitter.h:34
Global configuration file for the project.
double RealType
Type for real numbers.
Definition config.h:27
std::uint64_t countFmcwTriangleStarts(const ActiveStreamingSource &source, const RealType active_start, const RealType active_end)
Counts FMCW triangles that start inside the absolute interval.
StreamingWaveformKind
Streaming waveform shape cached for a currently active source.
ActiveStreamingSource makeActiveSource(const radar::Transmitter *const tx, const RealType segment_start, const RealType segment_end)
Builds an active-source cache from a streaming transmitter and segment bounds.
std::uint64_t countFmcwChirpStarts(const ActiveStreamingSource &source, const RealType active_start, const RealType active_end)
Counts FMCW chirps that start inside the absolute interval.
std::optional< RealType > firstFmcwTriangleStart(const ActiveStreamingSource &source, const RealType active_start, const RealType active_end)
Returns the first FMCW triangle start inside the absolute interval, if one exists.
ActiveStreamingSource makeActiveSourceFromWaveform(const fers_signal::RadarSignal *const signal, const RealType segment_start, const RealType segment_end)
Builds an active-source cache directly from a waveform for receiver-local LO references.
std::optional< RealType > firstFmcwChirpStart(const ActiveStreamingSource &source, const RealType active_start, const RealType active_end)
Returns the first FMCW chirp start inside the absolute interval, if one exists.
math::Vec3 max
Cached description of an active streaming transmitter segment.
RealType s_pi_alpha
Cached signed pi-scaled FMCW chirp-rate factor.
RealType triangle_period
Cached full triangle period in seconds.
RealType amplitude
Cached emitted signal amplitude.
RealType carrier_freq
Cached carrier frequency in hertz.
RealType two_pi_f0
Cached two-pi carrier angular frequency factor.
RealType neg_pi_alpha
Triangle down-leg quadratic coefficient.
RealType two_pi_f0_plus_B
Triangle down-leg linear coefficient.
RealType mod_phi_tri
Triangle period phase increment modulo 2*pi.
RealType mod_phi_up
Triangle leg phase increment modulo 2*pi.
RealType segment_start
Segment start time in seconds.
RealType signed_chirp_rate
Cached signed FMCW chirp rate in hertz per second.
RealType pi_alpha
Triangle up-leg quadratic coefficient.
const radar::Transmitter * transmitter
Transmitter active during this segment.
RealType chirp_duration
Cached FMCW chirp duration in seconds.
RealType chirp_period
Cached FMCW chirp period in seconds.
StreamingWaveformKind kind
Cached streaming waveform shape.
const fers_signal::FmcwChirpSignal * fmcw
Stable pointer to the linear FMCW waveform, if any.
bool is_fmcw
Compatibility flag for any FMCW source.
std::optional< std::size_t > chirp_count
Optional finite chirp count for the segment.
std::optional< std::size_t > triangle_count
Optional finite triangle count for the segment.
RealType segment_end
Segment end time in seconds.
const fers_signal::FmcwTriangleSignal * triangle
Stable pointer to the triangle waveform, if any.
RealType chirp_rate
Cached FMCW chirp rate in hertz per second.
RealType start_freq_off
Cached FMCW start frequency offset in hertz.
Tracks the current FMCW chirp boundary for a streaming path.
RealType t_n
Current chirp boundary time in seconds.
RealType triangle_phi_base
Current modular triangle base phase in radians.
bool triangle_initialized
True after the triangle tracker has been initialized.
std::size_t triangle_leg
Current triangle leg index: 0 for up-leg, 1 for down-leg.
std::size_t triangle_index
Current zero-based triangle index.
std::size_t n_current
Current zero-based chirp index.
bool initialized
True after the tracker has been initialized for a path.
RealType triangle_t_leg
Current triangle leg boundary time in seconds.
Tracks the current FMCW triangle leg boundary for a streaming path.
std::size_t m_current
Current leg index: 0 for up-leg, 1 for down-leg.
RealType phi_base
Current modular base phase in radians.
std::size_t M_current
Current zero-based triangle index.
RealType t_leg
Current leg boundary time in seconds.
bool initialized
True after the tracker has been initialized for a path.
Per-receiver FMCW tracker state for direct and reflected streaming paths.
std::vector< std::vector< FmcwChirpBoundaryTracker > > reflected
Trackers for reflected paths.
std::optional< RealType > last_dechirp_time
Last sample time used by the LO cursor.
std::vector< FmcwChirpBoundaryTracker > dechirp_reference
Trackers for receiver LO source segments.
std::vector< FmcwChirpBoundaryTracker > direct
Trackers for direct paths by source index.
std::size_t active_dechirp_source_index
Monotonic cursor for receiver LO source segments.
Holds the dynamic global state of the simulation.
std::vector< ActiveStreamingSource > active_streaming_transmitters
A global list of all currently active streaming transmitters.
RealType t_current
The master simulation clock, advanced by the event loop.
Tracks the current streaming waveform boundary for a path.
FmcwTriangleBoundaryTracker triangle
FmcwChirpBoundaryTracker linear
Header file for the Transmitter class in the radar namespace.