Example #1
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
Example #2
0
m = Model(name="mybot")
sdf = SDF(elements=[m])

geom = Box(SENSOR_BASE_THICKNESS, SENSOR_BASE_WIDTH, SENSOR_BASE_WIDTH, MASS)
base = StructureCombination("base", geom)

x_sensors = 0.5 * (SENSOR_BASE_THICKNESS + SENSOR_THICKNESS)
y_left_sensor = -0.5 * SENSOR_WIDTH - SEPARATION
y_right_sensor = 0.5 * SENSOR_WIDTH + SEPARATION

left = StructureCombination("left", Box(SENSOR_THICKNESS, SENSOR_WIDTH, SENSOR_HEIGHT, MASS))
left.set_position(Vector3(x_sensors, y_left_sensor, 0))

right = StructureCombination("right", Box(SENSOR_THICKNESS, SENSOR_WIDTH, SENSOR_HEIGHT, MASS))
right.set_position(Vector3(x_sensors, y_right_sensor, 0))

link = Link("my_link")
link.add_elements([base, left, right])


link.align_center_of_mass()
link.calculate_inertial()

m.add_element(link)

apply_surface_parameters(m)
m.translate(Vector3(0, 0, in_mm(30)))

with open("/home/elte/.gazebo/models/test_bot/model.sdf", "w") as f:
    f.write(str(sdf))
Example #3
0
group.align(
    # Center of the right face of box 1
    Vector3(1, 0, 0),

    # Vector normal to box 2 right face
    Vector3(1, 0, 0),

    # Vector normal to box 2 top face should align with...(*)
    Vector3(0, 0, 1),

    # Center of the top face of box 2
    Vector3(0, 0, 1.5),

    # Vector normal to box 2 top face
    Vector3(0, 0, 1),

    # (*)...vector normal to box 2 right face
    Vector3(1, 0, 0),

    # the link to align with
    link2
)

if __name__ == '__main__':
    sdf = SDF()
    model = Model("my_model")
    model.add_element(group)
    model.add_element(link2)
    sdf.add_element(model)
    print(str(sdf))
Example #4
0
from trollius import From
from tol.config import Config
from tol.manage import World

from sdfbuilder import SDF, Link, Model
from sdfbuilder.sensor import Sensor

conf = Config(visualize_sensors=True)

sdf = SDF()
model = Model("crash")
link = Link("my_link")
link.make_box(1.0, 1, 1, 1)
sensor = Sensor("sense", "contact")
link.add_element(sensor)
model.add_element(link)
sdf.add_element(model)
model.set_position(Vector3(0, 0, 0.5))


@trollius.coroutine
def run_server():
    world = yield From(World.create(conf))

    counter = 0
    while True:
        model.name = "test_bot_%d" % counter
        print("Inserting %s..." % model.name)
        fut = yield From(world.insert_model(sdf))
        yield From(fut)
        print("Done. Waiting...")