FERS 1.0.0
The Flexible Extensible Radar Simulator
Loading...
Searching...
No Matches
core::World Class Reference

The World class manages the simulator environment. More...

#include "world.h"

Public Member Functions

 World ()=default
 
 ~World () noexcept=default
 
 World (const World &)=delete
 
Worldoperator= (const World &)=delete
 
 World (World &&)=delete
 
Worldoperator= (World &&)=delete
 
void add (std::unique_ptr< radar::Platform > plat) noexcept
 Adds a radar platform to the simulation world.
 
void add (std::unique_ptr< radar::Transmitter > trans) noexcept
 Adds a radar transmitter to the simulation world.
 
void add (std::unique_ptr< radar::Receiver > recv) noexcept
 Adds a radar receiver to the simulation world.
 
void add (std::unique_ptr< radar::Target > target) noexcept
 Adds a radar target to the simulation world.
 
void add (std::unique_ptr< fers_signal::RadarSignal > waveform)
 Adds a radar signal (waveform) to the simulation world.
 
void add (std::unique_ptr< antenna::Antenna > antenna)
 Adds an antenna to the simulation world.
 
void add (std::unique_ptr< timing::PrototypeTiming > timing)
 Adds a timing source to the simulation world.
 
fers_signal::RadarSignalfindWaveform (const std::string &name)
 Finds a radar signal by name.
 
antenna::AntennafindAntenna (const std::string &name)
 Finds an antenna by name.
 
timing::PrototypeTimingfindTiming (const std::string &name)
 Finds a timing source by name.
 
const std::vector< std::unique_ptr< radar::Platform > > & getPlatforms () const noexcept
 Retrieves the list of platforms.
 
const std::vector< std::unique_ptr< radar::Target > > & getTargets () const noexcept
 Retrieves the list of radar targets.
 
const std::vector< std::unique_ptr< radar::Receiver > > & getReceivers () const noexcept
 Retrieves the list of radar receivers.
 
const std::vector< std::unique_ptr< radar::Transmitter > > & getTransmitters () const noexcept
 Retrieves the list of radar transmitters.
 
const std::unordered_map< std::string, std::unique_ptr< fers_signal::RadarSignal > > & getWaveforms () const noexcept
 Retrieves the map of radar signals (waveforms).
 
const std::unordered_map< std::string, std::unique_ptr< antenna::Antenna > > & getAntennas () const noexcept
 Retrieves the map of antennas.
 
const std::unordered_map< std::string, std::unique_ptr< timing::PrototypeTiming > > & getTimings () const noexcept
 Retrieves the map of timing prototypes.
 
void clear () noexcept
 Clears all objects and assets from the simulation world.
 
void scheduleInitialEvents ()
 Populates the event queue with the initial events for the simulation.
 
std::string dumpEventQueue () const
 Dumps the current state of the event queue to a string for debugging.
 
std::priority_queue< Event, std::vector< Event >, EventComparator > & getEventQueue () noexcept
 Gets a mutable reference to the global event queue.
 
SimulationStategetSimulationState () noexcept
 Gets a mutable reference to the global simulation state.
 

Detailed Description

The World class manages the simulator environment.

Definition at line 37 of file world.h.

Constructor & Destructor Documentation

◆ World() [1/3]

core::World::World ( )
default

◆ ~World()

core::World::~World ( )
defaultnoexcept

◆ World() [2/3]

core::World::World ( const World )
delete

◆ World() [3/3]

core::World::World ( World &&  )
delete

Member Function Documentation

◆ add() [1/7]

void core::World::add ( std::unique_ptr< antenna::Antenna antenna)

Adds an antenna to the simulation world.

Parameters
antennaA unique pointer to an Antenna object.
Exceptions
std::runtime_errorif an antenna with the same name already exists.

Definition at line 52 of file world.cpp.

53 {
54 if (_antennas.contains(antenna->getName()))
55 {
56 throw std::runtime_error("An antenna with the name " + antenna->getName() + " already exists.");
57 }
58 _antennas[antenna->getName()] = std::move(antenna);
59 }

◆ add() [2/7]

void core::World::add ( std::unique_ptr< fers_signal::RadarSignal waveform)

Adds a radar signal (waveform) to the simulation world.

Parameters
waveformA unique pointer to a RadarSignal object.
Exceptions
std::runtime_errorif a waveform with the same name already exists.

Definition at line 43 of file world.cpp.

44 {
45 if (_waveforms.contains(waveform->getName()))
46 {
47 throw std::runtime_error("A waveform with the name " + waveform->getName() + " already exists.");
48 }
49 _waveforms[waveform->getName()] = std::move(waveform);
50 }

