WarpTwin
Documentation for WarpTwin models and classes.
Loading...
Searching...
No Matches
SimulationExecutive.h
Go to the documentation of this file.
1/******************************************************************************
2* Copyright (c) ATTX INC 2025. All Rights Reserved.
3*
4* This software and associated documentation (the "Software") are the
5* proprietary and confidential information of ATTX INC. The Software is
6* furnished under a license agreement between ATTX and the user organization
7* and may be used or copied only in accordance with the terms of the agreement.
8* Refer to 'license/attx_license.adoc' for standard license terms.
9*
10* EXPORT CONTROL NOTICE: THIS SOFTWARE MAY INCLUDE CONTENT CONTROLLED UNDER THE
11* INTERNATIONAL TRAFFIC IN ARMS REGULATIONS (ITAR) OR THE EXPORT ADMINISTRATION
12* REGULATIONS (EAR99). No part of the Software may be used, reproduced, or
13* transmitted in any form or by any means, for any purpose, without the express
14* written permission of ATTX INC.
15******************************************************************************/
16/*
17Simulation Executive header file
18
19Author: Alex Reynolds
20*/
21#ifndef SIMULATION_SIMULATION_EXECUTIVE_H
22#define SIMULATION_SIMULATION_EXECUTIVE_H
23
25#include "frames/Frame.h"
31#include "logging/LogManager.h"
32#include "logging/CsvLogger.h"
34#include "utils/spiceutils.h"
35#include "SimLinux.h"
36#include "SimPlatform.h"
37#include "SimSetup.h"
38#include "flight/Scheduler.h"
39
40namespace warptwin {
41 class TimeTriggerMonitor;
42 class SimTerminationEvent;
43
65 public:
69
74 int parseArgs(int argc, char *argv[]);
75
79 int parseArgs(std::vector<std::string> arguments);
80
82 void integrator(int val) {_sim_scheduler.params.integrator_type(val);}
83 int integrator() {return _sim_scheduler.params.integrator_type();}
84
87 void setRateHz(unsigned int rate_hz);
88
91 void setRateSec(clockwerk::Time rate_sec);
92 void setRateSec(struct timespec rate_sec);
93 void setRateSec(double rate_sec);
94
97 void end(clockwerk::Time end_time);
98 void end(struct timespec end_time);
99 void end(double end_time);
100
104
108 int16 startup();
109
112 int16 step();
113
117 int16 step(const clockwerk::Time &step_size);
118
121 int16 run();
122
125 clockwerk::Time rate() {return _sim_scheduler.inputs.rate();}
126
129
136 std::vector<std::string> search(const std::string &s_val);
137
143 std::vector<std::string> searchFrameTree(const std::string &s_val);
144
150 std::vector<std::string> searchSimTree(const std::string &s_val);
151
154
157
160
162 void enableVisuals();
163
166 void disableVisuals();
167
170 bool visualsEnabled() {return _visuals_model != nullptr;}
171
174 unsigned int runNumber() {return _run_num;}
175
178 void runNumber(unsigned int run_num) {_run_num = run_num;}
179
183
187
191
194 double simTime() {return time().base_time().asFloatingPoint();}
195
199
206 void setTime(const std::string &time_in) {time().setTime(time_in);}
207
210 bool started() {return _started;}
211
213 bool isTerminated() {return _scheduler.isTerminated();}
214
216 void terminate() {_scheduler.terminate();}
217
220 void writeSimDataToJson(const std::string &filename);
221
227 int registerApp(warpos::App& app, int16 slot) {return _sim_scheduler.registerApp(app, slot);}
228
234
239 void setWarpLinkInterface(std::string ip="127.0.0.1", uint32 tlm_port=5005, uint32 cmd_port=5006)
240 {_sim_setup.setWarpLinkInterface(ip, tlm_port, cmd_port);}
241
247 void connectExternalSocket(clockwerk::DataIOBase& signal, std::string mode,
248 const std::string &ip, int port)
249 {_sim_scheduler.connectExternalSocket(signal, mode, ip, port);}
250
256 const std::string shmem_address)
257 {_sim_scheduler.connectExternalSharedMemory(signal, mode, shmem_address);}
258 protected:
261 void _configLogEverything(const std::string &filename);
262
265
267 void _printSimInfo();
268
271
274 int _rng_seed = 0;
275
277 unsigned int _run_num = 0;
278
286
291
294
296 // NOTE: We have to allocate on the heap here due to the fact that these are
297 // now models.
298 TimeTriggerMonitor* _term_monitor;
299 SimTerminationEvent* _term_event;
300
303
306 bool _real_time_mode = false;
307
310
313 bool _started = false;
314
316 unsigned long long _step_count = 0;
317
318 CsvLogger* _all_log = nullptr;
319
320 // Placeholder variables for OS, Platform, Setup, which are required by flight executive
321 // but not currently used in sim executive
322 SimLinux _sim_os;
323 SimPlatform _sim_platform;
324 SimSetup _sim_setup;
325
326 // Internal reference to simulation executive itself for logging
328 };
329
330}
331
332#endif
Definition DataIOBase.h:63
Wrapper to manage and convert time as timespce.
Definition Time.h:53
Base app class for derived implementation.
Definition App.h:55
Executive derivation specifically to run flight systems.
Definition FlightExecutive.h:46
warpos::Scheduler & _scheduler
System schedule, which determines what apps and functions run when.
Definition FlightExecutive.h:144
Class to parse arguments from the command line in any language.
Definition ArgParser.h:32
Class for logging to CSV.
Definition CsvLogger.h:35
Class to generate input dispersions for the simulation.
Definition DispersionEngine.h:76
Frame class definition.
Definition Frame.h:96
Class to manage logs.
Definition LogManager.h:41
Simple implementation of the scheduler class.
Definition SimScheduler.h:49
Class to manage time for the simulation object.
Definition SimTimeManager.h:70
clockwerk::DataIO< clockwerk::Time > base_time
This is the exact current time as the scheduler steps forward.
Definition SimTimeManager.h:152
void setTime(const std::string &time_input=DEFAULT_SIMULATION_TIME)
Function to set time by string input.
Definition SimTimeManager.cpp:193
double simTime()
Function to access sim time.
Definition SimulationExecutive.h:194
int16 run()
Function to execute run for the executive and its kids /.
Definition SimulationExecutive.cpp:266
SimScheduler _sim_scheduler
Definition SimulationExecutive.h:290
void enableVisuals()
Function to enable visuals for the simulation.
Definition SimulationExecutive.cpp:302
void disableVisuals()
Function to disable visuals for the simulation.
Definition SimulationExecutive.cpp:315
warptwin::SpiceManager & spiceManager()
Function to return pointer to the spice manager.
Definition SimulationExecutive.h:198
void _configureFromCmdLine()
Function to configure simulation executive from command line input.
Definition SimulationExecutive.cpp:108
int _rng_seed
Definition SimulationExecutive.h:274
warptwin::LogManager & logManager()
Getter for the log manager.
Definition SimulationExecutive.h:153
TimeTriggerMonitor * _term_monitor
Monitor and event to terminate sim run.
Definition SimulationExecutive.h:298
std::vector< std::string > search(const std::string &s_val)
Function to search the simulation and frame trees for a match.
Definition SimulationExecutive.cpp:365
bool isTerminated()
Get whether scheduler is terminated.
Definition SimulationExecutive.h:213
bool _real_time_mode
Definition SimulationExecutive.h:306
warptwin::DispersionEngine & dispersions()
Function to access dispersions.
Definition SimulationExecutive.h:186
void integrator(int val)
Functions to set and get our integrator.
Definition SimulationExecutive.h:82
void setTime(const std::string &time_in)
Function to set time by string input.
Definition SimulationExecutive.h:206
SpiceManager _spice_manager
The spice manager to control all spice interactions.
Definition SimulationExecutive.h:293
SimSetup _sim_setup
Definition SimulationExecutive.h:324
int parseArgs(int argc, char *argv[])
Wrapper around arg parse.
Definition SimulationExecutive.cpp:92
LogManager _log_manager
Definition SimulationExecutive.h:289
unsigned int _run_num
The run number.
Definition SimulationExecutive.h:277
DispersionEngine _dispersion_engine
To generate dispersions for the simulation.
Definition SimulationExecutive.h:273
log_level_e _local_log_level
Our local log level – allows a higher log level locally than the overall system.
Definition SimulationExecutive.h:309
void terminate()
Function to terminate scheduler.
Definition SimulationExecutive.h:216
int integrator()
Definition SimulationExecutive.h:83
int scheduleTelemetry(int apid, clockwerk::Time rate)
Schedule telemetry in the sim.
Definition SimulationExecutive.cpp:404
~SimulationExecutive()
Definition SimulationExecutive.cpp:81
warptwin::SimScheduler & schedule()
Getter for the schedule.
Definition SimulationExecutive.h:156
bool _started
Definition SimulationExecutive.h:313
void connectExternalSocket(clockwerk::DataIOBase &signal, std::string mode, const std::string &ip, int port)
Connect a signal to an external socket.
Definition SimulationExecutive.h:247
std::vector< std::string > searchSimTree(const std::string &s_val)
Function to search the simulation architecture tree for a match.
Definition SimulationExecutive.cpp:380
Frame & rootFrame()
Getter for the simulation root frame.
Definition SimulationExecutive.h:128
SimulationExecutive & exc
Definition SimulationExecutive.h:327
void connectExternalSharedMemory(clockwerk::DataIOBase &signal, std::string mode, const std::string shmem_address)
Connect a signal to an external socket.
Definition SimulationExecutive.h:255
Frame _root_frame
This is our sim's root frame, from which all other frames derive their relationships.
Definition SimulationExecutive.h:285
warptwin::SimTimeManager & time()
Override of time() from executive to return SimTimeManager.
Definition SimulationExecutive.h:190
SimulationExecutive()
Constructor for the simulation executive.
Definition SimulationExecutive.cpp:35
bool started()
Function to return whether the simulation executive is started.
Definition SimulationExecutive.h:210
void setRateSec(clockwerk::Time rate_sec)
Function to set the simulation run rate, in seconds as Time.
Definition SimulationExecutive.cpp:158
void _printSimInfo()
Function to print information associated with the simulation.
Definition SimulationExecutive.cpp:455
void setWarpLinkInterface(std::string ip="127.0.0.1", uint32 tlm_port=5005, uint32 cmd_port=5006)
Set the IP address, telemetry port, and coommand port with WarpLink.
Definition SimulationExecutive.h:239
warptwin::ArgParser & args()
Function to access args.
Definition SimulationExecutive.h:182
int registerApp(warpos::App &app, int16 slot)
Function to register apps with the scheduler. Depending on the scheduler implementation these may be ...
Definition SimulationExecutive.h:227
SimLinux _sim_os
Definition SimulationExecutive.h:322
void _configLogEverything(const std::string &filename)
Configure logger which will log all sim outputs.
Definition SimulationExecutive.cpp:422
clockwerk::Time end()
Function to return simulation end time.
Definition SimulationExecutive.cpp:88
warptwin::VisualsModel & visualsModel()
Getter for the visuals model.
Definition SimulationExecutive.h:159
clockwerk::Time rate()
Function to acces the run rate of the simulation.
Definition SimulationExecutive.h:125
void runNumber(unsigned int run_num)
Setter for run number.
Definition SimulationExecutive.h:178
int16 startup()
Function to initialize our simulation executive and everything it contains.
Definition SimulationExecutive.cpp:319
SimTerminationEvent * _term_event
Definition SimulationExecutive.h:299
std::vector< std::string > searchFrameTree(const std::string &s_val)
Function to search the frame tree for a match.
Definition SimulationExecutive.cpp:376
SimPlatform _sim_platform
Definition SimulationExecutive.h:323
ArgParser _args
To parse our command line arguments.
Definition SimulationExecutive.h:270
unsigned long long _step_count
Variable to track the number of steps the simulation has taken.
Definition SimulationExecutive.h:316
int16 step()
Function to step the scheduler by a single step.
Definition SimulationExecutive.cpp:194
void writeSimDataToJson(const std::string &filename)
Write all simulation data, including models, to json output.
Definition SimulationExecutive.cpp:384
bool visualsEnabled()
Indicator as to whether visuals are enabled.
Definition SimulationExecutive.h:170
unsigned int runNumber()
Getter for run number.
Definition SimulationExecutive.h:174
CsvLogger * _all_log
Definition SimulationExecutive.h:318
void setRateHz(unsigned int rate_hz)
Function to set the simulation run rate, in Hz.
Definition SimulationExecutive.cpp:149
VisualsModel * _visuals_model
Pointer to our visuals manager.
Definition SimulationExecutive.h:302
The Spice Manager is a single class instance to manage spice frames and return SPICE states.
Definition spiceutils.h:49
Class for managing WarpTwin visuals.
Definition VisualsModel.h:55
log_level_e
Log level enumerations.
Definition flighterrors.h:159
@ LOG_INFO
Definition flighterrors.h:163
Class to propagate CR3BP dynamics in characteristic units.
Definition statistics.hpp:22