PageRenderTime 27ms CodeModel.GetById 35ms RepoModel.GetById 0ms app.codeStats 0ms

/src/morse/sensors/human_posture.py

https://github.com/kargm/morse
Python | 153 lines | 139 code | 2 blank | 12 comment | 0 complexity | 444c093f9213e943f2b8c5cb6267f45d MD5 | raw file
  1. import math
  2. import GameLogic
  3. import morse.core.sensor
  4. class HumanPostureClass(morse.core.sensor.MorseSensorClass):
  5. """ Class definition for the human posture exporter.
  6. This sensor exports the posture of a human model moving in the simulator.
  7. A human posture is a vector of 39 floats. The 3 first are the [x,y,z]
  8. world position, the 3 next are the global rotation on the [x,y,z] axis.
  9. The 33 other one are described on a separate document (ask easisbot@laas.fr)
  10. Note: all angles are expressed in radians
  11. """
  12. def __init__(self, obj, parent=None):
  13. """ Constructor method.
  14. Receives the reference to the Blender object.
  15. The second parameter should be the name of the object's parent. """
  16. print("######## HUMAN POSTURE EXPORTER FOR '%s' INITIALIZING ########" % obj.name)
  17. # Call the constructor of the parent class
  18. super(self.__class__,self).__init__(obj, parent)
  19. self.local_data['x'] = 0.0
  20. self.local_data['y'] = 0.0
  21. self.local_data['z'] = 0.0
  22. self.local_data['roll'] = 0.0
  23. self.local_data['pitch'] = 0.0
  24. self.local_data['yaw'] = 0.0
  25. self.local_data['empty1'] = 0.0
  26. self.local_data['empty2'] = 0.0
  27. self.local_data['empty3'] = 0.0
  28. self.local_data['empty4'] = 0.0
  29. self.local_data['empty5'] = 0.0
  30. self.local_data['empty6'] = 0.0
  31. self.local_data['dof_12'] = 0.0
  32. self.local_data['dof_13'] = 0.0
  33. self.local_data['dof_14'] = 0.0
  34. self.local_data['dof_15'] = 0.0
  35. self.local_data['dof_16'] = 0.0
  36. self.local_data['dof_17'] = 0.0
  37. self.local_data['dof_18'] = 0.0
  38. self.local_data['dof_19'] = 0.0
  39. self.local_data['dof_20'] = 0.0
  40. self.local_data['dof_21'] = 0.0
  41. self.local_data['dof_22'] = 0.0
  42. self.local_data['dof_23'] = 0.0
  43. self.local_data['dof_24'] = 0.0
  44. self.local_data['dof_25'] = 0.0
  45. self.local_data['dof_26'] = 0.0
  46. self.local_data['dof_27'] = 0.0
  47. self.local_data['dof_28'] = 0.0
  48. self.local_data['dof_29'] = 0.0
  49. self.local_data['dof_30'] = 0.0
  50. self.local_data['dof_31'] = 0.0
  51. self.local_data['dof_32'] = 0.0
  52. self.local_data['dof_33'] = 0.0
  53. self.local_data['dof_34'] = 0.0
  54. self.local_data['dof_35'] = 0.0
  55. self.local_data['dof_36'] = 0.0
  56. self.local_data['dof_37'] = 0.0
  57. self.local_data['dof_38'] = 0.0
  58. self.local_data['dof_39'] = 0.0
  59. self.local_data['dof_40'] = 0.0
  60. self.local_data['dof_41'] = 0.0
  61. self.local_data['dof_42'] = 0.0
  62. self.local_data['dof_43'] = 0.0
  63. self.local_data['dof_44'] = 0.0
  64. self.local_data['dof_45'] = 0.0
  65. """
  66. self.data_keys = self.local_data.keys()
  67. # Initialise the copy of the data
  68. for variable in self.data_keys:
  69. self.modified_data.append(self.local_data[variable])
  70. """
  71. print ('######## HUMAN POSTURE EXPORTER INITIALIZED ########')
  72. def _read_pose(self, armature):
  73. for channel in armature.channels:
  74. if 'X_' not in channel.name:
  75. #rotation = channel.joint_rotation
  76. #print ("\tChannel '%s': (%.4f, %.4f, %.4f)" % (channel, rotation[0], rotation[1], rotation[2]))
  77. if channel.name == 'Chest':
  78. self.local_data['dof_12'] = channel.joint_rotation[1] #y
  79. self.local_data['dof_13'] = channel.joint_rotation[2] #x
  80. self.local_data['dof_14'] = channel.joint_rotation[0] #z
  81. if channel.name == 'Head':
  82. self.local_data['dof_15'] = - channel.joint_rotation[0] #z axis
  83. self.local_data['dof_16'] = channel.joint_rotation[2] #x axis
  84. self.local_data['dof_17'] = channel.joint_rotation[1] #y axis
  85. if channel.name == 'UpArm.R':
  86. self.local_data['dof_18'] = - channel.joint_rotation[1]
  87. self.local_data['dof_19'] = - channel.joint_rotation[0]
  88. self.local_data['dof_20'] = channel.joint_rotation[2]
  89. if channel.name == 'ForeArm.R':
  90. self.local_data['dof_21'] = channel.joint_rotation[2]
  91. if channel.name == 'Hand.R':
  92. self.local_data['dof_22'] = channel.joint_rotation[0]
  93. self.local_data['dof_23'] = channel.joint_rotation[1]
  94. self.local_data['dof_24'] = channel.joint_rotation[2]
  95. if channel.name == 'UpArm.L':
  96. self.local_data['dof_25'] = - channel.joint_rotation[1]
  97. self.local_data['dof_26'] = - channel.joint_rotation[0]
  98. self.local_data['dof_27'] = channel.joint_rotation[2]
  99. if channel.name == 'ForeArm.L':
  100. self.local_data['dof_28'] = channel.joint_rotation[2]
  101. if channel.name == 'Hand.L':
  102. self.local_data['dof_29'] = channel.joint_rotation[0]
  103. self.local_data['dof_30'] = channel.joint_rotation[1]
  104. self.local_data['dof_31'] = channel.joint_rotation[2]
  105. if channel.name == 'UpLeg.R' :
  106. self.local_data['dof_32'] = channel.joint_rotation[1]
  107. self.local_data['dof_33'] = channel.joint_rotation[0]
  108. self.local_data['dof_34'] = - channel.joint_rotation[2]
  109. if channel.name == 'LoLeg.R':
  110. self.local_data['dof_35'] = channel.joint_rotation[0]
  111. if channel.name == 'Foot.R':
  112. self.local_data['dof_36'] = channel.joint_rotation[0]
  113. self.local_data['dof_37'] = channel.joint_rotation[1]
  114. self.local_data['dof_38'] = channel.joint_rotation[2]
  115. if channel.name == 'UpLeg.L':
  116. self.local_data['dof_39'] = channel.joint_rotation[1]
  117. self.local_data['dof_40'] = channel.joint_rotation[0]
  118. self.local_data['dof_41'] = - channel.joint_rotation[2]
  119. if channel.name == 'LoLeg.L':
  120. self.local_data['dof_42'] = channel.joint_rotation[0]
  121. if channel.name == 'Foot.L':
  122. self.local_data['dof_43'] = channel.joint_rotation[0]
  123. self.local_data['dof_44'] = channel.joint_rotation[1]
  124. self.local_data['dof_45'] = channel.joint_rotation[2]
  125. def default_action(self):
  126. """ Extract the human posture """
  127. self.local_data['x'] = float(self.position_3d.x)
  128. self.local_data['y'] = float(self.position_3d.y)
  129. self.local_data['z'] = float(self.position_3d.z)
  130. self.local_data['yaw'] = float(self.position_3d.yaw) - 1.57 #pi/2
  131. self.local_data['pitch'] = float(self.position_3d.pitch)
  132. self.local_data['roll'] = float(self.position_3d.roll)
  133. self._read_pose(self.blender_obj)
  134. #print ("LOCAL_DATA: ", self.local_data)