◆ add() [3/7]

void core::World::add ( std::unique_ptr< radar::Platform plat)
noexcept

Adds a radar platform to the simulation world.

Parameters
platA unique pointer to a Platform object.

Definition at line 35 of file world.cpp.

35{ _platforms.push_back(std::move(plat)); }

Referenced by serial::json_to_world().

+ Here is the caller graph for this function:

◆ add() [4/7]

void core::World::add ( std::unique_ptr< radar::Receiver recv)
noexcept

Adds a radar receiver to the simulation world.

Parameters
recvA unique pointer to a Receiver object.

Definition at line 39 of file world.cpp.

39{ _receivers.push_back(std::move(recv)); }

◆ add() [5/7]

void core::World::add ( std::unique_ptr< radar::Target target)
noexcept

Adds a radar target to the simulation world.

Parameters
targetA unique pointer to a Target object.

Definition at line 41 of file world.cpp.

41{ _targets.push_back(std::move(target)); }

◆ add() [6/7]

void core::World::add ( std::unique_ptr< radar::Transmitter trans)
noexcept

Adds a radar transmitter to the simulation world.

Parameters
transA unique pointer to a Transmitter object.

Definition at line 37 of file world.cpp.

37{ _transmitters.push_back(std::move(trans)); }

◆ add() [7/7]

void core::World::add ( std::unique_ptr< timing::PrototypeTiming timing)

Adds a timing source to the simulation world.

Parameters
timingA unique pointer to a PrototypeTiming object.
Exceptions
std::runtime_errorif a timing source with the same name already exists.

Definition at line 61 of file world.cpp.

62 {
63 if (_timings.contains(timing->getName()))
64 {
65 throw std::runtime_error("A timing source with the name " + timing->getName() + " already exists.");
66 }
67 _timings[timing->getName()] = std::move(timing);
68 }

◆ clear()

void core::World::clear ( )
noexcept

Clears all objects and assets from the simulation world.

Definition at line 85 of file world.cpp.

86 {
87 _platforms.clear();
88 _transmitters.clear();
89 _receivers.clear();
90 _targets.clear();
91 _waveforms.clear();
92 _antennas.clear();
93 _timings.clear();
94 _event_queue = {};
95 _simulation_state = {};
96 }

Referenced by serial::json_to_world(), serial::parseSimulation(), and serial::parseSimulationFromString().

+ Here is the caller graph for this function:

◆ dumpEventQueue()

std::string core::World::dumpEventQueue ( ) const

Dumps the current state of the event queue to a string for debugging.

Returns
A formatted string representing the contents of the event queue.

Definition at line 180 of file world.cpp.

181 {
182 if (_event_queue.empty())
183 {
184 return "Event Queue is empty.\n";
185 }
186
187 std::stringstream ss;
188 ss << std::fixed << std::setprecision(6);
189
190 const std::string separator = "--------------------------------------------------------------------";
191 const std::string title = "| Event Queue Contents (" + std::to_string(_event_queue.size()) + " events)";
192
193 ss << separator << "\n"
194 << std::left << std::setw(separator.length() - 1) << title << "|\n"
195 << separator << "\n"
196 << "| " << std::left << std::setw(12) << "Timestamp" << " | " << std::setw(21) << "Event Type" << " | "
197 << std::setw(25) << "Source Object" << " |\n"
198 << separator << "\n";
199
200 auto queue_copy = _event_queue;
201
202 while (!queue_copy.empty())
203 {
204 const auto [timestamp, event_type, source_object] = queue_copy.top();
205 queue_copy.pop();
206
207 ss << "| " << std::right << std::setw(12) << timestamp << " | " << std::left << std::setw(21)
208 << toString(event_type) << " | " << std::left << std::setw(25) << source_object->getName() << " |\n";
209 }
210 ss << separator << "\n";
211
212 return ss.str();
213 }
std::string toString(const EventType type)
Converts an EventType enum to its string representation.
Definition sim_events.h:72

References core::toString().

+ Here is the call graph for this function:

◆ findAntenna()

Antenna * core::World::findAntenna ( const std::string &  name)

Finds an antenna by name.

Parameters
nameThe name of the antenna to find.
Returns
A pointer to the Antenna if found, or nullptr if not found.

Definition at line 75 of file world.cpp.

76 {
77 return _antennas.contains(name) ? _antennas[name].get() : nullptr;
78 }

Referenced by serial::json_to_world().

+ Here is the caller graph for this function:

◆ findTiming()

PrototypeTiming * core::World::findTiming ( const std::string &  name)

