Skip to content

Commit da01b28

Browse files
[Fix] Spider with blocks module
1 parent f7172f1 commit da01b28

File tree

2 files changed

+58
-1
lines changed

2 files changed

+58
-1
lines changed

examples/re_book/1_brain_evolution.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131
# Local libraries
3232
from ariel.simulation.environments import SimpleFlatWorld
33-
from new_bodies import body_spider45
33+
from ariel.body_phenotypes.robogen_lite.prebuilt_robots.spider_with_blocks import body_spider45
3434
from ariel.utils.tracker import Tracker
3535
from ariel.utils.renderers import VideoRecorder, video_renderer
3636

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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

Comments
 (0)