class Human(GroundRobot): """ Append a human model to the scene. Usage example: .. code-block:: python #! /usr/bin/env morseexec from morse.builder import * human = Human() human.translate(x=5.5, y=-3.2, z=0.0) human.rotate(z=-3.0) human.skeleton.add_stream('pocolibs') Currently, only one human per simulation is supported. Detailed documentation ---------------------- The MORSE human avatar is based on a 3D model generated from MakeHuman, and stored in human_rig.blend. The model is rigged with an armature (`human.skeleton`), used to control the postures of the human and to deform accordingly the human mesh. This armature is used by MORSE as both a :doc:`sensor to read and export the human pose <../sensors/armature_pose>` and :doc:`an actuator <../actuators/armature>` to modify the pose. TODO: give code examples to read and modify the pose The armature defines 5 particular points (**IK targets**) that can be manipulated to control the human model in a simpler way: the head, the two wrists and the two feet. """ # list of human bones that we want to control via IK targets IK_TARGETS = ["head", "wrist_L", "wrist_R", "foot_L", "foot_R"] def __init__(self, filename='human_rig', name = None): """ The 'style' parameter is only to switch to the mocap_human file. :param filename: the human model. Default: 'human_rig' """ GroundRobot.__init__(self, filename, name) self.properties(classpath = "morse.robots.human.Human") self.skeleton = None try: self.skeleton = Armature(armature_name = "HumanSkeleton") self.append(self.skeleton) except KeyError: logger.error("Could not find the human armature! (I was looking " +\ "for an object called 'HumanSkeleton' in the children " + \ "objects of the human). I won't be able to export the " + \ "human pose to any middleware.") if self.skeleton: self.skeleton.create_ik_targets(self.IK_TARGETS) for t, name in self.skeleton.ik_targets: t.parent = self._bpy_object # Add an armature sensor. "joint_stateS" to match standard ROS spelling. self.joint_states = ArmaturePose("joint_states") self.skeleton.append(self.joint_states) self.keyboard = Keyboard() self.keyboard.properties(Speed=1.15) self.append(self.keyboard) def add_interface(self, interface): if interface == "socket": self.joint_states.add_stream("socket") self.joint_states.add_service("socket") self.skeleton.add_service('socket') elif interface == "ros": self.joint_states.add_stream("ros") self.skeleton.add_service("ros") self.skeleton.add_overlay("ros", "morse.middleware.ros.overlays.armatures.ArmatureController") elif interface == "pocolibs": self.skeleton.properties(classpath="morse.sensors.human_posture.HumanPosture") self.add_stream(interface)
class Human(GroundRobot): """ Append a human model to the scene. The human model currently available in MORSE comes with its own subjective camera and several features for object manipulation. It also exposes a :doc:`human posture component <../sensors/human_posture>` that can be accessed by the ``armature`` member. Usage example: .. code-block:: python #! /usr/bin/env morseexec from morse.builder import * human = Human() human.translate(x=5.5, y=-3.2, z=0.0) human.rotate(z=-3.0) human.armature.add_stream('pocolibs') Currently, only one human per simulation is supported. """ def __init__(self, filename='human', name = None): """ The 'style' parameter is only to switch to the mocap_human file. :param filename: 'human' (default) or 'mocap_human' """ GroundRobot.__init__(self, filename, name) self.suffix = self.name[-4:] if self.name[-4] == "." else "" self.armature = None if filename == 'mocap_human': self.properties(classpath="morse.robots.mocap_human.MocapHuman") else: self.properties(classpath="morse.robots.human.Human") try: self.armature = Armature(armature_name = "HumanArmature" + self.suffix) self.append(self.armature) except KeyError: logger.error("Could not find the human armature! (I was looking " +\ "for an object called 'HumanArmature' in the human" +\ " children). I won't be able to export the human pose" +\ " to any middleware.") # Add an armature sensor. "joint_stateS" to match standard ROS spelling. self.joint_states = ArmaturePose() self.armature.append(self.joint_states) # fix for Blender 2.6 Animations armature_object = self.get_child(self.armature.name) if armature_object: hips = self.get_child("Hips_Empty") # IK human has no object called Hips_Empty, so avoid this step if hips: for i, actuator in enumerate(hips.game.actuators): actuator.layer = i for i, actuator in enumerate(armature_object.game.actuators): actuator.layer = i def after_renaming(self): if self._blender_filename == 'mocap_human': # no need for mocap return # Store the human real name (ie, after renaming) in its link 'POS_EMPTY' and 'Human_Camera' object, for later control. pos_empty = bpymorse.get_object("POS_EMPTY" + self.suffix) bpymorse.select_only(pos_empty) bpymorse.new_game_property() prop = pos_empty.game.properties # select the last property in the list (which is the one we just added) prop[-1].name = "human_name" prop[-1].type = "STRING" prop[-1].value = self.name human_camera = bpymorse.get_object("Human_Camera" + self.suffix) bpymorse.select_only(human_camera) bpymorse.new_game_property() prop = human_camera.game.properties # select the last property in the list (which is the one we just added) prop[-1].name = "human_name" prop[-1].type = "STRING" prop[-1].value = self.name def add_interface(self, interface): if interface == "socket": self.joint_states.add_stream("socket") self.armature.add_service('socket') elif interface == "ros": self.joint_states.add_stream("ros") self.armature.add_service("ros") self.armature.add_overlay("ros", "morse.middleware.ros.overlays.armatures.ArmatureController") elif interface == "pocolibs": self.armature.properties(classpath="morse.sensors.human_posture.HumanPosture") self.add_stream(interface) def use_world_camera(self): self.properties(WorldCamera = True) def disable_keyboard_control(self): self.properties(disable_keyboard_control = True)
class Human(GroundRobot): """ Append a human model to the scene. Usage example: .. code-block:: python #! /usr/bin/env morseexec from morse.builder import * human = Human() human.translate(x=5.5, y=-3.2, z=0.0) human.rotate(z=-3.0) human.skeleton.add_stream('pocolibs') Currently, only one human per simulation is supported. Detailed documentation ---------------------- The MORSE human avatar is based on a 3D model generated from MakeHuman, and stored in human_rig.blend. The model is rigged with an armature (`human.skeleton`), used to control the postures of the human and to deform accordingly the human mesh. This armature is used by MORSE as both a :doc:`sensor to read and export the human pose <../sensors/armature_pose>` and :doc:`an actuator <../actuators/armature>` to modify the pose. TODO: give code examples to read and modify the pose The armature defines 5 particular points (**IK targets**) that can be manipulated to control the human model in a simpler way: the head, the two wrists and the two feet. """ # list of human bones that we want to control via IK targets IK_TARGETS = ["head", "wrist_L", "wrist_R", "foot_L", "foot_R"] def __init__(self, filename='human_rig', name=None): """ :param filename: the human model. Default: 'human_rig' """ GroundRobot.__init__(self, filename, name) self.properties(classpath="morse.robots.human.Human") self.skeleton = None try: self.skeleton = Armature( armature_name=self.get_child("HumanSkeleton").name) self.append(self.skeleton) except KeyError: logger.error("Could not find the human armature! (I was looking " +\ "for an object called 'HumanSkeleton' in the children " + \ "objects of the human). I won't be able to export the " + \ "human pose to any middleware.") if self.skeleton: self.skeleton.create_ik_targets(self.IK_TARGETS) for t, name in self.skeleton.ik_targets: t.parent = self._bpy_object # Add an armature sensor. "joint_stateS" to match standard ROS spelling. self.joint_states = ArmaturePose("joint_states") self.skeleton.append(self.joint_states) def add_interface(self, interface): if interface == "socket": self.joint_states.add_stream("socket") self.joint_states.add_service("socket") self.skeleton.add_service('socket') elif interface == "ros": self.joint_states.add_stream("ros") self.skeleton.add_service("ros") self.skeleton.add_overlay( "ros", "morse.middleware.ros.overlays.armatures.ArmatureController") elif interface == "pocolibs": self.skeleton.properties( classpath="morse.sensors.human_posture.HumanPosture") self.add_stream(interface)
class Human(GroundRobot): """ Append a human model to the scene. The human model currently available in MORSE comes with its own subjective camera and several features for object manipulation. It also exposes a :doc:`human posture component <../sensors/human_posture>` that can be accessed by the ``armature`` member. Usage example: .. code-block:: python #! /usr/bin/env morseexec from morse.builder import * human = Human() human.translate(x=5.5, y=-3.2, z=0.0) human.rotate(z=-3.0) human.armature.add_stream('pocolibs') Currently, only one human per simulation is supported. """ def __init__(self, filename='human', name = None): """ The 'style' parameter is only to switch to the mocap_human file. :param filename: 'human' (default) or 'mocap_human' """ GroundRobot.__init__(self, filename, name) self.suffix = self.name[-4:] if self.name[-4] == "." else "" self.armature = None if filename == 'mocap_human': self.properties(classpath="morse.robots.mocap_human.MocapHuman") else: self.properties(classpath="morse.robots.human.Human") try: self.armature = Armature(armature_name = "HumanArmature" + self.suffix) self.append(self.armature) except KeyError: logger.error("Could not find the human armature! (I was looking " +\ "for an object called 'HumanArmature' in the human" +\ " children). I won't be able to export the human pose" +\ " to any middleware.") # Add an armature sensor. "joint_stateS" to match standard ROS spelling. self.joint_states = ArmaturePose() self.armature.append(self.joint_states) # fix for Blender 2.6 Animations armature_object = self.get_child(self.armature.name) if armature_object: hips = self.get_child("Hips_Empty") # IK human has no object called Hips_Empty, so avoid this step if hips: for i, actuator in enumerate(hips.game.actuators): actuator.layer = i for i, actuator in enumerate(armature_object.game.actuators): actuator.layer = i self.make_grasper('Hand_Grab.R') def after_renaming(self): if self._blender_filename == 'mocap_human': # no need for mocap return # Store the human real name (ie, after renaming) in its link 'POS_EMPTY' and 'Human_Camera' object, for later control. pos_empty = bpymorse.get_object("POS_EMPTY" + self.suffix) bpymorse.select_only(pos_empty) bpymorse.new_game_property() prop = pos_empty.game.properties # select the last property in the list (which is the one we just added) prop[-1].name = "human_name" prop[-1].type = "STRING" prop[-1].value = self.name human_camera = bpymorse.get_object("Human_Camera" + self.suffix) bpymorse.select_only(human_camera) bpymorse.new_game_property() prop = human_camera.game.properties # select the last property in the list (which is the one we just added) prop[-1].name = "human_name" prop[-1].type = "STRING" prop[-1].value = self.name def add_interface(self, interface): if interface == "socket": self.joint_states.add_stream("socket") self.armature.add_service('socket') elif interface == "ros": self.joint_states.add_stream("ros") self.armature.add_service("ros") self.armature.add_overlay("ros", "morse.middleware.ros.overlays.armatures.ArmatureController") elif interface == "pocolibs": self.armature.properties(classpath="morse.sensors.human_posture.HumanPosture") self.add_stream(interface) def use_world_camera(self): self.properties(WorldCamera = True) def disable_keyboard_control(self): self.properties(disable_keyboard_control = True)