STK12 and Python co-simulation (1): environment construction

Install Python and Jupyter notebook

The major bloggers have explained this, let me attach a few links.
Jupyter Notebook introduction, installation and use tutorial @ 知豆先生
jupyter notebook auto-completion @ CSDN How can there be children who don’t write code?
1. Must be sure when installing python Choose to have pip in the environment variables of the system
2. Remember your own Python installation path, which will be useful later

critical step

In the STK installation directory, find <your path>: agi.stk12-12.2.0-py3-none-any.whl in STK\bin\AgPythonAPI.
Mine is Enter cmd in the F:\STK\bin\AgPythonAPI
path bar, which means to open the command in the current directory Line
insert image description here
input pip install <TAB>and then Enter to install (TAB key is auto-completion, because there is only one file in this directory, so it will be easy to auto-completion)
insert image description here

STK configuration

In fact, STK can also not be configured. It depends on personal preference. According to the video requirements of the official website, it needs to be configured.

  1. Open STK, as shown in the figure, first close the pop-up window of creating a scene, and then click the icon of Python
    insert image description here

  2. Configure the Python path. Remember the role of your own Python path as mentioned above.
    insert image description here
    This is my own Python path. The first path is right to select Python.exe.
    insert image description here
    The second is the Scripts file, which is in the same level of directory. , and then double-click to enter
    insert image description here
    and then click OK
    insert image description here

  3. Then you get a tiny notebook inside the software
    insert image description here

  4. Regardless of this, complete other configurations first. Let’s create a new scene and name it casually.
    File > New > Name Any > OK . that close
    insert image description here

    insert image description here

Then find Integrated Jupyter Notebooks for Python in Edit > Preference
insert image description here
and pay attention to this localhost. Everyone may be different. Let’s copy it, open your browser, directly enter the address line of the browser, and press Enter to enter

insert image description here
insert image description here
You need to log in here, but it doesn’t matter, we follow his statement, just open a command, enter to jupyter notebook listfind the one where localhost is the same as yours, here mine is 5281, and then copy the token (in the command line, after selecting it, right click One click to copy)
insert image description here

Paste it here
insert image description here
and then just enter the New Password at will, 123 is fine, click Log in and ...
insert image description here
click to enter StarterScripy
to see the comfortable version

But

I think this method is a bit cumbersome, and the path cannot be defined by myself. The following method can create a notebook and link it.
After we create a new scene, we can open the Python window in the following way

  1. View>Toolbars>Intergrate ... (as shown in the picture)
    insert image description here
    Then, there will be an extra one
    insert image description here
    . Click the Python icon, and it will pop up.
    insert image description here
    Then enter the green notebook that has been turned on, add STK_PID in the last line
    to run
    and remember this PID, here is 40556, everyone’s may be different
    insert image description here
    Then, create a new notebook by yourself, my method is to open cmd and use ipython notebook directly in the path you want to put

Enter the following code, the STK_PID to be modified is obtained according to the previous step

from agi.stk12.stkdesktop import STKDesktop
from agi.stk12.stkobjects import *
from agi.stk12.stkutil import *
from agi.stk12.vgt import *
import os
STK_PID = 40556  # 根据自己刚刚得到的PID
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
If the permission is successful, it means that it is connected to STK.
Since we have already created the scene
, we only need to let the code link the existing scene.

scenario = root.CurrentScenario # 链接当前场景
scenario.SetTimePeriod('Today','+24hr') # 日期设置为今天
root.Rewind() # 复位

Create two simple components

# 添加地面站
target = AgTarget(scenario.Children.New(AgESTKObjectType.eTarget,"GroundTarget"))
target.Position.AssignGeodetic(50,-100,0)
# 添加卫星
satellite = AgSatellite(root.CurrentScenario.Children.New(AgESTKObjectType.eSatellite,"LeoSat"))
print(scenario.StartTime)
print(scenario.StopTime)
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');

STK will update components synchronously
insert image description here

Guess you like

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