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
|
2024-07-12 23:16:04 -07:00
|
|
|
import nhf.touhou.houjuu_nue.joints as MJ
|
2024-07-07 12:15:47 -07:00
|
|
|
from nhf.checks import pairwise_intersection
|
2024-06-20 23:29:18 -07:00
|
|
|
|
2024-07-12 23:16:04 -07:00
|
|
|
class TestJoints(unittest.TestCase):
|
2024-07-11 08:42:13 -07:00
|
|
|
|
2024-07-17 13:20:06 -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), [])
|
2024-07-17 21:37:08 -07:00
|
|
|
|
2024-07-12 23:16:04 -07:00
|
|
|
def test_shoulder_collision_0(self):
|
|
|
|
j = MJ.ShoulderJoint()
|
|
|
|
assembly = j.assembly()
|
|
|
|
self.assertEqual(pairwise_intersection(assembly), [])
|
2024-07-17 13:09:46 -07:00
|
|
|
|
2024-07-17 21:37:08 -07:00
|
|
|
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)
|
|
|
|
|
2024-07-17 13:09:46 -07:00
|
|
|
def test_shoulder_joint_dist(self):
|
|
|
|
"""
|
|
|
|
Tests the arm radius
|
|
|
|
"""
|
|
|
|
j = MJ.ShoulderJoint()
|
|
|
|
for deflection in [0, 40, 95, 120]:
|
|
|
|
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)
|
|
|
|
|
2024-07-12 23:16:04 -07:00
|
|
|
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), [])
|
2024-07-12 23:16:04 -07:00
|
|
|
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), [])
|
2024-07-12 23:16:04 -07:00
|
|
|
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), [])
|
|
|
|
|
2024-07-17 13:09:46 -07:00
|
|
|
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
|
|
|
|
2024-07-08 22:32:49 -07:00
|
|
|
def test_wings_assembly(self):
|
|
|
|
p = M.Parameters()
|
2024-07-16 17:18:28 -07:00
|
|
|
p.wings_harness_assembly()
|
2024-07-04 12:03:38 -07:00
|
|
|
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()
|