1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 """The interface to the MBDyn reference frames."""
23 import numpy as N
24 from types import ListType
25
26 from mbdyn.bindings.basic_objects import BasicObject
27
28
30 """The MBDyn reference frame that output values in
31 the absolute reference frame. The object definition is
32 coming from C{ReferenceFrame}, in 'I{reffrm.h}
33 and 'I{reference_frame.i}' for the SWIG interface.
34 Until now, only L{get_position} and L{get_orientation_matrix}
35 are available.
36 """
37
39 BasicObject.__init__(self, c_inst)
40 self.position = N.zeros((3, 1))
41 self._posC = self.c_inst.GetX()
42 self.orientation_matrix = N.zeros((3, 3))
43 self._omC = self.c_inst.GetR()
44 self.velocity = N.zeros((3, 1))
45 self.angular_velocity = N.zeros((3, 1))
46
48 """Fill the position array from the C++ instance."""
49
50 for idx in range(3):
51 self.position[idx][0] = self._posC.get_value(idx)
52
54 """Return a copy of the numpy array
55
56 @rtype: numpy array
57 @return: a 3x1 vector"""
58 self.fill_position()
59 return self.position.copy()
60
62 """Fill the orientation matrix from the C++ instance"""
63 for idx in range(3):
64 for jdx in range(3):
65 self.orientation_matrix[idx][jdx] = self._omC.get_value(idx,
66 jdx)
67
69 """Return a copy of the orientation matrix, defining
70 the reference frame.
71
72 @rtype: numpy array
73 @return: a 3x3 matrix"""
74 self.fill_position()
75 self.fill_orientation_matrix()
76 return self.orientation_matrix.copy()
77
79 mess = "ReferenceFrame pointer with label %s in MBDyn"
80 return mess % str(self.label)
81
82
84 """The list of MBDyn reference frames. This class is used
85 by L{WraptMBDyn} in case the input file parsing has created
86 some MBDyn reference frame instances."""
87
89 ListType.__init__(self)
90 self.labels = []
91
92 - def add(self, frame):
93 """Add a L{ReferenceFrame<mbdyn.bindings.frames.ReferenceFrame>}
94 to the list and keep track of its label"""
95 self.append(frame)
96 self.labels.append(frame.label)
97
99 """Return a L{mbdyn.bindings.frames.ReferenceFrame} from the label.
100 Used by L{mbdyn.references.ReferenceFrame} to get the mbdyn instance."""
101 return self[self.labels.index(label)]
102