STK&MATLAB connect(四)卫星

创建一个卫星(在当前场景的中心体上)

root.ExecuteCommand('New / */Satellite MySatellite');


将卫星的propagator设置为J4,并指定笛卡尔的位置

root.ExecuteCommand('SetUnits / km');%Default Connect Units are meters
root.ExecuteCommand('SetState */Satellite/MySatellite Cartesian J4Perturbation "UseAnalysisStartTime" "UseAnalysisStopTime" 60 ICRF "UseAnalysisStartTime" 6678.14 0 0 0 6.78953 3.68641');


设置卫星的初始状态并进行传播

root.ExecuteCommand('SetUnits / km');%Default Connect Units are meters
root.ExecuteCommand('SetState */Satellite/MySatellite Classical TwoBody "UseAnalysisStartTime" "UseAnalysisStopTime" 60 ICRF "UseAnalysisStartTime" 6678.14 0 28 180 0 180');


将卫星传播器设置为SGP4并进行传播

root.ExecuteCommand('SetState */Satellite/MySatellite SGP4 "UseAnalysisStartTime" "UseAnalysisStopTime" 60 25544 TLESource Automatic Source AGIServer UseTLE All SwitchMethod Epoch'); %25544 is the International Space Station


将卫星传播器设置为HPOP并设置力模型属性

root.ExecuteCommand('SetUnits / km');%Default Connect Units are meters
root.ExecuteCommand('SetState */Satellite/MySatellite Cartesian HPOP "UseAnalysisStartTime" "UseAnalysisStopTime" 60 Fixed "UseAnalysisStartTime" 6406.92 -1787.59 -506.422 2.10185 6.48871 3.64041');
root.ExecuteCommand('HPOP */Satellite/MySatellite Force Gravity "C:/Program Files/AGI/STK 12/STKData/CentralBodies/Earth/WGS84.grv" 21 21');
root.ExecuteCommand('HPOP */Satellite/MySatellite Drag On 0.01 0.01 "Jacchia 1960"');
root.ExecuteCommand('HPOP */Satellite/MySatellite Force SRP Off');
root.ExecuteCommand('HPOP */Satellite/MySatellite Integrator IntegMethod RKF78 StepControl RelativeError 1.0e-13 MinStepSize 0.1 MaxStepSize 30 InterpMethod LaGrange 7');


将卫星传播器设置为SPICE并进行传播

root.ExecuteCommand('SetState */Satellite/MySatellite SPICE File "C:/Program Files/AGI/STK 12/STKData/Spice/planets.bsp" BodyID 4 TimePeriod UseScenarioInterval');


将星历文件导出到场景文件夹中

scenPath = root.ExecuteCommand('GetDirectory / Scenario').Item(0);
root.ExecuteCommand(['ExportDataFile */Satellite/MySatellite Ephemeris "' scenPath '\MySatellite.e" Type STK CoordSys J2000 CentralBody Earth InterpBoundaries Include']);

应用1

uiap = actxserver('STK11.application');
root = uiap.Personality2;
root.NewScenario('MyScenario');
root.ExecuteCommand('New / */Satellite MySatellite');
root.ExecuteCommand('SetUnits / km');%Default Connect Units are meters
root.ExecuteCommand('SetState */Satellite/MySatellite Classical TwoBody "UseAnalysisStartTime" "UseAnalysisStopTime" 60 ICRF "UseAnalysisStartTime" 6678.14 0 28 180 0 180');
scenPath = root.ExecuteCommand('GetDirectory / Scenario').Item(0);
root.ExecuteCommand(['ExportDataFile */Satellite/MySatellite Ephemeris "' scenPath '\MySatellite.e" Type STK CoordSys J2000 CentralBody Earth InterpBoundaries Include']);

命令行输入:

cd(scenPath);
open MySatellite.e

即可得到星历文件,如图:STK&MATLAB connect(四)卫星_第1张图片 
设置卫星姿态基本旋转

