-
Notifications
You must be signed in to change notification settings - Fork 474
/
Copy pathjsbsim.pyx.in
1016 lines (789 loc) · 34.8 KB
/
jsbsim.pyx.in
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# cython: language_level=3
# distutils: language=c++
#
# JSBSim python interface using cython.
#
# Copyright (c) 2013 James Goppert
# Copyright (c) 2014-${THIS_YEAR} Bertrand Coconnier
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU Lesser General Public License as published by the Free
# Software Foundation; either version 2 of the License, or (at your option) any
# later version.
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
# details.
# You should have received a copy of the GNU Lesser General Public License along
# with this program; if not, write to the Free Software Foundation, Inc., 59
# Temple Place - Suite 330, Boston, MA 02111-1307, USA.
# Further information about the GNU Lesser General Public License can also be
# found on the world wide web at http://www.gnu.org.
"""An Open source flight dynamics & control software library
@DoxMainPage"""
from cython.operator cimport dereference as deref
from typing import Optional
import enum
import errno
import os
import site
import sys
import numpy
__version__='${PROJECT_VERSION}'
class BaseError(RuntimeError):
"""JSBSim base exception class."""
pass
class TrimFailureError(BaseError):
"""Exception class for trim failures."""
pass
class GeographicError(BaseError):
"""Exception class for geographic computation errors."""
pass
base_error = <PyObject*>BaseError
trimfailure_error = <PyObject*>TrimFailureError
geographic_error = <PyObject*>GeographicError
def get_default_root_dir() -> str:
"""Return the root dir to default aircraft data."""
for path in site.getsitepackages() + [site.USER_SITE]:
root_dir = os.path.join(path, 'jsbsim')
aircraft_dir = os.path.join(root_dir, 'aircraft')
if os.path.isdir(aircraft_dir):
return root_dir
raise IOError("Can't find the default root directory")
def _append_xml(name: str) -> str:
if len(name) < 4 or name[-4:] != '.xml':
return name+'.xml'
return name
cdef _convertToNumpyMat(const c_FGMatrix33& m):
return numpy.mat([[m.Entry(1, 1), m.Entry(1, 2), m.Entry(1, 3)],
[m.Entry(2, 1), m.Entry(2, 2), m.Entry(2, 3)],
[m.Entry(3, 1), m.Entry(3, 2), m.Entry(3, 3)]])
cdef _convertToNumpyVec(const c_FGColumnVector3& v):
return numpy.mat([v.Entry(1), v.Entry(2), v.Entry(3)]).T
cdef class FGPropagate:
"""@Dox(JSBSim::FGPropagate)"""
cdef shared_ptr[c_FGPropagate] thisptr
def __cinit__(self, FGFDMExec fdmex, *args, **kwargs):
if fdmex is not None:
self.thisptr.reset(new c_FGPropagate(fdmex.thisptr))
if not self.thisptr:
raise MemoryError()
def __bool__(self) -> bool:
"""Check if the object is initialized."""
if self.thisptr:
return True
return False
cdef __intercept_invalid_pointer(self):
if not self.thisptr:
raise BaseError("Object is not initialized")
def get_Tl2b(self) -> numpy.ndarray:
"""@Dox(JSBSim::FGPropagate::GetTl2b)"""
self.__intercept_invalid_pointer()
return _convertToNumpyMat(deref(self.thisptr).GetTl2b())
def get_Tec2b(self) -> numpy.ndarray:
"""@Dox(JSBSim::FGPropagate::GetTec2b)"""
self.__intercept_invalid_pointer()
return _convertToNumpyMat(deref(self.thisptr).GetTec2b())
def get_uvw(self) -> numpy.ndarray:
"""@Dox(JSBSim::FGPropagate::GetUVW)"""
self.__intercept_invalid_pointer()
return _convertToNumpyVec(deref(self.thisptr).GetUVW())
cdef class FGPropertyNode:
"""@Dox(JSBSim::FGPropertyNode)"""
cdef c_FGPropertyNode* thisptr
def __cinit__(self, *args, **kwargs):
self.thisptr = NULL
def __bool__(self) -> bool:
"""Check if the object is initialized."""
return self.thisptr is not NULL
def __str__(self) -> str:
if self.thisptr is not NULL:
return f"Property '{self.get_fully_qualified_name()}' (value: {self.get_double_value()})"
return "Uninitialized property"
cdef __intercept_invalid_pointer(self):
if self.thisptr is NULL:
raise BaseError("Object is not initialized")
cdef __validate_node_pointer(self, create: bool):
if self.thisptr is not NULL:
return self
else:
if create:
raise MemoryError()
return None
def get_name(self) -> str:
"""@Dox(JSBSim::FGPropertyManager::GetName)"""
self.__intercept_invalid_pointer()
return self.thisptr.GetName().decode()
def get_fully_qualified_name(self) -> str:
"""@Dox(JSBSim::FGPropertyManager::GetFullyQualifiedName)"""
self.__intercept_invalid_pointer()
return self.thisptr.GetFullyQualifiedName().decode()
def get_node(self, path: str, create: bool = False) -> Optional[FGPropertyNode]:
self.__intercept_invalid_pointer()
node = FGPropertyNode()
node.thisptr = self.thisptr.GetNode(path.encode(), create)
return node.__validate_node_pointer(create)
def get_double_value(self) -> float:
self.__intercept_invalid_pointer()
return self.thisptr.getDoubleValue()
def set_double_value(self, value: float) -> None:
self.__intercept_invalid_pointer()
self.thisptr.setDoubleValue(value)
cdef class FGPropertyManager:
"""@Dox(JSBSim::FGPropertyManager)"""
cdef shared_ptr[c_FGPropertyManager] thisptr
def __cinit__(self, FGPropertyNode node = None, *args, **kwargs):
if node is None:
self.thisptr.reset(new c_FGPropertyManager())
else:
try:
node.__intercept_invalid_pointer()
except BaseError:
raise BaseError("Cannot instantiate FGPropertyManager with an uninitialized property node.")
self.thisptr.reset(new c_FGPropertyManager(node.thisptr))
if not self.thisptr:
raise MemoryError()
def get_node(self, path: Optional[str] = None, create: bool = False) -> Optional[FGPropertyNode]:
"""@Dox(JSBSim::FGPropertyManager::GetNode)"""
node = FGPropertyNode()
if path is None:
node.thisptr = deref(self.thisptr).GetNode()
else:
node.thisptr = deref(self.thisptr).GetNode(path.encode(), create)
return node.__validate_node_pointer(create)
def hasNode(self, path: str) -> bool:
"""@Dox(JSBSim::FGPropertyManager::HasNode)"""
return deref(self.thisptr).HasNode(path.encode())
cdef class FGGroundReactions:
"""@Dox(JSBSim::FGGroundReactions)"""
cdef shared_ptr[c_FGGroundReactions] thisptr
def __cinit__(self, FGFDMExec fdmex, *args, **kwargs):
if fdmex is not None:
self.thisptr.reset(new c_FGGroundReactions(fdmex.thisptr))
if not self.thisptr:
raise MemoryError()
def __bool__(self) -> bool:
"""Check if the object is initialized."""
if self.thisptr:
return True
return False
cdef __intercept_invalid_pointer(self):
if not self.thisptr:
raise BaseError("Object is not initialized")
def get_gear_unit(self, gear: int) -> FGLGear:
"""@Dox(JSBSim::FGGroundReactions::GetGearUnit)"""
self.__intercept_invalid_pointer()
lgear = FGLGear()
lgear.thisptr = deref(self.thisptr).GetGearUnit(gear)
return lgear
def get_num_gear_units(self) -> int:
"""@Dox(JSBSim::FGGroundReactions::GetNumGearUnits)"""
self.__intercept_invalid_pointer()
return deref(self.thisptr).GetNumGearUnits()
cdef class FGLGear:
"""@Dox(JSBSim::FGLGear)"""
cdef shared_ptr[c_FGLGear] thisptr
def __bool__(self) -> bool:
"""Check if the object is initialized."""
if self.thisptr:
return True
return False
cdef __intercept_invalid_pointer(self):
if not self.thisptr:
raise BaseError("Object is not initialized")
def get_steer_norm(self) -> float:
"""@Dox(JSBSim::FGLGear::GetSteerNorm)"""
self.__intercept_invalid_pointer()
return deref(self.thisptr).GetSteerNorm()
def get_body_x_force(self) -> float:
"""@Dox(JSBSim::FGLGear::GetBodyXForce)"""
self.__intercept_invalid_pointer()
return deref(self.thisptr).GetBodyXForce()
def get_body_y_force(self) -> float:
"""@Dox(JSBSim::FGLGear::GetBodyYForce)"""
self.__intercept_invalid_pointer()
return deref(self.thisptr).GetBodyYForce()
def get_body_z_force(self) -> float:
"""@Dox(JSBSim::FGLGear::GetBodyZForce)"""
self.__intercept_invalid_pointer()
return deref(self.thisptr).GetBodyZForce()
def get_location(self) -> numpy.ndarray:
self.__intercept_invalid_pointer()
return _convertToNumpyVec(deref(self.thisptr).GetLocation())
def get_acting_location(self) -> numpy.ndarray:
self.__intercept_invalid_pointer()
return _convertToNumpyVec(deref(self.thisptr).GetActingLocation())
cdef class FGAuxiliary:
"""@Dox(JSBSim::FGAuxiliary)"""
cdef shared_ptr[c_FGAuxiliary] thisptr
def __cinit__(self, FGFDMExec fdmex, *args, **kwargs):
if fdmex is not None:
self.thisptr.reset(new c_FGAuxiliary(fdmex.thisptr))
if not self.thisptr:
raise MemoryError()
def __bool__(self) -> bool:
"""Check if the object is initialized."""
if self.thisptr:
return True
return False
cdef __intercept_invalid_pointer(self):
if not self.thisptr:
raise BaseError("Object is not initialized")
def get_Tw2b(self) -> numpy.ndarray:
"""@Dox(JSBSim::FGAuxiliary::GetTw2b)"""
self.__intercept_invalid_pointer()
return _convertToNumpyMat(deref(self.thisptr).GetTw2b())
def get_Tb2w(self) -> numpy.ndarray:
"""@Dox(JSBSim::FGAuxiliary::GetTb2w)"""
self.__intercept_invalid_pointer()
return _convertToNumpyMat(deref(self.thisptr).GetTb2w())
cdef class FGAerodynamics:
"""@Dox(JSBSim::FGAerodynamics)"""
cdef shared_ptr[c_FGAerodynamics] thisptr
def __cinit__(self, FGFDMExec fdmex, *args, **kwargs):
if fdmex is not None:
self.thisptr.reset(new c_FGAerodynamics(fdmex.thisptr))
if not self.thisptr:
raise MemoryError()
def __bool__(self) -> bool:
"""Check if the object is initialized."""
if self.thisptr:
return True
return False
cdef __intercept_invalid_pointer(self):
if not self.thisptr:
raise BaseError("Object is not initialized")
def get_moments_MRC(self) -> numpy.ndarray:
"""@Dox(JSBSim::FGAerodynamics::GetMomentsMRC)"""
self.__intercept_invalid_pointer()
return _convertToNumpyVec(deref(self.thisptr).GetMomentsMRC())
def get_forces(self) -> numpy.ndarray:
"""@Dox(JSBSim::FGAerodynamics::GetForces)"""
self.__intercept_invalid_pointer()
return _convertToNumpyVec(deref(self.thisptr).GetForces())
cdef class FGAircraft:
"""@Dox(JSBSim::FGAircraft)"""
cdef shared_ptr[c_FGAircraft] thisptr
def __cinit__(self, FGFDMExec fdmex, *args, **kwargs):
if fdmex is not None:
self.thisptr.reset(new c_FGAircraft(fdmex.thisptr))
if not self.thisptr:
raise MemoryError()
def __bool__(self) -> bool:
"""Check if the object is initialized."""
if self.thisptr:
return True
return False
cdef __intercept_invalid_pointer(self):
if not self.thisptr:
raise BaseError("Object is not initialized")
def get_xyz_rp(self) -> numpy.ndarray:
"""@Dox(JSBSim::FGAircraft::GetXYZrp)"""
self.__intercept_invalid_pointer()
return _convertToNumpyVec(deref(self.thisptr).GetXYZrp())
class eTemperature(enum.Enum):
eNoTempUnit = 0
eFahrenheit = 1
eCelsius = 2
eRankine = 3
eKelvin = 4
class ePressure(enum.Enum):
eNoPressUnit= 0
ePSF = 1
eMillibars = 2
ePascals = 3
eInchesHg = 4
cdef class FGAtmosphere:
"""@Dox(JSBSim::FGAtmosphere)"""
cdef shared_ptr[c_FGAtmosphere] thisptr
def __bool__(self) -> bool:
"""Check if the object is initialized."""
if self.thisptr:
return True
return False
cdef __intercept_invalid_pointer(self):
if not self.thisptr:
raise BaseError("Object is not initialized")
def set_temperature(self, t: float, h: float, unit: eTemperature) -> None:
"""@Dox(JSBSim::FGAtmosphere::SetTemperature)"""
self.__intercept_invalid_pointer()
deref(self.thisptr).SetTemperature(t, h, unit.value)
def get_temperature(self, h: float) -> float:
"""@Dox(JSBSim::FGAtmosphere::GetTemperature(double))"""
self.__intercept_invalid_pointer()
return deref(self.thisptr).GetTemperature(h)
def set_pressure_SL(self, unit: ePressure, p: float) -> None:
"""@Dox(JSBSim::FGAtmosphere::SetPressureSL)"""
self.__intercept_invalid_pointer()
deref(self.thisptr).SetPressureSL(unit.value, p)
cdef class FGMassBalance:
"""@Dox(JSBSim::FGMassBalance)"""
cdef shared_ptr[c_FGMassBalance] thisptr
def __cinit__(self, FGFDMExec fdmex, *args, **kwargs):
if fdmex is not None:
self.thisptr.reset(new c_FGMassBalance(fdmex.thisptr))
if not self.thisptr:
raise MemoryError()
def __bool__(self) -> bool:
"""Check if the object is initialized."""
if self.thisptr:
return True
return False
cdef __intercept_invalid_pointer(self):
if not self.thisptr:
raise BaseError("Object is not initialized")
def get_xyz_cg(self) -> numpy.ndarray:
"""@Dox(JSBSim::FGMassBalance::GetXYZcg)"""
self.__intercept_invalid_pointer()
return _convertToNumpyVec(deref(self.thisptr).GetXYZcg())
def get_J(self) -> numpy.ndarray:
"""@Dox(JSBSim::FGMassBalance::GetJ)"""
self.__intercept_invalid_pointer()
return _convertToNumpyMat(deref(self.thisptr).GetJ())
def get_Jinv(self) -> numpy.ndarray:
"""@Dox(JSBSim::FGMassBalance::GetJinv)"""
self.__intercept_invalid_pointer()
return _convertToNumpyMat(deref(self.thisptr).GetJinv())
cdef class FGJSBBase:
"""@Dox(JSBSim::FGJSBBase)"""
cdef c_FGJSBBase *baseptr
def __cinit__(self, *args, **kwargs):
if type(self) is FGJSBBase: # Check if it is called from a derived class
self.baseptr = new c_FGJSBBase()
if not self.baseptr:
raise MemoryError()
def __dealloc__(self) -> None:
if type(self) is FGJSBBase:
del self.baseptr
@property
def debug_lvl(self) -> None:
return self.baseptr.debug_lvl
@debug_lvl.setter
def debug_lvl(self, dbglvl: int) -> None:
self.baseptr.debug_lvl = dbglvl
def get_version(self) -> str:
"""@Dox(JSBSim::FGJSBBase::GetVersion)"""
return self.baseptr.GetVersion().decode('utf-8')
def disable_highlighting(self) -> None:
"""@Dox(JSBSim::FGJSBBase::disableHighLighting)"""
self.baseptr.disableHighLighting()
cdef class FGPropulsion:
"""@Dox(JSBSim::FGPropulsion)"""
cdef shared_ptr[c_FGPropulsion] thisptr
def __cinit__(self, FGFDMExec fdmex, *args, **kwargs):
if fdmex is not None:
self.thisptr.reset(new c_FGPropulsion(fdmex.thisptr))
if not self.thisptr:
raise MemoryError()
def __bool__(self) -> bool:
"""Check if the object is initialized."""
if self.thisptr:
return True
return False
cdef __intercept_invalid_pointer(self):
if not self.thisptr:
raise BaseError("Object is not initialized")
def init_running(self, n: int) -> None:
"""@Dox(JSBSim::FGPropulsion::InitRunning)"""
self.__intercept_invalid_pointer()
deref(self.thisptr).InitRunning(n)
def get_num_engines(self) -> int:
"""@Dox(JSBSim::FGPropulsion::GetNumEngines)"""
self.__intercept_invalid_pointer()
return deref(self.thisptr).GetNumEngines()
def get_engine(self, idx: int) -> FGEngine:
"""@Dox(JSBSim::FGPropulsion::GetEngine)"""
self.__intercept_invalid_pointer()
engine = FGEngine()
engine.thisptr = deref(self.thisptr).GetEngine(idx)
return engine
def get_steady_state(self) -> bool:
"""@Dox(JSBSim::FGPropulsion::GetSteadyState)"""
self.__intercept_invalid_pointer()
return deref(self.thisptr).GetSteadyState()
cdef class FGEngine:
"""@Dox(JSBSim::FGEngine)"""
cdef shared_ptr[c_FGEngine] thisptr
def __bool__(self) -> bool:
"""Check if the object is initialized."""
if self.thisptr:
return True
return False
cdef __intercept_invalid_pointer(self):
if not self.thisptr:
raise BaseError("Object is not initialized")
def init_running(self) -> int:
"""@Dox(JSBSim::FGEngine::InitRunning)"""
self.__intercept_invalid_pointer()
return deref(self.thisptr).InitRunning()
cdef class FGLinearization:
"""@Dox(JSBSim::FGLinearization)"""
cdef shared_ptr[c_FGLinearization] thisptr
def __cinit__(self, FGFDMExec fdmex, *args, **kwargs):
if fdmex is not None:
self.thisptr.reset(new c_FGLinearization(fdmex.thisptr))
if not self.thisptr:
raise MemoryError()
def __bool__(self) -> bool:
"""Check if the object is initialized."""
if self.thisptr:
return True
return False
cdef __intercept_invalid_pointer(self):
if not self.thisptr:
raise BaseError("Object is not initialized")
def write_scicoslab(self, path: str) -> None:
"""@Dox(JSBSim::FGLinearization::WriteScicoslab)"""
self.__intercept_invalid_pointer()
if path is None:
deref(self.thisptr).WriteScicoslab()
else:
deref(self.thisptr).WriteScicoslab(path.encode("utf-8"))
@property
def x0(self) -> numpy.ndarray:
"""Initial state"""
self.__intercept_invalid_pointer()
return numpy.array(deref(self.thisptr).GetInitialState())
@property
def u0(self) -> numpy.ndarray:
"""Initial input"""
self.__intercept_invalid_pointer()
return numpy.array(deref(self.thisptr).GetInitialInput())
@property
def y0(self) -> numpy.ndarray:
"""Initial output"""
self.__intercept_invalid_pointer()
return numpy.array(deref(self.thisptr).GetInitialOutput())
@property
def system_matrix(self) -> numpy.ndarray:
self.__intercept_invalid_pointer()
cdef const vector[vector[double]]* cdef_A = &deref(self.thisptr).GetSystemMatrix()
return numpy.array(deref(cdef_A))
@property
def input_matrix(self) -> numpy.ndarray:
self.__intercept_invalid_pointer()
cdef const vector[vector[double]]* cdef_B = &deref(self.thisptr).GetInputMatrix()
return numpy.array(deref(cdef_B))
@property
def output_matrix(self) -> numpy.ndarray:
self.__intercept_invalid_pointer()
cdef const vector[vector[double]]* cdef_C = &deref(self.thisptr).GetOutputMatrix()
return numpy.array(deref(cdef_C))
@property
def feedforward_matrix(self) -> numpy.ndarray:
self.__intercept_invalid_pointer()
cdef const vector[vector[double]]* cdef_D = &deref(self.thisptr).GetFeedforwardMatrix()
return numpy.array(deref(cdef_D))
@property
def state_space(self) -> tuple[numpy.ndarray]:
return (self.system_matrix, self.input_matrix, self.output_matrix, self.feedforward_matrix)
@property
def x_names(self) -> tuple[str]:
"""State names"""
self.__intercept_invalid_pointer()
cdef vector[string] names = deref(self.thisptr).GetStateNames()
return tuple(name.decode("utf-8") for name in names)
@property
def u_names(self) -> tuple[str]:
"Input names"
self.__intercept_invalid_pointer()
cdef vector[string] names = deref(self.thisptr).GetInputNames()
return tuple(name.decode("utf-8") for name in names)
@property
def y_names(self) -> tuple[str]:
"""Output names"""
self.__intercept_invalid_pointer()
cdef vector[string] names = deref(self.thisptr).GetOutputNames()
return tuple(name.decode("utf-8") for name in names)
@property
def x_units(self) -> tuple[str]:
"""State units"""
self.__intercept_invalid_pointer()
cdef vector[string] units = deref(self.thisptr).GetStateUnits()
return tuple(unit.decode("utf-8") for unit in units)
@property
def u_units(self) -> tuple[str]:
"""Input unit"""
self.__intercept_invalid_pointer()
cdef vector[string] units = deref(self.thisptr).GetInputUnits()
return tuple(unit.decode("utf-8") for unit in units)
@property
def y_units(self) -> tuple[str]:
"""Output units"""
self.__intercept_invalid_pointer()
cdef vector[string] units = deref(self.thisptr).GetOutputUnits()
return tuple(unit.decode("utf-8") for unit in units)
# this is the python wrapper class
cdef class FGFDMExec(FGJSBBase):
"""@Dox(JSBSim::FGFDMExec)"""
cdef c_FGFDMExec *thisptr # hold a C++ instance which we're wrapping
def __cinit__(self, root_dir, FGPropertyManager pm_root=None, *args,
**kwargs):
cdef c_FGPropertyManager* root
if pm_root:
root = pm_root.thisptr.get()
else:
root = NULL
self.thisptr = self.baseptr = new c_FGFDMExec(root, NULL)
if self.thisptr is NULL:
raise MemoryError()
if root_dir:
if not os.path.isdir(root_dir):
raise IOError("Can't find root directory: {0}".format(root_dir))
self.set_root_dir(root_dir)
self.set_output_path(".")
else:
self.set_root_dir(get_default_root_dir())
self.set_output_path(os.getcwd())
self.set_engine_path("engine")
self.set_aircraft_path("aircraft")
self.set_systems_path("systems")
def __dealloc__(self) -> None:
del self.thisptr
def __repr__(self) -> str:
return "FGFDMExec \n" \
"root dir\t:\t{0}\n" \
"aircraft path\t:\t{1}\n" \
"engine path\t:\t{2}\n" \
"systems path\t:\t{3}\n" \
"output path\t:\t{4}\n" \
.format(
self.get_root_dir(),
self.get_aircraft_path(),
self.get_engine_path(),
self.get_systems_path(),
self.get_output_path())
def __getitem__(self, key: str) -> float:
_key = key.strip()
pm = self.get_property_manager()
if not pm.hasNode(_key):
raise KeyError("No property named {}".format(_key))
return self.get_property_value(_key)
def __setitem__(self, key: str, value: float) -> None:
self.set_property_value(key.strip(), value)
def run(self) -> bool:
"""@Dox(JSBSim::FGFDMExec::Run)"""
return self.thisptr.Run()
def run_ic(self) -> bool:
"""@Dox(JSBSim::FGFDMExec::RunIC)"""
return self.thisptr.RunIC()
def load_model(self, model: str, add_model_to_path: bool = True) -> bool:
"""@Dox(JSBSim::FGFDMExec::LoadModel(const std::string &, bool))"""
return self.thisptr.LoadModel(model.encode(), add_model_to_path)
def load_model_with_paths(self, model: str, aircraft_path: str,
engine_path: str, systems_path: str,
add_model_to_path: bool = True) -> bool:
"""@Dox(JSBSim::FGFDMExec::LoadModel(const SGPath &, const SGPath &,
const SGPath &, const std::string &,
bool))"""
return self.thisptr.LoadModel(c_SGPath(aircraft_path.encode(), NULL),
c_SGPath(engine_path.encode(), NULL),
c_SGPath(systems_path.encode(), NULL),
model.encode(), add_model_to_path)
def load_script(self, script: str, delta_t: float = 0.0, initfile:str = "") -> bool:
"""@Dox(JSBSim::FGFDMExec::LoadScript)"""
scriptfile = os.path.join(self.get_root_dir(), script)
if not os.path.exists(scriptfile):
raise FileNotFoundError(errno.ENOENT, os.strerror(errno.ENOENT),
scriptfile)
return self.thisptr.LoadScript(c_SGPath(script.encode(), NULL), delta_t,
c_SGPath(initfile.encode(),NULL))
def load_planet(self, planet_path: str, useAircraftPath: bool) -> bool:
"""@Dox(JSBSim::FGFDMExec::LoadPlanet)"""
planet_file = _append_xml(planet_path)
if useAircraftPath and not os.path.isabs(planet_file):
planet_file = os.path.join(self.get_full_aircraft_path(), planet_file)
if not os.path.exists(planet_file):
raise FileNotFoundError(errno.ENOENT, os.strerror(errno.ENOENT),
planet_file)
return self.thisptr.LoadPlanet(c_SGPath(planet_file.encode(), NULL),
useAircraftPath)
def set_engine_path(self, path: str) -> bool:
"""@Dox(JSBSim::FGFDMExec::SetEnginePath) """
return self.thisptr.SetEnginePath(c_SGPath(path.encode(), NULL))
def set_aircraft_path(self, path: str) -> bool:
"""@Dox(JSBSim::FGFDMExec::SetAircraftPath)"""
return self.thisptr.SetAircraftPath(c_SGPath(path.encode(), NULL))
def set_systems_path(self, path: str) -> bool:
"""@Dox(JSBSim::FGFDMExec::SetSystemsPath) """
return self.thisptr.SetSystemsPath(c_SGPath(path.encode(), NULL))
def set_output_path(self, path: str) -> bool:
"""@Dox(JSBSim::FGFDMExec::SetOutputPath) """
return self.thisptr.SetOutputPath(c_SGPath(path.encode(), NULL))
def set_root_dir(self, path: str) -> None:
"""@Dox(JSBSim::FGFDMExec::SetRootDir)"""
self.thisptr.SetRootDir(c_SGPath(path.encode(), NULL))
def get_engine_path(self) -> str:
"""@Dox(JSBSim::FGFDMExec::GetEnginePath)"""
return self.thisptr.GetEnginePath().utf8Str().decode('utf-8')
def get_aircraft_path(self) -> str:
"""@Dox(JSBSim::FGFDMExec::GetAircraftPath)"""
return self.thisptr.GetAircraftPath().utf8Str().decode('utf-8')
def get_systems_path(self) -> str:
"""@Dox(JSBSim::FGFDMExec::GetSystemsPath)"""
return self.thisptr.GetSystemsPath().utf8Str().decode('utf-8')
def get_output_path(self) -> str:
"""@Dox(JSBSim::FGFDMExec::GetOutputPath)"""
return self.thisptr.GetOutputPath().utf8Str().decode('utf-8')
def get_full_aircraft_path(self) -> str:
"""@Dox(JSBSim::FGFDMExec::GetFullAircraftPath)"""
return self.thisptr.GetFullAircraftPath().utf8Str().decode('utf-8')
def get_root_dir(self) -> str:
"""@Dox(JSBSim::FGFDMExec::GetRootDir)"""
return self.thisptr.GetRootDir().utf8Str().decode('utf-8')
def get_property_value(self, name: str) -> float:
"""@Dox(JSBSim::FGFDMExec::GetPropertyValue) """
return self.thisptr.GetPropertyValue(name.encode())
def set_property_value(self, name: str, value: float) -> None:
"""@Dox(JSBSim::FGFDMExec::SetPropertyValue)"""
self.thisptr.SetPropertyValue(name.encode(), value)
def get_model_name(self) -> str:
"""@Dox(JSBSim::FGFDMExec::GetModelName)"""
return self.thisptr.GetModelName().decode()
def set_output_directive(self, fname: str) -> bool:
"""@Dox(JSBSim::FGFDMExec::SetOutputDirectives)"""
return self.thisptr.SetOutputDirectives(c_SGPath(fname.encode(), NULL))
# def force_output(self, index: int) -> None:
# """@Dox(JSBSim::FGFDMExec::ForceOutput)"""
# self.thisptr.ForceOutput(index)
def set_logging_rate(self, rate: float) -> None:
"""@Dox(JSBSim::FGFDMExec::SetLoggingRate)"""
self.thisptr.SetLoggingRate(rate)
def set_output_filename(self, n: int, fname: str) -> bool:
"""@Dox(JSBSim::FGFDMExec::SetOutputFileName)"""
return self.thisptr.SetOutputFileName(n, fname.encode())
def get_output_filename(self, n: int) -> str:
"""@Dox(JSBSim::FGFDMExec::GetOutputFileName)"""
return self.thisptr.GetOutputFileName(n).decode()
def do_trim(self, mode: int) -> None:
"""@Dox(JSBSim::FGFDMExec::DoTrim) """
self.thisptr.DoTrim(mode)
def disable_output(self) -> None:
"""@Dox(JSBSim::FGFDMExec::DisableOutput)"""
self.thisptr.DisableOutput()
def enable_output(self) -> None:
"""@Dox(JSBSim::FGFDMExec::EnableOutput)"""
self.thisptr.EnableOutput()
def hold(self) -> None:
"""@Dox(JSBSim::FGFDMExec::Hold)"""
self.thisptr.Hold()
def enable_increment_then_hold(self, time_steps: int) -> None:
"""@Dox(JSBSim::FGFDMExec::EnableIncrementThenHold)"""
self.thisptr.EnableIncrementThenHold(time_steps)
def check_incremental_hold(self) -> None:
"""@Dox(JSBSim::FGFDMExec::CheckIncrementalHold)"""
self.thisptr.CheckIncrementalHold()
def resume(self) -> None:
"""@Dox(JSBSim::FGFDMExec::Resume)"""
self.thisptr.Resume()
def holding(self) -> bool:
"""@Dox(JSBSim::FGFDMExec::Holding)"""
return self.thisptr.Holding()
def reset_to_initial_conditions(self, mode: int) -> None:
"""@Dox(JSBSim::FGFDMExec::ResetToInitialConditions)"""
self.thisptr.ResetToInitialConditions(mode)
def set_debug_level(self, level: int) -> None:
"""@Dox(JSBSim::FGFDMExec::SetDebugLevel)"""
self.thisptr.SetDebugLevel(level)
def query_property_catalog(self, check: str) -> str:
"""@Dox(JSBSim::FGFDMExec::QueryPropertyCatalog)"""
return (self.thisptr.QueryPropertyCatalog(check.encode())).decode('utf-8')
def get_property_catalog(self) -> list[str]:
"""Retrieves the property catalog as a list."""
return self.query_property_catalog('').rstrip().split('\n')
def print_property_catalog(self) -> None:
"""@Dox(JSBSim::FGFDMExec::PrintPropertyCatalog)"""
self.thisptr.PrintPropertyCatalog()
def print_simulation_configuration(self) -> None:
"""@Dox(JSBSim::FGFDMExec::PrintSimulationConfiguration)"""
self.thisptr.PrintSimulationConfiguration()
def set_trim_status(self, status: bool) -> None:
"""@Dox(JSBSim::FGFDMExec::SetTrimStatus)"""
self.thisptr.SetTrimStatus(status)
def get_trim_status(self) -> bool:
"""@Dox(JSBSim::FGFDMExec::GetTrimStatus)"""
return self.thisptr.GetTrimStatus()
def get_propulsion_tank_report(self) -> str:
"""@Dox(JSBSim::FGFDMExec::GetPropulsionTankReport)"""
return self.thisptr.GetPropulsionTankReport().decode()
def get_sim_time(self) -> float:
"""@Dox(JSBSim::FGFDMExec::GetSimTime)"""
return self.thisptr.GetSimTime()
def get_delta_t(self) -> float:
"""@Dox(JSBSim::FGFDMExec::GetDeltaT)"""
return self.thisptr.GetDeltaT()
def suspend_integration(self) -> None:
"""@Dox(JSBSim::FGFDMExec::SuspendIntegration)"""
self.thisptr.SuspendIntegration()
def resume_integration(self) -> None:
"""@Dox(JSBSim::FGFDMExec::ResumeIntegration)"""
self.thisptr.ResumeIntegration()
def integration_suspended(self) -> bool:
"""@Dox(JSBSim::FGFDMExec::IntegrationSuspended)"""
return self.thisptr.IntegrationSuspended()
def set_sim_time(self, time: float) -> bool:
"""@Dox(JSBSim::FGFDMExec::Setsim_time)"""
return self.thisptr.Setsim_time(time)
def set_dt(self, dt: float) -> None:
"""@Dox(JSBSim::FGFDMExec::Setdt)"""
self.thisptr.Setdt(dt)
def incr_time(self) -> float:
"""@Dox(JSBSim::FGFDMExec::IncrTime)"""
return self.thisptr.IncrTime()
def get_debug_level(self) -> int:
"""@Dox(JSBSim::FGFDMExec::GetDebugLevel) """
return self.thisptr.GetDebugLevel()
def load_ic(self, rstfile: str, useAircraftPath: bool) -> bool:
reset_file = _append_xml(rstfile)
if useAircraftPath and not os.path.isabs(reset_file):
reset_file = os.path.join(self.get_full_aircraft_path(), reset_file)
if not os.path.exists(reset_file):
raise FileNotFoundError(errno.ENOENT, os.strerror(errno.ENOENT),
reset_file)
return deref(self.thisptr.GetIC()).Load(c_SGPath(rstfile.encode(), NULL),
useAircraftPath)
def get_propagate(self) -> FGPropagate:
"""@Dox(JSBSim::FGFDMExec::GetPropagate)"""
propagate = FGPropagate(None)
propagate.thisptr = self.thisptr.GetPropagate()
return propagate
def get_property_manager(self) -> FGPropertyManager:
"""@Dox(JSBSim::FGFDMExec::GetPropertyManager)"""
pm = FGPropertyManager()
pm.thisptr = self.thisptr.GetPropertyManager()
return pm
def get_ground_reactions(self) -> FGGroundReactions:
"""@Dox(JSBSim::FGFDMExec::GetGroundReactions)"""
grndreact = FGGroundReactions(None)
grndreact.thisptr = self.thisptr.GetGroundReactions()
return grndreact
def get_auxiliary(self) -> FGAuxiliary:
"""@Dox(JSBSim::FGFDMExec::GetAuxiliary)"""
auxiliary = FGAuxiliary(None)
auxiliary.thisptr = self.thisptr.GetAuxiliary()
return auxiliary
def get_aerodynamics(self) -> FGAerodynamics:
"""@Dox(JSBSim::FGFDMExec::GetAerodynamics)"""
aerodynamics = FGAerodynamics(None)
aerodynamics.thisptr = self.thisptr.GetAerodynamics()
return aerodynamics
def get_aircraft(self) -> FGAircraft:
"""@Dox(JSBSim::FGFDMExec::GetAircraft)"""
aircraft = FGAircraft(None)
aircraft.thisptr = self.thisptr.GetAircraft()
return aircraft
def get_mass_balance(self) -> FGMassBalance: