ModelSpace
Documentation for ModelSpace models and classes.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
VisualsModel.h
Go to the documentation of this file.
1 /******************************************************************************
2 * Copyright (c) ATTX LLC 2024. All Rights Reserved.
3 *
4 * This software and associated documentation (the "Software") are the
5 * proprietary and confidential information of ATTX, LLC. 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, LLC.
15 ******************************************************************************/
16 /*
17 Visuals model header file
18 
19 Author: Alex Reynolds
20 */
21 
22 #ifndef SIMULATION_VISUALS_MODEL_H
23 #define SIMULATION_VISUALS_MODEL_H
24 
25 #include <string>
26 #include <map>
27 #include <set>
28 #include <fstream>
29 
31 #include "frames/Frame.h"
32 #include "dynamics/Quaternion.h"
33 #include "locations.h"
34 #include "flight/App.h"
35 #include "core/mathmacros.h"
36 
37 namespace modelspace {
38 
39  class RateMonitor;
40  class SimulationExecutive;
41  class GroundStationModel;
42 
54  class VisualsModel : public cfspp::App {
55  public:
56  // Model params
57  // NAME TYPE DEFAULT VALUE
61  SIGNAL(planet_frame, Frame*, nullptr)
63  SIGNAL(sc_rate, clockwerk::Time, clockwerk::Time(100, 0))
65  SIGNAL(gs_rate, clockwerk::Time, clockwerk::Time(1, 0))
67  SIGNAL(lead_time, clockwerk::Time, clockwerk::Time(5400, 0))
69  SIGNAL(trail_time, clockwerk::Time, clockwerk::Time(5400, 0))
72  SIGNAL(run_cesium_app, int, 1)
74  SIGNAL(max_range, double, 10000.0)
76  SIGNAL(max_range_rate, double, 1000.0)
78 
79  // Model inputs
80  // NAME TYPE DEFAULT VALUE
82 
84 
85  // Model outputs
86  // NAME TYPE DEFAULT VALUE
88 
90 
94  int addFrame(Frame* new_frame_ptr, const std::string& visual_model_dir = "");
95 
99  int addGroundStation(clockwerk::GraphTreeObject* new_gs_ptr);
100 
106  int addLink(const std::string& link_name, Frame* primary_sc_ptr, Frame* secondary_sc_ptr);
107 
112  int addSecondarySpacecraft(const std::string& link_name, Frame* secondary_sc_ptr);
113 
114  // Model-specific implementations of startup and derivative
115  VisualsModel(cfspp::FlightExecutive &e, const std::string &m_name="visuals_model");
116  virtual ~VisualsModel();
117 
119  protected:
120  int16 start() override;
121  int16 execute() override;
122 
123  struct RelMotion {
126  double range;
127  double range_rate;
128  };
129 
134  RelMotion computeRelativeMotion(Frame* primary_ptr, Frame* secondary_ptr);
135 
136  bool _data_written = false;
137 
139  void _runAppProcess();
140 
144  std::string _slurpFile(std::ifstream& in);
145 
147  void _writeCzmlFile();
148 
151 
153  std::ofstream _fout;
154 
156  std::string _sim_start_time;
157 
158  // Set of vectors to log tracked spacecraft frames, spacecraft models, spacecraft times, and spacecraft states at those times
159  std::vector<Frame*> _sc_frames;
160  std::vector<std::string> _sc_frame_models;
161  std::vector<double> _sc_times;
162  std::vector<std::vector<CartesianVector3>> _sc_positions;
163  std::vector<std::vector<clockwerk::Quaternion>> _sc_attitudes;
165  RateMonitor* _sc_rate_monitor; // Controls the rate of SC logging
166 
167  // Set of vectors to log ground station states
168  std::vector<GroundStationModel*> _gs_models;
169  std::vector<std::vector<std::string>> _gs_sign_times_et; // Vector of times when GS visibility changed. Must include zero time
170  std::vector<std::vector<bool>> _gs_sign_after_time; // Vector of GS visibility signs after corresponding entry in _gs_sign_times_et
171  // with true = visible and false = not visible
172  RateMonitor* _gs_rate_monitor; // Controls the rate of GS logging
173 
174  // Set of vectors to log linkages between spacecraft
175  std::vector<std::string> _link_names;
176  std::vector<Frame*> _primary_frames;
177  std::map<std::string, std::vector<Frame*>> _secondary_frames;
178  std::map<std::string, std::map<Frame*, std::vector<std::string>>> _sc_link_times_et_secondary;
179  std::map<std::string, std::map<Frame*, std::vector<bool>>> _sc_link_after_time_secondary;
180  };
181 }
182 
183 #endif
#define START_PARAMS
Definition: appmacros.h:42
#define END_OUTPUTS
Definition: appmacros.h:33
#define END_PARAMS
Definition: appmacros.h:47
#define START_OUTPUTS
Definition: appmacros.h:28
#define END_INPUTS
Definition: appmacros.h:40
#define START_INPUTS
Definition: appmacros.h:35
Base app class for derived implementation.
Definition: App.h:55
GraphTreeObject(const char *gt_nme="", GraphTreeObject **storage_array=nullptr, uint32 storage_size=0)
Name-based constructor for GraphTreeObject which will have no children by default.
Definition: GraphTreeObject.cpp:23
Frame class definition.
Definition: Frame.h:96
Implementation of the executive class for simulation.
Definition: SimulationExecutive.h:62
Class for managing ModelSpace visuals.
Definition: VisualsModel.h:54
std::vector< std::string > _sc_frame_models
Definition: VisualsModel.h:160
std::string _sim_start_time
Ephemeris time of simulation start.
Definition: VisualsModel.h:156
int addLink(const std::string &link_name, Frame *primary_sc_ptr, Frame *secondary_sc_ptr)
Create a link between two spacecraft (one primary and one secondary) for logging.
Definition: VisualsModel.cpp:130
bool _data_written
Definition: VisualsModel.h:136
SimulationExecutive * _smex
Handle to the simulation executive – should be used in place of exc.
Definition: VisualsModel.h:150
std::string _slurpFile(std::ifstream &in)
Load an entire file into a std::string.
Definition: VisualsModel.cpp:366
std::map< std::string, std::map< Frame *, std::vector< std::string > > > _sc_link_times_et_secondary
Definition: VisualsModel.h:178
std::vector< std::vector< std::string > > _gs_sign_times_et
Definition: VisualsModel.h:169
void forceWrite()
Definition: VisualsModel.h:118
RateMonitor * _gs_rate_monitor
Definition: VisualsModel.h:172
std::map< std::string, std::vector< Frame * > > _secondary_frames
Definition: VisualsModel.h:177
std::vector< std::vector< clockwerk::CartesianVector< 3 > > > _sc_positions
Definition: VisualsModel.h:162
int addGroundStation(clockwerk::GraphTreeObject *new_gs_ptr)
Add gs to visuals for logging.
Definition: VisualsModel.cpp:108
std::vector< double > _sc_times
Definition: VisualsModel.h:161
void _runAppProcess()
Kick off the python server application.
Definition: VisualsModel.cpp:330
std::vector< GroundStationModel * > _gs_models
Definition: VisualsModel.h:168
std::vector< Frame * > _sc_frames
Definition: VisualsModel.h:159
RelMotion computeRelativeMotion(Frame *primary_ptr, Frame *secondary_ptr)
Compute the relative motion between two frames.
Definition: VisualsModel.cpp:238
int addFrame(Frame *new_frame_ptr, const std::string &visual_model_dir="")
Add frame to visuals for logging.
Definition: VisualsModel.cpp:89
std::ofstream _fout
Stream variable to write file to.
Definition: VisualsModel.h:153
clockwerk::CartesianVector< 3 > _pos_f_planet_frame
Definition: VisualsModel.h:164
std::vector< std::string > _link_names
Definition: VisualsModel.h:175
RateMonitor * _sc_rate_monitor
Definition: VisualsModel.h:165
std::map< std::string, std::map< Frame *, std::vector< bool > > > _sc_link_after_time_secondary
Definition: VisualsModel.h:179
int16 start() override
Definition: VisualsModel.cpp:167
std::vector< std::vector< clockwerk::Quaternion > > _sc_attitudes
Definition: VisualsModel.h:163
void _writeCzmlFile()
Write out CZML file once all model stuff is done.
Definition: VisualsModel.cpp:372
std::vector< Frame * > _primary_frames
Definition: VisualsModel.h:176
std::vector< std::vector< bool > > _gs_sign_after_time
Definition: VisualsModel.h:170
int addSecondarySpacecraft(const std::string &link_name, Frame *secondary_sc_ptr)
Add a secondary spacecraft to an existing link.
Definition: VisualsModel.cpp:152
int16 execute() override
Definition: VisualsModel.cpp:247
#define CartesianVector3
Definition: mathmacros.h:42
Definition: DeadReckon.cpp:20
Definition: CircularBuffer.hpp:28
Class to propagate CR3BP dynamics in characteristic units.
Definition: statistics.hpp:22
SIGNAL(_mu, double, cfspp::earth_wgs84.mu)
Definition: VisualsModel.h:123
clockwerk::CartesianVector< 3 > rel_position
Definition: VisualsModel.h:124
double range_rate
Definition: VisualsModel.h:127
clockwerk::CartesianVector< 3 > rel_velocity
Definition: VisualsModel.h:125
double range
Definition: VisualsModel.h:126