feat: Add unit testing for onbashira collision
This commit is contained in:
parent
2840315a51
commit
de829577aa
|
@ -1,9 +1,10 @@
|
||||||
from nhf.build import Model, TargetKind, target, assembly, submodel
|
from nhf.build import Model, TargetKind, target, assembly, submodel
|
||||||
from nhf.materials import Role, Material
|
from nhf.materials import Role, Material
|
||||||
import nhf.utils
|
|
||||||
from nhf.parts.fasteners import FlatHeadBolt, HexNut, Washer
|
from nhf.parts.fasteners import FlatHeadBolt, HexNut, Washer
|
||||||
from nhf.parts.electronics import ArduinoUnoR3, BatteryBox18650
|
from nhf.parts.electronics import ArduinoUnoR3, BatteryBox18650
|
||||||
|
import nhf.utils
|
||||||
|
|
||||||
|
import unittest
|
||||||
from typing import Optional, Union
|
from typing import Optional, Union
|
||||||
import math
|
import math
|
||||||
from dataclasses import dataclass, field
|
from dataclasses import dataclass, field
|
||||||
|
@ -2448,6 +2449,19 @@ class Onbashira(Model):
|
||||||
material=self.material_side,
|
material=self.material_side,
|
||||||
role=Role.STRUCTURE | Role.DECORATION,
|
role=Role.STRUCTURE | Role.DECORATION,
|
||||||
)
|
)
|
||||||
|
for i in range(self.n_side):
|
||||||
|
name_bolt = f"chamber_back{i}boltFPI{i}"
|
||||||
|
a = a.addS(
|
||||||
|
BOLT_COMMON.generate(),
|
||||||
|
name=name_bolt,
|
||||||
|
material=self.material_fastener,
|
||||||
|
role=Role.CONNECTION,
|
||||||
|
)
|
||||||
|
a = a.constrain(
|
||||||
|
f"chamber_back?holeF{i}",
|
||||||
|
f"{name_bolt}?root",
|
||||||
|
"Plane",
|
||||||
|
)
|
||||||
if has_part(parts, "chamber_front"):
|
if has_part(parts, "chamber_front"):
|
||||||
a = a.addS(
|
a = a.addS(
|
||||||
self.chamber_front(),
|
self.chamber_front(),
|
||||||
|
@ -2455,6 +2469,19 @@ class Onbashira(Model):
|
||||||
material=self.material_side,
|
material=self.material_side,
|
||||||
role=Role.STRUCTURE | Role.DECORATION,
|
role=Role.STRUCTURE | Role.DECORATION,
|
||||||
)
|
)
|
||||||
|
for i in range(self.n_side):
|
||||||
|
name_bolt = f"chamber_front{i}boltFPI{i}"
|
||||||
|
a = a.addS(
|
||||||
|
BOLT_COMMON.generate(),
|
||||||
|
name=name_bolt,
|
||||||
|
material=self.material_fastener,
|
||||||
|
role=Role.CONNECTION,
|
||||||
|
)
|
||||||
|
a = a.constrain(
|
||||||
|
f"chamber_front?holeF{i}",
|
||||||
|
f"{name_bolt}?root",
|
||||||
|
"Plane",
|
||||||
|
)
|
||||||
if has_part(parts, "motor"):
|
if has_part(parts, "motor"):
|
||||||
a = a.add(self.assembly_motor(), name="motor")
|
a = a.add(self.assembly_motor(), name="motor")
|
||||||
if has_part(parts, "machine"):
|
if has_part(parts, "machine"):
|
||||||
|
@ -2474,7 +2501,6 @@ class Onbashira(Model):
|
||||||
"Plane",
|
"Plane",
|
||||||
)
|
)
|
||||||
|
|
||||||
# FIXME: Filter
|
|
||||||
if has_part(parts, ["motor", "ring2"]):
|
if has_part(parts, ["motor", "ring2"]):
|
||||||
for i in range(self.n_side // 2):
|
for i in range(self.n_side // 2):
|
||||||
j = self.n_side // 2 - 1 - i
|
j = self.n_side // 2 - 1 - i
|
||||||
|
@ -2488,29 +2514,34 @@ class Onbashira(Model):
|
||||||
# f"ring2/side{i*2+1}?holeStatorL",
|
# f"ring2/side{i*2+1}?holeStatorL",
|
||||||
# "Plane",
|
# "Plane",
|
||||||
#)
|
#)
|
||||||
|
|
||||||
if parts:
|
if parts:
|
||||||
return a.solve()
|
return a.solve()
|
||||||
|
|
||||||
for i in range(self.n_side):
|
for i in range(self.n_side):
|
||||||
j = (i + 1) % self.n_side
|
j = (i + 1) % self.n_side
|
||||||
ir = (self.n_side - i) % self.n_side
|
ir = (self.n_side - i) % self.n_side
|
||||||
|
|
||||||
coupler_name = f"stator_coupler{i}"
|
if has_part(parts, "ring1") or has_part(parts, "machine"):
|
||||||
a = a.addS(
|
coupler_name = f"stator_coupler{i}"
|
||||||
self.stator_coupler(),
|
a = a.addS(
|
||||||
name=coupler_name,
|
self.stator_coupler(),
|
||||||
material=self.material_brace,
|
name=coupler_name,
|
||||||
role=Role.STRUCTURE,
|
material=self.material_brace,
|
||||||
)
|
role=Role.STRUCTURE,
|
||||||
a = a.constrain(
|
)
|
||||||
f"{coupler_name}?holeOB",
|
if has_part(parts, "ring1"):
|
||||||
f"ring1/side{i}?holeStatorR",
|
a = a.constrain(
|
||||||
"Plane",
|
f"{coupler_name}?holeOB",
|
||||||
)
|
f"ring1/side{i}?holeStatorR",
|
||||||
a = a.constrain(
|
"Plane",
|
||||||
f"{coupler_name}?holeIF",
|
)
|
||||||
f"machine/stator1?holeF{ir}",
|
if has_part(parts, "machine"):
|
||||||
"Plane",
|
a = a.constrain(
|
||||||
)
|
f"{coupler_name}?holeIF",
|
||||||
|
f"machine/stator1?holeF{ir}",
|
||||||
|
"Plane",
|
||||||
|
)
|
||||||
|
|
||||||
#name_bolt =f"stator_outer_bolt{i}"
|
#name_bolt =f"stator_outer_bolt{i}"
|
||||||
#a = a.addS(
|
#a = a.addS(
|
||||||
|
@ -2525,31 +2556,7 @@ class Onbashira(Model):
|
||||||
# "Plane",
|
# "Plane",
|
||||||
#)
|
#)
|
||||||
|
|
||||||
name_bolt =f"chamber_back{i}boltFPI{i}"
|
|
||||||
a = a.addS(
|
|
||||||
BOLT_COMMON.generate(),
|
|
||||||
name=name_bolt,
|
|
||||||
material=self.material_fastener,
|
|
||||||
role=Role.CONNECTION,
|
|
||||||
)
|
|
||||||
a = a.constrain(
|
|
||||||
f"chamber_back?holeF{i}",
|
|
||||||
f"{name_bolt}?root",
|
|
||||||
"Plane",
|
|
||||||
)
|
|
||||||
|
|
||||||
name_bolt =f"chamber_front{i}boltFPI{i}"
|
|
||||||
a = a.addS(
|
|
||||||
BOLT_COMMON.generate(),
|
|
||||||
name=name_bolt,
|
|
||||||
material=self.material_fastener,
|
|
||||||
role=Role.CONNECTION,
|
|
||||||
)
|
|
||||||
a = a.constrain(
|
|
||||||
f"chamber_front?holeF{i}",
|
|
||||||
f"{name_bolt}?root",
|
|
||||||
"Plane",
|
|
||||||
)
|
|
||||||
for ih in range(len(self.angle_joint_bolt_position)):
|
for ih in range(len(self.angle_joint_bolt_position)):
|
||||||
a = a.constrain(
|
a = a.constrain(
|
||||||
f"chamber/side{i}?holeFPI{ih}",
|
f"chamber/side{i}?holeFPI{ih}",
|
||||||
|
@ -2597,3 +2604,16 @@ class Onbashira(Model):
|
||||||
)
|
)
|
||||||
|
|
||||||
return a.solve()
|
return a.solve()
|
||||||
|
|
||||||
|
|
||||||
|
class TestOnbashira(unittest.TestCase):
|
||||||
|
|
||||||
|
def test_collision(self):
|
||||||
|
from nhf.checks import pairwise_intersection
|
||||||
|
|
||||||
|
o = Onbashira()
|
||||||
|
a = o.assembly()
|
||||||
|
self.assertEqual(pairwise_intersection(a), [])
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
unittest.main()
|
||||||
|
|
Loading…
Reference in New Issue