lockwire 0.2.7__tar.gz → 0.2.8__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {lockwire-0.2.7 → lockwire-0.2.8}/PKG-INFO +1 -1
- {lockwire-0.2.7 → lockwire-0.2.8}/pyproject.toml +1 -1
- {lockwire-0.2.7 → lockwire-0.2.8}/src/lockwire/__init__.py +1 -1
- {lockwire-0.2.7 → lockwire-0.2.8}/src/lockwire/catalog.py +3 -3
- {lockwire-0.2.7 → lockwire-0.2.8}/src/lockwire/catalog_robots.yaml +48 -0
- {lockwire-0.2.7 → lockwire-0.2.8}/src/lockwire/checks.py +229 -3
- {lockwire-0.2.7 → lockwire-0.2.8}/src/lockwire/cli.py +132 -4
- {lockwire-0.2.7 → lockwire-0.2.8}/src/lockwire/mcp_server.py +1 -1
- lockwire-0.2.8/src/lockwire/mjcf.py +153 -0
- {lockwire-0.2.7 → lockwire-0.2.8}/src/lockwire/plan.py +1 -1
- {lockwire-0.2.7 → lockwire-0.2.8}/src/lockwire/scene_urdf.py +7 -2
- {lockwire-0.2.7 → lockwire-0.2.8}/src/lockwire/start_operation.py +22 -1
- {lockwire-0.2.7 → lockwire-0.2.8}/src/lockwire/urdf.py +37 -0
- {lockwire-0.2.7 → lockwire-0.2.8}/LICENSE +0 -0
- {lockwire-0.2.7 → lockwire-0.2.8}/NOTICE +0 -0
- {lockwire-0.2.7 → lockwire-0.2.8}/README.md +0 -0
- {lockwire-0.2.7 → lockwire-0.2.8}/src/lockwire/__main__.py +0 -0
- {lockwire-0.2.7 → lockwire-0.2.8}/src/lockwire/_filelock.py +0 -0
- {lockwire-0.2.7 → lockwire-0.2.8}/src/lockwire/advice.py +0 -0
- {lockwire-0.2.7 → lockwire-0.2.8}/src/lockwire/agent_setup.py +0 -0
- {lockwire-0.2.7 → lockwire-0.2.8}/src/lockwire/api.py +0 -0
- {lockwire-0.2.7 → lockwire-0.2.8}/src/lockwire/api_payload.py +0 -0
- {lockwire-0.2.7 → lockwire-0.2.8}/src/lockwire/bench.py +0 -0
- {lockwire-0.2.7 → lockwire-0.2.8}/src/lockwire/blame.py +0 -0
- {lockwire-0.2.7 → lockwire-0.2.8}/src/lockwire/catalog_seed.yaml +0 -0
- {lockwire-0.2.7 → lockwire-0.2.8}/src/lockwire/check_sim.py +0 -0
- {lockwire-0.2.7 → lockwire-0.2.8}/src/lockwire/cli_line.py +0 -0
- {lockwire-0.2.7 → lockwire-0.2.8}/src/lockwire/confine.py +0 -0
- {lockwire-0.2.7 → lockwire-0.2.8}/src/lockwire/constraints.py +0 -0
- {lockwire-0.2.7 → lockwire-0.2.8}/src/lockwire/copy.py +0 -0
- {lockwire-0.2.7 → lockwire-0.2.8}/src/lockwire/describe.py +0 -0
- {lockwire-0.2.7 → lockwire-0.2.8}/src/lockwire/drift.py +0 -0
- {lockwire-0.2.7 → lockwire-0.2.8}/src/lockwire/edit.py +0 -0
- {lockwire-0.2.7 → lockwire-0.2.8}/src/lockwire/emit_ts.py +0 -0
- {lockwire-0.2.7 → lockwire-0.2.8}/src/lockwire/examples/arm/LICENSE +0 -0
- {lockwire-0.2.7 → lockwire-0.2.8}/src/lockwire/examples/arm/NOTICE +0 -0
- {lockwire-0.2.7 → lockwire-0.2.8}/src/lockwire/examples/arm/contract.yaml +0 -0
- {lockwire-0.2.7 → lockwire-0.2.8}/src/lockwire/examples/arm/plan.yaml +0 -0
- {lockwire-0.2.7 → lockwire-0.2.8}/src/lockwire/examples/arm/scene.glb +0 -0
- {lockwire-0.2.7 → lockwire-0.2.8}/src/lockwire/examples/arm/starter.json +0 -0
- {lockwire-0.2.7 → lockwire-0.2.8}/src/lockwire/examples/drone/contract.yaml +0 -0
- {lockwire-0.2.7 → lockwire-0.2.8}/src/lockwire/examples/drone/plan.yaml +0 -0
- {lockwire-0.2.7 → lockwire-0.2.8}/src/lockwire/examples/drone/scene.glb +0 -0
- {lockwire-0.2.7 → lockwire-0.2.8}/src/lockwire/examples/drone/starter.json +0 -0
- {lockwire-0.2.7 → lockwire-0.2.8}/src/lockwire/examples/humanoid/NOTICE +0 -0
- {lockwire-0.2.7 → lockwire-0.2.8}/src/lockwire/examples/humanoid/contract.yaml +0 -0
- {lockwire-0.2.7 → lockwire-0.2.8}/src/lockwire/examples/humanoid/plan.yaml +0 -0
- {lockwire-0.2.7 → lockwire-0.2.8}/src/lockwire/examples/humanoid/scene.glb +0 -0
- {lockwire-0.2.7 → lockwire-0.2.8}/src/lockwire/examples/humanoid/starter.json +0 -0
- {lockwire-0.2.7 → lockwire-0.2.8}/src/lockwire/examples/quadruped/NOTICE +0 -0
- {lockwire-0.2.7 → lockwire-0.2.8}/src/lockwire/examples/quadruped/contract.yaml +0 -0
- {lockwire-0.2.7 → lockwire-0.2.8}/src/lockwire/examples/quadruped/plan.yaml +0 -0
- {lockwire-0.2.7 → lockwire-0.2.8}/src/lockwire/examples/quadruped/scene.glb +0 -0
- {lockwire-0.2.7 → lockwire-0.2.8}/src/lockwire/examples/quadruped/starter.json +0 -0
- {lockwire-0.2.7 → lockwire-0.2.8}/src/lockwire/examples/rover/NOTICE +0 -0
- {lockwire-0.2.7 → lockwire-0.2.8}/src/lockwire/examples/rover/contract.yaml +0 -0
- {lockwire-0.2.7 → lockwire-0.2.8}/src/lockwire/examples/rover/plan.yaml +0 -0
- {lockwire-0.2.7 → lockwire-0.2.8}/src/lockwire/examples/rover/scene.glb +0 -0
- {lockwire-0.2.7 → lockwire-0.2.8}/src/lockwire/examples/rover/starter.json +0 -0
- {lockwire-0.2.7 → lockwire-0.2.8}/src/lockwire/examples/servo-bench.yaml +0 -0
- {lockwire-0.2.7 → lockwire-0.2.8}/src/lockwire/export_mhs.py +0 -0
- {lockwire-0.2.7 → lockwire-0.2.8}/src/lockwire/factdiff.py +0 -0
- {lockwire-0.2.7 → lockwire-0.2.8}/src/lockwire/fieldpath.py +0 -0
- {lockwire-0.2.7 → lockwire-0.2.8}/src/lockwire/forces.py +0 -0
- {lockwire-0.2.7 → lockwire-0.2.8}/src/lockwire/gitref.py +0 -0
- {lockwire-0.2.7 → lockwire-0.2.8}/src/lockwire/hook_check.py +0 -0
- {lockwire-0.2.7 → lockwire-0.2.8}/src/lockwire/hw.py +0 -0
- {lockwire-0.2.7 → lockwire-0.2.8}/src/lockwire/mechanism.py +0 -0
- {lockwire-0.2.7 → lockwire-0.2.8}/src/lockwire/mesh_dae.py +0 -0
- {lockwire-0.2.7 → lockwire-0.2.8}/src/lockwire/mesh_simple.py +0 -0
- {lockwire-0.2.7 → lockwire-0.2.8}/src/lockwire/page.py +0 -0
- {lockwire-0.2.7 → lockwire-0.2.8}/src/lockwire/parts_list.py +0 -0
- {lockwire-0.2.7 → lockwire-0.2.8}/src/lockwire/plan_payload.py +0 -0
- {lockwire-0.2.7 → lockwire-0.2.8}/src/lockwire/plugins.py +0 -0
- {lockwire-0.2.7 → lockwire-0.2.8}/src/lockwire/report.py +0 -0
- {lockwire-0.2.7 → lockwire-0.2.8}/src/lockwire/report_html.py +0 -0
- {lockwire-0.2.7 → lockwire-0.2.8}/src/lockwire/report_json.py +0 -0
- {lockwire-0.2.7 → lockwire-0.2.8}/src/lockwire/review_draft.py +0 -0
- {lockwire-0.2.7 → lockwire-0.2.8}/src/lockwire/scan.py +0 -0
- {lockwire-0.2.7 → lockwire-0.2.8}/src/lockwire/scene.py +0 -0
- {lockwire-0.2.7 → lockwire-0.2.8}/src/lockwire/scene_import.py +0 -0
- {lockwire-0.2.7 → lockwire-0.2.8}/src/lockwire/scene_view.py +0 -0
- {lockwire-0.2.7 → lockwire-0.2.8}/src/lockwire/schema.py +0 -0
- {lockwire-0.2.7 → lockwire-0.2.8}/src/lockwire/sdf.py +0 -0
- {lockwire-0.2.7 → lockwire-0.2.8}/src/lockwire/serve.py +0 -0
- {lockwire-0.2.7 → lockwire-0.2.8}/src/lockwire/servo_bus.py +0 -0
- {lockwire-0.2.7 → lockwire-0.2.8}/src/lockwire/servo_bus_dxl.py +0 -0
- {lockwire-0.2.7 → lockwire-0.2.8}/src/lockwire/statics.py +0 -0
- {lockwire-0.2.7 → lockwire-0.2.8}/src/lockwire/swap.py +0 -0
- {lockwire-0.2.7 → lockwire-0.2.8}/src/lockwire/thrust.py +0 -0
- {lockwire-0.2.7 → lockwire-0.2.8}/src/lockwire/thrust_tables.yaml +0 -0
- {lockwire-0.2.7 → lockwire-0.2.8}/src/lockwire/units.py +0 -0
- {lockwire-0.2.7 → lockwire-0.2.8}/src/lockwire/vcs.py +0 -0
- {lockwire-0.2.7 → lockwire-0.2.8}/src/lockwire/whatif.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: lockwire
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.8
|
|
4
4
|
Summary: The physical-assumption contract for robots: checks that a robot's declared parts (power, weight, bus, torque) add up
|
|
5
5
|
Keywords: robotics,urdf,ros,preflight,lockfile,ci,hardware,drone
|
|
6
6
|
Author: Shivansh
|
|
@@ -208,7 +208,7 @@ def load_catalog(path: Path | str | None = None) -> Catalog:
|
|
|
208
208
|
|
|
209
209
|
# What a whole-robot sheet's mass figure includes; a URDF often models less.
|
|
210
210
|
Scope = Literal["with_battery", "dry", "with_gripper", "with_cable", "arm_only"]
|
|
211
|
-
RobotQuantity = Literal["mass_total", "dof", "reach_m", "payload_kg", "joint_speed_max"]
|
|
211
|
+
RobotQuantity = Literal["mass_total", "dof", "reach_m", "payload_kg", "joint_speed_max", "joint_torque_max"]
|
|
212
212
|
|
|
213
213
|
|
|
214
214
|
class RobotNumber(SourcedNumber):
|
|
@@ -252,8 +252,8 @@ class Robot(BaseModel):
|
|
|
252
252
|
@model_validator(mode="after")
|
|
253
253
|
def _required(self) -> Robot:
|
|
254
254
|
mass = self.numbers.get("mass_total")
|
|
255
|
-
if mass is None or mass.scope is None
|
|
256
|
-
raise ValueError(f"{self.id}: mass_total (with a scope)
|
|
255
|
+
if mass is None or mass.scope is None:
|
|
256
|
+
raise ValueError(f"{self.id}: mass_total (with a scope) is required")
|
|
257
257
|
return self
|
|
258
258
|
|
|
259
259
|
|
|
@@ -116,6 +116,54 @@ robots:
|
|
|
116
116
|
source: "https://www.unitree.com/go2/ — Weight (with battery) About 15kg"}
|
|
117
117
|
dof: {value: 12, unit: count, kind: datasheet, retrieved: 2026-11-04,
|
|
118
118
|
source: "https://www.unitree.com/go2/ — Aluminum knee joint motor 12 set"}
|
|
119
|
+
joint_torque_max: {value: 45, unit: N*m, kind: datasheet, retrieved: 2026-11-11,
|
|
120
|
+
source: "https://www.unitree.com/go2/ — Max Joint Torque About 45N·m (the largest joint motor)"}
|
|
121
|
+
known_urdf_deviations: []
|
|
122
|
+
- id: unitree-go2w
|
|
123
|
+
name: Unitree Go2-W
|
|
124
|
+
aliases: [go2w_description, go2w]
|
|
125
|
+
fingerprint: [base, Head_upper, Head_lower, FL_hip, FL_thigh, FL_calf, FL_calflower, FL_calflower1, FL_foot_motor, FL_foot, FR_hip, FR_thigh, FR_calf, FR_calflower, FR_calflower1, FR_foot_motor, FR_foot, RL_hip, RL_thigh, RL_calf, RL_calflower, RL_calflower1, RL_foot_motor, RL_foot, RR_hip, RR_thigh, RR_calf, RR_calflower, RR_calflower1, RR_foot_motor, RR_foot, imu, radar]
|
|
126
|
+
numbers:
|
|
127
|
+
mass_total: {value: 18, unit: kg, kind: datasheet, scope: with_battery, retrieved: 2026-11-11,
|
|
128
|
+
source: "https://www.unitree.com/go2-w — Weight (with battery) About 18kg"}
|
|
129
|
+
joint_torque_max: {value: 45, unit: N*m, kind: datasheet, retrieved: 2026-11-11,
|
|
130
|
+
source: "https://www.unitree.com/go2-w — Max Joint Torque About 45N.m (the largest joint motor)"}
|
|
131
|
+
known_urdf_deviations: []
|
|
132
|
+
- id: unitree-b2
|
|
133
|
+
name: Unitree B2
|
|
134
|
+
aliases: [b2_description, b2]
|
|
135
|
+
fingerprint: [base_link, lidar_link, f_dc_link, r_dc_link, imu_link, head_Link, tail_link, FL_hip, FL_hip_rotor, FL_thigh, FL_thigh_rotor, FL_calf, FL_calf_rotor, FL_foot, FR_hip, FR_hip_rotor, FR_thigh, FR_thigh_rotor, FR_calf, FR_calf_rotor, FR_foot, RL_hip, RL_hip_rotor, RL_thigh, RL_thigh_rotor, RL_calf, RL_calf_rotor, RL_foot, RR_hip, RR_hip_rotor, RR_thigh, RR_thigh_rotor, RR_calf, RR_calf_rotor, RR_foot, f_oc_link, r_oc_link]
|
|
136
|
+
numbers:
|
|
137
|
+
mass_total: {value: 60, unit: kg, kind: datasheet, scope: with_battery, retrieved: 2026-11-11,
|
|
138
|
+
source: "https://www.unitree.com/b2 — ≈ 60kg Total weight (battery included)"}
|
|
139
|
+
joint_torque_max: {value: 360, unit: N*m, kind: datasheet, retrieved: 2026-11-11,
|
|
140
|
+
source: "https://www.unitree.com/b2 — Max Joint Torque About 360N.m"}
|
|
141
|
+
known_urdf_deviations: []
|
|
142
|
+
- id: unitree-b2w
|
|
143
|
+
name: Unitree B2-W
|
|
144
|
+
aliases: [b2w_description, b2w]
|
|
145
|
+
fingerprint: [base_link, lidar_link, f_dc_link, r_dc_link, imu_link, head_Link, tail_link, FL_hip, FL_thigh, FL_calf, FL_foot, FR_hip, FR_thigh, FR_calf, FR_foot, RL_hip, RL_thigh, RL_calf, RL_foot, RR_hip, RR_thigh, RR_calf, RR_foot, f_oc_link, logo_link, r_oc_ink]
|
|
146
|
+
numbers:
|
|
147
|
+
mass_total: {value: 85, unit: kg, kind: datasheet, scope: with_battery, retrieved: 2026-11-11,
|
|
148
|
+
source: "https://www.unitree.com/b2-w — ≈85kg Total weight (battery included)"}
|
|
149
|
+
known_urdf_deviations: []
|
|
150
|
+
- id: unitree-b1
|
|
151
|
+
name: Unitree B1
|
|
152
|
+
aliases: [b1_description, b1]
|
|
153
|
+
fingerprint: [world, base, trunk, imu_link, left_side_camera_link, right_side_camera_link, head_camera_1_link, head_camera_2_link, tail_camera_link, FR_hip, FR_hip_rotor, FR_thigh, FR_thigh_rotor, FR_calf, FR_calf_rotor, FR_foot, FL_hip, FL_hip_rotor, FL_thigh, FL_thigh_rotor, FL_calf, FL_calf_rotor, FL_foot, RR_hip, RR_hip_rotor, RR_thigh, RR_thigh_rotor, RR_calf, RR_calf_rotor, RR_foot, RL_hip, RL_hip_rotor, RL_thigh, RL_thigh_rotor, RL_calf, RL_calf_rotor, RL_foot]
|
|
154
|
+
numbers:
|
|
155
|
+
mass_total: {value: 50, unit: kg, kind: datasheet, scope: with_battery, retrieved: 2026-11-11,
|
|
156
|
+
source: "https://www.unitree.com/b1 — Whole Machine (involve battery) About 50kg"}
|
|
157
|
+
known_urdf_deviations: []
|
|
158
|
+
- id: unitree-aliengo
|
|
159
|
+
name: Unitree Aliengo
|
|
160
|
+
aliases: [aliengo]
|
|
161
|
+
fingerprint: [world, base, trunk, imu_link, FR_hip, FR_hip_rotor, FR_thigh, FR_thigh_rotor, FR_calf, FR_calf_rotor, FR_foot, FL_hip, FL_hip_rotor, FL_thigh, FL_thigh_rotor, FL_calf, FL_calf_rotor, FL_foot, RR_hip, RR_hip_rotor, RR_thigh, RR_thigh_rotor, RR_calf, RR_calf_rotor, RR_foot, RL_hip, RL_hip_rotor, RL_thigh, RL_thigh_rotor, RL_calf, RL_calf_rotor, RL_foot]
|
|
162
|
+
numbers:
|
|
163
|
+
mass_total: {value: 21.5, unit: kg, kind: datasheet, scope: dry, retrieved: 2026-11-11,
|
|
164
|
+
source: "https://www.unitree.com/aliengo — Weight (without battery) 21.5kg ±1kg"}
|
|
165
|
+
dof: {value: 12, unit: count, kind: datasheet, retrieved: 2026-11-11,
|
|
166
|
+
source: "https://www.unitree.com/aliengo — Degrees of Freedom (number of motors) 12"}
|
|
119
167
|
known_urdf_deviations: []
|
|
120
168
|
- id: franka-fr3
|
|
121
169
|
name: Franka Research 3
|
|
@@ -4073,7 +4073,7 @@ def check_mesh_drift(
|
|
|
4073
4073
|
|
|
4074
4074
|
|
|
4075
4075
|
_SHEET_UNITS = {"kg": 1.0, "g": 1e-3, "m": 1.0, "mm": 1e-3, "count": 1.0, "rad/s": 1.0}
|
|
4076
|
-
_SHEET_UNITS |= {"deg/s": math.pi / 180, "rpm": math.pi / 30}
|
|
4076
|
+
_SHEET_UNITS |= {"deg/s": math.pi / 180, "rpm": math.pi / 30, "N*m": 1.0}
|
|
4077
4077
|
_SCOPE_WORDS = {
|
|
4078
4078
|
"with_battery": "includes the battery, computer and sensors",
|
|
4079
4079
|
"with_cable": "includes the cable",
|
|
@@ -4099,6 +4099,50 @@ def _model_file_links(c: Contract, contract_path: Path | None) -> list:
|
|
|
4099
4099
|
return []
|
|
4100
4100
|
|
|
4101
4101
|
|
|
4102
|
+
_TORQUE_TOL = 0.10 # the catalog's joint_torque_max and `check --torque` share it
|
|
4103
|
+
|
|
4104
|
+
|
|
4105
|
+
def check_torque_claims(
|
|
4106
|
+
c: Contract, claims: dict[str, float], source: str, scores: _ScoreBook
|
|
4107
|
+
) -> list[Finding]:
|
|
4108
|
+
"""Each joint's URDF effort limit vs the published torque (N*m) the user typed."""
|
|
4109
|
+
by_name = {j.name: j for j in (c.model.joints if c.model else [])}
|
|
4110
|
+
found = []
|
|
4111
|
+
for name, sheet in claims.items():
|
|
4112
|
+
limit = by_name[name].limits
|
|
4113
|
+
quantity = f"datasheet/{name}/joint_torque"
|
|
4114
|
+
expected = f"published {sheet:g} N*m ({source})"
|
|
4115
|
+
if not (limit and limit.effort_limit):
|
|
4116
|
+
found.append(
|
|
4117
|
+
Finding(
|
|
4118
|
+
severity="not_scored",
|
|
4119
|
+
quantity=quantity,
|
|
4120
|
+
observed="no effort limit in the model",
|
|
4121
|
+
expected=expected,
|
|
4122
|
+
action="add the joint's effort limit to the URDF to compare it",
|
|
4123
|
+
)
|
|
4124
|
+
)
|
|
4125
|
+
continue
|
|
4126
|
+
urdf = limit.effort_limit
|
|
4127
|
+
delta = (urdf - sheet) / sheet
|
|
4128
|
+
scores.record(quantity)
|
|
4129
|
+
if abs(delta) <= _TORQUE_TOL + 1e-9:
|
|
4130
|
+
scores.passed(quantity, f"URDF effort: {urdf:.4g}", expected, f"{delta:+.1%}")
|
|
4131
|
+
continue
|
|
4132
|
+
found.append(
|
|
4133
|
+
Finding(
|
|
4134
|
+
severity="warning",
|
|
4135
|
+
quantity=quantity,
|
|
4136
|
+
observed=f"URDF effort: {urdf:.4g}",
|
|
4137
|
+
expected=expected,
|
|
4138
|
+
delta=f"{delta:+.1%}",
|
|
4139
|
+
source=source,
|
|
4140
|
+
action="check the URDF effort limit against the published figure",
|
|
4141
|
+
)
|
|
4142
|
+
)
|
|
4143
|
+
return found
|
|
4144
|
+
|
|
4145
|
+
|
|
4102
4146
|
def check_datasheet_agreement(
|
|
4103
4147
|
c: Contract,
|
|
4104
4148
|
*,
|
|
@@ -4109,7 +4153,7 @@ def check_datasheet_agreement(
|
|
|
4109
4153
|
"""A recognised robot's URDF-derived numbers vs its vendor datasheet (catalog_robots.yaml).
|
|
4110
4154
|
|
|
4111
4155
|
Mass +-5 % and dof exact are violations; payload and joint speed (the URDF allowing more
|
|
4112
|
-
than the sheet) are warnings; reach (+-3 %) is passed when it agrees, else a not_scored note. A mass_total budget (`--mass`) wins over the
|
|
4156
|
+
than the sheet) and largest joint torque (+-10 %) are warnings; reach (+-3 %) is passed when it agrees, else a not_scored note. A mass_total budget (`--mass`) wins over the
|
|
4113
4157
|
row. Silent for an unrecognised robot. At most the 3 largest deltas are reported.
|
|
4114
4158
|
"""
|
|
4115
4159
|
if c.model is None:
|
|
@@ -4148,6 +4192,11 @@ def check_datasheet_agreement(
|
|
|
4148
4192
|
for j in moving
|
|
4149
4193
|
if j.type != "prismatic" and j.limits and j.limits.velocity
|
|
4150
4194
|
]
|
|
4195
|
+
efforts = [
|
|
4196
|
+
j.limits.effort_limit
|
|
4197
|
+
for j in joints
|
|
4198
|
+
if j.type in ("revolute", "continuous") and j.limits and j.limits.effort_limit
|
|
4199
|
+
]
|
|
4151
4200
|
derived = {
|
|
4152
4201
|
"mass_total": (
|
|
4153
4202
|
mass_sum,
|
|
@@ -4162,6 +4211,11 @@ def check_datasheet_agreement(
|
|
|
4162
4211
|
),
|
|
4163
4212
|
"payload_kg": (sum(payloads) if payloads else None, 0.0, "payload carried on links"),
|
|
4164
4213
|
"joint_speed_max": (max(speeds, default=None), 0.05, "fastest joint velocity limit, rad/s"),
|
|
4214
|
+
"joint_torque_max": (
|
|
4215
|
+
max(efforts, default=None),
|
|
4216
|
+
_TORQUE_TOL,
|
|
4217
|
+
"largest revolute joint effort, N*m",
|
|
4218
|
+
),
|
|
4165
4219
|
}
|
|
4166
4220
|
rows, who = dict(robot.numbers), {}
|
|
4167
4221
|
declared = next((b for b in c.budgets if b.kind == "mass_total"), None)
|
|
@@ -4935,7 +4989,10 @@ def check_urdf_sanity(c: Contract, *, contract_path: Path | None = None) -> list
|
|
|
4935
4989
|
limits[name] = (lo[0], hi[0])
|
|
4936
4990
|
# urdfdom joint.cpp: revolute/prismatic need <limit>, and a <limit> needs velocity
|
|
4937
4991
|
# (https://raw.githubusercontent.com/ros/urdfdom/master/urdf_parser/src/joint.cpp).
|
|
4938
|
-
|
|
4992
|
+
mimic = el.find("mimic") # a follower takes its target's motion (urdf.py:371)
|
|
4993
|
+
if mimic is not None and mimic.get("joint") in {j.get("name") for j in joints}:
|
|
4994
|
+
pass
|
|
4995
|
+
elif lim is None or lim.get("velocity") is None:
|
|
4939
4996
|
warn(
|
|
4940
4997
|
f"{name}/velocity",
|
|
4941
4998
|
f"moving joint {name} has no velocity limit",
|
|
@@ -4961,6 +5018,37 @@ def check_urdf_sanity(c: Contract, *, contract_path: Path | None = None) -> list
|
|
|
4961
5018
|
f"make {name}'s axis length 1",
|
|
4962
5019
|
severity="not_scored",
|
|
4963
5020
|
)
|
|
5021
|
+
# a continuous joint between limited ones: climb to a limited revolute, descend to a mover
|
|
5022
|
+
ends = [(j, j.find("parent"), j.find("child")) for j in joints]
|
|
5023
|
+
ends = [
|
|
5024
|
+
(j, a.get("link"), b.get("link")) for j, a, b in ends if a is not None and b is not None
|
|
5025
|
+
]
|
|
5026
|
+
above = {b: (j, a) for j, a, b in ends} # child link -> its joint and parent link
|
|
5027
|
+
|
|
5028
|
+
def _moves_below(link: str, seen: set[str]) -> bool:
|
|
5029
|
+
seen.add(link)
|
|
5030
|
+
return any(
|
|
5031
|
+
j.get("type", "fixed") != "fixed" or (b not in seen and _moves_below(b, seen))
|
|
5032
|
+
for j, a, b in ends
|
|
5033
|
+
if a == link
|
|
5034
|
+
)
|
|
5035
|
+
|
|
5036
|
+
for el, top, bottom in ends:
|
|
5037
|
+
if el.get("type") != "continuous" or not _moves_below(bottom, set()):
|
|
5038
|
+
continue
|
|
5039
|
+
link, seen, limited = top, set(), False
|
|
5040
|
+
while link in above and link not in seen and not limited:
|
|
5041
|
+
seen.add(link)
|
|
5042
|
+
j, link = above[link]
|
|
5043
|
+
limited = j.get("type") == "revolute" and j.get("name") in limits
|
|
5044
|
+
if limited:
|
|
5045
|
+
name = el.get("name", "?")
|
|
5046
|
+
warn(
|
|
5047
|
+
f"{name}/continuous",
|
|
5048
|
+
f"joint {name} is continuous (no position limit) inside a chain of limited joints",
|
|
5049
|
+
"a position limit like its neighbours (or a deliberate continuous joint)",
|
|
5050
|
+
f"give {name} lower/upper limits, or keep it if the maker meant it",
|
|
5051
|
+
)
|
|
4964
5052
|
two_parents = sorted(link for link, js in parents.items() if len(js) > 1)
|
|
4965
5053
|
# urdfdom initTree writes parent_link_tree[child] with no check for an existing parent,
|
|
4966
5054
|
# so ROS silently keeps one of two parent joints
|
|
@@ -5054,6 +5142,141 @@ def check_inertia_valid(c: Contract, *, contract_path: Path | None = None) -> li
|
|
|
5054
5142
|
return out
|
|
5055
5143
|
|
|
5056
5144
|
|
|
5145
|
+
def check_duplicate_inertial(c: Contract, *, contract_path: Path | None = None) -> list[Finding]:
|
|
5146
|
+
"""A link carrying the same inertial as the link it is fixed to double-counts its mass."""
|
|
5147
|
+
found = _urdf_root(c, contract_path)
|
|
5148
|
+
if found is None:
|
|
5149
|
+
return []
|
|
5150
|
+
path, root = found
|
|
5151
|
+
key = {}
|
|
5152
|
+
for link in root.findall("link"):
|
|
5153
|
+
i = link.find("inertial")
|
|
5154
|
+
if i is None:
|
|
5155
|
+
continue
|
|
5156
|
+
mass, org, ten = i.find("mass"), i.find("origin"), i.find("inertia")
|
|
5157
|
+
key[link.get("name")] = [
|
|
5158
|
+
*_floats(mass.get("value") if mass is not None else None),
|
|
5159
|
+
*_floats(org.get("xyz") if org is not None else None),
|
|
5160
|
+
*_floats(org.get("rpy") if org is not None else None),
|
|
5161
|
+
*(float((ten.get(k) if ten is not None else None) or 0) for k in _INERTIA_KEYS),
|
|
5162
|
+
]
|
|
5163
|
+
out = []
|
|
5164
|
+
for j in root.findall("joint"):
|
|
5165
|
+
p_, c_ = j.find("parent"), j.find("child")
|
|
5166
|
+
a, b = (key.get(e.get("link")) if e is not None else None for e in (p_, c_))
|
|
5167
|
+
if j.get("type") != "fixed" or not a or a[0] <= 0 or len(a) != len(b or ()):
|
|
5168
|
+
continue
|
|
5169
|
+
if all(math.isclose(x, y, rel_tol=1e-9, abs_tol=1e-12) for x, y in zip(a, b)):
|
|
5170
|
+
child, parent = c_.get("link"), p_.get("link")
|
|
5171
|
+
out.append(
|
|
5172
|
+
Finding(
|
|
5173
|
+
severity="warning",
|
|
5174
|
+
quantity=f"model/links/{child}/duplicate_inertial",
|
|
5175
|
+
observed=f"{child} has the same inertial as {parent}, fixed to it: "
|
|
5176
|
+
f"{a[0]:g} kg counted twice",
|
|
5177
|
+
expected="one inertial per rigid body",
|
|
5178
|
+
source=str(path),
|
|
5179
|
+
action=f"remove the inertial from {child} (or give it its own), then re-lock",
|
|
5180
|
+
next_command=_relock_command(path, contract_path, c.model.xacro_args),
|
|
5181
|
+
)
|
|
5182
|
+
)
|
|
5183
|
+
return out
|
|
5184
|
+
|
|
5185
|
+
|
|
5186
|
+
def check_sibling_effort(c: Contract, *, contract_path: Path | None = None) -> list[Finding]:
|
|
5187
|
+
"""Consecutive moving joints of one chain named alike whose effort differs 20x: a note."""
|
|
5188
|
+
if c.model is None:
|
|
5189
|
+
return []
|
|
5190
|
+
# ponytail: 20x keeps G1 knee 139 vs ankle 50 quiet; only joints sharing a first name token
|
|
5191
|
+
# and chained child->parent are compared, so shoulder-to-wrist taper is never flagged.
|
|
5192
|
+
stem = lambda j: re.sub(r"_joint$", "", j.name).split("_")[0] # noqa: E731
|
|
5193
|
+
by_parent = {j.parent: j for j in c.model.joints if j.limits and j.limits.effort_limit}
|
|
5194
|
+
out = []
|
|
5195
|
+
for a in c.model.joints:
|
|
5196
|
+
b = by_parent.get(a.child)
|
|
5197
|
+
if b is None or not (a.limits and a.limits.effort_limit) or stem(a) != stem(b):
|
|
5198
|
+
continue
|
|
5199
|
+
lo, hi = sorted((a, b), key=lambda j: j.limits.effort_limit)
|
|
5200
|
+
if hi.limits.effort_limit >= 20 * lo.limits.effort_limit:
|
|
5201
|
+
out.append(
|
|
5202
|
+
Finding(
|
|
5203
|
+
severity="not_scored",
|
|
5204
|
+
quantity=f"model/sibling/{lo.name}",
|
|
5205
|
+
observed=f"{lo.name} effort {lo.limits.effort_limit:g} vs {hi.name} "
|
|
5206
|
+
f"{hi.limits.effort_limit:g} in one chain",
|
|
5207
|
+
expected="neighbouring joints of one limb within 20x of each other",
|
|
5208
|
+
action=f"check {lo.name}'s effort against the datasheet; it may be a typo",
|
|
5209
|
+
)
|
|
5210
|
+
)
|
|
5211
|
+
return out
|
|
5212
|
+
|
|
5213
|
+
|
|
5214
|
+
SIDE = r"(?:^|_)(left|right|l|r|fl|fr|rl|rr)(?=_|$)" # a left/right name token, shared with diff
|
|
5215
|
+
_OTHER_SIDE = {"left": "right", "l": "r", "fl": "fr", "rl": "rr"}
|
|
5216
|
+
|
|
5217
|
+
|
|
5218
|
+
def _mirror_values(x: Any) -> dict[str, float]:
|
|
5219
|
+
if hasattr(x, "limits"):
|
|
5220
|
+
lim = x.limits
|
|
5221
|
+
return {"effort": lim and lim.effort or 0, "velocity": lim and lim.velocity or 0}
|
|
5222
|
+
moments = x.inertia.moments_kgm2 if x.inertia else (0, 0, 0)
|
|
5223
|
+
return {
|
|
5224
|
+
"mass": x.mass.base() if x.mass else 0,
|
|
5225
|
+
**{f"moment {i}": m for i, m in enumerate(moments, 1)},
|
|
5226
|
+
}
|
|
5227
|
+
|
|
5228
|
+
|
|
5229
|
+
def check_mirror(c: Contract, *, contract_path: Path | None = None) -> list[Finding]:
|
|
5230
|
+
"""Joints and links named as left/right twins must agree on effort, velocity, mass, inertia."""
|
|
5231
|
+
if c.model is None:
|
|
5232
|
+
return []
|
|
5233
|
+
# ponytail: 10% passes rounding; real asymmetries (B2 hip ixx 0.0033 vs 0.0026) are 25%.
|
|
5234
|
+
off = lambda x, y: abs(x - y) > 0.1 * max(x, y) and max(x, y) > 1e-6 # noqa: E731
|
|
5235
|
+
out: list[Finding] = []
|
|
5236
|
+
for items in (c.model.joints, c.model.links):
|
|
5237
|
+
table = {}
|
|
5238
|
+
for i in items:
|
|
5239
|
+
t = re.search(SIDE, i.name.lower())
|
|
5240
|
+
if t:
|
|
5241
|
+
table[re.sub(SIDE, "_~", i.name.lower()), t.group(1)] = i
|
|
5242
|
+
for (key, tok), a in table.items():
|
|
5243
|
+
b = table.get((key, _OTHER_SIDE.get(tok, "")))
|
|
5244
|
+
if b is None or (hasattr(a, "limits") and not (a.limits and b.limits)):
|
|
5245
|
+
continue # a mimic follower or fixed joint has no limits of its own
|
|
5246
|
+
va, vb = _mirror_values(a), _mirror_values(b)
|
|
5247
|
+
bad = [f"{k} {va[k]:g} vs {vb[k]:g}" for k in va if off(va[k], vb[k])]
|
|
5248
|
+
if bad:
|
|
5249
|
+
out.append(
|
|
5250
|
+
Finding(
|
|
5251
|
+
severity="warning",
|
|
5252
|
+
quantity=f"model/mirror/{a.name}",
|
|
5253
|
+
observed=f"{a.name} and {b.name} are left/right twins but differ: "
|
|
5254
|
+
+ "; ".join(bad),
|
|
5255
|
+
expected="mirrored sides carry the same values (within 10%)",
|
|
5256
|
+
action=f"check {a.name} and {b.name} against the datasheet or CAD",
|
|
5257
|
+
next_command=_relock_command(
|
|
5258
|
+
Path(_urdf_path_candidate(c.model) or c.model.source),
|
|
5259
|
+
contract_path,
|
|
5260
|
+
c.model.xacro_args,
|
|
5261
|
+
),
|
|
5262
|
+
)
|
|
5263
|
+
)
|
|
5264
|
+
if len(out) > 5: # one count instead of a wall of pairs
|
|
5265
|
+
out[5:] = [
|
|
5266
|
+
out[5].model_copy(
|
|
5267
|
+
update={
|
|
5268
|
+
"quantity": "model/mirror/more",
|
|
5269
|
+
"observed": f"{len(out) - 5} more left/right pairs differ",
|
|
5270
|
+
"action": "fix the pairs above, then re-run",
|
|
5271
|
+
}
|
|
5272
|
+
)
|
|
5273
|
+
]
|
|
5274
|
+
return out
|
|
5275
|
+
|
|
5276
|
+
|
|
5277
|
+
_INERTIA_KEYS = ("ixx", "ixy", "ixz", "iyy", "iyz", "izz")
|
|
5278
|
+
|
|
5279
|
+
|
|
5057
5280
|
def _link_primitives(
|
|
5058
5281
|
root: ET.Element,
|
|
5059
5282
|
) -> dict[str, list[list[tuple[tuple[float, ...], float, float]]]]:
|
|
@@ -6059,6 +6282,9 @@ CHECK_PACK_1 = (
|
|
|
6059
6282
|
check_urdf_sanity,
|
|
6060
6283
|
check_link_values,
|
|
6061
6284
|
check_inertia_valid,
|
|
6285
|
+
check_duplicate_inertial,
|
|
6286
|
+
check_mirror,
|
|
6287
|
+
check_sibling_effort,
|
|
6062
6288
|
check_inertia_scale,
|
|
6063
6289
|
check_mass_vs_size,
|
|
6064
6290
|
check_limit_unit_traps,
|
|
@@ -19,6 +19,7 @@ import os
|
|
|
19
19
|
import shutil
|
|
20
20
|
import sys
|
|
21
21
|
import xml.etree.ElementTree as ET
|
|
22
|
+
from dataclasses import replace
|
|
22
23
|
from pathlib import Path
|
|
23
24
|
from typing import Any
|
|
24
25
|
|
|
@@ -33,6 +34,7 @@ from lockwire import __version__, export_mhs, gitref
|
|
|
33
34
|
from lockwire import api, plugins
|
|
34
35
|
from lockwire.bench import DEFAULT_CORPUS_PATH, format_report, load_corpus, run_bench
|
|
35
36
|
from lockwire.catalog import load_catalog, load_robots, recognise
|
|
37
|
+
from lockwire.checks import SIDE as _SIDE
|
|
36
38
|
from lockwire.checks import is_lock_drift, run_record_checks, servo_stall_torque, shown_path
|
|
37
39
|
from lockwire.confine import confine
|
|
38
40
|
from lockwire.cli_line import argv_from_context, cli_line, cli_line as build_cli_line
|
|
@@ -86,6 +88,7 @@ from lockwire.schema import (
|
|
|
86
88
|
)
|
|
87
89
|
from lockwire.schema import load_contract as _load_contract_lib
|
|
88
90
|
from lockwire.sdf import parse_sdf
|
|
91
|
+
from lockwire.start_operation import MODEL_SUFFIXES
|
|
89
92
|
from lockwire.urdf import ModelDefect, _refuse_doctype_entity, parse_urdf, robot_name
|
|
90
93
|
|
|
91
94
|
|
|
@@ -633,6 +636,31 @@ def upgrade_cmd(
|
|
|
633
636
|
)
|
|
634
637
|
|
|
635
638
|
|
|
639
|
+
def _torque_claims(torque: list[str], source: str | None, out) -> dict[str, float]:
|
|
640
|
+
"""The `--torque 'JOINT=VALUE N*m'` claims, or one plain line and exit 2."""
|
|
641
|
+
import re
|
|
642
|
+
|
|
643
|
+
claims = {}
|
|
644
|
+
for text in torque:
|
|
645
|
+
m = re.fullmatch(r"\s*(.+?)\s*=\s*([0-9.]+(?:e[-+]?\d+)?)\s*(\S+)\s*", text, re.I)
|
|
646
|
+
line = (
|
|
647
|
+
"--torque needs --source <url> saying where the published torque comes from"
|
|
648
|
+
if not source
|
|
649
|
+
else f"--torque must look like 'knee=120 N*m', not {text!r}"
|
|
650
|
+
if not m
|
|
651
|
+
else f"--torque takes N*m only, not {m[3]!r}"
|
|
652
|
+
if m[3] not in ("N*m", "N·m")
|
|
653
|
+
else "--torque needs a value above 0"
|
|
654
|
+
if float(m[2]) <= 0
|
|
655
|
+
else None
|
|
656
|
+
)
|
|
657
|
+
if line:
|
|
658
|
+
out.print(line, highlight=False, markup=False)
|
|
659
|
+
raise typer.Exit(2)
|
|
660
|
+
claims[m[1]] = float(m[2])
|
|
661
|
+
return claims
|
|
662
|
+
|
|
663
|
+
|
|
636
664
|
@app.command(
|
|
637
665
|
help="Start here: check a robot model (URDF, xacro, SDF) and print a verdict.\n\n"
|
|
638
666
|
f"{exit_code_help('check')}"
|
|
@@ -680,6 +708,11 @@ def check(
|
|
|
680
708
|
[], "--xacro-arg", help="Model file only: a xacro argument, name=value."
|
|
681
709
|
),
|
|
682
710
|
lock: Path | None = typer.Option(None, "--lock", help="Model file only: keep the lock here."),
|
|
711
|
+
torque: list[str] = typer.Option(
|
|
712
|
+
[], "--torque", help="Model file only: published 'JOINT=VALUE N*m'; needs --source."
|
|
713
|
+
),
|
|
714
|
+
payload: str | None = typer.Option(None, "--payload", help="Model file only: load, '2 kg'."),
|
|
715
|
+
at: str | None = typer.Option(None, "--at", help="Link that carries --payload."),
|
|
683
716
|
output_format: str = typer.Option(
|
|
684
717
|
"text",
|
|
685
718
|
"--format",
|
|
@@ -711,7 +744,7 @@ def check(
|
|
|
711
744
|
False, "--all", help="Also print warnings, unjudged checks' detail and passed checks."
|
|
712
745
|
),
|
|
713
746
|
) -> None:
|
|
714
|
-
"""Start here: check a robot model (URDF, xacro, SDF) and print a verdict."""
|
|
747
|
+
"""Start here: check a robot model (URDF, xacro, SDF, MJCF) and print a verdict."""
|
|
715
748
|
# `--json -` makes stdout exactly one JSON document; the human report and errors go to stderr.
|
|
716
749
|
out = Console(stderr=True) if str(json_out) == "-" else console
|
|
717
750
|
if output_format not in ("text", "github"):
|
|
@@ -719,7 +752,7 @@ def check(
|
|
|
719
752
|
raise typer.Exit(2)
|
|
720
753
|
import tempfile
|
|
721
754
|
|
|
722
|
-
from lockwire.start_operation import
|
|
755
|
+
from lockwire.start_operation import add_payload, model_lock
|
|
723
756
|
|
|
724
757
|
model_file = (
|
|
725
758
|
contract if contract.suffix.lower() in MODEL_SUFFIXES and contract.is_file() else None
|
|
@@ -735,9 +768,24 @@ def check(
|
|
|
735
768
|
("--witness", witness),
|
|
736
769
|
("--xacro-arg", xacro_arg),
|
|
737
770
|
("--lock", lock),
|
|
771
|
+
("--torque", torque),
|
|
772
|
+
("--payload", payload),
|
|
773
|
+
("--at", at),
|
|
738
774
|
)
|
|
739
775
|
if v
|
|
740
776
|
]
|
|
777
|
+
if (
|
|
778
|
+
model_file is None
|
|
779
|
+
and given
|
|
780
|
+
and contract.is_file()
|
|
781
|
+
and contract.suffix not in (".yaml", ".yml")
|
|
782
|
+
):
|
|
783
|
+
out.print(
|
|
784
|
+
f"{contract} is not a model lockwire reads (URDF, xacro, SDF or MJCF).",
|
|
785
|
+
highlight=False,
|
|
786
|
+
markup=False,
|
|
787
|
+
)
|
|
788
|
+
raise typer.Exit(2)
|
|
741
789
|
if model_file is None and given:
|
|
742
790
|
out.print(
|
|
743
791
|
f"{', '.join(given)} works on a model file only: lockwire check <robot.urdf> "
|
|
@@ -750,12 +798,21 @@ def check(
|
|
|
750
798
|
out.print(f"'{contract}' is a folder; pass the lockfile or model inside it")
|
|
751
799
|
raise typer.Exit(2)
|
|
752
800
|
warned: list[str] = []
|
|
801
|
+
claims = _torque_claims(torque, source, out)
|
|
802
|
+
if bool(payload) != bool(at):
|
|
803
|
+
out.print("--payload and --at go together: --payload '2 kg' --at <link>", markup=False)
|
|
804
|
+
raise typer.Exit(2)
|
|
753
805
|
if model_file is not None:
|
|
754
806
|
folder = lock.parent if lock else Path(tempfile.mkdtemp(prefix="lockwire-"))
|
|
755
807
|
if not lock:
|
|
756
808
|
ctx.call_on_close(lambda: shutil.rmtree(folder, ignore_errors=True))
|
|
757
809
|
elif lock.exists():
|
|
758
|
-
out.print(
|
|
810
|
+
out.print(
|
|
811
|
+
f"{lock} already exists; run `lockwire check {lock}` to check against it, "
|
|
812
|
+
"or pick a new name.",
|
|
813
|
+
highlight=False,
|
|
814
|
+
markup=False,
|
|
815
|
+
)
|
|
759
816
|
raise typer.Exit(2)
|
|
760
817
|
try:
|
|
761
818
|
contract = model_lock(
|
|
@@ -768,6 +825,8 @@ def check(
|
|
|
768
825
|
xacro_args=_xacro_args(xacro_arg, out),
|
|
769
826
|
warnings=warned,
|
|
770
827
|
)
|
|
828
|
+
if payload:
|
|
829
|
+
add_payload(contract, at, payload, out)
|
|
771
830
|
if lock:
|
|
772
831
|
contract = contract.rename(lock)
|
|
773
832
|
except ModelDefect as error: # a real defect in the model: NO-GO, not a tool failure
|
|
@@ -803,6 +862,14 @@ def check(
|
|
|
803
862
|
)
|
|
804
863
|
links = [link.name for link in loaded.model.links] if loaded.model else []
|
|
805
864
|
robot = recognise(loaded.robot.name, links, robot_model)
|
|
865
|
+
joints = [j.name for j in loaded.model.joints] if loaded.model else []
|
|
866
|
+
if missing := [n for n in claims if n not in joints]:
|
|
867
|
+
out.print(
|
|
868
|
+
f"no joint named {missing[0]}; the joints are: {', '.join(joints)}",
|
|
869
|
+
highlight=False,
|
|
870
|
+
markup=False,
|
|
871
|
+
)
|
|
872
|
+
raise typer.Exit(2)
|
|
806
873
|
load_catalog() # a bad ~/.lockwire/parts.yaml stops here as one line, not mid-check
|
|
807
874
|
if servo:
|
|
808
875
|
servo_stall_torque(servo) # an unknown id stops here, before any verdict
|
|
@@ -818,6 +885,14 @@ def check(
|
|
|
818
885
|
model=robot_model,
|
|
819
886
|
servo=servo,
|
|
820
887
|
)
|
|
888
|
+
if claims:
|
|
889
|
+
from lockwire.checks import _ScoreBook, check_torque_claims
|
|
890
|
+
|
|
891
|
+
book = _ScoreBook()
|
|
892
|
+
findings += check_torque_claims(loaded, claims, source, book)
|
|
893
|
+
findings.scored = (findings.scored or 0) + len(book)
|
|
894
|
+
findings.scored_keys = (findings.scored_keys or frozenset()) | book.keys
|
|
895
|
+
findings.scored_records += book.records
|
|
821
896
|
if model_file is not None:
|
|
822
897
|
from lockwire.start_operation import (
|
|
823
898
|
drop_same_figure,
|
|
@@ -2393,6 +2468,33 @@ def mcp_cmd() -> None:
|
|
|
2393
2468
|
build_server().run("stdio")
|
|
2394
2469
|
|
|
2395
2470
|
|
|
2471
|
+
_MODEL_NOISE = tuple(f"model/{k}" for k in ("source", "structure_hash", "provenance"))
|
|
2472
|
+
|
|
2473
|
+
|
|
2474
|
+
def _pair_sides(before: Contract, after: Contract) -> None:
|
|
2475
|
+
"""Rename `after`'s links and joints to `before`'s when they differ only by a side token."""
|
|
2476
|
+
import re
|
|
2477
|
+
|
|
2478
|
+
def swaps(old: list[Any], new: list[Any]) -> dict[str, str]:
|
|
2479
|
+
key = lambda n: re.sub(_SIDE, "_~", n.lower()) # noqa: E731
|
|
2480
|
+
ours = {key(x.name): x.name for x in old}
|
|
2481
|
+
return {x.name: ours[key(x.name)] for x in new if ours.get(key(x.name), x.name) != x.name}
|
|
2482
|
+
|
|
2483
|
+
a, b = before.model, after.model
|
|
2484
|
+
joints, links = swaps(a.joints, b.joints), swaps(a.links, b.links)
|
|
2485
|
+
if len(joints) * 2 <= len(b.joints): # most joints must pair, else leave the names alone
|
|
2486
|
+
return
|
|
2487
|
+
for link in b.links:
|
|
2488
|
+
link.frame = links.get(link.frame, link.frame)
|
|
2489
|
+
link.name = links.get(link.name, link.name)
|
|
2490
|
+
for joint in b.joints:
|
|
2491
|
+
joint.name = joints.get(joint.name, joint.name)
|
|
2492
|
+
joint.parent, joint.child = (
|
|
2493
|
+
links.get(joint.parent, joint.parent),
|
|
2494
|
+
links.get(joint.child, joint.child),
|
|
2495
|
+
)
|
|
2496
|
+
|
|
2497
|
+
|
|
2396
2498
|
def _diff_side(
|
|
2397
2499
|
spec: str, contract: Path, repo: Path | None, *, exit_code: bool, side: str
|
|
2398
2500
|
) -> Contract:
|
|
@@ -2411,6 +2513,17 @@ def _diff_side(
|
|
|
2411
2513
|
"""
|
|
2412
2514
|
on_disk = Path(spec)
|
|
2413
2515
|
text: str | None = None
|
|
2516
|
+
if on_disk.is_file() and on_disk.suffix.lower() in MODEL_SUFFIXES:
|
|
2517
|
+
import tempfile
|
|
2518
|
+
|
|
2519
|
+
from lockwire.start_operation import model_lock
|
|
2520
|
+
|
|
2521
|
+
try:
|
|
2522
|
+
with tempfile.TemporaryDirectory() as folder:
|
|
2523
|
+
return _load_contract_lib(model_lock(on_disk, Path(folder)))
|
|
2524
|
+
except (OSError, ModelDefect, ValueError) as error:
|
|
2525
|
+
console.print(f"[red]diff failed:[/] {escape(_why(error))}")
|
|
2526
|
+
raise typer.Exit(2) from error
|
|
2414
2527
|
if not (on_disk.exists() and on_disk.is_file()):
|
|
2415
2528
|
if repo is None:
|
|
2416
2529
|
console.print("not a git repository — nothing to compare against")
|
|
@@ -2460,7 +2573,19 @@ def diff_cmd(
|
|
|
2460
2573
|
b if b is not None else str(contract), contract, repo, exit_code=exit_code, side="b"
|
|
2461
2574
|
)
|
|
2462
2575
|
|
|
2576
|
+
models = all(Path(x).suffix.lower() in MODEL_SUFFIXES for x in (a, b))
|
|
2577
|
+
if models:
|
|
2578
|
+
_pair_sides(before, after)
|
|
2463
2579
|
diff = fact_diff(before, after)
|
|
2580
|
+
if models: # two model files: the file's own path and hashes always differ
|
|
2581
|
+
diff.changes = [
|
|
2582
|
+
replace(c, witness=None, source=None) # the witness is the lock's own temp file
|
|
2583
|
+
for c in diff.changes
|
|
2584
|
+
if not c.path.startswith(_MODEL_NOISE)
|
|
2585
|
+
]
|
|
2586
|
+
if not json_output:
|
|
2587
|
+
mass = [sum(x.mass.value for x in c.model.links if x.mass) for c in (before, after)]
|
|
2588
|
+
console.print(f"mass: {mass[0]:g} kg -> {mass[1]:g} kg", highlight=False)
|
|
2464
2589
|
if json_output:
|
|
2465
2590
|
typer.echo(json.dumps(diff.as_json(), indent=2))
|
|
2466
2591
|
else:
|
|
@@ -2658,7 +2783,10 @@ def serve_cmd(
|
|
|
2658
2783
|
|
|
2659
2784
|
from lockwire.serve import run_server
|
|
2660
2785
|
except ImportError:
|
|
2661
|
-
print(
|
|
2786
|
+
print(
|
|
2787
|
+
'install the serve extra: pip install "lockwire[serve]" (repo: uv sync --extra serve)',
|
|
2788
|
+
file=sys.stderr,
|
|
2789
|
+
)
|
|
2662
2790
|
raise typer.Exit(2) from None
|
|
2663
2791
|
raise typer.Exit(
|
|
2664
2792
|
run_server(
|
|
@@ -221,7 +221,7 @@ def build_server() -> MCPServer:
|
|
|
221
221
|
if file.is_absolute() and file.is_relative_to(Path.cwd()): # hints run from the cwd
|
|
222
222
|
path = str(file := file.relative_to(Path.cwd()))
|
|
223
223
|
if file.suffix.lower() not in MODEL_SUFFIXES or not file.is_file():
|
|
224
|
-
raise ToolError(f"no .
|
|
224
|
+
raise ToolError(f"no {'/'.join(MODEL_SUFFIXES)} model at {path}")
|
|
225
225
|
from lockwire.urdf import ModelDefect
|
|
226
226
|
|
|
227
227
|
line = ["check", path] + (["--mass", datasheet_mass] if datasheet_mass else [])
|