root.ExecuteCommand('SetAttitude */Satellite/MySatellite Profile Spinning Inertial Axis 0 1 0 Body Axis 0 0 1 6 0 "UseAnalysisStartTime"');


设置卫星的外部姿态

root.ExecuteCommand('SetAttitude */Satellite/MySatellite File Filename "C:/Program Files/AGI/STK 11/Help/stktraining/text/AttitudeTimeEulerAngles_Example.a"');

应用2

uiap = actxserver('STK11.application');
root = uiap.Personality2;
root.NewScenario('MyScenario');
root.ExecuteCommand('New / */Satellite MySatellite');
root.ExecuteCommand('SetUnits / km');%Default Connect Units are meters
root.ExecuteCommand('SetState */Satellite/MySatellite Classical TwoBody "UseAnalysisStartTime" "UseAnalysisStopTime" 60 ICRF "UseAnalysisStartTime" 6678.14 0 28 180 0 180');
root.ExecuteCommand('SetAttitude */Satellite/MySatellite Profile Spinning Inertial Axis 0 1 0 Body Axis 0 0 1 6 0 "UseAnalysisStartTime"');
root.ExecuteCommand('SetAttitude */Satellite/MySatellite File Filename "C:/Program Files/AGI/STK 11/Help/stktraining/text/AttitudeTimeEulerAngles_Example.a"');

在stk的卫星三维视图中确实可以看到卫星姿态变化

STK&MATLAB connect(四)卫星_第2张图片 

 

注意:博主在测试官方例子的时候发现 root.ExecuteCommand('SetAttitude */Satellite/MySatellite File Filename "C:/Program Files/AGI/STK 11/Help/stktraining/text/AttitudeTimeEulerAngles_Example.a"');其中官方的代码与我电脑中AttitudeTimeEulerAngles_Example.a所在的路径有出入,如果不更改会出现调用错误


设置卫星姿态目标

root.ExecuteCommand('SetAttitude */Satellite/MySatellite Target On');
root.ExecuteCommand('SetAttitude */Satellite/MySatellite Target Clear');
root.ExecuteCommand('SetAttitude */Satellite/MySatellite Target Add AreaTarget/MyAreaTarget Times UseAccess On');

应用3

uiap = actxserver('STK11.application');
root = uiap.Personality2;
root.NewScenario('MyScenario');
root.ExecuteCommand('New / */AreaTarget MyAreaTarget');
root.ExecuteCommand('SetBoundary */AreaTarget/MyAreaTarget Pattern LatLon 3 0 -75 20 -60 0 0');
root.ExecuteCommand('New / */Satellite MySatellite');
root.ExecuteCommand('SetUnits / km');%Default Connect Units are meters
root.ExecuteCommand('SetState */Satellite/MySatellite Classical TwoBody "UseAnalysisStartTime" "UseAnalysisStopTime" 60 ICRF "UseAnalysisStartTime" 6678.14 0 28 180 0 180');
root.ExecuteCommand('SetAttitude */Satellite/MySatellite Target On');
root.ExecuteCommand('SetAttitude */Satellite/MySatellite Target Clear');
root.ExecuteCommand('SetAttitude */Satellite/MySatellite Target Add AreaTarget/MyAreaTarget Times UseAccess On');

可实现卫星扫描到区域目标都会改变朝向 


设置目标回转

root.ExecuteCommand('SetAttitude */Satellite/MySatellite Target On');
root.ExecuteCommand('SetAttitude */Satellite/MySatellite Target Clear');
root.ExecuteCommand('SetAttitude */Satellite/MySatellite Target Add AreaTarget/MyAreaTarget Times UseAccess On');
root.ExecuteCommand('SetAttitude */Satellite/MySatellite Target Slew Mode Constrained MaxSlewTime 20 SlewTimingBetweenTgts Optimal');
root.ExecuteCommand('SetAttitude */Satellite/MySatellite Target Slew Mode Constrained RateMagnitude 10 RateAxisX On RateAxisY On RateAxisZ On AccelMagnitude 10 AccelAxisX On AccelAxisY On AccelAxisZ On');
root.ExecuteCommand('SetAttitude */Satellite/MySatellite Target Slew Mode Constrained RateAxisX 5 RateAxisY 5 RateAxisZ 5 AccelAxisX 5 AccelAxisY 5 AccelAxisZ 5');


