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 FileSignal;
27 class RadarSignal;
29}
30
31namespace core
32{
33 /// Streaming waveform shape cached for a currently active source.
34 enum class StreamingWaveformKind : std::uint8_t
35 {
36 Cw,
39 FileCw,
41 Sfcw
42 };
43
44 /// Cached description of an active streaming transmitter segment.
46 {
47 const radar::Transmitter* transmitter = nullptr; ///< Transmitter active during this segment.
48 RealType segment_start = 0.0; ///< Segment start time in seconds.
49 RealType segment_end = 0.0; ///< Segment end time in seconds.
50
51 RealType carrier_freq = 0.0; ///< Cached carrier frequency in hertz.
52 RealType amplitude = 0.0; ///< Cached emitted signal amplitude.
53 StreamingWaveformKind kind = StreamingWaveformKind::Cw; ///< Cached streaming waveform shape.
54 bool is_fmcw = false; ///< Compatibility flag for any FMCW source.
55 bool is_sfcw = false; ///< Compatibility flag for any stepped-frequency source.
56
57 const fers_signal::FmcwChirpSignal* fmcw = nullptr; ///< Stable pointer to the linear FMCW waveform, if any.
58 const fers_signal::FmcwTriangleSignal* triangle = nullptr; ///< Stable pointer to the triangle waveform, if any.
59 const fers_signal::FileSignal* file = nullptr; ///< Stable pointer to the finite sampled waveform, if any.
61 nullptr; ///< Stable pointer to the stepped-frequency waveform, if any.
62 RealType chirp_duration = 0.0; ///< Cached FMCW chirp duration in seconds.
63 RealType chirp_period = 0.0; ///< Cached FMCW chirp period in seconds.
64 RealType chirp_rate = 0.0; ///< Cached FMCW chirp rate in hertz per second.
65 RealType signed_chirp_rate = 0.0; ///< Cached signed FMCW chirp rate in hertz per second.
66 RealType start_freq_off = 0.0; ///< Cached FMCW start frequency offset in hertz.
67 RealType two_pi_f0 = 0.0; ///< Cached two-pi carrier angular frequency factor.
68 RealType s_pi_alpha = 0.0; ///< Cached signed pi-scaled FMCW chirp-rate factor.
69 std::optional<std::size_t> chirp_count; ///< Optional finite chirp count for the segment.
70
71 RealType two_pi_f0_plus_B = 0.0; ///< Triangle down-leg linear coefficient.
72 RealType pi_alpha = 0.0; ///< Triangle up-leg quadratic coefficient.
73 RealType neg_pi_alpha = 0.0; ///< Triangle down-leg quadratic coefficient.
74 RealType mod_phi_up = 0.0; ///< Triangle leg phase increment modulo 2*pi.
75 RealType mod_phi_tri = 0.0; ///< Triangle period phase increment modulo 2*pi.
76 RealType triangle_period = 0.0; ///< Cached full triangle period in seconds.
77 std::optional<std::size_t> triangle_count; ///< Optional finite triangle count for the segment.
78 RealType file_duration = 0.0; ///< Duration of the finite file waveform in seconds.
79
80 RealType sfcw_step_size = 0.0; ///< Cached SFCW frequency step in hertz.
81 std::size_t sfcw_step_count = 0; ///< Cached SFCW steps per sweep.
82 RealType sfcw_dwell_time = 0.0; ///< Cached SFCW active dwell time in seconds.
83 RealType sfcw_step_period = 0.0; ///< Cached SFCW step period in seconds.
84 RealType sfcw_sweep_period = 0.0; ///< Cached SFCW sweep period in seconds.
85 std::optional<std::size_t> sfcw_sweep_count; ///< Optional finite SFCW sweep count for the segment.
86 };
87
88 /// Builds an active-source cache from a streaming transmitter and segment bounds.
90 RealType segment_end);
91
92 /// Builds an active-source cache directly from a waveform for receiver-local LO references.
94 RealType segment_start, RealType segment_end);
95
96 /// Returns the first FMCW chirp start inside the absolute interval, if one exists.
97 [[nodiscard]] std::optional<RealType> firstFmcwChirpStart(const ActiveStreamingSource& source,
99
100 /// Counts FMCW chirps that start inside the absolute interval.
103
104 /// Returns the first FMCW triangle start inside the absolute interval, if one exists.
105 [[nodiscard]] std::optional<RealType> firstFmcwTriangleStart(const ActiveStreamingSource& source,
107
108 /// Counts FMCW triangles that start inside the absolute interval.
111
112 /// Returns the first SFCW step start inside the absolute interval, if one exists.
113 [[nodiscard]] std::optional<RealType> firstSfcwStepStart(const ActiveStreamingSource& source, RealType active_start,
115
116 /// Counts SFCW active dwells that start inside the absolute interval.
119
120 /// Tracks the current FMCW chirp boundary for a streaming path.
122 {
123 bool initialized = false; ///< True after the tracker has been initialized for a path.
124 RealType t_n = 0.0; ///< Current chirp boundary time in seconds.
125 std::size_t n_current = 0; ///< Current zero-based chirp index.
126 bool triangle_initialized = false; ///< True after the triangle tracker has been initialized.
127 std::size_t triangle_leg = 0; ///< Current triangle leg index: 0 for up-leg, 1 for down-leg.
128 std::size_t triangle_index = 0; ///< Current zero-based triangle index.
129 RealType triangle_t_leg = 0.0; ///< Current triangle leg boundary time in seconds.
130 RealType triangle_phi_base = 0.0; ///< Current modular triangle base phase in radians.
131 };
132
133 /// Tracks the current FMCW triangle leg boundary for a streaming path.
135 {
136 bool initialized = false; ///< True after the tracker has been initialized for a path.
137 std::size_t m_current = 0; ///< Current leg index: 0 for up-leg, 1 for down-leg.
138 std::size_t M_current = 0; ///< Current zero-based triangle index.
139 RealType t_leg = 0.0; ///< Current leg boundary time in seconds.
140 RealType phi_base = 0.0; ///< Current modular base phase in radians.
141 };
142
143 /// Tracks the current streaming waveform boundary for a path.
149
150 /// Per-receiver FMCW tracker state for direct and reflected streaming paths.
152 {
153 std::vector<FmcwChirpBoundaryTracker> direct; ///< Trackers for direct paths by source index.
154 std::vector<std::vector<FmcwChirpBoundaryTracker>> reflected; ///< Trackers for reflected paths.
155 std::vector<FmcwChirpBoundaryTracker> dechirp_reference; ///< Trackers for receiver LO source segments.
156 std::size_t active_dechirp_source_index = 0; ///< Monotonic cursor for receiver LO source segments.
157 std::optional<RealType> last_dechirp_time = std::nullopt; ///< Last sample time used by the LO cursor.
158 };
159
160 /**
161 * @struct SimulationState
162 * @brief Holds the dynamic global state of the simulation.
163 *
164 * This includes the master simulation clock and lists of active objects
165 * that are needed for calculations across different event types.
166 */
168 {
169 /// The master simulation clock, advanced by the event loop.
171
172 /// A global list of all currently active streaming transmitters.
173 std::vector<ActiveStreamingSource> active_streaming_transmitters;
174 };
175}
File-backed sampled waveform with explicit radar-mode identity.
FMCW linear chirp signal implementation.
FMCW symmetric triangular modulation signal implementation.
Class representing a radar signal with associated properties.
Stepped-frequency continuous-wave signal implementation.
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.
std::uint64_t countSfcwStepStarts(const ActiveStreamingSource &source, const RealType active_start, const RealType active_end)
Counts SFCW active dwells 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.
std::optional< RealType > firstSfcwStepStart(const ActiveStreamingSource &source, const RealType active_start, const RealType active_end)
Returns the first SFCW step 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.
const fers_signal::SteppedFrequencySignal * sfcw
Stable pointer to the stepped-frequency waveform, if any.
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 file_duration
Duration of the finite file waveform in seconds.
RealType pi_alpha
Triangle up-leg quadratic coefficient.
const radar::Transmitter * transmitter
Transmitter active during this segment.
RealType sfcw_sweep_period
Cached SFCW sweep period in seconds.
RealType chirp_duration
Cached FMCW chirp duration in seconds.
bool is_sfcw
Compatibility flag for any stepped-frequency source.
RealType chirp_period
Cached FMCW chirp period in seconds.
std::size_t sfcw_step_count
Cached SFCW steps per sweep.
std::optional< std::size_t > sfcw_sweep_count
Optional finite SFCW sweep count for the segment.
StreamingWaveformKind kind
Cached streaming waveform shape.
const fers_signal::FmcwChirpSignal * fmcw
Stable pointer to the linear FMCW waveform, if any.
RealType sfcw_dwell_time
Cached SFCW active dwell time in seconds.
const fers_signal::FileSignal * file
Stable pointer to the finite sampled 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.
RealType sfcw_step_period
Cached SFCW step period in seconds.
const fers_signal::FmcwTriangleSignal * triangle
Stable pointer to the triangle waveform, if any.
RealType sfcw_step_size
Cached SFCW frequency step in hertz.
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.