HLCC Documentation 2.2.0
Loading...
Searching...
No Matches
Public Types | Public Member Functions | List of all members
hlcc::trksim::DataContext Class Reference

#include <dataContext.hpp>

Inheritance diagram for hlcc::trksim::DataContext:

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
 
ConfigGetConfig () override
 
const ConfigGetConfigConst () const
 
void UpdateDb () override
 
OldbInterfaceGetOldbInterface () 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
 
AmbientDataGetAmbientData ()
 
 DataContext (const DataContext &)=delete
 
DataContextoperator= (const DataContext &)=delete
 Disable copy constructor.
 

Detailed Description

This class provide access to the application run-time data including the in-memory DB.

Member Enumeration Documentation

◆ EstimatedState

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.

Enumerator
UNDEFINED 

Initial value, before a state was determined.

Currently unclear if this will also be used for other undefined situations in the future.

STANDING_STILL 

Telescope is standing still (close to alt/az target).

Note that the EstimatedState enum is only applicable when position control is working. Therefore STANDING_STILL means on alt/az target. Other parking or startup positions are not covered by this enum definition.

PRESETTING 

We have a target (ra/dec) and move, but are too far away from the target.

TRACKING 

We have a target (ra/dec) and move, and are close to the target.

MOVING 

We have a target (alt/az) and move, but are too far away from the target to be STANDING_STILL.

Constructor & Destructor Documentation

◆ DataContext() [1/2]

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.

Parameters
[in]oldb_interfaceCan be passed explicitly to use a mock for testing. Otherwise it will be created.

◆ ~DataContext()

hlcc::trksim::DataContext::~DataContext ( )
virtual

Destructor

◆ DataContext() [2/2]

hlcc::trksim::DataContext::DataContext ( const DataContext & )
delete

Member Function Documentation

◆ AddSkyOffset()

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.

◆ EnablePublishing()

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.

Parameters
enabledtrue enables publishing, false disables it (or also when the MS LSV does the publishing instead???)

◆ GetAmbientData()

AmbientData & hlcc::trksim::DataContext::GetAmbientData ( )

Gets ambient data that is relevant for astrometric transformations.

◆ GetConfig()

Config & hlcc::trksim::DataContext::GetConfig ( )
override
Returns
reference to the Config object.

◆ GetConfigConst()

const Config & hlcc::trksim::DataContext::GetConfigConst ( ) const
Returns
const reference to the Config object. This allows having const methods in DataContext that get config parameters.

◆ GetCurrentAltAz()

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).

◆ GetEstimatedState()

DataContext::EstimatedState hlcc::trksim::DataContext::GetEstimatedState ( ) const

Gets the state estimated by activity DoEstimation.

◆ GetOldbInterface()

OldbInterface & hlcc::trksim::DataContext::GetOldbInterface ( )
override
Returns
A reference to the OLDB interface object.

◆ GetPresetData()

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.

◆ GetSitePosition()

PositionOnEarth hlcc::trksim::DataContext::GetSitePosition ( ) const

Gets the configured position of the (ELT) telescope.

◆ GetTargetAltAz()

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.

Parameters
time_taiThe timestamp of the data to retrieve.
Returns
Matching (exact or nearest) or most recent target position, or std::nullopt if no target has been set.

◆ GetTargetAltAzValidity()

bool hlcc::trksim::DataContext::GetTargetAltAzValidity ( ) const

Gets the validity flag for the ALT/AZ target.

See GetTargetAltAz.

◆ GetTargetRaDec()

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.

◆ GetTargetRaDecApparent()

ptk::EquatorialPosition hlcc::trksim::DataContext::GetTargetRaDecApparent ( ) const

Gets the apparent position that corresponds to GetTargetRaDec(), as set in SetTargetRaDecApparent().

◆ GetTargetRaDecValidity()

bool hlcc::trksim::DataContext::GetTargetRaDecValidity ( ) const

Gets the validity flag for the current RA/DEC target.

See GetTargetRaDec.

◆ IsPublishingEnabled()

bool hlcc::trksim::DataContext::IsPublishingEnabled ( ) const

◆ MergeTargetAltAz()

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.

Parameters
alt_azThe new target position, with optional fields.
time_taiThe time (TAI) at which alt_az should be reached. Defaults to ptk::NextTimeEvent().
statsElapsedTimeStat reference
Returns
The new (merged) target position.

◆ operator=()

DataContext & hlcc::trksim::DataContext::operator= ( const DataContext & )
delete

Disable copy constructor.

◆ ReloadConfig()

void hlcc::trksim::DataContext::ReloadConfig ( )
override

Reload the configuration from file.

◆ SetCurrentAltAz()

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).

◆ SetEstimatedState()

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().

◆ SetPresetArgs()

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().

◆ SetTargetAltAz()

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.

Parameters
alt_azThe target position.
statspassed around to collect performance statistics.

◆ SetTargetAltAzToCurrent()

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.

◆ SetTargetAltAzValidity()

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.

◆ SetTargetRaDecApparent()

void hlcc::trksim::DataContext::SetTargetRaDecApparent ( const ptk::EquatorialPosition & pos_apparent)

Sets the calculated apparent position of the commanded RA/DEC target.

◆ SetTargetRaDecValidity()

void hlcc::trksim::DataContext::SetTargetRaDecValidity ( bool is_valid)

Sets the validity flag for the current RA/DEC target.

See GetTargetRaDec, SetTargetRaDec.

◆ UpdateDb()

void hlcc::trksim::DataContext::UpdateDb ( )
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.


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