Joint programming practice of STK and VC++ (the fourth round: inserting satellite objects from TLE data)

For how to insert satellite objects based on TLE data in STK, see my other article:

Insert satellite objects based on TLE data in STK9 .

This palindrome explores how to insert satellite objects from TLE data directly through VC++ programming using the example codes and interfaces provided by STK.

Pre-analysis:

According to the preliminary study of STK, when adding a satellite object, STK first creates a satellite object, which can do nothing (no settings), and the object at this time is an empty object (only name, no related configuration parameters), intuitive The result is that there will be no corresponding objects displayed in the 2D and 3D window, indicating that STK has not yet performed (the orbit related to the satellite) calculation. This is different from other objects. For example, adding ground facilities does not require object attribute configuration (such as the latitude and longitude settings of ground facilities). A ground facility object will be added at the current default position in the scene and displayed in the 2D and 3D scenes at the same time.

After you have an empty satellite object, you should continue to use the attribute configuration window of the satellite object or the satellite orbit wizard tool to further configure the related attributes of the satellite, such as the number of orbital hexadecimals, the type of orbit predictor, etc. After confirming the relevant operations, STK The orbit calculation will be performed according to the current settings. It should be (personal judgment) to cache the calculation results first, and the subsequent animation simulation or display is just a process of looking up the table, so it will feel smoother during the simulation.

When we update and confirm the properties of the object during the animation (simulation), the display of the 2D and 3D windows will be obviously stuck. The possible reason is that STK is calculating according to the latest changes and updating the corresponding data in the background. .

As mentioned above, the satellite can be configured in two ways, one is through the object properties window , including the 'Basic/basic' property of the satellite object, as well as 2D and 3D graphics (display) properties, constraints (Constraints), RF, DIS and other attribute configurations. In the basic attribute configuration, the user is provided to select the type of orbit predictor , and then further parameter configuration is performed according to the type of orbit predictor; the other is to configure through the orbit wizard (Orbit Wizard), and the user is provided to choose at this time Satellite orbit type, such as circular orbit (Circle), geosynchronous orbit (Geosynchronous), etc.

In STK’s operation of inserting satellites from TLE data, it is first necessary to read in TLE data (from the TLE data file) and satellite objects contained in the list data. After the user selects the relevant object from the list, click OK, and the object is added to the scene.

There is a problem here is the simulation time and satellite ephemeris time , TLE data gives the data of each satellite object at a certain moment, and the simulation time of the scene is specified by the user when creating a new scene, and adding multiple TLE data When objects are used, their TLE data moments (satellite ephemeris) may be different. When STK adds objects to the scene to perform calculations, (personal guess) it should be adjusted according to each time.

Therefore, if you analyze the TLE data by yourself, calculate and obtain relevant orbital parameters, and then use the classic orbital parameter method (such as the sample project Events given by STK) to add satellite objects, you need to solve the problem of conversion between simulation time and satellite ephemeris time . I am a non-professional person, it is better to see if STK provides relevant interfaces.

TLE data files are used with the SGP4 orbit predictor, so let's start with the SGP4 orbit predictor.

// Note: file agstkobjects.tlh, line 31327 begins to define, omitting unnecessary information analyzed in this article

IAgVePropagatorSGP4 : IAgVePropagator

{

    // properties

    _variant_t StartTime;

    _variant_t StopTime;

    double Step;

    IAgVeSGP4SegmentCollectionPtr Segments;

    VARIANT_BOOL UseScenarioAnalysisTime;

    VARIANT_BOOL AutoUpdateEnabled;            // Whether to automatically update according to the TLE data source

    IAgVeSGP4AutoUpdatePtr AutoUpdate;         // Auto update settings

    IAgVePropagatorSGP4CommonTasksPtr CommonTasks// Get Segments from TLE source

    IAgVeSGP4PropagatorSettingsPtr Settings ;     // SGP4 predictor settings

    // method

    HRESULT Propagate();

    _variant_t GetStartTime ( );

    void PutStartTime (const _variant_t & pVal );

    _variant_t GetStopTime ( );

    void PutStopTime (const _variant_t & pVal );

    double GetStep ( );

    void PutStep (double pVal );

    IAgVeSGP4SegmentCollectionPtr GetSegments ( );

    VARIANT_BOOL GetUseScenarioAnalysisTime ( );

    void PutUseScenarioAnalysisTime ( VARIANT_BOOL pRetVal );

    VARIANT_BOOL GetAutoUpdateEnabled ( );

    void PutAutoUpdateEnabled (VARIANT_BOOL pRetVal );

    IAgVeSGP4AutoUpdatePtr GetAutoUpdate ( );

    IAgVePropagatorSGP4CommonTasksPtr GetCommonTasks ( );

    IAgVeSGP4PropagatorSettingsPtr GetSettings ( );

};

除了一目了然的属性外,另外有三个属性:

  1. IAgVeSGP4SegmentCollectionPtr Segments;
  2. IAgVePropagatorSGP4CommonTasksPtr CommonTasks;
  3. IAgVeSGP4PropagatorSettingsPtr Settings

以及,一个方法:

  1. Propagatet()    // 执行轨道计算

