Package mbdyn :: Package bindings :: Module frames
[hide private]

Source Code for Module mbdyn.bindings.frames

  1  #!/usr/bin/env python 
  2  # -*- coding: utf-8 -*- 
  3  # 
  4  # This file is part of MBDyn sim suite. 
  5  # Copyright (C) 2007 André ESPAZE, as part of a Master thesis supervised by 
  6  # Martin O.L.Hansen (DTU) and Nicolas Chauvat (Logilab) 
  7   
  8  # MBDyn sim suite is free software; you can redistribute it and/or modify 
  9  # it under the terms of the GNU General Public License as published by 
 10  # the Free Software Foundation; either version 2 of the License, or 
 11  # (at your option) any later version. 
 12  # 
 13  # This program is distributed in the hope that it will be useful, 
 14  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
 15  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 16  # GNU General Public License for more details. 
 17  # 
 18  # You should have received a copy of the GNU General Public License 
 19  # along with this program; if not, write to the Free Software 
 20  # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 
 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   
29 -class ReferenceFrame(BasicObject):
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
38 - def __init__(self, c_inst=None):
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
47 - def fill_position(self):
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
53 - def get_position(self):
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
61 - def fill_orientation_matrix(self):
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
68 - def get_orientation_matrix(self):
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
78 - def __repr__(self):
79 mess = "ReferenceFrame pointer with label %s in MBDyn" 80 return mess % str(self.label)
81 82
83 -class FramesList(ListType):
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
88 - def __init__(self):
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
98 - def get_from_label(self, label):
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