Cosplay/nhf/touhou/houjuu_nue/test.py

125 lines
4.3 KiB
Python
Raw Normal View History

2024-06-20 23:29:18 -07:00
import unittest
2024-06-24 11:13:11 -07:00
import cadquery as Cq
2024-06-20 23:29:18 -07:00
import nhf.touhou.houjuu_nue as M
import nhf.touhou.houjuu_nue.joints as MJ
import nhf.touhou.houjuu_nue.electronics as ME
2024-07-07 12:15:47 -07:00
from nhf.checks import pairwise_intersection
2024-06-20 23:29:18 -07:00
class TestElectronics(unittest.TestCase):
def test_actuator_length(self):
self.assertAlmostEqual(
ME.LINEAR_ACTUATOR_50.conn_length, 103.9
)
self.assertAlmostEqual(
ME.LINEAR_ACTUATOR_30.conn_length, 83.9
)
def test_flexor(self):
flexor = ME.Flexor(
motion_span=60,
)
self.assertAlmostEqual(
flexor.target_length_at_angle(0),
flexor.actuator.stroke_length + flexor.actuator.conn_length)
self.assertAlmostEqual(
flexor.target_length_at_angle(flexor.motion_span),
flexor.actuator.conn_length)
class TestJoints(unittest.TestCase):
2024-07-11 08:42:13 -07:00
def test_shoulder_collision_of_torsion_joint(self):
j = MJ.ShoulderJoint()
assembly = j.torsion_joint.rider_track_assembly()
self.assertEqual(pairwise_intersection(assembly), [])
def test_shoulder_collision_0(self):
j = MJ.ShoulderJoint()
assembly = j.assembly()
self.assertEqual(pairwise_intersection(assembly), [])
def test_shoulder_align(self):
j = MJ.ShoulderJoint()
a = j.assembly()
l_t_c0 = a.get_abs_location("parent_top/lip?conn0")
l_b_c0 = a.get_abs_location("parent_bot/lip?conn0")
v = l_t_c0 - l_b_c0
self.assertAlmostEqual(v.x, 0)
self.assertAlmostEqual(v.y, 0)
def test_shoulder_joint_dist(self):
"""
Tests the arm radius
"""
j = MJ.ShoulderJoint()
2024-07-20 23:52:11 -07:00
for deflection in [0, 40, j.angle_max_deflection]:
with self.subTest(deflection=deflection):
a = j.assembly(deflection=deflection)
# Axle
o = a.get_abs_location("parent_top/track?spring")
l_c1 = a.get_abs_location("parent_top/lip?conn0")
l_c2= a.get_abs_location("parent_top/lip?conn1")
v_c = 0.5 * ((l_c1 - o) + (l_c2 - o))
v_c.z = 0
self.assertAlmostEqual(v_c.Length, j.parent_lip_ext)
def test_disk_collision_0(self):
j = MJ.DiskJoint()
2024-07-11 08:42:13 -07:00
assembly = j.assembly(angle=0)
self.assertEqual(pairwise_intersection(assembly), [])
def test_disk_collision_mid(self):
j = MJ.DiskJoint()
2024-07-11 08:42:13 -07:00
assembly = j.assembly(angle=j.movement_angle / 2)
self.assertEqual(pairwise_intersection(assembly), [])
def test_disk_collision_max(self):
j = MJ.DiskJoint()
2024-07-11 08:42:13 -07:00
assembly = j.assembly(angle=j.movement_angle)
self.assertEqual(pairwise_intersection(assembly), [])
def test_elbow_joint_dist(self):
"""
Tests the arm radius
"""
j = MJ.ElbowJoint()
for angle in [0, 10, 20, j.disk_joint.movement_angle]:
with self.subTest(angle=angle):
a = j.assembly(angle=angle)
o = a.get_abs_location("child/disk?mate_bot")
l_c1 = a.get_abs_location("child/lip?conn_top0")
l_c2 = a.get_abs_location("child/lip?conn_bot0")
v_c = 0.5 * ((l_c1 - o) + (l_c2 - o))
v_c.z = 0
self.assertAlmostEqual(v_c.Length, j.child_arm_radius)
l_p1 = a.get_abs_location("parent_upper/lip?conn_top0")
l_p2 = a.get_abs_location("parent_upper/lip?conn_bot0")
v_p = 0.5 * ((l_p1 - o) + (l_p2 - o))
v_p.z = 0
self.assertAlmostEqual(v_p.Length, j.parent_arm_radius)
2024-06-20 23:29:18 -07:00
class Test(unittest.TestCase):
2024-06-24 11:13:11 -07:00
def test_hs_joint_parent(self):
p = M.Parameters()
2024-07-16 17:18:28 -07:00
obj = p.harness.hs_joint_parent()
2024-06-26 06:42:50 -07:00
self.assertIsInstance(obj.val().solids(), Cq.Solid, msg="H-S joint must be in one piece")
2024-07-07 12:15:47 -07:00
def test_wings_assembly(self):
p = M.Parameters()
2024-07-16 17:18:28 -07:00
p.wings_harness_assembly()
def test_trident_assembly(self):
2024-06-25 06:11:48 -07:00
p = M.Parameters()
2024-07-16 17:18:28 -07:00
assembly = p.trident.assembly()
2024-06-26 06:42:50 -07:00
bbox = assembly.toCompound().BoundingBox()
length = bbox.zlen
self.assertGreater(length, 1300)
self.assertLess(length, 1700)
2024-07-07 21:45:10 -07:00
#def test_assemblies(self):
# p = M.Parameters()
# p.check_all()
2024-06-20 23:29:18 -07:00
if __name__ == '__main__':
unittest.main()