设置卫星模型的指向

root.ExecuteCommand('VO */Satellite/MySatellite ModelPointing "Solar_PanelsNode" Target Sun');


将卫星传播器设置为Astrogator,并清除片段  

root.ExecuteCommand('Astrogator */Satellite/MySatellite SetProp');


确定MCS中目前有哪些分段

ASTGSegments = root.ExecuteCommand('Astrogator_RM */Satellite/MySatellite GetValue MainSequence.SegmentList');


删除所有的段

for j = 0:ASTGSegments.Count - 2
Segment = strread(ASTGSegments.Item(j), '%s');
root.ExecuteCommand(['Astrogator */Satellite/MySatellite DeleteSegment ' Segment{1}]);
end


在MCS中插入一个初始状态段并进行配置

root.ExecuteCommand('Astrogator */Satellite/MySatellite InsertSegment - Initial_State'); root.ExecuteCommand('Astrogator */Satellite/MySatellite SetValue MainSequence.SegmentList.Initial_State.ComponentName Inner_Orbit'); %change name of the segment
root.ExecuteCommand('Astrogator */Satellite/MySatellite SetValue MainSequence.SegmentList.Inner_Orbit.InitialState.Epoch 0 EpSec'); %set epoch
root.ExecuteCommand('Astrogator */Satellite/MySatellite SetValue MainSequence.SegmentList.Inner_Orbit.InitialState.Keplerian.ElementType Osculating');
root.ExecuteCommand('Astrogator */Satellite/MySatellite SetValue MainSequence.SegmentList.Inner_Orbit.InitialState.Keplerian.PeriapsisRadSize 6700 km'); %default units are m
root.ExecuteCommand('Astrogator */Satellite/MySatellite SetValue MainSequence.SegmentList.Inner_Orbit.InitialState.Keplerian.w 0');
root.ExecuteCommand('Astrogator */Satellite/MySatellite SetValue MainSequence.SegmentList.Inner_Orbit.InitialState.Keplerian.ecc 0');
root.ExecuteCommand('Astrogator */Satellite/MySatellite SetValue MainSequence.SegmentList.Inner_Orbit.InitialState.Keplerian.inc 0');
root.ExecuteCommand('Astrogator */Satellite/MySatellite SetValue MainSequence.SegmentList.Inner_Orbit.InitialState.Keplerian.RAAN 0');
root.ExecuteCommand('Astrogator */Satellite/MySatellite SetValue MainSequence.SegmentList.Inner_Orbit.InitialState.Keplerian.TA 0');


在MCS中插入一个传播段,并进行配置

root.ExecuteCommand('Astrogator */Satellite/MySatellite InsertSegment - Propagate');
root.ExecuteCommand('Astrogator */Satellite/MySatellite SetValue MainSequence.SegmentList.Propagate.ComponentName Transfer_Ellipse'); %change name of the segment
root.ExecuteCommand('Astrogator */Satellite/MySatellite SetValue MainSequence.SegmentList.Transfer_Ellipse.Propagator "Earth Point Mass"');
root.ExecuteCommand('Astrogator */Satellite/MySatellite SetValue MainSequence.SegmentList.Transfer_Ellipse.StoppingConditions Duration');
root.ExecuteCommand('Astrogator */Satellite/MySatellite SetValue MainSequence.SegmentList.Transfer_Ellipse.StoppingConditions.Duration.TripValue 7200 Sec');
root.ExecuteCommand('Astrogator */Satellite/MySatellite SetValue MainSequence.SegmentList.Transfer_Ellipse.SegmentColor 16711680'); %set segment color to blue


在MCS中插入一个传播状态段,并添加/删除停止条件

