|
HLCC Documentation 2.2.0
|
#include <dataContext.hpp>
Public Types | |
| enum class | EstimatedState { UNDEFINED , STANDING_STILL , PRESETTING , TRACKING , MOVING } |
Public Member Functions | |
| DataContext (std::shared_ptr< OldbInterface > oldb_interface=nullptr) | |
| virtual | ~DataContext () |
| void | ReloadConfig () override |
| Config & | GetConfig () override |
| const Config & | GetConfigConst () const |
| void | UpdateDb () override |
| OldbInterface & | GetOldbInterface () override |
| void | EnablePublishing (bool enabled) |
| bool | IsPublishingEnabled () const |
| std::shared_ptr< const ::msif::PresetArgs > | GetPresetData () const |
| void | SetPresetArgs (std::shared_ptr< const ::msif::PresetArgs > preset_args) |
| ptk::EquatorialPosition | GetTargetRaDec () const |
| ptk::EquatorialPosition | GetTargetRaDecApparent () const |
| void | SetTargetRaDecApparent (const ptk::EquatorialPosition &pos_apparent) |
| bool | GetTargetRaDecValidity () const |
| void | SetTargetRaDecValidity (bool is_valid) |
| void | AddSkyOffset (ptk::Radians delta_ra, ptk::Radians delta_dec) |
| std::optional< ptk::HorizonPositionEsoTimestamped > | GetTargetAltAz (::taiclock::TaiClock::time_point time_tai=::taiclock::TaiClock::time_point{}) const |
| void | SetTargetAltAz (const ptk::HorizonPositionEsoTimestamped &alt_az, ElapsedTimeStats &stats) |
| void | SetTargetAltAzToCurrent (ElapsedTimeStats &stats) |
| ptk::HorizonPositionEsoTimestamped | MergeTargetAltAz (const AltAzOptional &alt_az, ElapsedTimeStats &stats, ::taiclock::TaiClock::time_point time_tai=ptk::NextTimeEvent()) |
| bool | GetTargetAltAzValidity () const |
| void | SetTargetAltAzValidity (bool is_valid) |
| ptk::HorizonPositionEsoTimestamped | GetCurrentAltAz () const |
| void | SetCurrentAltAz (const ptk::HorizonPositionEsoTimestamped &alt_az) |
| void | SetEstimatedState (EstimatedState state) |
| EstimatedState | GetEstimatedState () const |
| ptk::PositionOnEarth | GetSitePosition () const |
| AmbientData & | GetAmbientData () |
| DataContext (const DataContext &)=delete | |
| DataContext & | operator= (const DataContext &)=delete |
| Disable copy constructor. | |
This class provide access to the application run-time data including the in-memory DB.
|
strong |
Enum for the position/motion state of the telescope, as determined by the DoEstimation activity while the state machine is in the Operational state.
TODO: Refine this enum. What if we do not have any telescope target at all? TODO: Always keep DataContext::EstimatedStateToString impl up to date.
| hlcc::trksim::DataContext::DataContext | ( | std::shared_ptr< OldbInterface > | oldb_interface = nullptr | ) |
This constructor uses the application configuration to initialize the adapter object to the in-memory DB.
| [in] | oldb_interface | Can be passed explicitly to use a mock for testing. Otherwise it will be created. |
|
virtual |
Destructor
|
delete |
| void hlcc::trksim::DataContext::AddSkyOffset | ( | ptk::Radians | delta_ra, |
| ptk::Radians | delta_dec ) |
Adds a sky offset to the target RA/DEC that was commanded by a previous call to SetPresetArgs.
| void hlcc::trksim::DataContext::EnablePublishing | ( | bool | enabled | ) |
Normally methods of DataContext write to the OLDB, or also publish data on channels. This method allows controlling this behavior, e.g. for unit tests.
| enabled | true enables publishing, false disables it (or also when the MS LSV does the publishing instead???) |
| AmbientData & hlcc::trksim::DataContext::GetAmbientData | ( | ) |
Gets ambient data that is relevant for astrometric transformations.
| const Config & hlcc::trksim::DataContext::GetConfigConst | ( | ) | const |
| HorizonPositionEsoTimestamped hlcc::trksim::DataContext::GetCurrentAltAz | ( | ) | const |
Gets the current (actual) ALT/AZ position.
For its validity, check GetTargetAltAzValidity. The timestamp refers to the beginning of the time interval (TE_i) in which the value was simulated (i.e. the measurement was taken).
| DataContext::EstimatedState hlcc::trksim::DataContext::GetEstimatedState | ( | ) | const |
Gets the state estimated by activity DoEstimation.
|
override |
| std::shared_ptr< const::msif::PresetArgs > hlcc::trksim::DataContext::GetPresetData | ( | ) | const |
Gets a const view of the PresetData set in SetPresetArgs.
For its validity, check GetTargetRaDecValidity.
TODO: If needed, expose the full PresetArgs struct, not just the PresetData child.
| PositionOnEarth hlcc::trksim::DataContext::GetSitePosition | ( | ) | const |
Gets the configured position of the (ELT) telescope.
| std::optional< ptk::HorizonPositionEsoTimestamped > hlcc::trksim::DataContext::GetTargetAltAz | ( | ::taiclock::TaiClock::time_point | time_tai = ::taiclock::TaiClock::time_point{} | ) | const |
Gets the ALT/AZ target that matches the given timestamp either exactly, or otherwise the closest match.
If this method gets called before SetTargetAltAz or UpdateDb has been called, it returns std::nullopt.
If no timestamp is given (parameter time_tai defaulting to time 0), then the data with the latest timestamp gets returned. It is up to the client to verify the timestamp of the target, and to dismiss it if needed.
For target validity, check GetTargetAltAzValidity.
The timestamp refers to the time when the target should be reached. When presetting/tracking, the control loop calculates and inserts (SetTargetAltAz) targets for 100 ms in the future. The control loop always consumes targets for the current loop time, which is either a static target in case of commanded move, or the dynamic target it calculated two loop iterations (100 ms) before.
| time_tai | The timestamp of the data to retrieve. |
| bool hlcc::trksim::DataContext::GetTargetAltAzValidity | ( | ) | const |
Gets the validity flag for the ALT/AZ target.
See GetTargetAltAz.
| EquatorialPosition hlcc::trksim::DataContext::GetTargetRaDec | ( | ) | const |
Gets the current RA/DEC target (mean coordinates).
This is a convenience access (with type conversion) to the data returned by GetPresetData.
For its validity, check GetTargetRaDecValidity.
| ptk::EquatorialPosition hlcc::trksim::DataContext::GetTargetRaDecApparent | ( | ) | const |
Gets the apparent position that corresponds to GetTargetRaDec(), as set in SetTargetRaDecApparent().
| bool hlcc::trksim::DataContext::GetTargetRaDecValidity | ( | ) | const |
Gets the validity flag for the current RA/DEC target.
See GetTargetRaDec.
| bool hlcc::trksim::DataContext::IsPublishingEnabled | ( | ) | const |
| ptk::HorizonPositionEsoTimestamped hlcc::trksim::DataContext::MergeTargetAltAz | ( | const AltAzOptional & | alt_az, |
| ElapsedTimeStats & | stats, | ||
| ::taiclock::TaiClock::time_point | time_tai = ptk::NextTimeEvent() ) |
DEPRECATED. We no longer move ALT and AZ separately. Use SetTargetAltAz instead. We only keep this method just in case the strategy may change again.
Merges the optional ALT or AZ components into the best matching one of the existing target positions, and also merges the timestamp time_tai to that target.
This is needed because the ICD allows to set ALT and AZ separately.
Of all timestamped ALT/AZ target positions, it selects the one closest to time_tai for merging. Newer entries (more recent timestamps than that of alt_az) in the map get deleted, so that there cannot be timestamp-based confusion about the target.
| alt_az | The new target position, with optional fields. |
| time_tai | The time (TAI) at which alt_az should be reached. Defaults to ptk::NextTimeEvent(). |
| stats | ElapsedTimeStat reference |
|
delete |
Disable copy constructor.
|
override |
Reload the configuration from file.
| void hlcc::trksim::DataContext::SetCurrentAltAz | ( | const ptk::HorizonPositionEsoTimestamped & | alt_az | ) |
Set current position for the axes.
The timestamp refers to the beginning of the time interval (TE_i) in which the value was simulated (i.e. the measurement was taken).
| void hlcc::trksim::DataContext::SetEstimatedState | ( | EstimatedState | state | ) |
Sets the estimated state.
This method is called directly by activity DoEstimation, before it sends the internal NewEstimation event. When processing the NewEstimation event, the state machine's guard actions determine possible transitions, based on this state (and partly also on the current SM state).
Only after the SM transition, the new state gets written to OLDB by the SM callback in main().
| void hlcc::trksim::DataContext::SetPresetArgs | ( | std::shared_ptr< const ::msif::PresetArgs > | preset_args | ) |
Sets the full description of the sidereal Preset. The embedded RA/DEC target can then be retrieved separately using GetTargetRaDec().
| void hlcc::trksim::DataContext::SetTargetAltAz | ( | const ptk::HorizonPositionEsoTimestamped & | alt_az, |
| ElapsedTimeStats & | stats ) |
Sets the target position with the corresponding timestamp, and publishes the data.
Called by the control loop to advance the position when presetting or tracking. The timestamp refers to the time (beginning of interval) when the target should be reached.
When commanding moves, the meaning is different: the telescope moves at fixed speed, so that the timestamp only means that the target is currently valid, but does not mean that it should be reached at that timestamp.
It is OK to insert data with a future timestamp. However, due to the internal cleanup mechanism, only data less than 1 s in the future should be inserted to not lose current data.
Newer entries (more recent timestamps than that of alt_az) in the map get deleted, so that there cannot be timestamp-based confusion about the target.
| alt_az | The target position. |
| stats | passed around to collect performance statistics. |
| void hlcc::trksim::DataContext::SetTargetAltAzToCurrent | ( | ElapsedTimeStats & | stats | ) |
Sets the target position to the current value (as obtained by calling GetCurrentAltAz).
The new target position has the same timestamp as the current position. All other target positions, newer or older, get deleted.
| void hlcc::trksim::DataContext::SetTargetAltAzValidity | ( | bool | is_valid | ) |
Sets the validity flag for the current ALT/AZ target.
Note that calling SetTargetAltAz will set the validity to true, so that this method is mostly needed to set validity to false.
| void hlcc::trksim::DataContext::SetTargetRaDecApparent | ( | const ptk::EquatorialPosition & | pos_apparent | ) |
Sets the calculated apparent position of the commanded RA/DEC target.
| void hlcc::trksim::DataContext::SetTargetRaDecValidity | ( | bool | is_valid | ) |
Sets the validity flag for the current RA/DEC target.
See GetTargetRaDec, SetTargetRaDec.
|
override |
Try to connect to the DB and write the application configuration to the OLDB.
Initially called by rad::Application::Init. Later also called by, e.g., ActionsApp::SetConfig.
We initialize the telescope position with the value from OLDB, reflecting a previous run. The target pos also gets initialized to the current pos so that the telescope initially stands still.
rad::Application::Init calls only DataContext::UpdateDb, but no other, more suitable, init method of DataContext. Note that in the ctor of DataContext, Config is not yet initialized and thus we cannot use OldbInterface yet.