STK12 and Python co-simulation (2): simple routine

create scene

This article refers to the official website tutorial help
. The last book said that the two ways of creating scenes are actually quite cumbersome. Python can directly start and call the program. First, open the Jupyter notebook
or the regular import

from agi.stk12.stkdesktop import STKDesktop
from agi.stk12.stkobjects import *
from agi.stk12.stkutil import *
from agi.stk12.vgt import *
import os

Then the following code is called to start STK. After running, you can see that STK has started, but there is no scene created at this time, so it is empty

# STK_PID = 40556 
# stk = STKDesktop.AttachToApplication(pid=int(STK_PID))
stk = STKDesktop.StartApplication(visible=True) #using optional visible argument
root = stk.Root
print(type(root))

insert image description here

Next create the scene

scenario  = root.NewScenario('MyNewSc')  # 新建场景

Then STK will automatically create the scene
insert image description here

set scene time

scenario.SetTimePeriod('Today','+24hr') # 开始日期是今天,结束日期是24小时后
# scenario.SetTimePeriod('Today','+160min') # 结束日期是160分钟后
# scenario.SetTimePeriod('Today','+1600sec') # 结束日期是1600秒后
root.Rewind() # 执行后STK会重置时间轴

Another date format
so that you can set the date range you want

scenario.SetTimePeriod("1 Nov 2000 01:02:00.00","1 Nov 2000 03:04:00.00")

That is,
"day", "month" and "year" hour: minute: second

Can display the start and end dates of the current scene

print(scenario.StartTime)
print(scenario.StopTime)

Create some widgets

target = AgTarget(scenario.Children.New(AgESTKObjectType.eTarget,"GroundTarget")) # 地面站
target.Position.AssignGeodetic(50,-100,0) # 地面站位置

The target.Position.AssignGeodetic method, the first parameter is the latitude of lat, the range is [-90,90], the second is the longitude of lon, the range is [-180,180] and the third is the height (elevation), which can be float For example, the latitude
and longitude of Shanghai is (12148,31.25)
and the code is

target.Position.AssignGeodetic(31.25,121.48,0)

The point on the map corresponding to Shanghai
insert image description here
and... I searched for a long time and couldn't find how to delete a target, so let's write it later...

You can add a satellite and specify the parameters of the satellite.
Here is the classic two-body motion model (the first parameter).
The running time of the satellite is consistent with the start time of the scene (the second and third parameters).
Use the 60 ICRF coordinate system (the fourth parameter)
The number of six satellites (fifth parameter)

satellite = AgSatellite(root.CurrentScenario.Children.New(AgESTKObjectType.eSatellite,"LeoSat"))
root.ExecuteCommand('SetState */Satellite/LeoSat Classical TwoBody "' + 
                    str(scenario.StartTime) + '" "' + str(scenario.StopTime) + 
                    '" 60 ICRF "' + str(scenario.StartTime) + '" 7200000.0 0.0 90 0.0 0.0 0.0');
# 依次是 轨道高度 偏心率 倾角  近地点幅角度 升交点赤经 平近点角

computing access

access = satellite.GetAccessToObject(target) # 表示创建的satellite访问target 
access.ComputeAccess(); # 计算访问
accessDP = access.DataProviders.Item('Access Data')
results = accessDP.Exec(scenario.StartTime, scenario.StopTime)
accessStartTimes = results.DataSets.GetDataSetByName('Start Time').GetValues()
accessStopTimes = results.DataSets.GetDataSetByName('Stop Time').GetValues()
print(accessStartTimes,accessStopTimes)

Or in a more intuitive form, it will calculate the number of satellite visits to the ground, the start and end time within the simulation time

access = satellite.GetAccessToObject(target)
accessIntervals = access.ComputedAccessIntervalTimes
dataProviderElements = ['Start Time', 'Stop Time']
for i in range(0,accessIntervals.Count):
    times = accessIntervals.GetInterval(i)
    print(times)

insert image description here
Then, STK will emulate the effective path of access
insert image description here

Satellite's LLA (Geographic Coordinate State)

satelliteDP = satellite.DataProviders.Item('LLA State')
satelliteDP2 = satelliteDP.Group.Item('Fixed')
rptElements = ['Time', 'Lat', 'Lon', 'Alt']
satelliteDPTimeVar = satelliteDP2.ExecElements(accessStartTimes[0],accessStopTimes[0], 30, rptElements) # 30 表示每间隔
satelliteAltitude = satelliteDPTimeVar.DataSets.GetDataSetByName('Alt').GetValues()
print(satelliteAltitude)

satelliteDP2.ExecElements The first parameter of this function is the start of the access time you want to collect, the second parameter is the end of the access time, and the third parameter "30" indicates how often to collect, 30 means every 30 seconds Collect once, and the last rptElements represent the parameters to be obtained
. Then the satelliteDPTimeVar.DataSets.GetDataSetByName in this represents the data you want to collect.
The following shows the collection effect at intervals of 30s

That's all for today, don't forget to save the project

Guess you like

Origin blog.csdn.net/qq_42635142/article/details/126690380