Пример #1
0
    def _initialize(self, **kwargs):
        """
        :param kwargs:
        :return:
        """
        self.mass = MASS
        self.x = SENSOR_BASE_THICKNESS
        self.y = self.z = SENSOR_BASE_WIDTH
        super(LightSensor, self)._initialize(**kwargs)

        # Add the SDF camera sensor
        camera = SdfSensor(
                name="{}_light_sensor".format(self.id),
                sensor_type="camera",
                update_rate=self.conf.sensor_update_rate)

        # TODO: Set field of view
        cam_details = "<camera>" \
                      "<image>" \
                      "<width>1</width><height>1</height>" \
                      "</image>" \
                      "<clip><near>{}</near><far>{}</far></clip>" \
                      "</camera>".format(nf(in_mm(1)), nf(in_mm(50000)))
        camera.add_element(cam_details)
        camera.set_position(Vector3(0.5 * self.x, 0, 0))
        self.component.add_sensor(camera, "light")

        if self.conf.visualize_sensors:
            camera.add_element("<visualize>1</visualize>")

        self.apply_color()
Пример #2
0
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)
Пример #3
0
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)
Пример #4
0
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)
Пример #5
0
 def render_attributes(self):
     """
     :return:
     """
     attrs = super(VelocityMotor, self).render_attributes()
     attrs.update({'min_velocity': nf(self.min_velocity), 'max_velocity': nf(self.max_velocity)})
     return attrs
Пример #6
0
    def _initialize(self, **kwargs):
        """
        :param kwargs:
        :return:
        """
        self.mass = MASS
        self.x = SENSOR_BASE_THICKNESS
        self.y = self.z = SENSOR_BASE_WIDTH
        super(LightSensor, self)._initialize(**kwargs)

        # Add the SDF camera sensor
        camera = SdfSensor("%s_light_sensor" % self.id, "camera",
                           update_rate=self.conf.sensor_update_rate)

        # TODO Set field of view
        cam_details = "<camera>" \
                      "<image>" \
                      "<width>1</width><height>1</height>" \
                      "</image>" \
                      "<clip><near>%s</near><far>%s</far></clip>" \
                      "</camera>" % (nf(in_mm(1)), nf(in_mm(50000)))
        camera.add_element(cam_details)
        camera.set_position(Vector3(0.5 * self.x, 0, 0))
        self.component.add_sensor(camera, "light")

        if self.conf.visualize_sensors:
            camera.add_element("<visualize>1</visualize>")

        self.apply_color()
Пример #7
0
 def render_attributes(self):
     """
     :return:
     """
     attrs = super(VelocityMotor, self).render_attributes()
     attrs.update({'min_velocity': nf(self.min_velocity), 'max_velocity': nf(self.max_velocity)})
     return attrs
Пример #8
0
    def render_elements(self):
        """

        :return:
        """
        elms = super(BasicBattery, self).render_elements()
        return elms + [Element(tag_name="rv:level", body=nf(self.level))]
Пример #9
0
    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)
Пример #10
0
    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
Пример #11
0
    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
Пример #12
0
    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
Пример #13
0
    def render_attributes(self):
        """
        """
        attrs = super(NeuralConnection, self).render_attributes()
        attrs.update({
            'src': self.conn.src,
            'dst': self.conn.dst,
            'weight': nf(self.conn.weight)
        })

        return attrs
Пример #14
0
    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
Пример #15
0
 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