/src/morse/sensors/pose.py

https://github.com/peterroelants/morse · Python · 53 lines · 41 code · 3 blank · 9 comment · 0 complexity · 9df845bc7bb19065590fd923d207f4e4 MD5 · raw file

  1. import logging; logger = logging.getLogger("morse." + __name__)
  2. import GameLogic
  3. import math
  4. import morse.core.sensor
  5. class PoseClass(morse.core.sensor.MorseSensorClass):
  6. """ Robot pose sensor, including position and orientation """
  7. def __init__(self, obj, parent=None):
  8. """ Constructor method.
  9. Receives the reference to the Blender object.
  10. The second parameter should be the name of the object's parent.
  11. """
  12. logger.info('%s initialization' % obj.name)
  13. # Call the constructor of the parent class
  14. super(self.__class__,self).__init__(obj, parent)
  15. self.local_data['x'] = 0.0
  16. self.local_data['y'] = 0.0
  17. self.local_data['z'] = 0.0
  18. self.local_data['yaw'] = 0.0
  19. self.local_data['pitch'] = 0.0
  20. self.local_data['roll'] = 0.0
  21. logger.info('Component initialized')
  22. def default_action(self):
  23. """ Get the x, y, z, yaw, pitch and roll of the blender object. """
  24. x = self.position_3d.x
  25. y = self.position_3d.y
  26. z = self.position_3d.z
  27. yaw = self.position_3d.yaw
  28. pitch = self.position_3d.pitch
  29. roll = self.position_3d.roll
  30. # Store the orientation values in the robot's object
  31. self.robot_parent.yaw = yaw
  32. self.robot_parent.pitch = pitch
  33. self.robot_parent.roll = roll
  34. # Store the data acquired by this sensor that could be sent
  35. # via a middleware.
  36. self.local_data['x'] = float(x)
  37. self.local_data['y'] = float(y)
  38. self.local_data['z'] = float(z)
  39. # Store the data acquired by this sensor that could be sent
  40. # via a middleware.
  41. self.local_data['yaw'] = float(yaw)
  42. self.local_data['pitch'] = float(pitch)
  43. self.local_data['roll'] = float(roll)