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 render_elements(self): """ :return: """ elmns = super(PointIntensitySensor, self).render_elements() return elmns + [ Element(tag_name='rv:point', body='%s %s %s' % tuple(self.point)), Element(tag_name='rv:function', attributes={ 'i_max': self.i_max, 'r': self.r }) ]
def render_elements(self): """ :return: """ elms = super(BasicBattery, self).render_elements() return elms + [Element(tag_name="rv:level", body=nf(self.level))]
def render_elements(self): sub = [] for attr in ['p', 'i', 'd', 'i_max', 'i_min', 'cmd_max', 'cmd_min']: v = getattr(self, attr, None) if v is not None: sub.append(Element(tag_name='rv:'+attr, body=nf(v))) return super(PID, self).render_elements() + sub
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 __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 test_filter(self): root = Element() sub1 = A() sub2 = B() sub1a = A() sub1b = B() sub1c = C() sub2a = A() sub2b = B() sub2ab = B() sub1.add_elements([sub1a, sub1b, sub1c]) sub2.add_elements([sub2a, sub2b]) sub2a.add_element(sub2ab) root.add_elements([sub1, sub2]) check = root.get_elements_of_type(B, recursive=False) self.assertEquals([sub2], check) check = root.get_elements_of_type(B, recursive=True) self.assertEquals([sub1b, sub1c, sub2, sub2ab, sub2b], check)
def render_elements(self): """ Adds attributes as elements """ elms = [Element(tag_name='rv:'+param, body=nf(self.params[param])) for param in self.params] return super(Neuron, self).render_elements() + elms
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