Finds a timing source by name.

Parameters
nameThe name of the timing source to find.
Returns
A pointer to the PrototypeTiming if found, or nullptr if not found.

Definition at line 80 of file world.cpp.

81 {
82 return _timings.contains(name) ? _timings[name].get() : nullptr;
83 }

Referenced by serial::json_to_world().

+ Here is the caller graph for this function:

◆ findWaveform()

RadarSignal * core::World::findWaveform ( const std::string &  name)

Finds a radar signal by name.

Parameters
nameThe name of the radar signal to find.
Returns
A pointer to the RadarSignal if found, or nullptr if not found.

Definition at line 70 of file world.cpp.

71 {
72 return _waveforms.contains(name) ? _waveforms[name].get() : nullptr;
73 }

Referenced by serial::json_to_world().

+ Here is the caller graph for this function:

◆ getAntennas()

const std::unordered_map< std::string, std::unique_ptr< antenna::Antenna > > & core::World::getAntennas ( ) const
noexcept

Retrieves the map of antennas.

Returns
A const reference to the map of antenna names to Antenna objects.

Definition at line 183 of file world.h.

184 {
185 return _antennas;
186 }

Referenced by serial::world_to_json(), and serial::world_to_xml_string().

+ Here is the caller graph for this function:

◆ getEventQueue()

std::priority_queue< Event, std::vector< Event >, EventComparator > & core::World::getEventQueue ( )
noexcept

Gets a mutable reference to the global event queue.

Returns
A reference to the priority queue of events.

Definition at line 219 of file world.h.

220 {
221 return _event_queue;
222 }

Referenced by core::runEventDrivenSim().

+ Here is the caller graph for this function:

◆ getPlatforms()

const std::vector< std::unique_ptr< radar::Platform > > & core::World::getPlatforms ( ) const
noexcept

Retrieves the list of platforms.

Returns
A const reference to a vector of unique pointers to Platform objects.

Definition at line 133 of file world.h.

134 {
135 return _platforms;
136 }

Referenced by serial::world_to_json(), and serial::world_to_xml_string().

+ Here is the caller graph for this function:

◆ getReceivers()

const std::vector< std::unique_ptr< radar::Receiver > > & core::World::getReceivers ( ) const
noexcept

Retrieves the list of radar receivers.

Returns
A const reference to a vector of unique pointers to Receiver objects.

Definition at line 153 of file world.h.

154 {
155 return _receivers;
156 }

Referenced by simulation::calculatePreviewLinks(), serial::KmlGenerator::generateKml(), serial::json_to_world(), core::runEventDrivenSim(), and serial::world_to_json().

+ Here is the caller graph for this function:

◆ getSimulationState()

SimulationState & core::World::getSimulationState ( )
noexcept

Gets a mutable reference to the global simulation state.

Returns
A reference to the SimulationState object.

Definition at line 228 of file world.h.

228{ return _simulation_state; }

Referenced by core::runEventDrivenSim().

+ Here is the caller graph for this function:

◆ getTargets()

const std::vector< std::unique_ptr< radar::Target > > & core::World::getTargets ( ) const
noexcept

Retrieves the list of radar targets.

Returns
A const reference to a vector of unique pointers to Target objects.

Definition at line 143 of file world.h.

144 {
145 return _targets;
146 }

Referenced by simulation::calculatePreviewLinks(), serial::KmlGenerator::generateKml(), serial::json_to_world(), core::runEventDrivenSim(), and serial::world_to_json().

+ Here is the caller graph for this function:

◆ getTimings()

const std::unordered_map< std::string, std::unique_ptr< timing::PrototypeTiming > > & core::World::getTimings ( ) const
noexcept

Retrieves the map of timing prototypes.

Returns
A const reference to the map of timing names to PrototypeTiming objects.

Definition at line 193 of file world.h.

194 {
195 return _timings;
196 }

Referenced by serial::world_to_json(), and serial::world_to_xml_string().

+ Here is the caller graph for this function:

◆ getTransmitters()

const std::vector< std::unique_ptr< radar::Transmitter > > & core::World::getTransmitters ( ) const
noexcept

Retrieves the list of radar transmitters.

Returns
A const reference to a vector of unique pointers to Transmitter objects.

Definition at line 163 of file world.h.

164 {
165 return _transmitters;
166 }

Referenced by simulation::calculatePreviewLinks(), serial::KmlGenerator::generateKml(), and serial::world_to_json().

+ Here is the caller graph for this function:

◆ getWaveforms()

const std::unordered_map< std::string, std::unique_ptr< fers_signal::RadarSignal > > & core::World::getWaveforms ( ) const
noexcept

