You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
1.3 KiB
Python

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

import matlab.engine
import os
eng = matlab.engine.start_matlab()
modelName = 'sat9_new'
objectName = 'Solar panel1'
# 参数初始化
eng.eval("initial_data_new()", nargout=0)
# 从input.txt中读取参数
with open('input.txt', 'r') as file:
lines = file.readlines()
work_mode_param, maneuverYN_param = lines[1].strip().split(' ')
work_mode_param = int(work_mode_param)
maneuverYN_param = int(maneuverYN_param)
# 帆板工作模式
work_mode_list = ["1帆板锁定模式", "2正常跟踪模式", "3快速捕获模式", "4仅+Y帆板驱动", "5仅-Y帆板驱动"]
work_mode = work_mode_list[work_mode_param]
maneuverYNList = ['on', 'off']
maneuverYN = maneuverYNList[maneuverYN_param]
# 加载初始化变量
eng.eval("load initial_data.mat", nargout=0)
# 加载模型
eng.eval("model = '{}'".format(modelName), nargout=0)
eng.eval("load_system(model)", nargout=0)
# 设置模型参数
eng.eval("set_param('sat9_new/Solar panel1', 'work_mode', '{}')".format(work_mode), nargout=0)
eng.eval("set_param('sat9_new/Solar panel1', 'maneuverYN', '{}')".format(maneuverYN), nargout=0)
# eng.set_param(modelName + '/' + objectName + '/work_mode', 'Value', '1帆板锁定模式', nargout=0)
# eng.set_param(modelName + '/' + objectName, 'maneuverYN', 'on')
# 执行模型
eng.sim(modelName)
# 保存结果
eng.saveResult(nargout=0)
# 结束
eng.quit()