-
Notifications
You must be signed in to change notification settings - Fork 0
/
main1.py
87 lines (69 loc) · 2.8 KB
/
main1.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
from Basilisk.moduleTemplates import cModuleTemplate
from Basilisk.moduleTemplates import cppModuleTemplate
from Basilisk.utilities import SimulationBaseClass
from Basilisk.utilities import macros
from Basilisk.architecture import messaging
from Basilisk.utilities import SimulationBaseClass
from Basilisk.utilities import macros
from Basilisk.utilities import orbitalMotion, macros, unitTestSupport
from Basilisk.utilities import RigidBodyKinematics as rbk
import matplotlib.pyplot as plt
from Basilisk.utilities import unitTestSupport
import sys
def run():
scSim = SimulationBaseClass.SimBaseClass()
#dynProcess = scSim.CreateNewProcess("name", priority)
dynProcess = scSim.CreateNewProcess("dynamicsProcess")
fswProcess = scSim.CreateNewProcess("fswProcess")
#dynProcess.addTask(scSim.CreateNewTask("name", updateRate, priority))
#dynProcess.addTask(scSim.CreateNewTask("name", updateRate, priority, FirstStart=delayStartTime))
dynProcess.addTask(scSim.CreateNewTask("dynamicsTask", macros.sec2nano(5.)))
mod1 = cModuleTemplate.cModuleTemplate()
mod1.ModelTag = "cModule1"
mod2 = cppModuleTemplate.CppModuleTemplate()
mod2.ModelTag = "cppModule2"
mod3 = cModuleTemplate.cModuleTemplate()
mod3.ModelTag = "cModule3"
#scSim.AddModelToTask("taskName", module, priority)
scSim.AddModelToTask("dynamicsTask", mod1)
scSim.AddModelToTask("dynamicsTask", mod2, 10)
scSim.AddModelToTask("dynamicsTask", mod3, 5)
mod1.dataInMsg.subscribeTo(mod1.dataOutMsg)
msgData = messaging.CModuleTemplateMsgPayload()
msgData.dataVector = [1., 2., 3.]
msg = messaging.CModuleTemplateMsg().write(msgData)
# connect to stand-alone msg
mod1.dataInMsg.subscribeTo(msg)
msgRec = mod1.dataOutMsg.recorder()
scSim.AddModelToTask("dynamicsTask", msgRec)
msgRec2 = mod1.dataOutMsg.recorder(macros.sec2nano(20.))
scSim.AddModelToTask("dynamicsTask", msgRec2)
dynProcess.addTask(scSim.CreateNewTask("sensorTask", macros.sec2nano(10.)))
fswProcess.addTask(scSim.CreateNewTask("fswTask", macros.sec2nano(10.)))
scSim.InitializeSimulation()
scSim.ConfigureStopTime(macros.sec2nano(20.0))
scSim.ExecuteSimulation()
scSim.ShowExecutionOrder()
fig = scSim.ShowExecutionFigure(True)
# plot recorded data
plt.close("all")
plt.figure(1)
figureList = {}
for idx in range(3):
plt.plot(msgRec.times() * macros.NANO2SEC, msgRec.dataVector[:, idx],
color=unitTestSupport.getLineColor(idx, 3),
label='$x_{' + str(idx) + '}$')
plt.plot(msgRec2.times() * macros.NANO2SEC, msgRec2.dataVector[:, idx],
'--',
color=unitTestSupport.getLineColor(idx, 3),
label=r'$\hat x_{' + str(idx) + '}$')
plt.legend(loc='lower right')
plt.xlabel('Time [sec]')
plt.ylabel('Module Data [units]')
#if "pytest" not in sys.modules:
plt.show()
figureList["bsk-4"] = plt.figure(1)
plt.close("all")
return figureList
if __name__ == "__main__":
run()