Retrieves the map of radar signals (waveforms).

Returns
A const reference to the map of signal names to RadarSignal objects.

Definition at line 173 of file world.h.

174 {
175 return _waveforms;
176 }

Referenced by serial::world_to_json(), and serial::world_to_xml_string().

+ Here is the caller graph for this function:

◆ operator=() [1/2]

World & core::World::operator= ( const World )
delete

◆ operator=() [2/2]

World & core::World::operator= ( World &&  )
delete

◆ scheduleInitialEvents()

void core::World::scheduleInitialEvents ( )

Populates the event queue with the initial events for the simulation.

This method should be called after all simulation objects have been parsed and added to the world.

Definition at line 98 of file world.cpp.

99 {
100 const RealType sim_start = params::startTime();
101 const RealType sim_end = params::endTime();
102
103 for (const auto& transmitter : _transmitters)
104 {
105 if (transmitter->getMode() == radar::OperationMode::PULSED_MODE)
106 {
107 // Find the first valid pulse time starting from the simulation start time.
108 if (auto start_time = transmitter->getNextPulseTime(sim_start); start_time)
109 {
110 if (*start_time <= sim_end)
111 {
112 _event_queue.push({*start_time, EventType::TX_PULSED_START, transmitter.get()});
113 }
114 }
115 }
116 else // CW_MODE
117 {
118 const auto& schedule = transmitter->getSchedule();
119 if (schedule.empty())
120 {
121 // Legacy behavior: Always on for simulation duration
122 _event_queue.push({sim_start, EventType::TX_CW_START, transmitter.get()});
123 _event_queue.push({sim_end, EventType::TX_CW_END, transmitter.get()});
124 }
125 else
126 {
127 for (const auto& period : schedule)
128 {
129 // Clip periods to simulation bounds
130 const RealType start = std::max(sim_start, period.start);
131 const RealType end = std::min(sim_end, period.end);
132
133 if (start < end)
134 {
135 _event_queue.push({start, EventType::TX_CW_START, transmitter.get()});
136 _event_queue.push({end, EventType::TX_CW_END, transmitter.get()});
137 }
138 }
139 }
140 }
141 }
142
143 for (const auto& receiver : _receivers)
144 {
145 if (receiver->getMode() == radar::OperationMode::PULSED_MODE)
146 {
147 // Schedule the first receive window checking against schedule
148 const RealType nominal_start = receiver->getWindowStart(0);
149 if (auto start = receiver->getNextWindowTime(nominal_start); start && *start < params::endTime())
150 {
151 _event_queue.push({*start, EventType::RX_PULSED_WINDOW_START, receiver.get()});
152 }
153 }
154 else // CW_MODE
155 {
156 const auto& schedule = receiver->getSchedule();
157 if (schedule.empty())
158 {
159 // Legacy behavior: Always on for simulation duration
160 _event_queue.push({params::startTime(), EventType::RX_CW_START, receiver.get()});
161 _event_queue.push({params::endTime(), EventType::RX_CW_END, receiver.get()});
162 }
163 else
164 {
165 for (const auto& period : schedule)
166 {
167 const RealType start = std::max(params::startTime(), period.start);
168 const RealType end = std::min(params::endTime(), period.end);
169 if (start < end)
170 {
171 _event_queue.push({start, EventType::RX_CW_START, receiver.get()});
172 _event_queue.push({end, EventType::RX_CW_END, receiver.get()});
173 }
174 }
175 }
176 }
177 }
178 }
double RealType
Type for real numbers.
Definition config.h:27
@ RX_PULSED_WINDOW_START
A pulsed receiver opens its listening window.
@ TX_CW_START
A continuous-wave transmitter starts transmitting.
@ TX_CW_END
A continuous-wave transmitter stops transmitting.
@ TX_PULSED_START
A pulsed transmitter begins emitting a pulse.
@ RX_CW_END
A continuous-wave receiver stops listening.
@ RX_CW_START
A continuous-wave receiver starts listening.
RealType endTime() noexcept
Get the end time for the simulation.
Definition parameters.h:97
RealType startTime() noexcept
Get the start time for the simulation.
Definition parameters.h:91
@ PULSED_MODE
The component operates in a pulsed mode.

References params::endTime(), radar::PULSED_MODE, core::RX_CW_END, core::RX_CW_START, core::RX_PULSED_WINDOW_START, params::startTime(), core::TX_CW_END, core::TX_CW_START, and core::TX_PULSED_START.

Referenced by serial::json_to_world().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

The documentation for this class was generated from the following files: