FERS 0.1.0
The Flexible Extensible Radar Simulator
Loading...
Searching...
No Matches
world.h
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-only
2//
3// Copyright (c) 2006-2008 Marc Brooker and Michael Inggs
4// Copyright (c) 2008-present FERS Contributors (see AUTHORS.md).
5//
6// See the GNU GPLv2 LICENSE file in the FERS project root for more information.
7
8/**
9 * @file world.h
10 * @brief Header file for the World class in the simulator.
11 */
12
13#pragma once
14
15#include <memory>
16#include <queue>
17#include <string>
18#include <unordered_map>
19#include <vector>
20
22#include "core/sim_events.h"
23#include "core/sim_id.h"
25#include "radar/platform.h"
26#include "radar/receiver.h"
27#include "radar/target.h"
28#include "radar/transmitter.h"
29#include "signal/radar_signal.h"
31
32namespace core
33{
34 /**
35 * @class World
36 * @brief The World class manages the simulator environment.
37 */
38 class World
39 {
40 public:
41 World() = default;
42
44
46
48
50
52
53 /**
54 * @brief Adds a radar platform to the simulation world.
55 *
56 * @param plat A unique pointer to a Platform object.
57 */
59
60 /**
61 * @brief Adds a radar transmitter to the simulation world.
62 *
63 * @param trans A unique pointer to a Transmitter object.
64 */
66
67 /**
68 * @brief Adds a radar receiver to the simulation world.
69 *
70 * @param recv A unique pointer to a Receiver object.
71 */
73
74 /**
75 * @brief Adds a radar target to the simulation world.
76 *
77 * @param target A unique pointer to a Target object.
78 */
80
81 /**
82 * @brief Adds a radar signal (waveform) to the simulation world.
83 *
84 * @param waveform A unique pointer to a RadarSignal object.
85 * @throws std::runtime_error if a waveform with the same ID already exists.
86 */
87 void add(std::unique_ptr<fers_signal::RadarSignal> waveform);
88
89 /**
90 * @brief Adds an antenna to the simulation world.
91 *
92 * @param antenna A unique pointer to an Antenna object.
93 * @throws std::runtime_error if an antenna with the same ID already exists.
94 */
96
97 /**
98 * @brief Adds a timing source to the simulation world.
99 *
100 * @param timing A unique pointer to a PrototypeTiming object.
101 * @throws std::runtime_error if a timing source with the same ID already exists.
102 */
103 void add(std::unique_ptr<timing::PrototypeTiming> timing);
104
105 /**
106 * @brief Finds a radar signal by ID.
107 *
108 * @param id The ID of the radar signal to find.
109 * @return A pointer to the RadarSignal if found, or nullptr if not found.
110 */
111 [[nodiscard]] fers_signal::RadarSignal* findWaveform(const SimId id);
112
113 /**
114 * @brief Finds an antenna by ID.
115 *
116 * @param id The ID of the antenna to find.
117 * @return A pointer to the Antenna if found, or nullptr if not found.
118 */
120
121 /**
122 * @brief Finds a timing source by ID.
123 *
124 * @param id The ID of the timing source to find.
125 * @return A pointer to the PrototypeTiming if found, or nullptr if not found.
126 */
127 [[nodiscard]] timing::PrototypeTiming* findTiming(const SimId id);
128
129 /**
130 * @brief Finds a platform by ID.
131 *
132 * @param id The ID of the platform to find.
133 * @return A pointer to the Platform if found, or nullptr if not found.
134 */
136
137 /**
138 * @brief Finds a transmitter by ID.
139 *
140 * @param id The ID of the transmitter to find.
141 * @return A pointer to the Transmitter if found, or nullptr if not found.
142 */
144
145 /**
146 * @brief Finds a transmitter by name.
147 *
148 * @param name The transmitter name to find.
149 * @return A pointer to the Transmitter if found, or nullptr if not found.
150 */
151 [[nodiscard]] radar::Transmitter* findTransmitterByName(const std::string& name);
152
153 /**
154 * @brief Finds a receiver by ID.
155 *
156 * @param id The ID of the receiver to find.
157 * @return A pointer to the Receiver if found, or nullptr if not found.
158 */
160
161 /**
162 * @brief Finds a waveform by name.
163 *
164 * @param name The waveform name to find.
165 * @return A pointer to the RadarSignal if found, or nullptr if not found.
166 */
167 [[nodiscard]] fers_signal::RadarSignal* findWaveformByName(const std::string& name);
168
169 /**
170 * @brief Finds the earliest simulation time that can require CW phase-noise samples.
171 *
172 * Includes active streaming transmitters and receivers. Pre-start transmitter periods that cross the
173 * simulation start are included so retarded emissions can sample transmitter phase noise before t_start.
174 *
175 * @return Earliest required lookup time, or params::startTime() if no streaming component overlaps.
176 */
178
179 /**
180 * @brief Finds a target by ID.
181 *
182 * @param id The ID of the target to find.
183 * @return A pointer to the Target if found, or nullptr if not found.
184 */
186
187 /**
188 * @brief Replaces an existing target, updating internal pointers.
189 * @param target Unique pointer to the new target.
190 */
191 void replace(std::unique_ptr<radar::Target> target);
192
193 /**
194 * @brief Replaces an existing antenna, updating internal pointers.
195 * @param antenna Unique pointer to the new antenna.
196 */
198
199 /**
200 * @brief Replaces an existing waveform, updating internal pointers.
201 * @param waveform Unique pointer to the new waveform.
202 */
203 void replace(std::unique_ptr<fers_signal::RadarSignal> waveform);
204
205 /**
206 * @brief Replaces an existing timing prototype and refreshes dependent radar timing models.
207 * @param timing Unique pointer to the new timing prototype.
208 */
209 void replace(std::unique_ptr<timing::PrototypeTiming> timing);
210
211 /**
212 * @brief Retrieves the list of platforms.
213 *
214 * @return A const reference to a vector of unique pointers to Platform objects.
215 */
217 {
218 return _platforms;
219 }
220
221 /**
222 * @brief Retrieves the list of radar targets.
223 *
224 * @return A const reference to a vector of unique pointers to Target objects.
225 */
226 [[nodiscard]] const std::vector<std::unique_ptr<radar::Target>>& getTargets() const noexcept
227 {
228 return _targets;
229 }
230
231 /**
232 * @brief Retrieves the list of radar receivers.
233 *
234 * @return A const reference to a vector of unique pointers to Receiver objects.
235 */
236 [[nodiscard]] const std::vector<std::unique_ptr<radar::Receiver>>& getReceivers() const noexcept
237 {
238 return _receivers;
239 }
240
241 /**
242 * @brief Retrieves the list of radar transmitters.
243 *
244 * @return A const reference to a vector of unique pointers to Transmitter objects.
245 */
246 [[nodiscard]] const std::vector<std::unique_ptr<radar::Transmitter>>& getTransmitters() const noexcept
247 {
248 return _transmitters;
249 }
250
251 /**
252 * @brief Retrieves the map of radar signals (waveforms).
253 * @return A const reference to the map of signal names to RadarSignal objects.
254 */
255 [[nodiscard]] const std::unordered_map<SimId, std::unique_ptr<fers_signal::RadarSignal>>&
257 {
258 return _waveforms;
259 }
260
261 /**
262 * @brief Retrieves the map of antennas.
263 * @return A const reference to the map of antenna names to Antenna objects.
264 */
265 [[nodiscard]] const std::unordered_map<SimId, std::unique_ptr<antenna::Antenna>>& getAntennas() const noexcept
266 {
267 return _antennas;
268 }
269
270 /**
271 * @brief Retrieves the map of timing prototypes.
272 * @return A const reference to the map of timing names to PrototypeTiming objects.
273 */
274 [[nodiscard]] const std::unordered_map<SimId, std::unique_ptr<timing::PrototypeTiming>>&
276 {
277 return _timings;
278 }
279
280 /**
281 * @brief Clears all objects and assets from the simulation world.
282 */
283 void clear() noexcept;
284
285 /**
286 * @brief Exchanges all owned world state with another world.
287 */
288 void swap(World& other) noexcept;
289
290 /**
291 * @brief Populates the event queue with the initial events for the simulation.
292 * This method should be called after all simulation objects have been parsed and added to the world.
293 */
295
296 /**
297 * @brief Resolves and validates receiver FMCW dechirp references after all components are loaded.
298 *
299 * @throws std::runtime_error if a dechirped receiver has an invalid or inactive LO reference.
300 */
302
303 /**
304 * @brief Dumps the current state of the event queue to a string for debugging.
305 * @return A formatted string representing the contents of the event queue.
306 */
307 [[nodiscard]] std::string dumpEventQueue() const;
308
309 /**
310 * @brief Gets a mutable reference to the global event queue.
311 * @return A reference to the priority queue of events.
312 */
314 {
315 return _event_queue;
316 }
317
318 /**
319 * @brief Gets a mutable reference to the global simulation state.
320 * @return A reference to the SimulationState object.
321 */
322 [[nodiscard]] SimulationState& getSimulationState() noexcept { return _simulation_state; }
323
324 private:
325 void scheduleInitialTransmitterEvents(radar::Transmitter* transmitter, RealType sim_start, RealType sim_end);
326 void scheduleInitialPulsedTransmitterEvent(radar::Transmitter* transmitter, RealType sim_start,
328 void scheduleInitialStreamingTransmitterEvents(radar::Transmitter* transmitter, RealType sim_start,
330 void pushStreamingTransmitterEvents(radar::Transmitter* transmitter, RealType start, RealType end);
331
332 void scheduleInitialReceiverEvents(radar::Receiver* receiver, RealType sim_start, RealType sim_end);
333 void scheduleInitialPulsedReceiverEvent(radar::Receiver* receiver, RealType sim_end);
334 void scheduleInitialStreamingReceiverEvents(radar::Receiver* receiver, RealType sim_start, RealType sim_end);
335 void pushStreamingReceiverEvents(radar::Receiver* receiver, RealType start, RealType end);
336
337 std::vector<std::unique_ptr<radar::Platform>> _platforms; ///< Owned radar platforms.
338
339 std::vector<std::unique_ptr<radar::Transmitter>> _transmitters; ///< Owned transmitters.
340
341 std::vector<std::unique_ptr<radar::Receiver>> _receivers; ///< Owned receivers.
342
343 std::vector<std::unique_ptr<radar::Target>> _targets; ///< Owned targets.
344
345 std::unordered_map<SimId, std::unique_ptr<fers_signal::RadarSignal>> _waveforms; ///< Owned waveform assets.
346
347 std::unordered_map<std::string, SimId> _waveform_ids_by_name; ///< Waveform name to ID lookup.
348
349 std::unordered_map<std::string, radar::Transmitter*> _transmitters_by_name; ///< Transmitter name lookup.
350
351 std::unordered_map<SimId, std::unique_ptr<antenna::Antenna>> _antennas; ///< Owned antenna assets.
352
353 std::unordered_map<SimId, std::unique_ptr<timing::PrototypeTiming>> _timings; ///< Owned timing prototypes.
354
355 std::priority_queue<Event, std::vector<Event>, EventComparator> _event_queue; ///< Pending simulation events.
356
357 SimulationState _simulation_state; ///< Mutable runtime simulation state.
358 };
359}
Header file defining various types of antennas and their gain patterns.
const Transmitter & transmitter
const Receiver & receiver
The World class manages the simulator environment.
Definition world.h:39
void scheduleInitialEvents()
Populates the event queue with the initial events for the simulation.
Definition world.cpp:439
World()=default
void add(std::unique_ptr< radar::Platform > plat) noexcept
Adds a radar platform to the simulation world.
Definition world.cpp:110
void replace(std::unique_ptr< radar::Target > target)
Replaces an existing target, updating internal pointers.
Definition world.cpp:281
fers_signal::RadarSignal * findWaveform(const SimId id)
Finds a radar signal by ID.
Definition world.cpp:153
~World() noexcept=default
const std::vector< std::unique_ptr< radar::Target > > & getTargets() const noexcept
Retrieves the list of radar targets.
Definition world.h:226
radar::Target * findTarget(const SimId id)
Finds a target by ID.
Definition world.cpp:273
fers_signal::RadarSignal * findWaveformByName(const std::string &name)
Finds a waveform by name.
Definition world.cpp:203
const std::unordered_map< SimId, std::unique_ptr< antenna::Antenna > > & getAntennas() const noexcept
Retrieves the map of antennas.
Definition world.h:265
radar::Receiver * findReceiver(const SimId id)
Finds a receiver by ID.
Definition world.cpp:195
radar::Transmitter * findTransmitter(const SimId id)
Finds a transmitter by ID.
Definition world.cpp:181
void clear() noexcept
Clears all objects and assets from the simulation world.
Definition world.cpp:407
void resolveReceiverDechirpReferences()
Resolves and validates receiver FMCW dechirp references after all components are loaded.
Definition world.cpp:552
const std::unordered_map< SimId, std::unique_ptr< fers_signal::RadarSignal > > & getWaveforms() const noexcept
Retrieves the map of radar signals (waveforms).
Definition world.h:256
timing::PrototypeTiming * findTiming(const SimId id)
Finds a timing source by ID.
Definition world.cpp:165
SimulationState & getSimulationState() noexcept
Gets a mutable reference to the global simulation state.
Definition world.h:322
antenna::Antenna * findAntenna(const SimId id)
Finds an antenna by ID.
Definition world.cpp:159
const std::unordered_map< SimId, std::unique_ptr< timing::PrototypeTiming > > & getTimings() const noexcept
Retrieves the map of timing prototypes.
Definition world.h:275
void swap(World &other) noexcept
Exchanges all owned world state with another world.
Definition world.cpp:422
const std::vector< std::unique_ptr< radar::Platform > > & getPlatforms() const noexcept
Retrieves the list of platforms.
Definition world.h:216
std::string dumpEventQueue() const
Dumps the current state of the event queue to a string for debugging.
Definition world.cpp:618
radar::Platform * findPlatform(const SimId id)
Finds a platform by ID.
Definition world.cpp:171
std::priority_queue< Event, std::vector< Event >, EventComparator > & getEventQueue() noexcept
Gets a mutable reference to the global event queue.
Definition world.h:313
const std::vector< std::unique_ptr< radar::Transmitter > > & getTransmitters() const noexcept
Retrieves the list of radar transmitters.
Definition world.h:246
const std::vector< std::unique_ptr< radar::Receiver > > & getReceivers() const noexcept
Retrieves the list of radar receivers.
Definition world.h:236
radar::Transmitter * findTransmitterByName(const std::string &name)
Finds a transmitter by name.
Definition world.cpp:189
RealType earliestPhaseNoiseLookupStart() const
Finds the earliest simulation time that can require CW phase-noise samples.
Definition world.cpp:209
Manages radar signal reception and response processing.
Definition receiver.h:47
Represents a radar transmitter system.
Definition transmitter.h:34
double RealType
Type for real numbers.
Definition config.h:27
Defines the Platform class used in radar simulation.
Header file for the PrototypeTiming class.
Classes for handling radar waveforms and signals.
Radar Receiver class for managing signal reception and response handling.
Defines the core structures for the event-driven simulation engine.
uint64_t SimId
64-bit Unique Simulation ID.
Definition sim_id.h:18
math::Vec3 max
Defines the global state for the event-driven simulation engine.
A custom comparator for the event priority queue.
Definition sim_events.h:59
Represents a single event in the simulation's time-ordered queue.
Definition sim_events.h:45
Holds the dynamic global state of the simulation.
Defines classes for radar targets and their Radar Cross-Section (RCS) models.
Header file for the Transmitter class in the radar namespace.