|
| 1 | +import math |
| 2 | +import sys |
| 3 | +from typing import Callable |
| 4 | + |
| 5 | +import numpy as np |
| 6 | + |
| 7 | +from ariel.body_phenotypes.robogen_lite.config import ModuleFaces |
| 8 | +from ariel.body_phenotypes.robogen_lite.modules.brick import BrickModule |
| 9 | +from ariel.body_phenotypes.robogen_lite.modules.core import CoreModule |
| 10 | +from ariel.body_phenotypes.robogen_lite.modules.hinge import HingeModule |
| 11 | + |
| 12 | +current_module = sys.modules[__name__] |
| 13 | + |
| 14 | +SUBMODULES = HingeModule | BrickModule |
| 15 | +MODULES = CoreModule | SUBMODULES |
| 16 | + |
| 17 | +faces = [ |
| 18 | + ModuleFaces.FRONT, ModuleFaces.LEFT, ModuleFaces.BACK, ModuleFaces.RIGHT, |
| 19 | +] |
| 20 | +F, L, B, R = faces |
| 21 | + |
| 22 | +def make_core(): |
| 23 | + core = CoreModule(index=0) |
| 24 | + core.name = "C" |
| 25 | + return core |
| 26 | + |
| 27 | +def attach(parent: MODULES, |
| 28 | + face: ModuleFaces, |
| 29 | + module: SUBMODULES, |
| 30 | + name: str, |
| 31 | + rotation: float = 0) -> SUBMODULES: |
| 32 | + |
| 33 | + name = f"{parent.name}-{name}" |
| 34 | + parent.sites[face].attach_body(body=module.body, prefix=name + "-") |
| 35 | + |
| 36 | + module.name = name |
| 37 | + |
| 38 | + if rotation != 0: |
| 39 | + module.rotate(rotation) |
| 40 | + |
| 41 | + return module |
| 42 | + |
| 43 | +def body_spider() -> CoreModule: |
| 44 | + core = make_core() |
| 45 | + |
| 46 | + for i, f in enumerate(faces, start=1): |
| 47 | + h0 = attach(core, f, HingeModule(index=i), f"{f.name[0]}H") |
| 48 | + b0 = attach(h0, F, BrickModule(index=4+i), "B") |
| 49 | + h1 = attach(b0, F, HingeModule(index=8+i), "H", rotation=90) |
| 50 | + b1 = attach(h1, F, BrickModule(index=12+i), "B") |
| 51 | + |
| 52 | + return core |
| 53 | + |
| 54 | +def body_spider45() -> CoreModule: |
| 55 | + core = body_spider() |
| 56 | + core.spec.body("core").quat = (math.cos(math.pi / 8), 0, 0, math.sin(math.pi / 8)) |
| 57 | + return core |
0 commit comments