实现了yaw轴的转动,mid360参数更加接近实际的参数
This commit is contained in:
1 parent
72f407c110
commit
96445bd5f1
61 files changed
+2460
-235
No files matched your search
@@ -0,0 +1,166 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Lock the two decisions that are easy to get silently wrong in build_vehicle:
|
||||
|
||||
1. which parts rotate with the gimbal yaw (`classify`)
|
||||
2. where the yaw axis actually is (`find_yaw_axis`)
|
||||
|
||||
Both used to be wrong: the motor centre was taken as the yaw axis even though a
|
||||
belt drives it (89.9 mm offset), and the broad `基座装配` keyword pulled the
|
||||
motor and base plates into the rotating mesh.
|
||||
"""
|
||||
|
||||
import os
|
||||
from pathlib import Path
|
||||
import struct
|
||||
import sys
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
|
||||
TOOLS = Path(__file__).resolve().parents[1]
|
||||
sys.path.insert(0, str(TOOLS))
|
||||
import build_vehicle
|
||||
|
||||
|
||||
PREFIX = '完全车2 - 装配体-3 '
|
||||
|
||||
|
||||
def write_box_stl(path, lo, hi):
|
||||
"""Write a one-triangle binary STL whose bounding box is exactly [lo, hi]."""
|
||||
vertices = [(lo[0], lo[1], lo[2]),
|
||||
(hi[0], lo[1], lo[2]),
|
||||
(lo[0], hi[1], hi[2])]
|
||||
path.parent.mkdir(parents=True, exist_ok=True)
|
||||
with open(path, 'wb') as handle:
|
||||
handle.write(b'\0' * 80)
|
||||
handle.write(struct.pack('<I', 1))
|
||||
handle.write(struct.pack('<3f', 0.0, 0.0, 1.0))
|
||||
for vertex in vertices:
|
||||
handle.write(struct.pack('<3f', *vertex))
|
||||
handle.write(struct.pack('<H', 0))
|
||||
return path
|
||||
|
||||
|
||||
class ClassifyTest(unittest.TestCase):
|
||||
"""`classify` decides what spins with the yaw; getting it wrong is visible."""
|
||||
|
||||
def test_chassis_parts_stay_with_the_base(self):
|
||||
# '基座装配' alone would match all of these; the explicit chassis list wins.
|
||||
for name in (
|
||||
PREFIX + '基座装配-1 RoboMaster GM6020 直流无刷电机-1.STL',
|
||||
PREFIX + '基座装配-1 35齿小带轮-1.STL',
|
||||
PREFIX + '基座装配-1 涨紧轮-1.STL',
|
||||
PREFIX + '基座装配-1 涨紧轮-2.STL',
|
||||
PREFIX + '基座装配-1 上供皮带2-1.STL',
|
||||
PREFIX + '基座装配-1 基座铝件-1.STL',
|
||||
PREFIX + '基座装配-1 支座碳板-1.STL',
|
||||
PREFIX + '基座装配-1 打印件补强板-1.STL',
|
||||
PREFIX + '基座装配-1 轴承压板-1.STL',
|
||||
PREFIX + '基座装配-1 15.5直径滑环-1.STL',
|
||||
PREFIX + '基座装配-1 thrust ball bearings gb-1.STL',
|
||||
PREFIX + '基座装配-1 内70外86外圈-1 内60外76内圈-1.STL',
|
||||
PREFIX + 'F6703ZZ法兰轴承-1.STL',
|
||||
PREFIX + '大yaw6020底板-1.STL',
|
||||
):
|
||||
with self.subTest(name=name):
|
||||
self.assertEqual(build_vehicle.classify(name), 'base')
|
||||
|
||||
def test_rotating_parts_follow_the_gimbal(self):
|
||||
for name in (
|
||||
PREFIX + '基座装配-1 70齿大带轮-1.STL',
|
||||
PREFIX + '基座装配-1 云台内圈-1.STL',
|
||||
PREFIX + '八爪拨盘平面盘体-1.STL',
|
||||
PREFIX + '八爪拨盘柱体-1.STL',
|
||||
PREFIX + 'yaw板^装配体-1.STL',
|
||||
PREFIX + '小云台装配体-1 鹅颈云台-相机架-顶部保护板-v1.0-1.STL',
|
||||
PREFIX + '小云台装配体-1 相机支架-v1.0-2.STL',
|
||||
PREFIX + '24哨兵-拨盘-电机带轮垫片-1.STL',
|
||||
):
|
||||
with self.subTest(name=name):
|
||||
self.assertEqual(build_vehicle.classify(name), 'gimbal')
|
||||
|
||||
def test_wheels_win_over_every_other_keyword(self):
|
||||
self.assertEqual(
|
||||
build_vehicle.classify(PREFIX + '轮系-1 装配体1-1.STL'), 'wheel1')
|
||||
self.assertEqual(
|
||||
build_vehicle.classify(PREFIX + '轮系-4 装配体1-1.STL'), 'wheel4')
|
||||
|
||||
def test_wheel_side_parts_do_not_join_the_gimbal(self):
|
||||
# The four wheel hubs carry their own Z21 sleeves; 'Z21胀紧' must not
|
||||
# drag them into the gimbal because they spin with the wheels.
|
||||
for index in (1, 2, 3, 4):
|
||||
name = PREFIX + f'轮系-{index} Z21胀紧联结套[Z21-10].step-2.STL'
|
||||
with self.subTest(name=name):
|
||||
self.assertEqual(build_vehicle.classify(name), 'base')
|
||||
|
||||
|
||||
class YawAxisTest(unittest.TestCase):
|
||||
"""`find_yaw_axis` must refuse an off-axis candidate set instead of drifting."""
|
||||
|
||||
def setUp(self):
|
||||
temp = tempfile.TemporaryDirectory(prefix='sentry yaw ')
|
||||
self.addCleanup(temp.cleanup)
|
||||
self.root = Path(temp.name)
|
||||
|
||||
def place(self, name, centre_x, centre_z):
|
||||
"""A part centred at (centre_x, centre_z) mm in SW x/z, 10 mm across."""
|
||||
return write_box_stl(
|
||||
self.root / name,
|
||||
(centre_x - 5.0, 0.0, centre_z - 5.0),
|
||||
(centre_x + 5.0, 100.0, centre_z + 5.0))
|
||||
|
||||
def test_coaxial_parts_give_their_shared_centre(self):
|
||||
files = [self.place('a 70齿大带轮-1.STL', 31386.4, 10455.2),
|
||||
self.place('b 云台内圈-1.STL', 31386.4, 10455.2),
|
||||
self.place('c 15.5直径滑环-1.STL', 31386.5, 10455.3)]
|
||||
axis, count, spread = build_vehicle.find_yaw_axis(files)
|
||||
self.assertEqual(count, 3)
|
||||
self.assertAlmostEqual(axis[0], 31386.43, places=1)
|
||||
self.assertAlmostEqual(axis[1], 10455.23, places=1)
|
||||
self.assertLess(max(spread), build_vehicle.YAW_AXIS_SPREAD_MM)
|
||||
|
||||
def test_motor_style_offset_is_rejected(self):
|
||||
# e.g. accidentally including a belt-driven motor beside the pulley.
|
||||
files = [self.place('a 70齿大带轮-1.STL', 31386.4, 10455.2),
|
||||
self.place('b 云台内圈-1.STL', 31386.4, 10455.2),
|
||||
self.place('c 35齿小带轮-1.STL', 31476.3, 10455.0)]
|
||||
# 35齿小带轮 is not a YAW_AXIS_KEY, so it is ignored entirely.
|
||||
axis, count, _ = build_vehicle.find_yaw_axis(files)
|
||||
self.assertEqual(count, 2)
|
||||
self.assertAlmostEqual(axis[0], 31386.4, places=1)
|
||||
|
||||
# But a *keyword* part that sits off-axis must raise, not average.
|
||||
files.append(self.place('d 70齿大带轮-2.STL', 31476.3, 10455.0))
|
||||
with self.assertRaisesRegex(build_vehicle.YawAxisError, '不共轴'):
|
||||
build_vehicle.find_yaw_axis(files)
|
||||
|
||||
def test_no_candidates_returns_none(self):
|
||||
files = [self.place('wheel 轮系-1 装配体1-1.STL', 31599.0, 10621.0)]
|
||||
self.assertEqual(build_vehicle.find_yaw_axis(files), (None, 0, (0.0, 0.0)))
|
||||
|
||||
def test_unreadable_candidate_is_skipped(self):
|
||||
good = self.place('a 70齿大带轮-1.STL', 1000.0, 2000.0)
|
||||
bad = self.root / 'b 云台内圈-1.STL'
|
||||
bad.write_bytes(b'not an stl')
|
||||
axis, count, _ = build_vehicle.find_yaw_axis([good, bad])
|
||||
self.assertEqual(count, 1)
|
||||
self.assertAlmostEqual(axis[0], 1000.0, places=1)
|
||||
self.assertAlmostEqual(axis[1], 2000.0, places=1)
|
||||
|
||||
|
||||
class KeywordTest(unittest.TestCase):
|
||||
"""The keyword lists themselves are part of the contract."""
|
||||
|
||||
def test_axis_keys_exclude_generic_fasteners(self):
|
||||
# '胀紧联结套' appears on the motor shaft and all four wheel hubs.
|
||||
self.assertNotIn('胀紧联结套', build_vehicle.YAW_AXIS_KEYS)
|
||||
for key in ('70齿大带轮', '云台内圈', '滑环'):
|
||||
self.assertIn(key, build_vehicle.YAW_AXIS_KEYS)
|
||||
|
||||
def test_motor_is_not_an_axis_key(self):
|
||||
self.assertNotIn('GM6020', build_vehicle.YAW_AXIS_KEYS)
|
||||
self.assertIn('GM6020', build_vehicle.CHASSIS_KEYS)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main(verbosity=2)
|
||||
Reference in new issue
Block a user