root.ExecuteCommand('Astrogator */Satellite/MySatellite InsertSegment - Propagate');
root.ExecuteCommand('Astrogator */Satellite/MySatellite SetValue MainSequence.SegmentList.Propagate.ComponentName Propagate2'); %change name of the segment
root.ExecuteCommand('Astrogator */Satellite/MySatellite SetValue MainSequence.SegmentList.Propagate2.StoppingConditions Apoapsis'); %overwrites any stopping conditions already there, unless specified


在MCS中插入一个目标序列段,并进行配置

root.ExecuteCommand('Astrogator */Satellite/MySatellite InsertSegment - Target_Sequence');
root.ExecuteCommand('Astrogator */Satellite/MySatellite SetValue MainSequence.SegmentList.Target_Sequence.ComponentName Start_Transfer'); %change name of the segment
root.ExecuteCommand('Astrogator */Satellite/MySatellite InsertSegment MainSequence.SegmentList.Start_Transfer.SegmentList.- Maneuver');
root.ExecuteCommand('Astrogator */Satellite/MySatellite SetValue MainSequence.SegmentList.Start_Transfer.SegmentList.Maneuver.ComponentName DV1');
root.ExecuteCommand('Astrogator */Satellite/MySatellite SetValue MainSequence.SegmentList.Start_Transfer.SegmentList.DV1.MnvrType Impulsive');
root.ExecuteCommand('Astrogator */Satellite/MySatellite SetValue MainSequence.SegmentList.Start_Transfer.SegmentList.DV1.AttitudeControl Thrust Vector');
root.ExecuteCommand('Astrogator */Satellite/MySatellite SetValue MainSequence.SegmentList.Start_Transfer.SegmentList.DV1.ThrustAxes "Satellite VNC(Earth)"');
root.ExecuteCommand('Astrogator */Satellite/MySatellite AddMCSSegmentControl MainSequence.SegmentList.Start_Transfer.SegmentList.DV1 ImpulsiveMnvr.Cartesian.X');
root.ExecuteCommand('Astrogator */Satellite/MySatellite SetValue MainSequence.SegmentList.Start_Transfer.SegmentList.DV1.Results "Radius Of Apoapsis"');
root.ExecuteCommand('Astrogator */Satellite/MySatellite SetMCSControlValue MainSequence.SegmentList.Start_Transfer.Profiles.Differential_Corrector DV1 ImpulsiveMnvr.Cartesian.X Active true');
root.ExecuteCommand('Astrogator */Satellite/MySatellite SetMCSControlValue MainSequence.SegmentList.Start_Transfer.Profiles.Differential_Corrector DV1 ImpulsiveMnvr.Cartesian.X MaxStep 0.3 m/sec');
root.ExecuteCommand('Astrogator */Satellite/MySatellite SetMCSConstraintValue MainSequence.SegmentList.Start_Transfer.Profiles.Differential_Corrector DV1 "Radius Of Apoapsis" Active true');
root.ExecuteCommand('Astrogator */Satellite/MySatellite SetMCSConstraintValue MainSequence.SegmentList.Start_Transfer.Profiles.Differential_Corrector DV1 "Radius Of Apoapsis" Desired 42238 km');
root.ExecuteCommand('Astrogator */Satellite/MySatellite SetMCSConstraintValue MainSequence.SegmentList.Start_Transfer.Profiles.Differential_Corrector DV1 "Radius Of Apoapsis" Tolerance 0.1 km');
root.ExecuteCommand('Astrogator */Satellite/MySatellite SetValue MainSequence.SegmentList.Start_Transfer.Profiles.Differential_Corrector.MaxIterations 50');
root.ExecuteCommand('Astrogator */Satellite/MySatellite SetValue MainSequence.SegmentList.Start_Transfer.Action Run active profiles');
root.ExecuteCommand('Astrogator */Satellite/MySatellite RunMCS');


运行Astrogator MCS

root.ExecuteCommand('Astrogator */Satellite/MySatellite RunMCS');

你可能感兴趣的:(STK&MATLAB,connect连接,matlab)