class Wall(Model): """ Simple wall model to wall off the """ def __init__(self, name, start, end, thickness, height, **kwargs): """ Construct a wall of the given thickness and height from `start` to `end`. This simply results in a box. :param start: Starting point of the wall. :type start: Vector3 :param end: Ending point of the wall. :type end: Vector3 :return: """ super(Wall, self).__init__(name, static=True, **kwargs) assert start.z == end.z, "Walls with different start / end z are undefined." center = 0.5 * (end + start) diff = end - start size = abs(diff) self.wall = Link("wall_link") self.wall.make_box(10e10, size, thickness, height) # Rotate the wall so it aligns with the vector from # x to y self.align( Vector3(0, 0, 0), Vector3(1, 0, 0), Vector3(0, 0, 1), center, diff, Vector3(0, 0, 1), Posable("mock") ) self.add_element(self.wall)
def gen_boxes(model_name, dimensions=4, spacing=0.5, size=0.05, height=0.015, center_sq=1): model = Model(model_name, static=True) for x in range(-dimensions, dimensions + 1): for y in range(-dimensions, dimensions + 1): l = Link("box") if (abs(x) >= center_sq or abs(y) >= center_sq): l.make_box(1, size, size, height) pos = Vector3(spacing * x, spacing * y, height / 2) l.set_position(pos) #l.rotate_around(Vector3(0, 0, 1), math.radians(x*y), relative_to_child=False) model.add_element(l) return model
def gen_boxes(dimensions=4, spacing=0.5, size=0.05): for x in range(-dimensions,dimensions+1): for y in range(-dimensions,dimensions+1): l = Link("box") #box_geom = Box(1.0, 1.0, 1.0, mass=0.5) #b = StructureCombination("box", box_geom) #l.add_element(b) if (x!=0 or y!=0): l.make_box(1, size, size, 0.01*max(abs(x),abs(y))) pos = Vector3(spacing*x,spacing*y,0) l.set_position(pos) l.rotate_around(Vector3(0, 0, 1), math.radians(x*y), relative_to_child=False) model.add_element(l)
def gen_steps(model_name, num_steps=6, offset=0.4, height=0.02, width=3.0, depth=0.2, incline=0): model = Model(model_name, static=True) steps = PosableGroup() for x in range(0, num_steps): l = Link("box") l.make_box(1, depth, width, height) pos = Vector3(offset + depth * x, 0, height / 2 + x * height) l.set_position(pos) steps.add_element(l) for x in range(0, 4): steps.set_rotation( Quaternion.from_rpy(0, math.radians(-incline), math.radians(90 * x))) model.add_element(steps.copy()) return model
from __future__ import print_function import sys from sdfbuilder import Link, Model, SDF from sdfbuilder.math import Vector3 # Create two similar boxes link1 = Link("box1") link1.make_box(1.0, 0.1, 0.3, 0.5) link2 = Link("box2") link2.make_box(1.0, 0.1, 0.3, 0.5) # Align the top of box2 with the front of box1 link2.align(Vector3(0, 0, 0.25), Vector3(0, 0, -1), Vector3(1, 0, 0), Vector3(0, -0.15, 0), Vector3(0, 1, 0), Vector3(0, 0, 1), link1) if __name__ == '__main__': sdf = SDF() model = Model("my_model") model.add_element(link1) model.add_element(link2) sdf.add_element(model) print(str(sdf))
from sdfbuilder import Link, PosableGroup, SDF, Model from sdfbuilder.math import Vector3 from math import pi link = Link("my_link") minibox = Link("my_minibox") # Link one is a vertical box link.make_box(1.0, 2, 2, 4) # Minibox is... well, a mini box minibox.make_box(0.1, 0.2, 0.2, 0.2) minibox.align( # Bottom left corner of minibox Vector3(-0.1, -0.1, -0.1), # Normal vector Vector3(-0.1, -0.1, -0.1), # Tangent vector Vector3(-0.1, -0.1, 0.2), # Top left of link Vector3(-1, -1, 2), # Normal vector Vector3(0, 0, 1), # Tangent vector
sys.path.append(os.path.dirname(os.path.abspath(__file__))+'/../') import trollius 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)
from __future__ import print_function import sys from sdfbuilder import Link, Model, SDF from sdfbuilder.math import Vector3 # Create two similar boxes link1 = Link("box1") link1.make_box(1.0, 0.1, 0.3, 0.5) link2 = Link("box2") link2.make_box(1.0, 0.1, 0.3, 0.5) # Align the top of box2 with the front of box1 link2.align( Vector3(0, 0, 0.25), Vector3(0, 0, -1), Vector3(1, 0, 0), Vector3(0, -0.15, 0), Vector3(0, 1, 0), Vector3(0, 0, 1), link1 ) if __name__ == '__main__': sdf = SDF() model = Model("my_model") model.add_element(link1) model.add_element(link2) sdf.add_element(model)