def apply_surface_parameters(model): """ Applies surface parameters to all collisions in the given model. :param model: :type model: Model :return: """ # Add friction surfaces to all body parts surf = Element(tag_name="surface") friction = Friction( friction=constants.SURFACE_FRICTION1, friction2=constants.SURFACE_FRICTION2, slip1=constants.SURFACE_SLIP1, slip2=constants.SURFACE_SLIP2 ) contact = "<contact>" \ "<ode>" \ "<kd>%s</kd>" \ "<kp>%s</kp>" \ "</ode>" \ "</contact>" % ( nf(constants.SURFACE_KD), nf(constants.SURFACE_KP) ) surf.add_element(contact) surf.add_element(friction) collisions = model.get_elements_of_type(Collision, recursive=True) for collision in collisions: collision.add_element(surf)
def apply_surface_parameters(model, intended_step_size=0.005): """ Applies surface parameters to all collisions in the given model. :param model: :type model: Model :param intended_step_size: :return: """ surface_kd = constants.SURFACE_ERP / (constants.SURFACE_CFM * intended_step_size) surface_kp = 1.0 / constants.SURFACE_CFM - (constants.SURFACE_ERP / constants.SURFACE_CFM) # Add friction surfaces to all body parts surf = Element(tag_name="surface") friction = Friction( friction=constants.SURFACE_FRICTION1, friction2=constants.SURFACE_FRICTION2, slip1=constants.SURFACE_SLIP1, slip2=constants.SURFACE_SLIP2 ) contact = "<contact>" \ "<ode>" \ "<kd>%s</kd>" \ "<kp>%s</kp>" \ "</ode>" \ "</contact>" % ( nf(surface_kd), nf(surface_kp) ) surf.add_element(contact) surf.add_element(friction) collisions = model.get_elements_of_type(Collision, recursive=True) for collision in collisions: collision.add_element(surf)
def get_sdf_model( self, robot, controller_plugin=None, update_rate=5, name="sdf_robot", analyzer_mode=False, battery=None, brain_conf=None ): """ :param robot: Protobuf robot :type robot: Robot :param controller_plugin: Name of the shared library of the model plugin :type controller_plugin: str|none :param update_rate: Update rate as used by the default controller :type update_rate: float :param name: Name of the SDF model :type name: str :param analyzer_mode: :type analyzer_mode: bool :param battery: A Battery element to be added to the plugin if applicable. :type battery: Element :param brain_conf: Brain configuration data :type brain_conf: dict :return: The sdf-builder Model :rtype: Model """ model = Model(name) # Create the model plugin element plugin = Element(tag_name='plugin', attributes={ 'name': 'robot_controller', 'filename': controller_plugin }) # Add body config element config = Element(tag_name='rv:robot_config', attributes={ 'xmlns:rv': 'https://github.com/ElteHupkes/revolve' }) config.add_element(Element(tag_name='rv:update_rate', body=nf(update_rate))) plugin.add_element(config) # Add brain config element brain_config = Element(tag_name='rv:brain', attributes=brain_conf) config.add_element(brain_config) self.brain_builder.build(robot, model, brain_config, analyzer_mode) self.body_builder.build(robot, model, config, analyzer_mode) if battery: config.add_element(battery) if controller_plugin: # Only add the plugin element when required model.add_element(plugin) return model
def __init__(self, diameter=3.0, height=3.0, name="birth_clinic"): """ :param diameter: Intended diameter of the birth clinic :param name: :return: """ super(BirthClinic, self).__init__(name=name, static=True) self.diameter = diameter scale = diameter / MESH_DIAMETER # Cannot go higher than mesh height, or lower than the bottom # of the slice. scaled_height = scale * MESH_HEIGHT self.height = max(min(height, scaled_height), SLICE_FRACTION * scaled_height) mesh = Mesh("model://tol_robot/meshes/BirthClinic.dae", scale=scale) col = Collision("bc_col", mesh) surf = Element(tag_name="surface") friction = Friction( friction=0.01, friction2=0.01, slip1=1.0, slip2=1.0 ) contact = "<contact>" \ "<ode>" \ "<kd>%s</kd>" \ "<kp>%s</kp>" \ "</ode>" \ "</contact>" % ( nf(constants.SURFACE_KD), nf(constants.SURFACE_KP) ) surf.add_element(friction) surf.add_element(contact) col.add_element(surf) vis = Visual("bc_vis", mesh.copy()) self.link = Link("bc_link", elements=[col, vis]) # By default the model has 0.5 * scale * MESH_HEIGHT below # and above the surface. Translate such that we have exactly # the desired height instead. self.link.translate(Vector3(0, 0, self.height - (0.5 * scaled_height))) self.add_element(self.link)
def get_sdf_model(self, robot, controller_plugin=None, update_rate=5, name="sdf_robot", analyzer_mode=False, battery=None, brain_conf=None): """ :param robot: Protobuf robot :type robot: Robot :param controller_plugin: Name of the shared library of the model plugin :type controller_plugin: str|none :param update_rate: Update rate as used by the default controller :type update_rate: float :param name: Name of the SDF model :type name: str :param analyzer_mode: :type analyzer_mode: bool :param battery: A Battery element to be added to the plugin if applicable. :type battery: Element :param brain_conf: Brain configuration data :type brain_conf: dict :return: The sdf-builder Model :rtype: Model """ model = Model(name) # Create the model plugin element plugin = Element(tag_name='plugin', attributes={ 'name': 'robot_controller', 'filename': controller_plugin }) # Add body config element config = Element(tag_name='rv:robot_config', attributes={ 'xmlns:rv': 'https://github.com/ElteHupkes/revolve' }) config.add_element(Element(tag_name='rv:update_rate', body=nf(update_rate))) plugin.add_element(config) # Add brain config element brain_config = Element(tag_name='rv:brain', attributes=brain_conf) config.add_element(brain_config) self.brain_builder.build(robot, model, brain_config, analyzer_mode) self.body_builder.build(robot, model, config, analyzer_mode) if battery: config.add_element(battery) if controller_plugin: # Only add the plugin element when required model.add_element(plugin) return model