为清晰起见,利用VS2017集成编译环境提供的‘转到定义’功能,将SGP4轨道预报器相关的STK COM接口对象及属性画出来,如下图:

图中标记了小红旗的为关键属性或方法,分析如下:

SGP4预报器有两个重要属性:

  1. IAgVeSGP4SegmentCollectionPtr Segments
  2. IAgVePropagatorSGP4CommonTasksPtr CommonTasks

其中,Segments包含了当前有效的所有TLE对象(在SGP4接口类中称为‘Segment’)的集合,Segments有一个属性为IAgVeSGP4SegmentPtr Item[],那个‘Item[]’应该就是TLE对象数组,该接口类另外提供了一个接口类IAgVeSGP4LoadFile支持从TLE文件加载TLE对象(Segments)。

CommonTasks属性对象则另外提供了加载TLE对象的方法,即:AddSegsFromFile(),个人感觉通过该方法加入的Segments也保存在了SegmentCollection集合中。

开始尝试!

1、下载TLE数据

参考本人之前一篇文章‘STK9中根据TLE数据插入卫星对象’,下载中国空间站轨道参数,另存为文本文件,如下图:

2、定制界面

如下图,增加一个操作按钮,当新建场景后,允许通过TLE数据文件插入卫星对象。

3、定制按钮点击事件代码,如下:

如果对各文件(例如***Dlg.cpp, ***Helper.cpp)不熟悉,请参见本系列之前文章。

// ***Dlg.cpp

// 通过TLE数据文件插入卫星对象,统一起见,均通过Helper执行实际的操作

 void CEventsDlg::OnBnClickedAddtle()

 {

     try

     {

         CObjectModelHelper helper;

         helper.LoadTLE(m_pRoot);

     }

     catch (_com_error& err)

     {

         ReportComError(err);

     }

     UpdateDisplayState();

 }

// ObjectModelHelper.cpp

// 由TLE数据(文件)添加卫星对象

void CObjectModelHelper::LoadTLE(STKObjects::IAgStkObjectRootPtr pRoot)

{

    _bstr_t                   bstrName;

    _bstr_t                   bstrSSCNum;

    _bstr_t                   bstrTLEFile;

    IAgStkObjectPtr           pNewObj;     // STK Object

    IAgSatellitePtr           pSat;        // STK卫星对象

    IAgVePropagatorSGP4Ptr    pSGP4Prop;   // SGP4轨道预报器

    IAgVeSGP4SegmentCollectionPtr segments; // TLE对象集合

    IAgVeSGP4LoadFilePtr   pSGP4LoadFile;

    SAFEARRAY*                pArray = NULL;

    // 确保首先执行了 NewScenario 操作

    ASSERT(pRoot != NULL);

    // 参照STK的示例代码,首先获取当前场景,通过当前场景新增一个卫星对象

    bstrName = "TianGong";

    pNewObj = pRoot->GetCurrentScenario()->GetChildren()->New(eSatellite, bstrName);

    pSat = pNewObj;

    // 设置轨道预报器:SGP4。注:STK给的对外接口中定义了 15 种轨道预报器

    pSat->SetPropagatorType(ePropagatorSGP4);

    pSGP4Prop = pSat->Propagator;

    // TLE数据

    bstrSSCNum = "48274"; // 卫星编号,TLE轨道数据第1行以及第2行第03-07列(通常为5位数字)

    bstrTLEFile = "D:\\tledata_TianGong_220406.txt";

    // 加载TLE数据,方法一:由CommonTask加入

    // 此方法加入数据后,SGP4SegmentCollection会自动生效,即 Segments->Count 不为 0

    if (pSGP4Prop->CommonTasks->AddSegsFromFile(bstrSSCNum, bstrTLEFile) != S_OK) {

        AfxMessageBox("Load TLE data failed!");

        return;

    }

    // 加载TLE数据,方法二:由Segments对象加载

    // 此方法加载数据后,SGP4SegmentCollection的Segments对象不会立刻生效,需要在调用轨道计算方法

    // Propagate()之后才会生效

    //segments = pSGP4Prop->Segments;

    //segments->LoadMethodType = eFileLoad;

    //pSGP4LoadFile = segments->LoadMethod;

    //pSGP4LoadFile->File = bstrTLEFile;

    //pArray = pSGP4LoadFile->GetSegsFromFile(bstrSSCNum);

    // 执行轨道计算(预报器计算,并显示)

    pSGP4Prop->Propagate();

    if (pSGP4Prop->Segments->Count == 0) {

        AfxMessageBox("No valid TLE data loaded!");

    }

}

It has been verified that both methods can successfully add satellite objects through TLE data, and the effect is as follows:

Topics to continue exploring:

  1. As can be seen from the figure above, the satellite orbit drawn in the 3D window is obviously a polygon. How to make it smoother?
  2. Attempt to load multiple satellite objects at once through the TLE data file by using wildcards in SSCNum.
  3. SGP4 forecaster supports automatic update, including online automatic update and automatic update based on local data files, it is worth trying.

Guess you like

Origin blog.csdn.net/wangyulj/article/details/123998028