From f627339caf59ce2a12629ea6405314aead024624 Mon Sep 17 00:00:00 2001 From: yassinsolim Date: Sat, 10 Oct 2026 19:49:10 -0600 Subject: [PATCH 01/12] Set joint limits where the CAD parts first touch Each pitch joint stops about 1 degree before two parts touch, found by scripts/cad/joint_clearance.py: 135 degrees either way for the shoulder, 147 for the elbow and 93 for the wrist pitch. Base yaw and wrist roll never touch, so they turn 180 degrees either way. Collision boxes follow each CAD part, and the arm keeps 2 mm (self_collision_clearance) from its base and shoulder while the table keeps its 10 mm. Where the forearm folds back against the shoulder, boxes are too coarse, so the elbow follows a table of its limits over the shoulder angle, measured from the CAD and kept in the URDF. Teleop refuses a table height or clearance that is not finite, and a negative clearance. --- BuildInstructions.md | 24 +- README.md | 2 +- scripts/cad/build_arm_description.py | 89 +++-- scripts/cad/joint_clearance.py | 364 ++++++++++++++++++ .../test/test_arm_description.py | 43 ++- waybionic_description/urdf/waybionic_arm.urdf | 211 ++++++++-- waybionic_teleop/config/xbox_teleop.yaml | 6 +- waybionic_teleop/test/test_collision.py | 67 +++- waybionic_teleop/test/test_incision.py | 9 +- waybionic_teleop/test/test_kinematics.py | 17 +- .../test/test_sim_arm_drives_node.py | 10 +- waybionic_teleop/test/test_teleop_node.py | 10 +- .../test/test_xbox_teleop_node.py | 7 +- .../waybionic_teleop/collision.py | 84 +++- .../waybionic_teleop/xbox_teleop_node.py | 8 +- 15 files changed, 824 insertions(+), 127 deletions(-) create mode 100644 scripts/cad/joint_clearance.py diff --git a/BuildInstructions.md b/BuildInstructions.md index 5105335a..489a0309 100644 --- a/BuildInstructions.md +++ b/BuildInstructions.md @@ -395,11 +395,14 @@ the point moves onto the axis instead of the arm moving. Further away, the group rather than pull the tool back: press Y, withdraw the tool in another group, then select the incision group again to set a new incision point. -The current arm URDF has provisional joint limits, and the collision checks below model -each link as a box; they have been tested with simulated drives only. The simulated -CAN map is not a powered-arm safety case. Do not change a wrist bound or operate powered -motors until Mechanical identifies the URDF joint and measures signed travel from upright -zero, including any cable or gear stop. +The arm URDF's joint limits come from the CAD: each pitch joint stops about 1 degree +before two parts touch, 135 degrees either way for the shoulder, 147 for the elbow and +93 for the wrist pitch (found with `scripts/cad/joint_clearance.py`). Base yaw and +wrist roll never touch another part, so they turn 180 degrees either way until their +cabling is measured. These limits and the collision checks below have been tested with +simulated drives only. The simulated CAN map is not a powered-arm safety case. Do not +operate powered motors until Mechanical confirms the signed travel of each joint from +upright zero on the built arm, including any cable or gear stop. In simulation, a zero-velocity joint command (including B and controller timeout) sends an MKS F5 frame with zero speed and zero acceleration to each moving drive. @@ -413,15 +416,20 @@ not connect powered drives or treat it as a hardware E-stop test; drive identities, wiring, zeroing and electrical safety still need hardware verification. Every group stops a move before any part of the arm comes within 10 mm of the -table or folds into the arm's own base. The checks use a box around each link, -which you can see by ticking **Collision Enabled** on RViz's RobotModel display. +table or within 2 mm of the arm's own base and shoulder. The checks use a box +around each CAD part, which you can see by ticking **Collision Enabled** on RViz's +RobotModel display. Boxes are too coarse where the forearm folds back against the +shoulder, so there the elbow follows a table of its limits against the shoulder +angle, measured from the CAD 1 degree before the parts touch (`waybionic_fold` in +the URDF). The tool's box is a placeholder around the RViz jaws, which reach 30 mm past `tool_link`, until the real tool is modelled; a longer tool needs a longer box. When a move stops, the diagnostics panel names the part, for example `At limit: forearm_link: table`. If the arm stands on a raised mount, set `table_height` in `waybionic_teleop/config/xbox_teleop.yaml` to the table's height above the bottom of the base. `collision_clearance` in the same file sets the 10 mm -margin. If the arm is already touching something, the only moves still allowed are +margin to the table, and `self_collision_clearance` the 2 mm margin to the base and +shoulder. If the arm is already touching something, the only moves still allowed are the ones that back out of it: a move that presses any contact further in is refused, even if it would ease another contact at the same time. diff --git a/README.md b/README.md index 1a0dcf0c..fca465b4 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ Currently, this repository contains the clean foundation and the SolidWorks-expo ## Packages - **`waybionic_description`** - Hardware description, URDF/Xacro files, and meshes. `waybionic_arm.urdf` is generated from the mechanical team's `full-arm-smaller.SLDASM` by the tools in `scripts/cad/`; regenerate it after CAD changes instead of editing it. The geometric placeholder model remains available. + Hardware description, URDF/Xacro files, and meshes. `waybionic_arm.urdf` is generated from the mechanical team's `full-arm-smaller.SLDASM` by the tools in `scripts/cad/`; regenerate it after CAD changes instead of editing it, with the joint limits `scripts/cad/joint_clearance.py` finds where the parts first touch. The geometric placeholder model remains available. - **`waybionic_bringup`** Launch files and RViz configurations to bring up the robot state and visualization. - **`waybionic_teleop`** diff --git a/scripts/cad/build_arm_description.py b/scripts/cad/build_arm_description.py index 690eb7ef..f2dd9b56 100644 --- a/scripts/cad/build_arm_description.py +++ b/scripts/cad/build_arm_description.py @@ -19,7 +19,8 @@ Joint axes come from the named mates below. Joint zero is the upright pose used by the mechanical team's fk.py (links along +Z, pitch about +Y); the saved CAD -pose is reported as joint values. Limits are provisional until hardware sets them. +pose is reported as joint values. Each part gets its own collision box, so the +teleop collision checks follow the parts rather than one box per link. """ import argparse @@ -27,6 +28,7 @@ import json import math from pathlib import Path +from xml.sax.saxutils import quoteattr REPOSITORY = Path(__file__).resolve().parents[2] URDF_PATH = REPOSITORY / 'waybionic_description' / 'urdf' / 'waybionic_arm.urdf' @@ -53,17 +55,36 @@ } # name, parent, child, axis mate, origin plane mate, SolidWorks rotor, limits in degrees. +# The pitch limits stop about 1 degree before two CAD parts touch, found with +# scripts/cad/joint_clearance.py; base yaw and wrist roll never touch, so cabling sets them. JOINTS = ( ('joint_1', 'base_link', 'shoulder_link', 'Concentric124', 'Coincident70', 'outer_ring_sweep_loose-1', (-180.0, 180.0)), ('joint_2', 'shoulder_link', 'upper_arm_link', 'Concentric112', 'Coincident57', - 'outer-ring-Nema23-1', (-90.0, 90.0)), + 'outer-ring-Nema23-1', (-135.0, 135.0)), ('joint_3', 'upper_arm_link', 'forearm_link', 'Concentric127', 'Coincident71', - 'outer_ring_sweep_loose-2', (-90.0, 90.0)), + 'outer_ring_sweep_loose-2', (-147.0, 147.0)), ('joint_4', 'forearm_link', 'wrist_pitch_link', 'Concentric139', None, - 'DifferentialHousing-1', (-90.0, 90.0)), + 'DifferentialHousing-1', (-93.0, 93.0)), ('joint_5', 'wrist_pitch_link', 'wrist_roll_link', 'Concentric143', None, - 'straight bevel pinion_iso-3', (-90.0, 90.0)), + 'straight bevel pinion_iso-3', (-180.0, 180.0)), +) +# How far the elbow folds before the forearm meets the shoulder depends on the shoulder angle: +# shoulder angles from START in steps of STEP degrees, then the elbow's upper and lower limits +# there, 1 degree short of contact (scripts/cad/joint_clearance.py). The collision boxes are +# too coarse for this pair, so the teleop collision check reads this table instead. +ELBOW_FOLD = ( + -135.0, 5.0, + (147.3, 147.4, 147.4, 147.5, 147.6, 147.6, 147.6, 147.6, 147.6, 147.7, 147.7, 147.7, 147.7, + 147.7, 147.7, 147.7, 147.7, 147.7, 147.7, 147.7, 147.7, 147.7, 147.7, 147.6, 147.6, 147.6, + 147.6, 147.5, 147.5, 147.4, 147.4, 147.3, 147.2, 147.1, 147.0, 146.3, 144.8, 143.3, 141.6, + 139.9, 138.1, 136.4, 134.7, 133.1, 131.7, 130.2, 128.9, 127.6, 126.5, 125.6, 124.8, 124.3, + 121.9, 121.9, 122.6), + (-122.7, -121.9, -121.8, -124.3, -124.8, -125.6, -126.5, -127.6, -128.8, -130.1, -131.6, + -133.2, -134.7, -136.4, -138.1, -139.8, -141.6, -143.3, -144.8, -146.3, -147.0, -147.1, + -147.2, -147.3, -147.4, -147.4, -147.5, -147.5, -147.5, -147.6, -147.6, -147.6, -147.6, + -147.6, -147.7, -147.7, -147.7, -147.7, -147.7, -147.7, -147.7, -147.7, -147.7, -147.7, + -147.7, -147.6, -147.6, -147.6, -147.6, -147.6, -147.5, -147.5, -147.5, -147.4, -147.3), ) DESCRIPTIONS = { 'joint_1': 'base yaw', 'joint_2': 'shoulder pitch', 'joint_3': 'elbow pitch', @@ -473,9 +494,10 @@ def world_frame(self, link): def quantized_link_mesh(model, link, grid): - """Triangles per color in link coordinates, snapped to a grid with per-face normals.""" + """Triangles per color in link coordinates, snapped to a grid, and each part's extent.""" export = model.export groups = {} + extents = {} to_link = model.frames[link].inverse() * model.to_base stats = {'input': 0, 'output': 0, 'bodies': 0, 'flipped': 0, 'conflicts': 0} for name in sorted(model.assigned[link]): @@ -532,9 +554,13 @@ def quantized_link_mesh(model, link, grid): length = norm(normals[old]) group['positions'].append(keys[old]) group['normals'].append(scale(normals[old], 1.0 / length) if length > 1e-15 else (0.0, 0.0, 1.0)) + low, high = extents.setdefault(name, (list(keys[old]), list(keys[old]))) + for axis in range(3): + low[axis] = min(low[axis], keys[old][axis]) + high[axis] = max(high[axis], keys[old][axis]) group['triangles'].extend(tuple(remap[k] for k in triangle) for triangle in triangles) stats['output'] += len(triangles) - return groups, stats + return groups, stats, extents def write_collada(path, link, groups): @@ -592,19 +618,25 @@ def write_collada(path, link, groups): path.write_text('\n'.join(lines), encoding='utf-8') -def collision_box(groups): - """Return the centre and size of the box around a link's mesh, in link coordinates.""" - points = [point for group in groups.values() for point in group['positions']] - low = [min(point[axis] for point in points) for axis in range(3)] - high = [max(point[axis] for point in points) for axis in range(3)] - return [(a + b) / 2 for a, b in zip(low, high)], [b - a for a, b in zip(low, high)] +def part_boxes(extents): + """Return [(part, centre, size)]: one box per part, leaving out boxes inside another.""" + items = sorted(extents.items()) + + def inside(box, other): + return all(other[0][a] <= box[0][a] and box[1][a] <= other[1][a] for a in range(3)) + + kept = [(name, box) for index, (name, box) in enumerate(items) + if not any(inside(box, other) and (not inside(other, box) or position < index) + for position, (_, other) in enumerate(items) if position != index)] + return [(name, [(a + b) / 2 for a, b in zip(low, high)], [b - a for a, b in zip(low, high)]) + for name, (low, high) in kept] -def collision_lines(center, size): +def collision_lines(name, center, size): return [ - ' ', - f' ', - f' ', + f' ', + f' ', + f' ', ' '] @@ -616,7 +648,8 @@ def write_urdf(model, source, boxes): ' Do not edit by hand; re-export the SolidWorks assembly and re-run the script.', ' Joint zero is the upright pose from the mechanical fk.py (links along +Z,', f' pitch about +Y). Saved CAD pose in degrees {angles}.', - ' Limits are provisional; effort and velocity are placeholders for display. -->', + ' Each pitch joint stops about 1 degree before two parts touch; one collision box', + ' per part. Effort and velocity are placeholders for display. -->', ''] for link in LINKS: lines += [ @@ -624,12 +657,12 @@ def write_urdf(model, source, boxes): ' ', f' ', ' ', - *collision_lines(*boxes[link]), + *[line for box in boxes[link] for line in collision_lines(*box)], ' '] lines += [ ' ', ' ', - *collision_lines(*TOOL_BOX), + *collision_lines('placeholder_jaws', *TOOL_BOX), ' '] for joint in model.joints: kind = 'continuous' if joint['mimic'] else 'revolute' @@ -647,12 +680,24 @@ def write_urdf(model, source, boxes): if joint['mimic']: lines.append(f' ') lines.append(' ') + start, step, upper, lower = ELBOW_FOLD + shoulder = next(limits for name, *_, limits in JOINTS if name == 'joint_2') + if (len(upper) != len(lower) or start != shoulder[0] + or abs(start + step * (len(upper) - 1) - shoulder[1]) > 1e-6): + raise ValueError('ELBOW_FOLD must span the shoulder limits; re-run joint_clearance.py') lines += [ ' ', ' ', ' ', f' ', ' ', + ' ', + f' ', '', ''] URDF_PATH.write_text('\n'.join(lines), encoding='utf-8') @@ -794,10 +839,10 @@ def main(): total_in = total_out = 0 boxes = {} for link in LINKS: - groups, stats = quantized_link_mesh(model, link, arguments.grid) + groups, stats, extents = quantized_link_mesh(model, link, arguments.grid) path = MESH_DIRECTORY / f'{link}.dae' write_collada(path, link, groups) - boxes[link] = collision_box(groups) + boxes[link] = part_boxes(extents) total_in += stats['input'] total_out += stats['output'] print(f' {path.name}: {stats["input"]} -> {stats["output"]} triangles, {len(groups)} colors, ' diff --git a/scripts/cad/joint_clearance.py b/scripts/cad/joint_clearance.py new file mode 100644 index 00000000..87830579 --- /dev/null +++ b/scripts/cad/joint_clearance.py @@ -0,0 +1,364 @@ +#!/usr/bin/env python3 +"""Find how far the arm's pitch joints turn before two CAD parts touch. + + python3 scripts/cad/joint_clearance.py build/cad/arm_export.json + +After a CAD change, copy the printed limits into JOINTS and ELBOW_FOLD in +build_arm_description.py and rebuild the URDF. This script needs numpy and +scipy; the build script does not. + +Each part's SolidWorks tessellation is sampled densely in its link frame, with +outward normals. For a joint, the links it carries turn as one body against +the rest of the arm. A sample that ends up more than PENETRATION inside a part +of the other body is a clash once a winding number and the exact distance to +that part's triangles confirm it. Samples already inside in the upright pose +are press fits and are ignored. Gearbox internals are skipped: they are +enclosed, and static CAD cannot model their eccentric motion. Base yaw and +wrist roll turn round parts in round housings, so cabling sets their range. + +How far the elbow folds before the forearm meets the shoulder also depends on +the shoulder angle, so that is tabulated against it. The collision boxes are +too coarse for that pair, and the teleop collision check uses the table. +""" + +import argparse +import importlib.util +import math +from pathlib import Path +import textwrap + +import numpy as np +from scipy.spatial import cKDTree + +DENSITY = 2.0e6 # samples per square metre of surface +PENETRATION = 0.0005 # m inside another part that counts as a clash +GROWTH = 0.00025 # m deeper than in the upright pose +SEARCH = 0.004 # m +NEIGHBOURS = 6 +CONTACT = 0.001 # m between forearm and shoulder samples that counts as touching +MARGIN = 1.0 # degrees kept clear of contact +INTERNAL = ('discs-sweep', 'disc-bearing', 'loose_disc', 'inner_bearing', 'shaft-sweep', + 'NEMA23SHAFT', 'outer_ball_bearing', 'outer-ring-bearing', 'bearing_brace', + 'updatednema23bearingbrace', 'top-sweep') +PITCH_JOINTS = ('joint_2', 'joint_3', 'joint_4') +FOLD = ('forearm_link', 'shoulder_link', 'joint_3', 'joint_2') + +spec = importlib.util.spec_from_file_location( + 'build_arm_description', Path(__file__).resolve().with_name('build_arm_description.py')) +arm = importlib.util.module_from_spec(spec) +spec.loader.exec_module(arm) + + +def rotation(axis, angle): + return np.array(arm.rotation_about(axis, angle)) + + +def rpy(roll, pitch, yaw): + return rotation((0, 0, 1), yaw) @ rotation((0, 1, 0), pitch) @ rotation((1, 0, 0), roll) + + +class Arm: + """Sampled CAD parts in their link frames, and the joint tree.""" + + def __init__(self, export_path, seed=7): + export = arm.Export(export_path) + self.model = arm.Model(export, arm.check_components(export)) + self.rng = np.random.default_rng(seed) + self.parts = {} # link -> [(part, points, normals, triangles per body)] + for link, names in self.model.assigned.items(): + self.parts[link] = [(name, *self._sample(export, name, link)) for name in sorted(names) + if not name.split('/')[-1].startswith(INTERNAL)] + + def _sample(self, export, name, link): + component = export.components[name] + pose = (self.model.frames[link].inverse() * self.model.to_base + * arm.solidworks_pose(component['transform'])) + turn, origin = np.array(pose.rotation), np.array(pose.origin) + bodies = {} + for face in component['faces']: + vertices, indices = export.face_arrays(face) + v = np.frombuffer(vertices.tobytes(), dtype=np.float32).reshape(-1, 3).astype(float) + t = np.frombuffer(indices.tobytes(), dtype=np.int32).reshape(-1, 3) + bodies.setdefault(face['body'], []).append(v[t]) + points, normals, solids = [], [], [] + for triangles in bodies.values(): + tri = np.vstack(triangles) + solids.append(tri @ turn.T + origin) + a, b, c = tri[:, 0], tri[:, 1], tri[:, 2] + cross = np.cross(b - a, c - a) + if np.einsum('ij,ij->', a, np.cross(b, c)) < 0: + cross = -cross # make the normals point out of the body + area = 0.5 * np.linalg.norm(cross, axis=1) + good = area > 1e-14 + a, b, c, cross, area = a[good], b[good], c[good], cross[good], area[good] + count = np.maximum(1, np.floor(area * DENSITY + self.rng.random(len(area))).astype(int)) + which = np.repeat(np.arange(len(a)), count) + r1, r2 = np.sqrt(self.rng.random(len(which))), self.rng.random(len(which)) + local = ((1 - r1)[:, None] * a[which] + (r1 * (1 - r2))[:, None] * b[which] + + (r1 * r2)[:, None] * c[which]) + points.append(local @ turn.T + origin) + normals.append((cross[which] / (2.0 * area[which])[:, None]) @ turn.T) + return np.vstack(points), np.vstack(normals), solids + + def joint(self, name): + return next(joint for joint in self.model.joints if joint['name'] == name) + + def poses(self, q): + poses = {'base_link': (np.eye(3), np.zeros(3))} + for joint in self.model.joints: + angle = q.get(joint['name'], 0.0) + if joint['mimic']: + angle = joint['mimic'][1] * q.get(joint['mimic'][0], 0.0) + r, o = poses[joint['parent']] + poses[joint['child']] = (r @ rpy(*joint['rpy']) @ rotation(joint['axis'], angle), + o + r @ np.array(joint['xyz'])) + return poses + + def subtree(self, link): + found = {link} + for joint in self.model.joints: + if joint['parent'] in found: + found.add(joint['child']) + return found + + def cloud(self, link): + return np.vstack([points for _, points, _, _ in self.parts[link]]) + + +def inside(point, solids): + """True if point is inside a closed body (generalized winding number above one half).""" + for tri in solids: + a, b, c = tri[:, 0] - point, tri[:, 1] - point, tri[:, 2] - point + la, lb, lc = (np.linalg.norm(x, axis=1) for x in (a, b, c)) + numerator = np.einsum('ij,ij->i', a, np.cross(b, c)) + denominator = (la * lb * lc + np.einsum('ij,ij->i', a, b) * lc + + np.einsum('ij,ij->i', a, c) * lb + np.einsum('ij,ij->i', b, c) * la) + if abs(np.arctan2(numerator, denominator).sum() / (2.0 * math.pi)) > 0.5: + return True + return False + + +def _segment(p, a, b): + ab = b - a + t = np.clip(np.einsum('ij,ij->i', p - a, ab) + / np.maximum(np.einsum('ij,ij->i', ab, ab), 1e-30), 0.0, 1.0) + return np.linalg.norm(p - (a + t[:, None] * ab), axis=1) + + +def depth(point, solids): + """How far point is inside the bodies (distance to the nearest triangle), or 0 outside.""" + if not inside(point, solids): + return 0.0 + best = math.inf + for tri in solids: + a, b, c = tri[:, 0], tri[:, 1], tri[:, 2] + n = np.cross(b - a, c - a) + length = np.linalg.norm(n, axis=1) + ok = length > 1e-15 + n = n / np.where(ok, length, 1.0)[:, None] + height = np.einsum('ij,ij->i', point - a, n) + v0, v1, v2 = c - a, b - a, point - height[:, None] * n - a + d00, d01, d11 = (np.einsum('ij,ij->i', x, y) for x, y in ((v0, v0), (v0, v1), (v1, v1))) + d02, d12 = np.einsum('ij,ij->i', v0, v2), np.einsum('ij,ij->i', v1, v2) + det = d00 * d11 - d01 * d01 + with np.errstate(divide='ignore', invalid='ignore'): + u = (d11 * d02 - d01 * d12) / det + v = (d00 * d12 - d01 * d02) / det + within = ok & (u >= 0) & (v >= 0) & (u + v <= 1) + p = np.broadcast_to(point, a.shape) + edges = np.minimum(np.minimum(_segment(p, a, b), _segment(p, b, c)), _segment(p, c, a)) + best = min(best, float(np.where(within, np.abs(height), edges).min())) + return best + + +def signed(tree, normals, points): + """Signed distance to the nearest samples (negative inside), and the nearest sample.""" + distance, index = tree.query(points, k=NEIGHBOURS, distance_upper_bound=SEARCH, workers=-1) + near = np.flatnonzero(np.isfinite(distance[:, NEIGHBOURS // 2])) + value = np.full(len(points), np.inf) + if len(near): + ok = np.isfinite(distance[near]) + safe = np.where(ok, index[near], 0) + s = np.einsum('ijk,ijk->ij', points[near][:, None, :] - tree.data[safe], normals[safe]) + inner = np.nanmedian(np.where(ok, s, np.nan), axis=1) < 0.0 + value[near] = np.where(inner, -distance[near, 0], distance[near, 0]) + return value, index[:, 0] + + +class Sweep: + """One joint turning from the upright pose, its links against the rest of the arm.""" + + def __init__(self, robot, name): + self.robot, self.joint = robot, robot.joint(name) + self.axis = np.array(self.joint['axis']) + moving = robot.subtree(self.joint['child']) + poses = robot.poses({}) + self.child0 = poses[self.joint['child']] + self.fixed = self._gather([link for link in robot.parts if link not in moving], poses, None) + # The moving links are kept in the child frame, where they never move. + self.moving = self._gather([link for link in robot.parts if link in moving], poses, + self.child0) + self.start = self._depths(0.0) + + def _gather(self, links, poses, frame): + """Points, normals, labels and bodies in the base frame, or in frame = (rotation, origin).""" + points, normals, labels, solids = [], [], [], {} + for link in links: + r, o = poses[link] + if frame is not None: + r, o = frame[0].T @ r, frame[0].T @ (o - frame[1]) + for name, local, n, bodies in self.robot.parts[link]: + points.append(local @ r.T + o) + normals.append(n @ r.T) + labels += [f'{link}: {name}'] * len(local) + solids[f'{link}: {name}'] = [tri @ r.T + o for tri in bodies] + points = np.vstack(points) + return {'points': points, 'normals': np.vstack(normals), 'labels': np.array(labels), + 'solids': solids, 'tree': cKDTree(points)} + + def child_pose(self, angle): + return self.robot.poses({self.joint['name']: angle})[self.joint['child']] + + def _depths(self, angle): + r, o = self.child_pose(angle) + moving_world = self.moving['points'] @ r.T + o + fixed_local = (self.fixed['points'] - o) @ r + into_fixed = signed(self.fixed['tree'], self.fixed['normals'], moving_world) + into_moving = signed(self.moving['tree'], self.moving['normals'], fixed_local) + return into_fixed, into_moving, moving_world, fixed_local + + def _radius(self, local): + """Distance of a point in the child frame from the joint axis.""" + return float(np.linalg.norm(local - self.axis * (local @ self.axis))) + + def clashes(self, angle): + """Return {(moving part, fixed part): (depth, radius)} at this angle, and the lowest + moving point. Radius is the clashing point's distance from the joint axis.""" + (into_fixed, fixed_index), (into_moving, moving_index), world, local = self._depths(angle) + r0, o0 = self.child0 + pairs = {} + + def add(pair, now, point): + if now > pairs.get(pair, (0.0, 0.0))[0]: + pairs[pair] = (now, self._radius(point)) + + for i in np.flatnonzero((into_fixed < -PENETRATION) & (self.start[0][0] >= -PENETRATION)): + pair = (self.moving['labels'][i], self.fixed['labels'][fixed_index[i]]) + solids = self.fixed['solids'][pair[1]] + now = depth(world[i], solids) + if now > PENETRATION and now - depth( + self.moving['points'][i] @ r0.T + o0, solids) > GROWTH: + add(pair, now, self.moving['points'][i]) + for i in np.flatnonzero((into_moving < -PENETRATION) & (self.start[1][0] >= -PENETRATION)): + pair = (self.moving['labels'][moving_index[i]], self.fixed['labels'][i]) + solids = self.moving['solids'][pair[0]] + now = depth(local[i], solids) + if now > PENETRATION and now - depth( + (self.fixed['points'][i] - o0) @ r0, solids) > GROWTH: + add(pair, now, local[i]) + return pairs, float(world[:, 2].min()) + + def first_contact(self, sign, step=1.0): + """Degrees turned in one direction when two parts first touch, the parts, and where + the arm meets the table (the plane under the base).""" + angle, table = 0.0, None + while angle < 181.0: + angle += step + pairs, lowest = self.clashes(sign * math.radians(angle)) + if table is None and lowest < 0.0: + table = angle + if pairs: + fine = angle - step + while fine < angle: + fine += 0.05 + pairs, _ = self.clashes(sign * math.radians(fine)) + if pairs: + break + # Back off by the angle that took the deepest point that far in. + touch = fine - max(math.degrees(inside_by / max(radius, 1e-3)) + for inside_by, radius in pairs.values()) + return touch, sorted(pairs), table + return None, [], table + + +class Fold: + """How far one link folds against another, for each angle of the joint between them.""" + + def __init__(self, robot, link, obstacle, joint, across): + self.robot, self.link, self.obstacle = robot, link, obstacle + self.joint, self.across = joint, across + self.points = robot.cloud(link) + self.tree = cKDTree(robot.cloud(obstacle)) + axis = np.array(robot.joint(joint)['axis']) + # No point of the link moves faster than this per radian of the joint. + self.reach = float(np.linalg.norm( + self.points - np.outer(self.points @ axis, axis), axis=1).max()) + + def distance(self, across, angle): + poses = self.robot.poses({self.across: across, self.joint: angle}) + ro, oo = poses[self.obstacle] + rl, ol = poses[self.link] + moved = self.points @ (ro.T @ rl).T + ro.T @ (ol - oo) + return float(self.tree.query(moved, distance_upper_bound=0.25, workers=-1)[0].min()) + + def contact(self, across, sign): + """Degrees the joint turns before contact, or None within half a turn.""" + angle = 0.0 + while angle < math.pi: + gap = self.distance(across, sign * angle) + if gap < CONTACT: + return math.degrees(angle) + # Conservative advancement: no point can close more than the gap in one step. + angle += max((gap - CONTACT / 2) / self.reach, math.radians(0.02)) + return None + + +def main(): + parser = argparse.ArgumentParser(description=__doc__.splitlines()[0]) + parser.add_argument('export', type=Path, help='JSON written by export_solidworks_assembly') + parser.add_argument('--fold-step', type=float, default=5.0, + help='shoulder angle step of the elbow fold table in degrees') + args = parser.parse_args() + robot = Arm(args.export) + + print('Pitch joints from the upright pose (base yaw and wrist roll do not touch):') + for name in PITCH_JOINTS: + sweep = Sweep(robot, name) + found = [] + for sign in (1, -1): + angle, pairs, table = sweep.first_contact(sign) + found.append(angle) + where = f'touches at {sign * angle:+.2f}' if angle is not None else 'clear to 181' + meets = f', meets the table at {sign * table:+.0f}' if table is not None else '' + print(f' {name} {"+-"[sign < 0]}: {where}{meets}', flush=True) + for moving, fixed in pairs[:3]: + print(f' {moving} -> {fixed}') + upper, lower = (math.floor(angle - MARGIN) if angle is not None else 180 for angle in found) + print(f' limits ({-lower:.1f}, {upper:.1f})') + + link, obstacle, joint, across = FOLD + fold = Fold(robot, link, obstacle, joint, across) + low, high = robot.joint(across)['limits'] + print(f'Elbow fold against the shoulder, {MARGIN:.0f} degree short of contact:') + upper, lower = [], [] + for index in range(int(round((high - low) / args.fold_step)) + 1): + shoulder = low + index * args.fold_step + values = [] + for sign in (1, -1): + angle = fold.contact(math.radians(shoulder), sign) + values.append(sign * (math.floor((angle - MARGIN) * 10) / 10 if angle is not None + else 180.0)) + upper.append(values[0]) + lower.append(values[1]) + print(f' {across} {shoulder:+7.1f}: {joint} from {values[1]:+7.1f} to {values[0]:+7.1f}', + flush=True) + print('ELBOW_FOLD = (') + print(f' {low:.1f}, {args.fold_step:.1f},') + for values in (upper, lower): + print(textwrap.fill(', '.join(f'{value:.1f}' for value in values) + '),', width=99, + initial_indent=' (', subsequent_indent=' ')) + print(')') + + +if __name__ == '__main__': + main() diff --git a/waybionic_description/test/test_arm_description.py b/waybionic_description/test/test_arm_description.py index b70fa046..20e364df 100644 --- a/waybionic_description/test/test_arm_description.py +++ b/waybionic_description/test/test_arm_description.py @@ -1,6 +1,7 @@ """Check the generated WayBionic arm description and its COLLADA meshes.""" import ast +import math from pathlib import Path import xml.etree.ElementTree as ET @@ -69,23 +70,43 @@ def test_link_meshes_are_valid_z_up_collada(robot): assert 0 <= min(indices) and max(indices) < vertices -def test_every_mesh_is_inside_its_collision_box(robot): +def test_every_mesh_vertex_is_inside_a_collision_box_of_its_link(robot): for link in robot.findall('link'): if link.get('name') == 'tool_link': continue - boxes = link.findall('collision') - assert len(boxes) == 1, link.get('name') - center = [float(value) for value in boxes[0].find('origin').get('xyz').split()] - size = [float(value) for value in boxes[0].find('geometry/box').get('size').split()] - assert boxes[0].find('origin').get('rpy') == '0 0 0' + boxes = [] + for collision in link.findall('collision'): + assert collision.get('name'), link.get('name') + assert collision.find('origin').get('rpy') == '0 0 0' + center = [float(value) for value in collision.find('origin').get('xyz').split()] + size = [float(value) for value in collision.find('geometry/box').get('size').split()] + # Boxes are written to 0.01 mm. + boxes.append([(c - s / 2 - 2e-5, c + s / 2 + 2e-5) for c, s in zip(center, size)]) + assert boxes, link.get('name') uri = link.find('visual/geometry/mesh').get('filename') mesh = ET.parse(PACKAGE / uri[len('package://waybionic_description/'):]).getroot() values = [float(value) for value in mesh.find(f'.//{COLLADA}float_array').text.split()] - for axis in range(3): - points = values[axis::3] - # The box is written to 0.1 mm. - assert center[axis] - size[axis] / 2 <= min(points) + 1e-4 - assert max(points) <= center[axis] + size[axis] / 2 + 1e-4 + for point in zip(values[0::3], values[1::3], values[2::3]): + assert any(all(low <= p <= high for p, (low, high) in zip(point, box)) + for box in boxes), (link.get('name'), point) + + +def test_elbow_fold_table_covers_the_shoulder_range(robot): + joints = {joint.get('name'): joint for joint in robot.findall('joint')} + folds = robot.findall('waybionic_fold') + assert len(folds) == 1 + fold = folds[0] + assert (fold.get('link'), fold.get('obstacle')) == ('forearm_link', 'shoulder_link') + assert joints[fold.get('joint')].find('child').get('link') == 'forearm_link' + shoulder = joints[fold.get('across')].find('limit') + start, step = float(fold.get('start')), float(fold.get('step')) + upper = [float(value) for value in fold.get('upper').split()] + lower = [float(value) for value in fold.get('lower').split()] + assert len(upper) == len(lower) >= 2 and step > 0.0 + assert start == pytest.approx(math.degrees(float(shoulder.get('lower'))), abs=1e-3) + assert start + step * (len(upper) - 1) == pytest.approx( + math.degrees(float(shoulder.get('upper'))), abs=1e-3) + assert all(low < 0.0 < high for low, high in zip(lower, upper)) def test_the_tool_box_encloses_the_placeholder_jaws(robot): diff --git a/waybionic_description/urdf/waybionic_arm.urdf b/waybionic_description/urdf/waybionic_arm.urdf index cd3f4885..cd8d6207 100644 --- a/waybionic_description/urdf/waybionic_arm.urdf +++ b/waybionic_description/urdf/waybionic_arm.urdf @@ -3,49 +3,178 @@ Do not edit by hand; re-export the SolidWorks assembly and re-run the script. Joint zero is the upright pose from the mechanical fk.py (links along +Z, pitch about +Y). Saved CAD pose in degrees joint_1=-8.93, joint_2=-8.78, joint_3=45.14, joint_4=5.08, joint_5=0.00. - Limits are provisional; effort and velocity are placeholders for display. --> + Each pitch joint stops about 1 degree before two parts touch; one collision box + per part. Effort and velocity are placeholders for display. --> - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - + + + + + + + + + + + + + + + + + + + + + + + - + @@ -54,32 +183,52 @@ - - - + + + + + + + + + + + - - - + + + + + + + + + + + - - - + + + + + + + - + @@ -98,7 +247,7 @@ - + @@ -106,7 +255,7 @@ - + @@ -114,7 +263,7 @@ - + @@ -122,7 +271,7 @@ - + @@ -145,4 +294,10 @@ + + diff --git a/waybionic_teleop/config/xbox_teleop.yaml b/waybionic_teleop/config/xbox_teleop.yaml index 8af6fd18..722a1b10 100644 --- a/waybionic_teleop/config/xbox_teleop.yaml +++ b/waybionic_teleop/config/xbox_teleop.yaml @@ -57,7 +57,9 @@ xbox_teleop: tool_open_axis: left_trigger tool_frame: tool_link base_frame: base_link - # Moves stop before any link's collision box comes within collision_clearance (m) of the - # table, table_height (m) above the bottom of the base, or of the base and shoulder. + # Moves stop before any part's collision box comes within collision_clearance (m) of the + # table, table_height (m) above the bottom of the base, or within self_collision_clearance + # (m) of the base and shoulder. table_height: 0.0 collision_clearance: 0.01 + self_collision_clearance: 0.002 diff --git a/waybionic_teleop/test/test_collision.py b/waybionic_teleop/test/test_collision.py index b083c26b..4ef94eb7 100644 --- a/waybionic_teleop/test/test_collision.py +++ b/waybionic_teleop/test/test_collision.py @@ -2,20 +2,20 @@ import math from pathlib import Path +import re import pytest from waybionic_teleop.collision import _intrusion, _overlap, _rotation, ArmCollision from waybionic_teleop.gamepad import AXES, BUTTONS -from waybionic_teleop.kinematics import ArmKinematics +from waybionic_teleop.kinematics import ArmKinematics, joint_limits from waybionic_teleop.teleop import ArmTeleop, config_from_parameters from waybionic_teleop.xbox_teleop_node import JAW_OPEN_GAP, JAW_SIZE URDF = (Path(__file__).resolve().parents[2] / 'waybionic_description' / 'urdf' / 'waybionic_arm.urdf').read_text(encoding='utf-8') -LIMITS = {'joint_1': (-math.pi, math.pi), 'joint_2': (-1.5708, 1.5708), - 'joint_3': (-1.5708, 1.5708), 'joint_4': (-1.5708, 1.5708), - 'joint_5': (-1.5708, 1.5708)} +COLLISION = re.compile(r'', re.S) +LIMITS = joint_limits(URDF, ['joint_1', 'joint_2', 'joint_3', 'joint_4', 'joint_5']) DT = 1.0 / 120.0 @@ -49,6 +49,31 @@ def test_folding_back_into_the_base_is_caught_past_todays_joint_limits(check): assert not any('table' in hit for hit in hits) +def test_the_elbow_folds_until_the_forearm_almost_touches_the_shoulder(check): + # The forearm's boxes would stop this near 134 degrees; the CAD fold table allows 147. + assert check.hits(pose(0, 146, 0)) == [] and check.hits(pose(0, -146, 0)) == [] + assert check.hits(pose(0, 149, 0)) == ['forearm_link: shoulder_link'] + assert check.hits(pose(0, -149, 0)) == ['forearm_link: shoulder_link'] + + +def test_the_fold_limit_follows_the_shoulder_angle(): + # With the shoulder tilted, the forearm meets the shoulder sooner on that side. + away = ArmCollision.from_urdf(URDF, table_z=-10.0) + for sign in (1, -1): + assert 'forearm_link: shoulder_link' not in away.hits(pose(sign * 90, sign * 128, 0)) + assert 'forearm_link: shoulder_link' in away.hits(pose(sign * 90, sign * 133, 0)) + + +@pytest.mark.parametrize('old, new', [ + ('across="joint_2"', 'across="joint_9"'), ('start="-135"', 'start="nan"'), + ('step="5"', 'step="0"'), ('upper="147.3 ', 'upper="'), ('lower="-122.7', 'lower="inf'), +]) +def test_an_unusable_fold_table_is_refused(old, new): + assert old in URDF + with pytest.raises(ValueError, match='waybionic_fold'): + ArmCollision.from_urdf(URDF.replace(old, new)) + + def test_table_height_and_clearance_are_configurable(): # This pose's tool tip is 175 mm above the bottom of the base. joints = pose(28.6, 80.2, 71.1, 0.1) @@ -57,15 +82,24 @@ def test_table_height_and_clearance_are_configurable(): assert ArmCollision.from_urdf(URDF, table_z=0.1, clearance=0.1).hits(joints) +def test_the_base_and_shoulder_have_their_own_smaller_clearance(): + # The elbow bend is between 2 and 10 mm from the base's lid here. + joints = pose(-127, 60, 0, math.radians(5)) + assert ArmCollision.from_urdf(URDF).hits(joints) == [] + assert ArmCollision.from_urdf(URDF, self_clearance=0.01).hits(joints) == [ + 'forearm_link: base_link'] + + def test_a_urdf_without_collision_boxes_is_refused(): with pytest.raises(ValueError, match='no collision box'): - ArmCollision.from_urdf(URDF.replace('', '')) - # Every link the checks rely on needs its box, including the upper arm and the tool. + ArmCollision.from_urdf(re.sub(COLLISION, '', URDF)) + # Every link the checks rely on needs its boxes, including the upper arm and the tool. for link in ('upper_arm_link', 'tool_link'): - start = URDF.index('', URDF.index(f'')) - end = URDF.index('', start) + len('') + start = URDF.index(f'') + end = URDF.index('', start) with pytest.raises(ValueError, match=link): - ArmCollision.from_urdf(URDF[:start] + URDF[end:]) + ArmCollision.from_urdf( + URDF[:start] + re.sub(COLLISION, '', URDF[start:end]) + URDF[end:]) @pytest.mark.parametrize('extra, roots', [ @@ -178,10 +212,10 @@ def test_teleop_refuses_to_slide_the_forearm_further_into_the_side_of_the_base( parameters, check): teleop = ArmTeleop(config_from_parameters(parameters('xbox_teleop.yaml', 'xbox_teleop')), LIMITS, ArmKinematics.from_urdf(URDF), check) - # Folded back past today's joint limits, the end of the forearm reaches into the side of - # the base. Turning the base towards zero slides it further in along that side, while its - # overlap across the side, the smallest of the separating-axis overlaps, shrinks. - start, turned = pose(-130, 40, 0, math.radians(15)), pose(-130, 40, 0, math.radians(14.5)) + # Folded back with the shoulder near its limit, the elbow bend reaches into the base's lid. + # Turning the base towards zero slides it further in, while its smallest separating-axis + # overlap shrinks. + start, turned = pose(-130, 60, 0, math.radians(5)), pose(-130, 60, 0, math.radians(4.5)) assert check.hits(start) == check.hits(turned) == ['forearm_link: base_link'] assert separating_axis_depth(check, turned) < separating_axis_depth(check, start) assert (check.check(turned)['forearm_link: base_link'] @@ -213,10 +247,11 @@ def sample(*pressed, **axes): def separating_axis_depth(check, joints): - """Return the forearm's smallest overlap with the base across the separating axes.""" + """Return the deepest overlap of a forearm part with the base across the separating axes.""" poses = check.poses(joints) - return _overlap(next(check.world_boxes(poses, 'forearm_link')), - next(check.world_boxes(poses, 'base_link')), check.clearance) + return max(_overlap(box, obstacle, check.self_clearance) + for box in check.world_boxes(poses, 'forearm_link') + for obstacle in check.world_boxes(poses, 'base_link')) def jaw_bottom(check, joints): diff --git a/waybionic_teleop/test/test_incision.py b/waybionic_teleop/test/test_incision.py index 529a2ce2..809d745a 100644 --- a/waybionic_teleop/test/test_incision.py +++ b/waybionic_teleop/test/test_incision.py @@ -139,10 +139,11 @@ def test_roll_turns_the_tool_without_moving_it_off_the_incision(teleop, arm): assert arm.forward(teleop.targets)[1] == pytest.approx(pitch, abs=1e-9) -@pytest.mark.parametrize('axes, joint', [ - ({'left_y': -1.0}, 'joint_4'), ({'right_y': 1.0}, 'joint_3'), ({'right_y': -1.0}, 'joint_4')]) +@pytest.mark.parametrize('axes, joint, bound', [ + ({'left_y': -1.0}, 'joint_4', 1), ({'right_y': 1.0}, 'joint_4', 0), + ({'right_y': -1.0}, 'joint_4', 1)]) def test_moving_into_a_joint_limit_sends_targets_within_the_urdf_limits( - parameters, arm, axes, joint): + parameters, arm, axes, joint, bound): limits = joint_limits(URDF, arm.joints) params = {**parameters('xbox_teleop.yaml', 'xbox_teleop'), 'initial_speed_level': 3} teleop = ArmTeleop(config_from_parameters(params), limits, arm) @@ -158,7 +159,7 @@ def test_moving_into_a_joint_limit_sends_targets_within_the_urdf_limits( break else: pytest.fail(f'{joint} never reached its limit') - assert teleop.targets[joint] == pytest.approx(limits[joint][1], abs=1e-6) + assert teleop.targets[joint] == pytest.approx(limits[joint][bound], abs=1e-6) assert through(arm, teleop.targets, teleop.incision)[0] < 1e-6 diff --git a/waybionic_teleop/test/test_kinematics.py b/waybionic_teleop/test/test_kinematics.py index d7f1faa8..4a1b9061 100644 --- a/waybionic_teleop/test/test_kinematics.py +++ b/waybionic_teleop/test/test_kinematics.py @@ -164,11 +164,12 @@ def test_tilting_pivots_the_tool_about_a_fixed_tip(arm): def test_tilting_stops_at_a_joint_limit_with_the_tip_in_place(arm): - path = cut(arm, (0.0, 0.0, 0.0), 2.0, pitch_rate=-0.2) + # Tilting the tool back about its tip pitches the wrist until it reaches its limit. + path = cut(arm, (0.0, 0.0, 0.0), 11.5, pitch_rate=-0.2) joints, fraction, blocked = arm.jog(path[-1], (0.0, 0.0, 0.0), -0.2, 0.0, DT, LIMITS, MAX_RATE) - assert blocked == ['joint_3'] and fraction == pytest.approx(0.0, abs=1e-6) - assert joints['joint_3'] == pytest.approx(LIMITS['joint_3'][1], abs=1e-6) + assert blocked == ['joint_4'] and fraction == pytest.approx(0.0, abs=1e-6) + assert joints['joint_4'] == pytest.approx(LIMITS['joint_4'][0], abs=1e-6) assert arm.forward(joints)[0] == pytest.approx(arm.forward(DOWN)[0], abs=1e-9) @@ -204,17 +205,17 @@ def test_other_arm_layouts_are_rejected(change): def test_joint_limits_match_the_model_and_allow_only_explicit_missing_placeholders(): assert joint_limits(URDF, ['joint_1', 'joint_2']) == { 'joint_1': (-3.141593, 3.141593), - 'joint_2': (-1.570796, 1.570796)} + 'joint_2': (-2.356194, 2.356194)} assert joint_limits(URDF, ['tool_grip'], required=False) == {} with pytest.raises(ValueError, match='tool_grip'): joint_limits(URDF, ['tool_grip']) @pytest.mark.parametrize('bad', [ - URDF.replace('lower="-1.570796"', 'lower="nan"', 1), - URDF.replace('upper="1.570796"', 'upper="inf"', 1), - URDF.replace('upper="1.570796"', 'upper="-2"', 1), - URDF.replace('lower="-1.570796" ', '', 1), + URDF.replace('lower="-2.356194"', 'lower="nan"', 1), + URDF.replace('upper="2.356194"', 'upper="inf"', 1), + URDF.replace('upper="2.356194"', 'upper="-3"', 1), + URDF.replace('lower="-2.356194" ', '', 1), URDF.replace('', ''), ]) def test_invalid_or_duplicate_urdf_joint_bounds_are_rejected(bad): diff --git a/waybionic_teleop/test/test_sim_arm_drives_node.py b/waybionic_teleop/test/test_sim_arm_drives_node.py index 23b9bf8a..f6adc624 100644 --- a/waybionic_teleop/test/test_sim_arm_drives_node.py +++ b/waybionic_teleop/test/test_sim_arm_drives_node.py @@ -145,7 +145,7 @@ def test_malformed_commands_stop_all_drives_instead_of_partially_updating(node, @pytest.mark.parametrize('bad', [ - URDF.replace('upper="1.570796"', 'upper="nan"', 1), + URDF.replace('upper="2.356194"', 'upper="nan"', 1), URDF.replace('name="joint_2" type="revolute"', 'name="other" type="revolute"', 1), ]) def test_invalid_or_missing_model_limit_requires_repair_and_new_enable(node, bad): @@ -531,7 +531,7 @@ def test_a_cartesian_tilt_into_a_joint_limit_keeps_the_drives_enabled(node, para teleop.group = [group.name for group in teleop.groups].index('cartesian') tilt_up = [int(name == 'dpad_right') for name in BUTTONS] at_limit = 0 - for _ in range(600): + for _ in range(1500): teleop.update([0.0] * len(AXES), tilt_up, {}, node.period) targets = teleop.command_targets node.on_enabled(Bool(data=True)) @@ -539,13 +539,13 @@ def test_a_cartesian_tilt_into_a_joint_limit_keeps_the_drives_enabled(node, para velocity=[teleop.velocities[joint] for joint in targets])) advance(node) assert node.authorized, node.stop_reason - at_limit += 'joint_3' in teleop.blocked + at_limit += 'joint_4' in teleop.blocked if at_limit == 20: break else: - pytest.fail('the Cartesian tilt never reached the joint_3 limit') + pytest.fail('the Cartesian tilt never reached the joint_4 limit') assert node.rejected == 0 - assert node.commanded['joint_3'] == pytest.approx(node.limits['joint_3'][1], abs=1e-9) + assert node.commanded['joint_4'] == pytest.approx(node.limits['joint_4'][0], abs=1e-9) @pytest.mark.parametrize('module, class_name', SHUTDOWN_NODES) diff --git a/waybionic_teleop/test/test_teleop_node.py b/waybionic_teleop/test/test_teleop_node.py index 87e85f69..221186fb 100644 --- a/waybionic_teleop/test/test_teleop_node.py +++ b/waybionic_teleop/test/test_teleop_node.py @@ -1,6 +1,7 @@ """The teleop node stays off for an arm whose description has no collision boxes.""" from pathlib import Path +import re import pytest import rclpy @@ -36,10 +37,11 @@ def node(context, parameters): def without_box(link): - """Return the arm description with one link's collision box taken out.""" - start = URDF.index('', URDF.index(f'')) - end = URDF.index('', start) + len('') - return URDF[:start] + URDF[end:] + """Return the arm description with one link's collision boxes taken out.""" + start = URDF.index(f'') + end = URDF.index('', start) + return URDF[:start] + re.sub(r'', '', URDF[start:end], + flags=re.S) + URDF[end:] def test_the_arm_description_starts_teleop_with_its_collision_checks(node): diff --git a/waybionic_teleop/test/test_xbox_teleop_node.py b/waybionic_teleop/test/test_xbox_teleop_node.py index 36f1b384..523775e2 100644 --- a/waybionic_teleop/test/test_xbox_teleop_node.py +++ b/waybionic_teleop/test/test_xbox_teleop_node.py @@ -168,7 +168,7 @@ def test_stale_joint_feedback_cannot_be_used_to_enable(node): def test_bad_description_and_mismatched_joint_map_fail_closed(node): - node.load(String(data=URDF.replace('upper="1.570796"', 'upper="nan"', 1))) + node.load(String(data=URDF.replace('upper="2.356194"', 'upper="nan"', 1))) assert node.teleop is None and 'invalid limits' in node.problem node.config.groups[2].joints.reverse() node.load(String(data=URDF)) @@ -177,9 +177,10 @@ def test_bad_description_and_mismatched_joint_map_fail_closed(node): @pytest.mark.parametrize('change', [ {'rate_hz': 0.0}, {'input_timeout_s': 0.0}, {'input_timeout_s': -0.5}, - {'input_timeout_s': math.inf}, + {'input_timeout_s': math.inf}, {'table_height': math.nan}, {'collision_clearance': -0.01}, + {'self_collision_clearance': -0.001}, {'self_collision_clearance': math.inf}, ]) -def test_the_rate_and_input_timeout_must_be_positive(monkeypatch, parameters, change): +def test_the_rate_timeout_and_collision_settings_must_be_valid(monkeypatch, parameters, change): monkeypatch.setenv('ROS_AUTOMATIC_DISCOVERY_RANGE', 'OFF') context = rclpy.Context() rclpy.init(context=context) diff --git a/waybionic_teleop/waybionic_teleop/collision.py b/waybionic_teleop/waybionic_teleop/collision.py index fb4873f7..e138ca0d 100644 --- a/waybionic_teleop/waybionic_teleop/collision.py +++ b/waybionic_teleop/waybionic_teleop/collision.py @@ -1,10 +1,12 @@ """ Keep the arm's links off the table and out of its own base (pure logic, no ROS). -Each link's collision boxes come from the URDF, and every check happens in the base frame. -The moving links must stay above the table, and the forearm, wrist and tool must stay out of -the base and shoulder, the parts they can fold into. Adjacent links overlap at their joints, -so those pairs are never compared. +Each link's collision boxes come from the URDF (one per CAD part), and every check happens +in the base frame. The moving links must stay above the table, and the forearm, wrist and tool +must stay out of the base and shoulder, the parts they can fold into. Adjacent links overlap +at their joints, so those pairs are never compared; the joint limits keep them apart. Where +the URDF has a fold table for a pair (waybionic_fold, measured from the CAD), the table replaces +the boxes for it: the elbow may fold until the forearm is about to touch the shoulder. """ import math @@ -52,15 +54,52 @@ def _rpy(roll, pitch, yaw): _rotation((0.0, 1.0, 0.0), pitch), _rotation((1.0, 0.0, 0.0), roll))) +class Fold: + """Limits of one joint against another joint's angle, linearly interpolated.""" + + def __init__(self, element, boxes, joints): + self.link, self.obstacle = element.get('link'), element.get('obstacle') + self.joint, self.across = element.get('joint'), element.get('across') + try: + self.start, self.step = float(element.get('start')), float(element.get('step')) + self.upper = [math.radians(float(v)) for v in element.get('upper').split()] + self.lower = [math.radians(float(v)) for v in element.get('lower').split()] + except (AttributeError, TypeError, ValueError): + raise ValueError('waybionic_fold needs numeric start, step, upper and lower') from None + if not (math.isfinite(self.start) and math.isfinite(self.step) and self.step > 0.0 + and len(self.upper) == len(self.lower) >= 2 + and all(math.isfinite(value) for value in self.upper + self.lower)): + raise ValueError('waybionic_fold needs finite values, a positive step and matching ' + 'tables') + if self.link not in boxes or not {self.joint, self.across} <= joints: + raise ValueError('waybionic_fold refers to an unknown joint or link') + + def limits(self, across): + """Return (lower, upper) in radians at this angle of the other joint.""" + x = (math.degrees(across) - self.start) / self.step + index = min(max(int(math.floor(x)), 0), len(self.upper) - 2) + t = min(max(x - index, 0.0), 1.0) + return tuple(table[index] + t * (table[index + 1] - table[index]) + for table in (self.lower, self.upper)) + + def excess(self, positions): + """How far past the table the joint is, in radians, or 0.""" + lower, upper = self.limits(positions.get(self.across, 0.0)) + angle = positions.get(self.joint, 0.0) + return max(angle - upper, lower - angle, 0.0) + + class ArmCollision: """Collision boxes and joint tree read from a URDF.""" - def __init__(self, boxes, joints, root, table_z=0.0, clearance=0.01): + def __init__(self, boxes, joints, root, table_z=0.0, clearance=0.01, self_clearance=0.002, + folds=()): self.boxes, self.joints, self.root = boxes, joints, root - self.table_z, self.clearance = table_z, clearance + self.table_z, self.clearance, self.self_clearance = table_z, clearance, self_clearance + self.folds = {(fold.link, fold.obstacle): fold for fold in folds} @classmethod - def from_urdf(cls, urdf, table_z=0.0, clearance=0.01): + def from_urdf(cls, urdf, table_z=0.0, clearance=0.01, self_clearance=0.002): """Read boxes and joints; raise ValueError without boxes for the base and folding links.""" try: robot = ET.fromstring(urdf) @@ -96,7 +135,9 @@ def from_urdf(cls, urdf, table_z=0.0, clearance=0.01): if link.get('name') not in children] if len(roots) != 1: raise ValueError(f'robot_description needs one root link, not {len(roots)}') - checker = cls(boxes, joints, roots[0], table_z, clearance) + names = {joint['name'] for joint in joints.values()} + folds = [Fold(element, boxes, names) for element in robot.findall('waybionic_fold')] + checker = cls(boxes, joints, roots[0], table_z, clearance, self_clearance, folds) checker.poses({}) return checker @@ -140,8 +181,9 @@ def check(self, positions): Return {collision: intrusion}: each contact, and how far into it the arm reaches. Against the table that is the depth in m. Inside the base or shoulder it is the volume - in m^3 of the link's box within the obstacle's box grown by the clearance, which, unlike - a depth, grows whichever way the link pushes further in. + in m^3 of the link's boxes within the obstacle's boxes grown by the self-collision + clearance, which, unlike a depth, grows whichever way the link pushes further in. Past + a fold table it is the angle in radians beyond the table. """ poses = self.poses(positions) found = {} @@ -152,17 +194,31 @@ def check(self, positions): for center, axes, half in self.world_boxes(poses, link)) if lowest < self.table_z + self.clearance: found[f'{link}: table'] = self.table_z + self.clearance - lowest + world = {link: [(box, math.sqrt(_dot(box[2], box[2]))) + for box in self.world_boxes(poses, link)] for link in BODY + FOLDING} for link in FOLDING: for body in BODY: - volume = sum(_intrusion(box, obstacle, self.clearance) - for box in self.world_boxes(poses, link) - for obstacle in self.world_boxes(poses, body) - if _overlap(box, obstacle, self.clearance) > 0.0) + fold = self.folds.get((link, body)) + if fold is not None: + excess = fold.excess(positions) + if excess > 0.0: + found[f'{link}: {body}'] = excess + continue + volume = sum(_intrusion(box, obstacle, self.self_clearance) + for box, radius in world[link] for obstacle, reach in world[body] + # Boxes whose bounding spheres are apart cannot overlap. + if _squared_distance(box[0], obstacle[0]) + < (radius + reach + self.self_clearance) ** 2 + and _overlap(box, obstacle, self.self_clearance) > 0.0) if volume > 0.0: found[f'{link}: {body}'] = volume return found +def _squared_distance(a, b): + return sum((x - y) ** 2 for x, y in zip(a, b)) + + def _intrusion(a, b, margin): """Return the volume of box a inside box b grown by margin on every side.""" (center_a, axes_a, half_a), (center_b, axes_b, half_b) = a, b diff --git a/waybionic_teleop/waybionic_teleop/xbox_teleop_node.py b/waybionic_teleop/waybionic_teleop/xbox_teleop_node.py index 1d71cf3c..4252eda9 100644 --- a/waybionic_teleop/waybionic_teleop/xbox_teleop_node.py +++ b/waybionic_teleop/waybionic_teleop/xbox_teleop_node.py @@ -67,6 +67,11 @@ def __init__(self, **kwargs): self.base_frame = params['base_frame'] self.table_height = float(params.get('table_height', 0.0)) self.clearance = float(params.get('collision_clearance', 0.01)) + self.self_clearance = float(params.get('self_collision_clearance', 0.002)) + if not (math.isfinite(self.table_height) and 0 <= self.clearance < math.inf + and 0 <= self.self_clearance < math.inf): + raise ValueError('table_height must be finite, and collision_clearance and ' + 'self_collision_clearance zero or more and finite') self.teleop = None self.problem = 'Waiting for robot_description' self.joy = None @@ -115,7 +120,8 @@ def load(self, message): # The collision boxes are the only thing keeping the arm off the table and out of # its own base, so a description without them leaves teleop off rather than # running it unprotected. - collision = ArmCollision.from_urdf(message.data, self.table_height, self.clearance) + collision = ArmCollision.from_urdf(message.data, self.table_height, self.clearance, + self.self_clearance) except ValueError as error: self.teleop, self.problem = None, str(error) self.get_logger().error(f'Teleop disabled: {error}') From 661b236cb52a744ea130a3068bd4e86c80b10484 Mon Sep 17 00:00:00 2001 From: yassinsolim Date: Sat, 10 Oct 2026 19:50:08 -0600 Subject: [PATCH 02/12] Run the teleop tests over the URDF's joint limits The teleop, demo, incision and straight-cut tests read the joint limits from the URDF instead of assuming the old 90 degree ones, and the demo test runs with the collision checks on, as the teleop node does. Tilting the tool up about its tip now stops at the wrist pitch limit rather than the elbow's. --- waybionic_teleop/test/test_demo_script.py | 10 +++++----- waybionic_teleop/test/test_incision.py | 8 +++----- waybionic_teleop/test/test_straight_cut.py | 10 ++++------ waybionic_teleop/test/test_teleop.py | 12 +++++------- 4 files changed, 17 insertions(+), 23 deletions(-) diff --git a/waybionic_teleop/test/test_demo_script.py b/waybionic_teleop/test/test_demo_script.py index 68c9aded..d47591f1 100644 --- a/waybionic_teleop/test/test_demo_script.py +++ b/waybionic_teleop/test/test_demo_script.py @@ -5,16 +5,15 @@ import pytest +from waybionic_teleop.collision import ArmCollision from waybionic_teleop.demo_script import ( CARTESIAN, DemoPlayer, LINES, operator_active, TeleopState) -from waybionic_teleop.kinematics import ArmKinematics +from waybionic_teleop.kinematics import ArmKinematics, joint_limits from waybionic_teleop.teleop import ArmTeleop, config_from_parameters URDF = (Path(__file__).resolve().parents[2] / 'waybionic_description' / 'urdf' / 'waybionic_arm.urdf').read_text(encoding='utf-8') -LIMITS = {'joint_1': (-math.pi, math.pi), 'joint_2': (-1.5708, 1.5708), - 'joint_3': (-1.5708, 1.5708), 'joint_4': (-1.5708, 1.5708), - 'joint_5': (-1.5708, 1.5708)} +LIMITS = joint_limits(URDF, ['joint_1', 'joint_2', 'joint_3', 'joint_4', 'joint_5']) RATE = 120.0 # The teleop node's input timeout and how often it reports its state. INPUT_TIMEOUT_S = 0.5 @@ -57,8 +56,9 @@ def play(teleop, kinematics, measured, seconds): def make_teleop(parameters): def make(**state): kinematics = ArmKinematics.from_urdf(URDF) + # Like the teleop node, with the collision checks on. teleop = ArmTeleop(config_from_parameters(parameters('xbox_teleop.yaml', 'xbox_teleop')), - LIMITS, kinematics) + LIMITS, kinematics, ArmCollision.from_urdf(URDF)) for name, value in state.items(): setattr(teleop, name, value) return teleop, kinematics diff --git a/waybionic_teleop/test/test_incision.py b/waybionic_teleop/test/test_incision.py index 809d745a..40a493e4 100644 --- a/waybionic_teleop/test/test_incision.py +++ b/waybionic_teleop/test/test_incision.py @@ -10,17 +10,15 @@ from waybionic_teleop.kinematics import ArmKinematics, joint_limits from waybionic_teleop.teleop import ArmTeleop, config_from_parameters -LIMITS = {'joint_1': (-math.pi, math.pi), 'joint_2': (-1.5708, 1.5708), - 'joint_3': (-1.5708, 1.5708), 'joint_4': (-1.5708, 1.5708), - 'joint_5': (-1.5708, 1.5708)} +URDF = (Path(__file__).resolve().parents[2] / 'waybionic_description' / 'urdf' + / 'waybionic_arm.urdf').read_text(encoding='utf-8') +LIMITS = joint_limits(URDF, ['joint_1', 'joint_2', 'joint_3', 'joint_4', 'joint_5']) # The tool leaning forward and down, about 45 degrees from vertical. LEANING = {'joint_1': 0.3, 'joint_2': 0.4, 'joint_3': 1.2, 'joint_4': 0.8, 'joint_5': 0.0, 'tool_grip': 0.0} # The tool leaning forward and down, its tip about 60 mm above the table. NEAR_TABLE = {'joint_1': 0.2, 'joint_2': 0.87, 'joint_3': 1.5, 'joint_4': -0.17, 'joint_5': 0.0, 'tool_grip': 0.0} -URDF = (Path(__file__).resolve().parents[2] / 'waybionic_description' / 'urdf' - / 'waybionic_arm.urdf').read_text(encoding='utf-8') DT = 1.0 / 120.0 diff --git a/waybionic_teleop/test/test_straight_cut.py b/waybionic_teleop/test/test_straight_cut.py index f445e501..782e6e88 100644 --- a/waybionic_teleop/test/test_straight_cut.py +++ b/waybionic_teleop/test/test_straight_cut.py @@ -7,15 +7,13 @@ from waybionic_teleop import drive_map, mks_can from waybionic_teleop.gamepad import AXES, BUTTONS -from waybionic_teleop.kinematics import ArmKinematics +from waybionic_teleop.kinematics import ArmKinematics, joint_limits from waybionic_teleop.sim_drives import SimulatedServo from waybionic_teleop.teleop import ArmTeleop, config_from_parameters URDF = (Path(__file__).resolve().parents[2] / 'waybionic_description' / 'urdf' / 'waybionic_arm.urdf').read_text(encoding='utf-8') -LIMITS = {'joint_1': (-math.pi, math.pi), 'joint_2': (-1.5708, 1.5708), - 'joint_3': (-1.5708, 1.5708), 'joint_4': (-1.5708, 1.5708), - 'joint_5': (-1.5708, 1.5708)} +LIMITS = joint_limits(URDF, ['joint_1', 'joint_2', 'joint_3', 'joint_4', 'joint_5']) DOWN = {'joint_1': 0.1, 'joint_2': 0.5, 'joint_3': 1.4, 'joint_4': math.pi - 1.9, 'joint_5': 0.0, 'tool_grip': 0.0} SUBSTEPS = 10 @@ -158,7 +156,7 @@ def test_cartesian_next_setpoint_stays_at_the_tip_when_tilt_hits_a_limit(drives, teleop.group = 2 mapping = arm_map(drives, 30.0) period = 1.0 / drives['rate_hz'] - for _ in range(350): + for _ in range(1100): teleop.update(*sample('dpad_right'), DOWN, period) tip, _ = arm.forward(teleop.targets) ahead, _ = arm.forward(teleop.command_targets) @@ -168,7 +166,7 @@ def test_cartesian_next_setpoint_stays_at_the_tip_when_tilt_hits_a_limit(drives, moves = mapping.synchronized(teleop.command_targets, mapping.to_counts(teleop.targets), period, drives['max_rpm']) assert [axis for axis, rpm in moves] == mapping.to_counts(teleop.command_targets) - if 'joint_3' in teleop.blocked: + if 'joint_4' in teleop.blocked: break else: pytest.fail('the Cartesian tilt never reached its joint limit') diff --git a/waybionic_teleop/test/test_teleop.py b/waybionic_teleop/test/test_teleop.py index 9c3dc252..efbfac07 100644 --- a/waybionic_teleop/test/test_teleop.py +++ b/waybionic_teleop/test/test_teleop.py @@ -6,17 +6,15 @@ import pytest from waybionic_teleop.gamepad import AXES, BUTTONS -from waybionic_teleop.kinematics import ArmKinematics +from waybionic_teleop.kinematics import ArmKinematics, joint_limits from waybionic_teleop.teleop import ArmTeleop, config_from_parameters -LIMITS = {'joint_1': (-math.pi, math.pi), 'joint_2': (-1.5708, 1.5708), - 'joint_3': (-1.5708, 1.5708), 'joint_4': (-1.5708, 1.5708), - 'joint_5': (-1.5708, 1.5708)} +URDF = (Path(__file__).resolve().parents[2] / 'waybionic_description' / 'urdf' + / 'waybionic_arm.urdf').read_text(encoding='utf-8') +LIMITS = joint_limits(URDF, ['joint_1', 'joint_2', 'joint_3', 'joint_4', 'joint_5']) HOME = dict.fromkeys([*LIMITS, 'tool_grip'], 0.0) # Tool pointing straight down in front of the base, where straight cuts start. DOWN = {**HOME, 'joint_1': 0.1, 'joint_2': 0.5, 'joint_3': 1.4, 'joint_4': math.pi - 1.9} -URDF = (Path(__file__).resolve().parents[2] / 'waybionic_description' / 'urdf' - / 'waybionic_arm.urdf').read_text(encoding='utf-8') DT = 0.02 @@ -139,7 +137,7 @@ def test_b_stop_needs_a_fresh_start_with_centered_sticks_to_rearm(teleop): def test_joint_limits_stop_motion_and_are_reported(teleop): press(teleop, 'start') run(teleop, 6.0, left_y=1.0) - assert teleop.targets['joint_2'] == pytest.approx(1.5708) + assert teleop.targets['joint_2'] == pytest.approx(LIMITS['joint_2'][1]) assert teleop.blocked == ['joint_2'] From 02f95f8e2c74fed818c186fea9123b2a4416495f Mon Sep 17 00:00:00 2001 From: yassinsolim Date: Sun, 11 Oct 2026 02:24:51 -0600 Subject: [PATCH 03/12] Stop the arm where its CAD parts meet the base The forearm now folds over the round base by a table of elbow limits measured from the CAD at any yaw (joint_clearance.py, 2.5 degree steps), as it already did against the shoulder. The build script gives a part that is round about a joint axis a cylinder, and a part round on one side, such as the wrist's differential housing, a cylinder with a box for the rest, so the shapes fit those parts however the joints turn. The collision check counts a cylinder as a 32-sided prism turned to face the other shape, so spinning a round part about its own axis cannot change a contact. --- BuildInstructions.md | 24 +- scripts/cad/build_arm_description.py | 252 +++++++++++++----- scripts/cad/joint_clearance.py | 107 +++++--- .../test/test_arm_description.py | 118 ++++++-- waybionic_description/urdf/waybionic_arm.urdf | 168 +++++++----- waybionic_teleop/config/xbox_teleop.yaml | 2 +- waybionic_teleop/test/test_collision.py | 138 +++++++--- waybionic_teleop/test/test_incision.py | 2 +- .../waybionic_teleop/collision.py | 205 ++++++++++---- .../waybionic_teleop/xbox_teleop_node.py | 2 +- 10 files changed, 727 insertions(+), 291 deletions(-) diff --git a/BuildInstructions.md b/BuildInstructions.md index 489a0309..cc5e5689 100644 --- a/BuildInstructions.md +++ b/BuildInstructions.md @@ -417,11 +417,14 @@ identities, wiring, zeroing and electrical safety still need hardware verificati Every group stops a move before any part of the arm comes within 10 mm of the table or within 2 mm of the arm's own base and shoulder. The checks use a box -around each CAD part, which you can see by ticking **Collision Enabled** on RViz's -RobotModel display. Boxes are too coarse where the forearm folds back against the -shoulder, so there the elbow follows a table of its limits against the shoulder -angle, measured from the CAD 1 degree before the parts touch (`waybionic_fold` in -the URDF). +around each CAD part, or a cylinder where a part, or one side of it, is round +about a joint axis, such as the base's lid, the tool mount and the lower half of +the wrist's housing, so they fit those parts however the joints turn. You can see +them by ticking **Collision Enabled** on RViz's RobotModel display. They are too +coarse where the forearm folds against the shoulder or the base, so there the elbow +follows tables of its limits against the shoulder angle, measured from the CAD +1 degree before the parts touch (`waybionic_fold` in the URDF); the base's table +holds at every yaw. The tool's box is a placeholder around the RViz jaws, which reach 30 mm past `tool_link`, until the real tool is modelled; a longer tool needs a longer box. When a move stops, the diagnostics panel names the part, for example @@ -429,12 +432,13 @@ When a move stops, the diagnostics panel names the part, for example `table_height` in `waybionic_teleop/config/xbox_teleop.yaml` to the table's height above the bottom of the base. `collision_clearance` in the same file sets the 10 mm margin to the table, and `self_collision_clearance` the 2 mm margin to the base and -shoulder. If the arm is already touching something, the only moves still allowed are -the ones that back out of it: a move that presses any contact further in is -refused, even if it would ease another contact at the same time. +shoulder; the forearm's tables keep their 1 degree instead. If the arm is already +touching something, the only moves still allowed are the ones that back out of it: +a move that presses any contact further in is refused, even if it would ease +another contact at the same time. -The boxes are what makes any of this work. A `robot_description` without a -collision box for the base, shoulder, upper arm, forearm, wrist, wrist roll or tool +The collision shapes are what make any of this work. A `robot_description` without +collision shapes for the base, shoulder, upper arm, forearm, wrist, wrist roll or tool leaves teleop disabled, and the diagnostics panel names the missing links. A description reload while teleop is enabled disables teleop and holds the arm where it is, and the drives stop on any `robot_description` change, so Start has to be diff --git a/scripts/cad/build_arm_description.py b/scripts/cad/build_arm_description.py index f2dd9b56..45b7ef6e 100644 --- a/scripts/cad/build_arm_description.py +++ b/scripts/cad/build_arm_description.py @@ -20,7 +20,11 @@ Joint axes come from the named mates below. Joint zero is the upright pose used by the mechanical team's fk.py (links along +Z, pitch about +Y); the saved CAD pose is reported as joint values. Each part gets its own collision box, so the -teleop collision checks follow the parts rather than one box per link. +teleop collision checks follow the parts rather than one box per link. A part +that is round about a joint axis through its link, such as the base's lid or the +tool mount on the wrist roll, gets a cylinder instead, which fits it equally well +however the joint turns. So does a part's round side beyond a joint axis, such as +the lower half of the wrist's differential housing, with a box for the rest. """ import argparse @@ -69,23 +73,48 @@ ('joint_5', 'wrist_pitch_link', 'wrist_roll_link', 'Concentric143', None, 'straight bevel pinion_iso-3', (-180.0, 180.0)), ) -# How far the elbow folds before the forearm meets the shoulder depends on the shoulder angle: -# shoulder angles from START in steps of STEP degrees, then the elbow's upper and lower limits -# there, 1 degree short of contact (scripts/cad/joint_clearance.py). The collision boxes are -# too coarse for this pair, so the teleop collision check reads this table instead. -ELBOW_FOLD = ( - -135.0, 5.0, - (147.3, 147.4, 147.4, 147.5, 147.6, 147.6, 147.6, 147.6, 147.6, 147.7, 147.7, 147.7, 147.7, - 147.7, 147.7, 147.7, 147.7, 147.7, 147.7, 147.7, 147.7, 147.7, 147.7, 147.6, 147.6, 147.6, - 147.6, 147.5, 147.5, 147.4, 147.4, 147.3, 147.2, 147.1, 147.0, 146.3, 144.8, 143.3, 141.6, - 139.9, 138.1, 136.4, 134.7, 133.1, 131.7, 130.2, 128.9, 127.6, 126.5, 125.6, 124.8, 124.3, - 121.9, 121.9, 122.6), - (-122.7, -121.9, -121.8, -124.3, -124.8, -125.6, -126.5, -127.6, -128.8, -130.1, -131.6, - -133.2, -134.7, -136.4, -138.1, -139.8, -141.6, -143.3, -144.8, -146.3, -147.0, -147.1, - -147.2, -147.3, -147.4, -147.4, -147.5, -147.5, -147.5, -147.6, -147.6, -147.6, -147.6, - -147.6, -147.7, -147.7, -147.7, -147.7, -147.7, -147.7, -147.7, -147.7, -147.7, -147.7, - -147.7, -147.6, -147.6, -147.6, -147.6, -147.6, -147.5, -147.5, -147.5, -147.4, -147.3), -) +# How far the elbow folds before the forearm meets the shoulder, or the base at any yaw, depends +# on the shoulder angle: for each, shoulder angles from START in steps of STEP degrees, then the +# elbow's upper and lower limits there, 1 degree short of contact +# (scripts/cad/joint_clearance.py). The collision shapes are too coarse for these pairs, so the +# teleop collision check reads these tables instead. +ELBOW_FOLDS = { + 'shoulder_link': ( + -135.0, 5.0, + (147.3, 147.4, 147.4, 147.5, 147.6, 147.6, 147.6, 147.6, 147.6, 147.7, 147.7, 147.7, 147.7, + 147.7, 147.7, 147.7, 147.7, 147.7, 147.7, 147.7, 147.7, 147.7, 147.7, 147.6, 147.6, 147.6, + 147.6, 147.5, 147.5, 147.4, 147.4, 147.3, 147.2, 147.1, 147.0, 146.3, 144.8, 143.3, 141.6, + 139.9, 138.1, 136.4, 134.7, 133.1, 131.7, 130.2, 128.9, 127.6, 126.5, 125.6, 124.8, 124.3, + 121.9, 121.9, 122.6), + (-122.7, -121.9, -121.8, -124.3, -124.8, -125.6, -126.5, -127.6, -128.8, -130.1, -131.6, + -133.2, -134.7, -136.4, -138.1, -139.8, -141.6, -143.3, -144.8, -146.3, -147.0, -147.1, + -147.2, -147.3, -147.4, -147.4, -147.5, -147.5, -147.5, -147.6, -147.6, -147.6, -147.6, + -147.6, -147.7, -147.7, -147.7, -147.7, -147.7, -147.7, -147.7, -147.7, -147.7, -147.7, + -147.7, -147.6, -147.6, -147.6, -147.6, -147.6, -147.5, -147.5, -147.5, -147.4, -147.3), + ), + 'base_link': ( + -135.0, 2.5, + (172.7, 176.0, 178.5, 180.0, 180.0, 180.0, 180.0, 180.0, 180.0, 180.0, 180.0, 180.0, 180.0, + 180.0, 180.0, 180.0, 180.0, 180.0, 180.0, 180.0, 180.0, 180.0, 180.0, 180.0, 180.0, 180.0, + 180.0, 180.0, 180.0, 180.0, 180.0, 180.0, 180.0, 178.7, 178.1, 177.4, 176.5, 175.5, 174.6, + 173.6, 172.7, 171.8, 170.8, 169.9, 168.8, 167.8, 166.9, 165.9, 164.9, 164.0, 163.0, 162.0, + 161.1, 160.1, 159.1, 158.1, 156.7, 155.3, 154.3, 152.0, 149.6, 147.4, 145.4, 143.4, 141.6, + 139.9, 138.2, 136.6, 135.0, 133.5, 132.0, 130.5, 128.9, 127.5, 125.9, 124.3, 121.7, 120.1, + 118.4, 116.8, 115.0, 113.2, 111.3, 109.3, 107.2, 105.1, 103.0, 100.9, 98.8, 96.5, 95.9, + 93.7, 91.2, 88.8, 86.2, 83.5, 80.8, 77.9, 74.9, 71.7, 68.3, 64.0, 59.4, 54.3, 49.1, 43.9, + 35.8, 24.6, 9.9), + (-9.9, -24.5, -35.8, -43.8, -49.1, -54.3, -59.4, -64.0, -68.3, -71.7, -74.9, -77.9, -80.8, + -83.5, -86.2, -88.8, -91.2, -93.6, -95.9, -96.5, -98.8, -100.9, -103.0, -105.1, -107.3, + -109.3, -111.3, -113.2, -115.0, -116.8, -118.4, -120.1, -121.7, -124.3, -125.9, -127.4, + -128.9, -130.5, -132.0, -133.5, -135.0, -136.6, -138.2, -139.9, -141.6, -143.4, -145.4, + -147.4, -149.6, -152.1, -154.3, -155.3, -156.7, -158.1, -159.1, -160.1, -161.0, -162.0, + -163.0, -164.0, -164.9, -165.9, -166.9, -167.9, -168.8, -169.8, -170.7, -171.8, -172.7, + -173.6, -174.6, -175.5, -176.5, -177.4, -178.1, -178.8, -180.0, -180.0, -180.0, -180.0, + -180.0, -180.0, -180.0, -180.0, -180.0, -180.0, -180.0, -180.0, -180.0, -180.0, -180.0, + -180.0, -180.0, -180.0, -180.0, -180.0, -180.0, -180.0, -180.0, -180.0, -180.0, -180.0, + -180.0, -180.0, -180.0, -180.0, -178.5, -176.0, -172.7), + ), +} DESCRIPTIONS = { 'joint_1': 'base yaw', 'joint_2': 'shoulder pitch', 'joint_3': 'elbow pitch', 'joint_4': 'wrist pitch (differential housing)', 'joint_5': 'wrist roll (output bevel)', @@ -98,6 +127,11 @@ # Threaded screws and the enclosed cycloidal discs dominate the triangle count. COARSE_PARTS = ('m3-', 'discs-sweep', 'loose_disc') COARSE_GRID = 0.0012 +# A part, or its side beyond a joint axis, is round about the axis when its circle about it fits +# in the part's box to within this, allowing for the vertex grid and small flats. +ROUND_TOLERANCE = 0.001 +# URDF cylinders run along z; these turn one onto a link's x, y or z axis. +CYLINDER_RPY = ((0.0, math.pi / 2, 0.0), (-math.pi / 2, 0.0, 0.0), (0.0, 0.0, 0.0)) # SolidWorks is Y-up. base_link: X = SolidWorks -Z (arm forward), Y = -X, Z = +Y. SOLIDWORKS_TO_BASE = ((0.0, 0.0, -1.0), (-1.0, 0.0, 0.0), (0.0, 1.0, 0.0)) @@ -494,10 +528,10 @@ def world_frame(self, link): def quantized_link_mesh(model, link, grid): - """Triangles per color in link coordinates, snapped to a grid, and each part's extent.""" + """Triangles per color in link coordinates, snapped to a grid, and each part's triangles.""" export = model.export groups = {} - extents = {} + parts = {} to_link = model.frames[link].inverse() * model.to_base stats = {'input': 0, 'output': 0, 'bodies': 0, 'flipped': 0, 'conflicts': 0} for name in sorted(model.assigned[link]): @@ -554,13 +588,10 @@ def quantized_link_mesh(model, link, grid): length = norm(normals[old]) group['positions'].append(keys[old]) group['normals'].append(scale(normals[old], 1.0 / length) if length > 1e-15 else (0.0, 0.0, 1.0)) - low, high = extents.setdefault(name, (list(keys[old]), list(keys[old]))) - for axis in range(3): - low[axis] = min(low[axis], keys[old][axis]) - high[axis] = max(high[axis], keys[old][axis]) group['triangles'].extend(tuple(remap[k] for k in triangle) for triangle in triangles) + parts.setdefault(name, []).extend(tuple(keys[k] for k in triangle) for triangle in triangles) stats['output'] += len(triangles) - return groups, stats, extents + return groups, stats, parts def write_collada(path, link, groups): @@ -618,29 +649,121 @@ def write_collada(path, link, groups): path.write_text('\n'.join(lines), encoding='utf-8') -def part_boxes(extents): - """Return [(part, centre, size)]: one box per part, leaving out boxes inside another.""" - items = sorted(extents.items()) - - def inside(box, other): - return all(other[0][a] <= box[0][a] and box[1][a] <= other[1][a] for a in range(3)) - - kept = [(name, box) for index, (name, box) in enumerate(items) - if not any(inside(box, other) and (not inside(other, box) or position < index) - for position, (_, other) in enumerate(items) if position != index)] - return [(name, [(a + b) / 2 for a, b in zip(low, high)], [b - a for a, b in zip(low, high)]) - for name, (low, high) in kept] - - -def collision_lines(name, center, size): +def joint_axes(model): + """Return {link: [(point, axis index)]}: the joint axes through each link along its axes.""" + axes = {} + for joint in model.joints: + r, p, y = joint['rpy'] + rotation = matmul(rotation_about((0, 0, 1), y), matmul(rotation_about((0, 1, 0), p), rotation_about((1, 0, 0), r))) + for link, point, direction in ((joint['child'], (0.0, 0.0, 0.0), joint['axis']), + (joint['parent'], joint['xyz'], apply(rotation, joint['axis']))): + index = max(range(3), key=lambda a: abs(direction[a])) + if abs(abs(direction[index]) - 1.0) < 1e-9: + axes.setdefault(link, set()).add((tuple(round(value, 9) for value in point), index)) + return {link: sorted(found) for link, found in axes.items()} + + +def bounds(points): + return [min(p[a] for p in points) for a in range(3)], [max(p[a] for p in points) for a in range(3)] + + +def split(triangles, point, axis, sign, offset): + """Return the triangles' corners on the sign side of the plane across axis, offset back past + point, and the rest; where an edge crosses the plane, the crossing goes in both.""" + beyond, rest = set(), set() + for triangle in triangles: + corners = [(p, sign * (p[axis] - point[axis]) + offset) for p in triangle] + for p, depth in corners: + (beyond if depth > 0.0 else rest).add(p) + for (p, a), (q, b) in zip(corners, corners[1:] + corners[:1]): + if (a > 0.0) != (b > 0.0): + crossing = tuple(x + a / (a - b) * (y - x) for x, y in zip(p, q)) + beyond.add(crossing) + rest.add(crossing) + return list(beyond), list(rest) + + +def part_shapes(parts, axes): + """ + Return [(part, centre, size, radius, axis)] around each part's triangles: a box, with radius + None, or a cylinder along the link's axis-th axis. A part round about a joint axis through + its link, with the circle inside the part's box, gets a cylinder; so does a part's round + side, reaching back past the axis as far as the part still fits the circle, with a box for + the rest. A shape is left out when the corners it holds are inside another shape. + """ + shapes = [] + for name, triangles in sorted(parts.items()): + corners = list({p for triangle in triangles for p in triangle}) + low, high = bounds(corners) + best, rest_volume = [(name, low, high, None, 2, corners)], math.inf + for point, k in axes: + u, v = (a for a in range(3) if a != k) + room = min(point[u] - low[u], high[u] - point[u], point[v] - low[v], high[v] - point[v]) + + def distance(p): + return math.hypot(p[u] - point[u], p[v] - point[v]) + + def fits(found, reach): + return found[0] and max(map(distance, found[0])) <= reach + + for side in (None, (u, 1.0), (u, -1.0), (v, 1.0), (v, -1.0)): + beyond, rest = (corners, []) if side is None else split(triangles, point, *side, 0.0) + if side is not None and fits((beyond, rest), room + ROUND_TOLERANCE): + # Move the plane back past the axis, from corner to corner of the rest, while + # the round side grows by no more than half the tolerance. + reach = min(room + ROUND_TOLERANCE, max(map(distance, beyond)) + ROUND_TOLERANCE / 2) + axis, sign = side + offsets = sorted(offset for offset in {sign * (point[axis] - p[axis]) for p in corners} + if offset > 0.0) + lowest, highest = 0, len(offsets) - 1 + while lowest <= highest: + middle = (lowest + highest) // 2 + found = split(triangles, point, axis, sign, offsets[middle]) + if fits(found, reach): + (beyond, rest), lowest = found, middle + 1 + else: + highest = middle - 1 + if not beyond or (side is not None and not rest): + continue + radius = max(map(distance, beyond)) + volume = math.prod(b - a for a, b in zip(*bounds(rest))) if rest else 0.0 + if radius <= room + ROUND_TOLERANCE and volume < rest_volume: + cylinder_low = [point[a] - radius for a in range(3)] + cylinder_high = [point[a] + radius for a in range(3)] + cylinder_low[k], cylinder_high[k] = min(p[k] for p in beyond), max(p[k] for p in beyond) + best = [(name, cylinder_low, cylinder_high, radius, k, beyond)] + best += [(name, *bounds(rest), None, 2, rest)] if rest else [] + rest_volume = volume + shapes += best + + def holds(shape, p): + _, low, high, radius, k, _ = shape + if not all(low[a] <= p[a] <= high[a] for a in range(3)): + return False + u, v = (a for a in range(3) if a != k) + return radius is None or math.hypot(p[u] - (low[u] + high[u]) / 2, p[v] - (low[v] + high[v]) / 2) <= radius + + # Larger shapes first, so a shape is only left out for one that stays. + kept = set() + for index in sorted(range(len(shapes)), key=lambda i: -math.prod(b - a for a, b in zip(*shapes[i][1:3]))): + if not any(all(holds(shapes[other], p) for p in shapes[index][5]) for other in kept): + kept.add(index) + return [(name, [(a + b) / 2 for a, b in zip(low, high)], [b - a for a, b in zip(low, high)], radius, k) + for index, (name, low, high, radius, k, _) in enumerate(shapes) if index in kept] + + +def collision_lines(name, center, size, radius=None, axis=2): + rpy = CYLINDER_RPY[axis] if radius is not None else (0.0, 0.0, 0.0) + geometry = (f'' if radius is None + else f'') return [ f' ', - f' ', - f' ', + f' ', + f' {geometry}', ' '] -def write_urdf(model, source, boxes): +def write_urdf(model, source, shapes): angles = ', '.join(f'{name}={math.degrees(model.cad_angles[name]):.2f}' for name, *_ in JOINTS) lines = [ '', @@ -648,8 +771,9 @@ def write_urdf(model, source, boxes): ' Do not edit by hand; re-export the SolidWorks assembly and re-run the script.', ' Joint zero is the upright pose from the mechanical fk.py (links along +Z,', f' pitch about +Y). Saved CAD pose in degrees {angles}.', - ' Each pitch joint stops about 1 degree before two parts touch; one collision box', - ' per part. Effort and velocity are placeholders for display. -->', + ' Each pitch joint stops about 1 degree before two parts touch. Each part has a', + ' collision box, or a cylinder where it is round about a joint axis, with a box for', + ' any side of it that is not. Effort and velocity are placeholders for display. -->', ''] for link in LINKS: lines += [ @@ -657,7 +781,7 @@ def write_urdf(model, source, boxes): ' ', f' ', ' ', - *[line for box in boxes[link] for line in collision_lines(*box)], + *[line for shape in shapes[link] for line in collision_lines(*shape)], ' '] lines += [ ' ', @@ -680,26 +804,27 @@ def write_urdf(model, source, boxes): if joint['mimic']: lines.append(f' ') lines.append(' ') - start, step, upper, lower = ELBOW_FOLD shoulder = next(limits for name, *_, limits in JOINTS if name == 'joint_2') - if (len(upper) != len(lower) or start != shoulder[0] - or abs(start + step * (len(upper) - 1) - shoulder[1]) > 1e-6): - raise ValueError('ELBOW_FOLD must span the shoulder limits; re-run joint_clearance.py') + for start, step, upper, lower in ELBOW_FOLDS.values(): + if (len(upper) != len(lower) or start != shoulder[0] + or abs(start + step * (len(upper) - 1) - shoulder[1]) > 1e-6): + raise ValueError('ELBOW_FOLDS must span the shoulder limits; re-run joint_clearance.py') lines += [ ' ', ' ', ' ', f' ', ' ', - ' ', - f' ', - '', - ''] + ' '] + for obstacle, (start, step, upper, lower) in ELBOW_FOLDS.items(): + lines += [ + f' '] + lines += ['', ''] URDF_PATH.write_text('\n'.join(lines), encoding='utf-8') @@ -837,18 +962,19 @@ def main(): MESH_DIRECTORY.mkdir(parents=True, exist_ok=True) total_in = total_out = 0 - boxes = {} + shapes = {} + axes = joint_axes(model) for link in LINKS: - groups, stats, extents = quantized_link_mesh(model, link, arguments.grid) + groups, stats, parts = quantized_link_mesh(model, link, arguments.grid) path = MESH_DIRECTORY / f'{link}.dae' write_collada(path, link, groups) - boxes[link] = part_boxes(extents) + shapes[link] = part_shapes(parts, axes.get(link, [])) total_in += stats['input'] total_out += stats['output'] print(f' {path.name}: {stats["input"]} -> {stats["output"]} triangles, {len(groups)} colors, ' f'{path.stat().st_size / 1e6:.2f} MB, {stats["flipped"]}/{stats["bodies"]} bodies flipped, ' f'{stats["conflicts"]} winding conflicts') - write_urdf(model, source, boxes) + write_urdf(model, source, shapes) print(f'Wrote {URDF_PATH.relative_to(REPOSITORY)} ({total_in} -> {total_out} triangles)') return 0 diff --git a/scripts/cad/joint_clearance.py b/scripts/cad/joint_clearance.py index 87830579..61077772 100644 --- a/scripts/cad/joint_clearance.py +++ b/scripts/cad/joint_clearance.py @@ -3,7 +3,7 @@ python3 scripts/cad/joint_clearance.py build/cad/arm_export.json -After a CAD change, copy the printed limits into JOINTS and ELBOW_FOLD in +After a CAD change, copy the printed limits into JOINTS and ELBOW_FOLDS in build_arm_description.py and rebuild the URDF. This script needs numpy and scipy; the build script does not. @@ -16,9 +16,11 @@ enclosed, and static CAD cannot model their eccentric motion. Base yaw and wrist roll turn round parts in round housings, so cabling sets their range. -How far the elbow folds before the forearm meets the shoulder also depends on -the shoulder angle, so that is tabulated against it. The collision boxes are -too coarse for that pair, and the teleop collision check uses the table. +How far the elbow folds before the forearm meets the shoulder or the base also +depends on the shoulder angle, so that is tabulated against it. The base is +round, so its gap is measured in distance from the yaw axis and height, which +is the gap at the nearest yaw. The collision shapes are too coarse for these +pairs, and the teleop collision check uses the tables. """ import argparse @@ -35,13 +37,18 @@ GROWTH = 0.00025 # m deeper than in the upright pose SEARCH = 0.004 # m NEIGHBOURS = 6 -CONTACT = 0.001 # m between forearm and shoulder samples that counts as touching +CONTACT = 0.001 # m between forearm and shoulder or base samples that counts as touching +FAR = 0.25 # m beyond which a fold's gap is only bounded +SPARSE = 0.004 # m cells of the samples that find a fold's closest region MARGIN = 1.0 # degrees kept clear of contact INTERNAL = ('discs-sweep', 'disc-bearing', 'loose_disc', 'inner_bearing', 'shaft-sweep', 'NEMA23SHAFT', 'outer_ball_bearing', 'outer-ring-bearing', 'bearing_brace', 'updatednema23bearingbrace', 'top-sweep') PITCH_JOINTS = ('joint_2', 'joint_3', 'joint_4') -FOLD = ('forearm_link', 'shoulder_link', 'joint_3', 'joint_2') +# The link that folds, what it folds against, the joint tabulated, the joint across and its step +# in degrees. The base's limit bends sharply near some shoulder angles, so it needs finer steps. +FOLDS = (('forearm_link', 'shoulder_link', 'joint_3', 'joint_2', 5.0), + ('forearm_link', 'base_link', 'joint_3', 'joint_2', 2.5)) spec = importlib.util.spec_from_file_location( 'build_arm_description', Path(__file__).resolve().with_name('build_arm_description.py')) @@ -125,6 +132,11 @@ def cloud(self, link): return np.vstack([points for _, points, _, _ in self.parts[link]]) +def radial(points): + """Distance from the z axis and height, which base yaw leaves unchanged.""" + return np.column_stack((np.hypot(points[:, 0], points[:, 1]), points[:, 2])) + + def inside(point, solids): """True if point is inside a closed body (generalized winding number above one half).""" for tri in solids: @@ -288,18 +300,44 @@ def __init__(self, robot, link, obstacle, joint, across): self.robot, self.link, self.obstacle = robot, link, obstacle self.joint, self.across = joint, across self.points = robot.cloud(link) - self.tree = cKDTree(robot.cloud(obstacle)) + # Base yaw turns the link about the base's z axis: compared in radial(), the gap is the + # one at the nearest yaw. There the base's samples crowd onto its profile, so keep one + # per 0.1 mm cell. + self.any_yaw = obstacle == 'base_link' + cloud = robot.cloud(obstacle) + if self.any_yaw: + cloud = np.unique(np.round(radial(cloud), 4), axis=0) + self.tree = cKDTree(cloud) axis = np.array(robot.joint(joint)['axis']) # No point of the link moves faster than this per radian of the joint. self.reach = float(np.linalg.norm( self.points - np.outer(self.points @ axis, axis), axis=1).max()) + # One sample per SPARSE cell finds the closest region fast. Every sample is within + # self.cover of its sparse representative, so only those near the closest need checking. + cells = np.floor(self.points / SPARSE).astype(np.int64) + self.sparse = self.points[np.unique(cells, axis=0, return_index=True)[1]] + cover, self.representative = cKDTree(self.sparse).query(self.points, workers=-1) + self.cover = float(cover.max()) def distance(self, across, angle): + """The gap, or a lower bound on it when it is beyond FAR.""" poses = self.robot.poses({self.across: across, self.joint: angle}) ro, oo = poses[self.obstacle] rl, ol = poses[self.link] - moved = self.points @ (ro.T @ rl).T + ro.T @ (ol - oo) - return float(self.tree.query(moved, distance_upper_bound=0.25, workers=-1)[0].min()) + turn, shift = ro.T @ rl, ro.T @ (ol - oo) + + def gaps(points): + moved = points @ turn.T + shift + if self.any_yaw: + moved = radial(moved) + return self.tree.query(moved, distance_upper_bound=FAR, workers=-1)[0] + + sparse = gaps(self.sparse) + best = float(sparse.min()) + if best >= FAR: + return FAR - self.cover + near = sparse[self.representative] < best + self.cover + return min(best, float(gaps(self.points[near]).min()), FAR - self.cover) def contact(self, across, sign): """Degrees the joint turns before contact, or None within half a turn.""" @@ -316,8 +354,6 @@ def contact(self, across, sign): def main(): parser = argparse.ArgumentParser(description=__doc__.splitlines()[0]) parser.add_argument('export', type=Path, help='JSON written by export_solidworks_assembly') - parser.add_argument('--fold-step', type=float, default=5.0, - help='shoulder angle step of the elbow fold table in degrees') args = parser.parse_args() robot = Arm(args.export) @@ -336,28 +372,33 @@ def main(): upper, lower = (math.floor(angle - MARGIN) if angle is not None else 180 for angle in found) print(f' limits ({-lower:.1f}, {upper:.1f})') - link, obstacle, joint, across = FOLD - fold = Fold(robot, link, obstacle, joint, across) - low, high = robot.joint(across)['limits'] - print(f'Elbow fold against the shoulder, {MARGIN:.0f} degree short of contact:') - upper, lower = [], [] - for index in range(int(round((high - low) / args.fold_step)) + 1): - shoulder = low + index * args.fold_step - values = [] - for sign in (1, -1): - angle = fold.contact(math.radians(shoulder), sign) - values.append(sign * (math.floor((angle - MARGIN) * 10) / 10 if angle is not None - else 180.0)) - upper.append(values[0]) - lower.append(values[1]) - print(f' {across} {shoulder:+7.1f}: {joint} from {values[1]:+7.1f} to {values[0]:+7.1f}', - flush=True) - print('ELBOW_FOLD = (') - print(f' {low:.1f}, {args.fold_step:.1f},') - for values in (upper, lower): - print(textwrap.fill(', '.join(f'{value:.1f}' for value in values) + '),', width=99, - initial_indent=' (', subsequent_indent=' ')) - print(')') + tables = {} + for link, obstacle, joint, across, step in FOLDS: + fold = Fold(robot, link, obstacle, joint, across) + low, high = robot.joint(across)['limits'] + print(f'Elbow fold against {obstacle}, {MARGIN:.0f} degree short of contact:') + upper, lower = [], [] + for index in range(int(round((high - low) / step)) + 1): + shoulder = low + index * step + values = [] + for sign in (1, -1): + angle = fold.contact(math.radians(shoulder), sign) + values.append(sign * (math.floor((angle - MARGIN) * 10) / 10 if angle is not None + else 180.0)) + upper.append(values[0]) + lower.append(values[1]) + print(f' {across} {shoulder:+7.1f}: {joint} from {values[1]:+7.1f} to ' + f'{values[0]:+7.1f}', flush=True) + tables[obstacle] = (low, step, upper, lower) + print('ELBOW_FOLDS = {') + for obstacle, (low, step, upper, lower) in tables.items(): + print(f" '{obstacle}': (") + print(f' {low:.1f}, {step:.1f},') + for values in (upper, lower): + print(textwrap.fill(', '.join(f'{value:.1f}' for value in values) + '),', width=99, + initial_indent=' (', subsequent_indent=' ')) + print(' ),') + print('}') if __name__ == '__main__': diff --git a/waybionic_description/test/test_arm_description.py b/waybionic_description/test/test_arm_description.py index 20e364df..bea29c2e 100644 --- a/waybionic_description/test/test_arm_description.py +++ b/waybionic_description/test/test_arm_description.py @@ -70,43 +70,103 @@ def test_link_meshes_are_valid_z_up_collada(robot): assert 0 <= min(indices) and max(indices) < vertices -def test_every_mesh_vertex_is_inside_a_collision_box_of_its_link(robot): +def test_every_mesh_vertex_is_inside_a_collision_shape_of_its_link(robot): for link in robot.findall('link'): if link.get('name') == 'tool_link': continue - boxes = [] - for collision in link.findall('collision'): - assert collision.get('name'), link.get('name') - assert collision.find('origin').get('rpy') == '0 0 0' - center = [float(value) for value in collision.find('origin').get('xyz').split()] - size = [float(value) for value in collision.find('geometry/box').get('size').split()] - # Boxes are written to 0.01 mm. - boxes.append([(c - s / 2 - 2e-5, c + s / 2 + 2e-5) for c, s in zip(center, size)]) - assert boxes, link.get('name') + shapes = [collision_shape(collision) for collision in link.findall('collision')] + assert shapes, link.get('name') uri = link.find('visual/geometry/mesh').get('filename') mesh = ET.parse(PACKAGE / uri[len('package://waybionic_description/'):]).getroot() values = [float(value) for value in mesh.find(f'.//{COLLADA}float_array').text.split()] for point in zip(values[0::3], values[1::3], values[2::3]): - assert any(all(low <= p <= high for p, (low, high) in zip(point, box)) - for box in boxes), (link.get('name'), point) - - -def test_elbow_fold_table_covers_the_shoulder_range(robot): + assert any(inside(point, *shape) for shape in shapes), (link.get('name'), point) + + +def collision_shape(collision): + """Return (centre, half sizes, radius, axis); a box has radius and axis None.""" + assert collision.get('name') + center = [float(value) for value in collision.find('origin').get('xyz').split()] + roll, pitch, yaw = (float(value) for value in collision.find('origin').get('rpy').split()) + box = collision.find('geometry/box') + if box is not None: + assert (roll, pitch, yaw) == (0.0, 0.0, 0.0), collision.get('name') + return center, [float(value) / 2 for value in box.get('size').split()], None, None + cylinder = collision.find('geometry/cylinder') + # Where the origin's rotation turns the cylinder's z axis; it must be one of the link's axes. + direction = (math.cos(roll) * math.sin(pitch), -math.sin(roll), + math.cos(roll) * math.cos(pitch)) + axis = max(range(3), key=lambda a: abs(direction[a])) + assert yaw == 0.0, collision.get('name') + assert abs(direction[axis]) == pytest.approx(1.0, abs=1e-6), collision.get('name') + radius = float(cylinder.get('radius')) + half = [radius] * 3 + half[axis] = float(cylinder.get('length')) / 2 + return center, half, radius, axis + + +def inside(point, center, half, radius, axis): + """Check whether point is within the shape, which is written to 0.01 mm.""" + if not all(abs(p - c) <= h + 2e-5 for p, c, h in zip(point, center, half)): + return False + if radius is None: + return True + across = [a for a in range(3) if a != axis] + return math.dist([point[a] for a in across], [center[a] for a in across]) <= radius + 2e-5 + + +def test_round_parts_are_cylinders_about_a_joint_axis(robot): + axes = {} + for joint in robot.findall('joint'): + if joint.find('axis') is None: + continue + assert joint.find('origin').get('rpy') == '0 0 0' + direction = [float(value) for value in joint.find('axis').get('xyz').split()] + axis = max(range(3), key=lambda a: abs(direction[a])) + origin = [float(value) for value in joint.find('origin').get('xyz').split()] + axes.setdefault(joint.find('child').get('link'), []).append(([0.0] * 3, axis)) + axes.setdefault(joint.find('parent').get('link'), []).append((origin, axis)) + cylinders = {} + for link in robot.findall('link'): + for collision in link.findall('collision'): + center, _, radius, axis = collision_shape(collision) + if radius is None: + continue + assert any(axis == along and all(abs(center[a] - point[a]) < 1e-5 + for a in range(3) if a != along) + for point, along in axes[link.get('name')]), collision.get('name') + cylinders[collision.get('name').split('/')[-1]] = (radius, 'xyz'[axis]) + # Yaw turns the arm about the base's z axis and wrist roll the tool mount about its own; the + # wrist's differential housing is round below the pitch axis, its y axis. + assert cylinders['BaseHousingLid-Shahmeen-Aug8-1'] == (pytest.approx(0.1, abs=1e-3), 'z') + assert cylinders['base-housing-Shahmeen-aug1-c-clamp-1'] == (pytest.approx(0.1, abs=1e-3), 'z') + assert cylinders['Bridget - base V6-1'] == (pytest.approx(0.0352, abs=1e-3), 'z') + assert cylinders['DifferentialHousing-1'] == (pytest.approx(0.04, abs=1e-3), 'y') + housing = [collision_shape(collision) for collision + in robot.find("link[@name='wrist_pitch_link']").findall('collision')] + boxes = [(center, half) for center, half, radius, _ in housing if radius is None] + assert len(housing) == 2 and len(boxes) == 1 + # Its top, narrower than the round part, has a box above the pitch axis. + (center, half), = boxes + assert center[2] - half[2] > 0.0 and half[0] < cylinders['DifferentialHousing-1'][0] + + +def test_elbow_fold_tables_cover_the_shoulder_range(robot): joints = {joint.get('name'): joint for joint in robot.findall('joint')} - folds = robot.findall('waybionic_fold') - assert len(folds) == 1 - fold = folds[0] - assert (fold.get('link'), fold.get('obstacle')) == ('forearm_link', 'shoulder_link') - assert joints[fold.get('joint')].find('child').get('link') == 'forearm_link' - shoulder = joints[fold.get('across')].find('limit') - start, step = float(fold.get('start')), float(fold.get('step')) - upper = [float(value) for value in fold.get('upper').split()] - lower = [float(value) for value in fold.get('lower').split()] - assert len(upper) == len(lower) >= 2 and step > 0.0 - assert start == pytest.approx(math.degrees(float(shoulder.get('lower'))), abs=1e-3) - assert start + step * (len(upper) - 1) == pytest.approx( - math.degrees(float(shoulder.get('upper'))), abs=1e-3) - assert all(low < 0.0 < high for low, high in zip(lower, upper)) + folds = {fold.get('obstacle'): fold for fold in robot.findall('waybionic_fold')} + assert sorted(folds) == ['base_link', 'shoulder_link'] + for fold in folds.values(): + assert fold.get('link') == 'forearm_link' + assert joints[fold.get('joint')].find('child').get('link') == 'forearm_link' + shoulder = joints[fold.get('across')].find('limit') + start, step = float(fold.get('start')), float(fold.get('step')) + upper = [float(value) for value in fold.get('upper').split()] + lower = [float(value) for value in fold.get('lower').split()] + assert len(upper) == len(lower) >= 2 and step > 0.0 + assert start == pytest.approx(math.degrees(float(shoulder.get('lower'))), abs=1e-3) + assert start + step * (len(upper) - 1) == pytest.approx( + math.degrees(float(shoulder.get('upper'))), abs=1e-3) + assert all(low < 0.0 < high for low, high in zip(lower, upper)) def test_the_tool_box_encloses_the_placeholder_jaws(robot): diff --git a/waybionic_description/urdf/waybionic_arm.urdf b/waybionic_description/urdf/waybionic_arm.urdf index cd8d6207..c9b7a1e6 100644 --- a/waybionic_description/urdf/waybionic_arm.urdf +++ b/waybionic_description/urdf/waybionic_arm.urdf @@ -3,8 +3,9 @@ Do not edit by hand; re-export the SolidWorks assembly and re-run the script. Joint zero is the upright pose from the mechanical fk.py (links along +Z, pitch about +Y). Saved CAD pose in degrees joint_1=-8.93, joint_2=-8.78, joint_3=45.14, joint_4=5.08, joint_5=0.00. - Each pitch joint stops about 1 degree before two parts touch; one collision box - per part. Effort and velocity are placeholders for display. --> + Each pitch joint stops about 1 degree before two parts touch. Each part has a + collision box, or a cylinder where it is round about a joint axis, with a box for + any side of it that is not. Effort and velocity are placeholders for display. --> @@ -12,11 +13,11 @@ - + - + @@ -28,11 +29,11 @@ - + - + @@ -44,15 +45,15 @@ - + - + - + @@ -60,44 +61,52 @@ - - + + - - + + - - + + + + + + - - + + - - + + - - + + - - + + + + + + - + @@ -109,36 +118,44 @@ - - + + + + + + + + + + - - + + - - + + - - + + - - + + - - + + - - + + @@ -146,12 +163,20 @@ - - + + + + + + + + + + - - + + @@ -166,8 +191,8 @@ - - + + @@ -175,8 +200,12 @@ - - + + + + + + @@ -184,16 +213,20 @@ - - + + + + + + - - + + - - + + @@ -201,16 +234,20 @@ - - + + + + + + - - + + - - + + @@ -219,11 +256,11 @@ - + - - + + @@ -294,10 +331,13 @@ - + + diff --git a/waybionic_teleop/config/xbox_teleop.yaml b/waybionic_teleop/config/xbox_teleop.yaml index 722a1b10..1999528e 100644 --- a/waybionic_teleop/config/xbox_teleop.yaml +++ b/waybionic_teleop/config/xbox_teleop.yaml @@ -57,7 +57,7 @@ xbox_teleop: tool_open_axis: left_trigger tool_frame: tool_link base_frame: base_link - # Moves stop before any part's collision box comes within collision_clearance (m) of the + # Moves stop before any part's collision shape comes within collision_clearance (m) of the # table, table_height (m) above the bottom of the base, or within self_collision_clearance # (m) of the base and shoulder. table_height: 0.0 diff --git a/waybionic_teleop/test/test_collision.py b/waybionic_teleop/test/test_collision.py index 4ef94eb7..562e0a18 100644 --- a/waybionic_teleop/test/test_collision.py +++ b/waybionic_teleop/test/test_collision.py @@ -1,4 +1,4 @@ -"""The arm's collision boxes keep its links off the table and out of its own base.""" +"""The arm's collision shapes keep its links off the table and out of its own base.""" import math from pathlib import Path @@ -6,7 +6,7 @@ import pytest -from waybionic_teleop.collision import _intrusion, _overlap, _rotation, ArmCollision +from waybionic_teleop.collision import _intrusion, _rotation, ArmCollision from waybionic_teleop.gamepad import AXES, BUTTONS from waybionic_teleop.kinematics import ArmKinematics, joint_limits from waybionic_teleop.teleop import ArmTeleop, config_from_parameters @@ -64,6 +64,33 @@ def test_the_fold_limit_follows_the_shoulder_angle(): assert 'forearm_link: shoulder_link' in away.hits(pose(sign * 90, sign * 133, 0)) +@pytest.mark.parametrize('yaw', [0.0, math.radians(45)]) +def test_the_forearm_folds_onto_the_base_until_just_before_its_parts_touch(yaw): + # With the table out of the way, the CAD parts touch at these elbow angles at either yaw. + away = ArmCollision.from_urdf(URDF, table_z=-10.0) + for shoulder, touch in ((45, 130.2), (90, 97.2)): + assert away.hits(pose(shoulder, touch - 1.4, 0, yaw)) == [] + assert 'forearm_link: base_link' in away.hits(pose(shoulder, touch + 0.3, 0, yaw)) + # Folded back to the shoulder's limit, the forearm clears the base with the elbow bent up; + # bent down, it touches the base at -11 degrees. + for elbow in (60, 90, -9.5): + assert away.hits(pose(-135, elbow, 0, yaw)) == [] + assert away.hits(pose(-135, -11.5, 0, yaw)) == ['forearm_link: base_link'] + + +@pytest.mark.parametrize('yaw', [0.0, math.radians(45)]) +def test_the_wrist_and_tool_stop_just_before_their_parts_touch_the_base(yaw): + # With the table out of the way, the CAD parts come within 1 mm of the base at these elbow + # angles at either yaw: the tool mount, the tool and the wrist's differential housing. The + # 2 mm clearance stops the elbow up to 1.3 degrees before them. + away = ArmCollision.from_urdf(URDF, table_z=-10.0) + for shoulder, wrist, touch, link in ((45, 60, 120.5, 'wrist_roll_link'), + (30, 90, 122.85, 'tool_link'), + (60, 45, 118.95, 'wrist_pitch_link')): + assert away.hits(pose(shoulder, touch - 1.3, wrist, yaw)) == [] + assert f'{link}: base_link' in away.hits(pose(shoulder, touch + 0.3, wrist, yaw)) + + @pytest.mark.parametrize('old, new', [ ('across="joint_2"', 'across="joint_9"'), ('start="-135"', 'start="nan"'), ('step="5"', 'step="0"'), ('upper="147.3 ', 'upper="'), ('lower="-122.7', 'lower="inf'), @@ -83,11 +110,11 @@ def test_table_height_and_clearance_are_configurable(): def test_the_base_and_shoulder_have_their_own_smaller_clearance(): - # The elbow bend is between 2 and 10 mm from the base's lid here. - joints = pose(-127, 60, 0, math.radians(5)) + # The tool is between 2 and 10 mm from the base's lid here. + joints = pose(30, 121.5, 90, math.radians(45)) assert ArmCollision.from_urdf(URDF).hits(joints) == [] assert ArmCollision.from_urdf(URDF, self_clearance=0.01).hits(joints) == [ - 'forearm_link: base_link'] + 'tool_link: base_link'] def test_a_urdf_without_collision_boxes_is_refused(): @@ -181,57 +208,92 @@ def test_teleop_refuses_a_step_that_presses_one_contact_deeper(parameters, check teleop = ArmTeleop(config_from_parameters(parameters('xbox_teleop.yaml', 'xbox_teleop')), LIMITS, ArmKinematics.from_urdf(URDF), check) # Folded flat onto the table. Lifting the elbow from here eases five of the six contacts - # by more than it costs, so a total would call it an escape, but the forearm itself is - # pressed about 3 mm further into the table. - start = pose(90, 90, 5) - before, after = check.check(start), check.check(pose(90, 85, 5)) + # by more than it costs, so a total would call it an escape, but the tool itself is + # pressed more than 1 mm further into the table. + start = pose(90, 85, 40) + before, after = check.check(start), check.check(pose(90, 80, 40)) assert set(after) == set(before) and sum(after.values()) < sum(before.values()) - assert after['forearm_link: table'] > before['forearm_link: table'] + 0.002 + assert after['tool_link: table'] > before['tool_link: table'] + 0.001 for button in ('start', 'y'): teleop.update(*sample(button), start, DT) teleop.update(*sample(), start, DT) for _ in range(round(0.5 / DT)): teleop.update(*sample(left_y=-1.0), dict(teleop.targets), DT) assert teleop.targets['joint_3'] == start['joint_3'] - assert teleop.blocked == ['forearm_link: table'] + assert teleop.blocked == ['tool_link: table'] def test_the_intrusion_is_the_volume_inside_the_grown_obstacle(): square = ((1.0, 0.0, 0.0), (0.0, 1.0, 0.0), (0.0, 0.0, 1.0)) - obstacle = ((0.0, 0.0, 0.0), square, (0.1, 0.1, 0.1)) + obstacle = ((0.0, 0.0, 0.0), square, (0.1, 0.1, 0.1), None) # 30 mm into one face of the obstacle grown by 10 mm, and flush with three others. - side = ((0.13, 0.0, 0.01), square, (0.05, 0.11, 0.1)) + side = ((0.13, 0.0, 0.01), square, (0.05, 0.11, 0.1), None) assert _intrusion(side, obstacle, 0.01) == pytest.approx(0.03 * 0.22 * 0.2) turn = _rotation((0.0, 0.0, 1.0), 0.3) - inside = ((0.0, 0.02, 0.0), tuple(zip(*turn)), (0.01, 0.02, 0.03)) + inside = ((0.0, 0.02, 0.0), tuple(zip(*turn)), (0.01, 0.02, 0.03), None) assert _intrusion(inside, obstacle, 0.01) == pytest.approx(8 * 0.01 * 0.02 * 0.03) - assert _intrusion(((0.5, 0.0, 0.0), square, (0.1, 0.1, 0.1)), obstacle, 0.01) == 0.0 + assert _intrusion(((0.5, 0.0, 0.0), square, (0.1, 0.1, 0.1), None), obstacle, 0.01) == 0.0 -def test_teleop_refuses_to_slide_the_forearm_further_into_the_side_of_the_base( - parameters, check): +@pytest.mark.parametrize('start, contact', [ + (pose(45, 129.5, 0), 'forearm_link: base_link'), + (pose(45, 121.0, 60), 'wrist_roll_link: base_link'), +]) +def test_teleop_never_presses_the_arm_further_into_the_base(parameters, start, contact): + away = ArmCollision.from_urdf(URDF, table_z=-10.0) teleop = ArmTeleop(config_from_parameters(parameters('xbox_teleop.yaml', 'xbox_teleop')), - LIMITS, ArmKinematics.from_urdf(URDF), check) - # Folded back with the shoulder near its limit, the elbow bend reaches into the base's lid. - # Turning the base towards zero slides it further in, while its smallest separating-axis - # overlap shrinks. - start, turned = pose(-130, 60, 0, math.radians(5)), pose(-130, 60, 0, math.radians(4.5)) - assert check.hits(start) == check.hits(turned) == ['forearm_link: base_link'] - assert separating_axis_depth(check, turned) < separating_axis_depth(check, start) - assert (check.check(turned)['forearm_link: base_link'] - > check.check(start)['forearm_link: base_link']) + LIMITS, ArmKinematics.from_urdf(URDF), away) + # Past the forearm's table, or with the tool mount in the base's round housing. + assert away.hits(start) == [contact] teleop.update(*sample('start'), start, DT) teleop.update(*sample(), start, DT) - for _ in range(round(0.5 / DT)): - teleop.update(*sample(left_x=-1.0), dict(teleop.targets), DT) - assert teleop.targets['joint_1'] == start['joint_1'] - assert teleop.blocked == ['forearm_link: base_link'] - # Raising the shoulder backs it out. + # The base is round, so turning it slides the arm round the base without pressing in. + for _ in range(round(0.25 / DT)): + teleop.update(*sample(left_x=1.0), dict(teleop.targets), DT) + assert teleop.targets['joint_1'] > start['joint_1'] + 0.05 + assert away.check(teleop.targets)[contact] == pytest.approx(away.check(start)[contact]) + teleop.update(*sample('y'), dict(teleop.targets), DT) + teleop.update(*sample(), dict(teleop.targets), DT) + assert teleop.active_group.name == 'upper' + before = dict(teleop.targets) + # Left stick up bends the elbow further in, which is refused. for _ in range(round(0.5 / DT)): teleop.update(*sample(left_y=1.0), dict(teleop.targets), DT) - assert teleop.targets['joint_2'] > start['joint_2'] + 0.1 - assert (check.check(teleop.targets).get('forearm_link: base_link', 0.0) - < check.check(start)['forearm_link: base_link']) + assert teleop.targets['joint_3'] == before['joint_3'] + assert contact in teleop.blocked + for _ in range(round(0.5 / DT)): + teleop.update(*sample(left_y=-1.0), dict(teleop.targets), DT) + assert teleop.targets['joint_3'] < before['joint_3'] - 0.05 + assert away.check(teleop.targets).get(contact, 0.0) < away.check(before)[contact] + + +def test_a_cylinder_counts_as_a_prism_turned_to_face_the_other_shape(): + square = ((1.0, 0.0, 0.0), (0.0, 1.0, 0.0), (0.0, 0.0, 1.0)) + cylinder = ((0.0, 0.0, 0.0), square, (0.1, 0.1, 0.05), 0.1) + # 20 mm into the side of the cylinder grown by 10 mm, square on to it, at any turn. + for angle in (0.0, 0.3, 1.0, 2.5): + turn = _rotation((0.0, 0.0, 1.0), angle) + side = ((0.13 * math.cos(angle), 0.13 * math.sin(angle), 0.0), tuple(zip(*turn)), + (0.04, 0.01, 0.01), None) + assert _intrusion(side, cylinder, 0.01) == pytest.approx(0.02 * 0.02 * 0.02) + deeper = ((0.12, 0.0, 0.0), square, (0.04, 0.01, 0.01), None) + assert _intrusion(deeper, cylinder, 0.01) == pytest.approx(0.03 * 0.02 * 0.02) + inside = ((0.0, 0.03, 0.0), square, (0.01, 0.02, 0.03), None) + assert _intrusion(inside, cylinder, 0.01) == pytest.approx(8 * 0.01 * 0.02 * 0.03) + for clear in ((0.2, 0.0, 0.0), (0.0, 0.0, 0.1)): + assert _intrusion((clear, square, (0.03, 0.03, 0.03), None), cylinder, 0.01) == 0.0 + # A disc pressed into a box or a cylinder: spinning it about its own axis changes nothing, + # and pressing it further in adds to the volume. + box = ((0.0, 0.0, 0.0), square, (0.1, 0.1, 0.05), None) + for obstacle in (box, cylinder): + disc = ((0.125, 0.0, 0.0), square, (0.02, 0.02, 0.01), 0.02) + pressed = _intrusion(disc, obstacle, 0.01) + assert pressed > 0.0 + for angle in (0.4, 1.3): + spun = (disc[0], tuple(zip(*_rotation((0.0, 0.0, 1.0), angle))), disc[2], disc[3]) + assert _intrusion(spun, obstacle, 0.01) == pytest.approx(pressed) + further = ((0.12, 0.0, 0.0), square, disc[2], disc[3]) + assert _intrusion(further, obstacle, 0.01) > pressed def test_the_check_reports_a_depth_for_every_collision_it_names(check): @@ -246,14 +308,6 @@ def sample(*pressed, **axes): return [axes.get(name, 0.0) for name in AXES], [int(name in pressed) for name in BUTTONS] -def separating_axis_depth(check, joints): - """Return the deepest overlap of a forearm part with the base across the separating axes.""" - poses = check.poses(joints) - return max(_overlap(box, obstacle, check.self_clearance) - for box in check.world_boxes(poses, 'forearm_link') - for obstacle in check.world_boxes(poses, 'base_link')) - - def jaw_bottom(check, joints): """Return the height of the lowest corner of the RViz jaws, fully open.""" rotation, origin = check.poses(joints)['tool_link'] diff --git a/waybionic_teleop/test/test_incision.py b/waybionic_teleop/test/test_incision.py index 40a493e4..9900a150 100644 --- a/waybionic_teleop/test/test_incision.py +++ b/waybionic_teleop/test/test_incision.py @@ -179,7 +179,7 @@ def test_an_incision_move_into_the_table_is_refused_but_backing_out_is_not( run(teleop, 0.3) first = teleop.incision stopped = False - for _ in range(round(3.0 / DT)): + for _ in range(round(4.0 / DT)): before = dict(teleop.targets) teleop.update(*sample(**into), dict(teleop.targets), DT) assert check.hits(teleop.targets) == [] diff --git a/waybionic_teleop/waybionic_teleop/collision.py b/waybionic_teleop/waybionic_teleop/collision.py index e138ca0d..a8d8558c 100644 --- a/waybionic_teleop/waybionic_teleop/collision.py +++ b/waybionic_teleop/waybionic_teleop/collision.py @@ -1,12 +1,15 @@ """ Keep the arm's links off the table and out of its own base (pure logic, no ROS). -Each link's collision boxes come from the URDF (one per CAD part), and every check happens -in the base frame. The moving links must stay above the table, and the forearm, wrist and tool -must stay out of the base and shoulder, the parts they can fold into. Adjacent links overlap -at their joints, so those pairs are never compared; the joint limits keep them apart. Where -the URDF has a fold table for a pair (waybionic_fold, measured from the CAD), the table replaces -the boxes for it: the elbow may fold until the forearm is about to touch the shoulder. +Each link's collision shapes come from the URDF, made from its CAD parts: a cylinder for a part +round about a joint axis, such as the base's lid or the tool mount, a cylinder and a box for a +part round on one side, such as the wrist's differential housing, and otherwise a box. Every +check happens in the base frame. The moving links must stay above the table, and the forearm, +wrist and tool must stay out of the base and shoulder, the parts they can fold into. Adjacent +links overlap at their joints, so those pairs are never compared; the joint limits keep them +apart. Where the URDF has a fold table for a pair (waybionic_fold, measured from the CAD), the +table replaces the shapes for it: the elbow may fold until the forearm is about to touch the +shoulder or the base. """ import math @@ -17,6 +20,13 @@ FOLDING = ('forearm_link', 'wrist_pitch_link', 'wrist_left_gear_link', 'wrist_right_gear_link', 'wrist_roll_link', 'tool_link') REQUIRED = BODY + ('upper_arm_link',) + FOLDING +# A cylinder counts as the prism with this many sides around it, at most 0.5 % wider. +SIDES = 32 +_WIDER = 1.0 / math.cos(math.pi / SIDES) +_SIDES = tuple((math.cos(2.0 * math.pi * side / SIDES), math.sin(2.0 * math.pi * side / SIDES)) + for side in range(SIDES)) +_CORNERS = tuple((math.cos(math.pi * (2 * side + 1) / SIDES), + math.sin(math.pi * (2 * side + 1) / SIDES)) for side in range(SIDES)) def _vector(element, name, default=(0.0, 0.0, 0.0)): @@ -57,7 +67,7 @@ def _rpy(roll, pitch, yaw): class Fold: """Limits of one joint against another joint's angle, linearly interpolated.""" - def __init__(self, element, boxes, joints): + def __init__(self, element, links, joints): self.link, self.obstacle = element.get('link'), element.get('obstacle') self.joint, self.across = element.get('joint'), element.get('across') try: @@ -71,7 +81,7 @@ def __init__(self, element, boxes, joints): and all(math.isfinite(value) for value in self.upper + self.lower)): raise ValueError('waybionic_fold needs finite values, a positive step and matching ' 'tables') - if self.link not in boxes or not {self.joint, self.across} <= joints: + if self.link not in links or not {self.joint, self.across} <= joints: raise ValueError('waybionic_fold refers to an unknown joint or link') def limits(self, across): @@ -90,32 +100,37 @@ def excess(self, positions): class ArmCollision: - """Collision boxes and joint tree read from a URDF.""" + """Collision shapes and joint tree read from a URDF.""" - def __init__(self, boxes, joints, root, table_z=0.0, clearance=0.01, self_clearance=0.002, + def __init__(self, shapes, joints, root, table_z=0.0, clearance=0.01, self_clearance=0.002, folds=()): - self.boxes, self.joints, self.root = boxes, joints, root + self.shapes, self.joints, self.root = shapes, joints, root self.table_z, self.clearance, self.self_clearance = table_z, clearance, self_clearance self.folds = {(fold.link, fold.obstacle): fold for fold in folds} @classmethod def from_urdf(cls, urdf, table_z=0.0, clearance=0.01, self_clearance=0.002): - """Read boxes and joints; raise ValueError without boxes for the base and folding links.""" + """Read shapes and joints; raise ValueError if a required link has no shapes.""" try: robot = ET.fromstring(urdf) except ET.ParseError as error: raise ValueError(f'robot_description is not valid XML: {error}') from None - boxes = {} + shapes = {} for link in robot.findall('link'): for collision in link.findall('collision'): box = collision.find('geometry/box') - if box is None: + cylinder = collision.find('geometry/cylinder') + if box is None and cylinder is None: continue + if box is not None: + half, radius = tuple(size / 2.0 for size in _vector(box, 'size')), None + else: + radius = float(cylinder.get('radius', 0.0)) + half = (radius, radius, float(cylinder.get('length', 0.0)) / 2.0) origin = collision.find('origin') - boxes.setdefault(link.get('name'), []).append(( - _vector(origin, 'xyz'), _rpy(*_vector(origin, 'rpy')), - tuple(size / 2.0 for size in _vector(box, 'size')))) - missing = [name for name in REQUIRED if name not in boxes] + shapes.setdefault(link.get('name'), []).append(( + _vector(origin, 'xyz'), _rpy(*_vector(origin, 'rpy')), half, radius)) + missing = [name for name in REQUIRED if name not in shapes] if missing: raise ValueError('robot_description has no collision box for ' + ', '.join(missing)) joints, children = {}, set() @@ -136,8 +151,8 @@ def from_urdf(cls, urdf, table_z=0.0, clearance=0.01, self_clearance=0.002): if len(roots) != 1: raise ValueError(f'robot_description needs one root link, not {len(roots)}') names = {joint['name'] for joint in joints.values()} - folds = [Fold(element, boxes, names) for element in robot.findall('waybionic_fold')] - checker = cls(boxes, joints, roots[0], table_z, clearance, self_clearance, folds) + folds = [Fold(element, shapes, names) for element in robot.findall('waybionic_fold')] + checker = cls(shapes, joints, roots[0], table_z, clearance, self_clearance, folds) checker.poses({}) return checker @@ -165,12 +180,19 @@ def poses(self, positions): pending.remove(child) return poses - def world_boxes(self, poses, link): + def world_shapes(self, poses, link): + """ + Yield (centre, axes, half sizes, radius) for the link's shapes in the root frame. + + A box has radius None. A cylinder runs along axes[2], with half sizes (radius, radius, + half length). + """ rotation, origin = poses[link] - for center, box_rotation, half in self.boxes.get(link, []): - world = _multiply(rotation, box_rotation) + for center, local, half, radius in self.shapes.get(link, []): + world = _multiply(rotation, local) axes = tuple(tuple(world[row][column] for row in range(3)) for column in range(3)) - yield tuple(o + d for o, d in zip(origin, _apply(rotation, center))), axes, half + yield (tuple(o + d for o, d in zip(origin, _apply(rotation, center))), axes, half, + radius) def hits(self, positions): """Return what would collide at these joint positions, such as 'forearm_link: table'.""" @@ -181,21 +203,21 @@ def check(self, positions): Return {collision: intrusion}: each contact, and how far into it the arm reaches. Against the table that is the depth in m. Inside the base or shoulder it is the volume - in m^3 of the link's boxes within the obstacle's boxes grown by the self-collision + in m^3 of the link's shapes within the obstacle's shapes grown by the self-collision clearance, which, unlike a depth, grows whichever way the link pushes further in. Past a fold table it is the angle in radians beyond the table. """ poses = self.poses(positions) + world = {link: [(shape, _reach(shape)) for shape in self.world_shapes(poses, link)] + for link in self.shapes} found = {} - for link in self.boxes: + for link, placed in world.items(): if link in BODY: continue - lowest = min(center[2] - sum(h * abs(axis[2]) for h, axis in zip(half, axes)) - for center, axes, half in self.world_boxes(poses, link)) + lowest = min(_lowest(shape) for shape, _ in placed) if lowest < self.table_z + self.clearance: found[f'{link}: table'] = self.table_z + self.clearance - lowest - world = {link: [(box, math.sqrt(_dot(box[2], box[2]))) - for box in self.world_boxes(poses, link)] for link in BODY + FOLDING} + margin = self.self_clearance for link in FOLDING: for body in BODY: fold = self.folds.get((link, body)) @@ -204,12 +226,14 @@ def check(self, positions): if excess > 0.0: found[f'{link}: {body}'] = excess continue - volume = sum(_intrusion(box, obstacle, self.self_clearance) - for box, radius in world[link] for obstacle, reach in world[body] - # Boxes whose bounding spheres are apart cannot overlap. - if _squared_distance(box[0], obstacle[0]) - < (radius + reach + self.self_clearance) ** 2 - and _overlap(box, obstacle, self.self_clearance) > 0.0) + # Shapes whose bounding spheres are apart cannot overlap, nor can two boxes + # that a separating axis keeps apart. + volume = sum(_intrusion(shape, obstacle, margin) + for shape, reach in world[link] for obstacle, extent in world[body] + if _squared_distance(shape[0], obstacle[0]) + < (reach + extent + margin) ** 2 + and (shape[3] is not None or obstacle[3] is not None + or _overlap(shape, obstacle, margin) > 0.0)) if volume > 0.0: found[f'{link}: {body}'] = volume return found @@ -219,11 +243,77 @@ def _squared_distance(a, b): return sum((x - y) ** 2 for x, y in zip(a, b)) -def _intrusion(a, b, margin): - """Return the volume of box a inside box b grown by margin on every side.""" - (center_a, axes_a, half_a), (center_b, axes_b, half_b) = a, b - # Work relative to b's centre, which keeps the volume sums well conditioned. - offset = tuple(ca - cb for ca, cb in zip(center_a, center_b)) +def _reach(shape): + """Return the radius of a sphere about the shape's centre that holds all of it.""" + _, _, half, radius = shape + if radius is None: + return math.sqrt(_dot(half, half)) + return math.hypot(radius * _WIDER, half[2]) + + +def _lowest(shape): + """Return the height of the shape's lowest point.""" + center, axes, half, radius = shape + if radius is None: + return center[2] - sum(h * abs(axis[2]) for h, axis in zip(half, axes)) + tilt = abs(axes[2][2]) + return center[2] - half[2] * tilt - radius * math.sqrt(max(0.0, 1.0 - tilt * tilt)) + + +def _spread(shape, normal): + """Return how far the shape reaches from its centre along a unit normal.""" + _, axes, half, radius = shape + if radius is None: + return sum(h * abs(_dot(normal, axis)) for h, axis in zip(half, axes)) + along = abs(_dot(normal, axes[2])) + return half[2] * along + radius * _WIDER * math.sqrt(max(0.0, 1.0 - along * along)) + + +def _facing(cylinder, toward): + """Return the cylinder's cross axes, turned so that the first points at toward.""" + center, (first, second, axis), _, _ = cylinder + offset = tuple(t - c for t, c in zip(toward, center)) + along = _dot(offset, axis) + outward = tuple(o - along * a for o, a in zip(offset, axis)) + length = math.sqrt(_dot(outward, outward)) + if length < 1e-9: + return first, second + first = tuple(value / length for value in outward) + return first, _cross(axis, first) + + +def _planes(shape, toward, margin): + """Yield the shape's face planes as (outward normal, distance from its centre), grown.""" + _, axes, half, radius = shape + if radius is None: + for axis, h in zip(axes, half): + yield axis, h + margin + yield tuple(-value for value in axis), h + margin + return + first, second = _facing(shape, toward) + yield first, radius + margin + yield axes[2], half[2] + margin + yield tuple(-value for value in axes[2]), half[2] + margin + for c, s in _SIDES[1:]: + yield tuple(c * u + s * v for u, v in zip(first, second)), radius + margin + + +def _faces(shape, origin): + """ + Return the shape's faces relative to origin, each counterclockwise seen from outside. + + A cylinder's prism turns to face origin, so turning about its axis changes nothing. + """ + center, axes, half, radius = shape + offset = tuple(c - o for c, o in zip(center, origin)) + if radius is not None: + first, second = _facing(shape, origin) + top, bottom = ([tuple(o + side * half[2] * a + radius * _WIDER * (c * u + s * v) + for o, a, u, v in zip(offset, axes[2], first, second)) + for c, s in _CORNERS] for side in (1.0, -1.0)) + return [top, bottom[::-1]] + [ + [bottom[k], bottom[(k + 1) % SIDES], top[(k + 1) % SIDES], top[k]] + for k in range(SIDES)] faces = [] for i in range(3): j, k = (i + 1) % 3, (i + 2) % 3 @@ -232,17 +322,38 @@ def _intrusion(a, b, margin): for along_j, along_k in ((-1.0, -1.0), (1.0, -1.0), (1.0, 1.0), (-1.0, 1.0)): signs = [0.0] * 3 signs[i], signs[j], signs[k] = side, along_j, along_k - loop.append(tuple(o + sum(s * h * u[n] for s, h, u in zip(signs, half_a, axes_a)) + loop.append(tuple(o + sum(s * h * u[n] for s, h, u in zip(signs, half, axes)) for n, o in enumerate(offset))) - # Each face runs counterclockwise seen from outside the box. faces.append(loop if side > 0.0 else loop[::-1]) - for axis, half in zip(axes_b, half_b): - for normal in (axis, tuple(-value for value in axis)): - faces = _clip(faces, normal, half + margin) + return faces + + +def _volume(faces): return sum(_dot(face[0], _cross(p, q)) for face in faces for p, q in zip(face[1:], face[2:])) / 6.0 +def _intrusion(a, b, margin): + """ + Return the volume of shape a inside shape b grown by margin on every side. + + A cylinder counts as the SIDES-sided prism around it, turned to face the other shape. + """ + offset = tuple(x - y for x, y in zip(a[0], b[0])) + cutting = [] + for normal, limit in _planes(b, a[0], margin): + middle, spread = _dot(normal, offset), _spread(a, normal) + if middle - spread >= limit: + return 0.0 + if middle + spread > limit: + cutting.append((normal, limit)) + # Work relative to b's centre, which keeps the volume sums well conditioned. + faces = _faces(a, b[0]) + for normal, limit in cutting: + faces = _clip(faces, normal, limit) + return _volume(faces) + + def _clip(faces, normal, limit): """Cut a convex polyhedron, given as outward faces, down to normal . point <= limit.""" distances = [_dot(normal, point) - limit for face in faces for point in face] @@ -276,7 +387,7 @@ def _clip(faces, normal, limit): def _overlap(a, b, margin): """Return how far two oriented boxes overlap within margin (separating axes), or 0.""" - (center_a, axes_a, half_a), (center_b, axes_b, half_b) = a, b + (center_a, axes_a, half_a, _), (center_b, axes_b, half_b, _) = a, b gap = tuple(cb - ca for ca, cb in zip(center_a, center_b)) candidates = list(axes_a) + list(axes_b) + [ _cross(u, v) for u in axes_a for v in axes_b] diff --git a/waybionic_teleop/waybionic_teleop/xbox_teleop_node.py b/waybionic_teleop/waybionic_teleop/xbox_teleop_node.py index 4252eda9..79f36f6e 100644 --- a/waybionic_teleop/waybionic_teleop/xbox_teleop_node.py +++ b/waybionic_teleop/waybionic_teleop/xbox_teleop_node.py @@ -117,7 +117,7 @@ def load(self, message): joints = {joint for group in self.config.groups for joint in group.joints} try: limits = joint_limits(message.data, joints) - # The collision boxes are the only thing keeping the arm off the table and out of + # The collision shapes are the only thing keeping the arm off the table and out of # its own base, so a description without them leaves teleop off rather than # running it unprotected. collision = ArmCollision.from_urdf(message.data, self.table_height, self.clearance, From af3e599c7b7fcb5837662c88833585c8d9e6a1bb Mon Sep 17 00:00:00 2001 From: yassinsolim Date: Sun, 11 Oct 2026 03:15:09 -0600 Subject: [PATCH 04/12] Press Start in the Cartesian launch test only once the drives have the model --- waybionic_bringup/test/test_cartesian_launch.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/waybionic_bringup/test/test_cartesian_launch.py b/waybionic_bringup/test/test_cartesian_launch.py index 3231f02f..a71982cd 100644 --- a/waybionic_bringup/test/test_cartesian_launch.py +++ b/waybionic_bringup/test/test_cartesian_launch.py @@ -75,13 +75,18 @@ def hold(seconds, *pressed, record=False, **axes): try: deadline = time.monotonic() + 30.0 - # Press Start only once teleop has loaded the robot description (the group row - # appears) and receives the controller, or the press is lost on a slow machine. + # Press Start only once teleop (the group row) and the drives (a gate waiting for + # Start, not a model) have the robot description and teleop receives the controller, + # or the press is lost on a slow machine. while time.monotonic() < deadline and not ( 'teleop.group' in diagnostics and diagnostics['teleop.input'].level == DiagnosticStatus.OK + and 'arm.command_gate' in diagnostics + and diagnostics['arm.command_gate'].level == DiagnosticStatus.WARN and buffer.can_transform('base_link', 'tool_link', Time())): hold(0.1) + self.assertEqual(diagnostics['arm.command_gate'].level, DiagnosticStatus.WARN, + 'the drives never loaded the robot description') hold(0.2, 'start') hold(0.3, 'y') # Bend the shoulder, elbow and wrist away from the upright pose. From 346f51b177db274c1001c02c380da79bb3b3f644 Mon Sep 17 00:00:00 2001 From: Yassin Soliman <108886216+yassinsolim@users.noreply.github.com> Date: Fri, 16 Oct 2026 19:28:08 -0600 Subject: [PATCH 05/12] Refuse fold tables and collision shapes that do not fit the arm A fold table replaces the shapes for its pair, so it must pair a folding link with the base or shoulder, use two joints that move one against the other, cover the other joint's whole range, keep lower below upper, and appear once per pair. Shapes need positive finite sizes, vectors three finite numbers, joints a nonzero axis and mimics finite values, so a bad value disables teleop instead of dropping a shape from the checks. --- waybionic_teleop/test/test_collision.py | 35 +++++++ .../waybionic_teleop/collision.py | 97 ++++++++++++++++--- 2 files changed, 119 insertions(+), 13 deletions(-) diff --git a/waybionic_teleop/test/test_collision.py b/waybionic_teleop/test/test_collision.py index 562e0a18..e9496c03 100644 --- a/waybionic_teleop/test/test_collision.py +++ b/waybionic_teleop/test/test_collision.py @@ -94,6 +94,16 @@ def test_the_wrist_and_tool_stop_just_before_their_parts_touch_the_base(yaw): @pytest.mark.parametrize('old, new', [ ('across="joint_2"', 'across="joint_9"'), ('start="-135"', 'start="nan"'), ('step="5"', 'step="0"'), ('upper="147.3 ', 'upper="'), ('lower="-122.7', 'lower="inf'), + # Each table replaces the shapes for its pair, so it must fit the joint tree. + ('obstacle="shoulder_link"', 'obstacle="upper_arm_link"'), + ('link="forearm_link" obstacle="base_link"', 'link="upper_arm_link" obstacle="base_link"'), + ('joint="joint_3" across="joint_2" start="-135" step="5"', + 'joint="joint_1" across="joint_2" start="-135" step="5"'), + ('across="joint_2" start="-135" step="5"', 'across="joint_3" start="-135" step="5"'), + ('across="joint_2" start="-135" step="5"', 'across="joint_4" start="-135" step="5"'), + ('start="-135" step="5"', 'start="-130" step="5"'), + ('start="-135" step="2.5"', 'start="-135" step="2"'), + ('upper="147.3 ', 'upper="-130 '), ]) def test_an_unusable_fold_table_is_refused(old, new): assert old in URDF @@ -101,6 +111,31 @@ def test_an_unusable_fold_table_is_refused(old, new): ArmCollision.from_urdf(URDF.replace(old, new)) +def test_a_second_fold_table_for_one_pair_is_refused(): + fold = re.search(r'', URDF, re.S).group(0) + with pytest.raises(ValueError, match='two waybionic_fold tables for one pair'): + ArmCollision.from_urdf(URDF.replace('', fold + '\n')) + + +@pytest.mark.parametrize('old, new', [ + ('', ''), + ('', ''), + ('', ''), + ('', ''), + (' lower + SPAN_TOLERANCE_DEG + or end < upper - SPAN_TOLERANCE_DEG): + raise ValueError(f'waybionic_fold for {self.link} and {self.obstacle} covers ' + f'{self.across} from {self.start:g} to {end:g} degrees, not its ' + f'whole range {lower:.2f} to {upper:.2f}') + if any(low > high for low, high in zip(self.lower, self.upper)): + raise ValueError(f'waybionic_fold for {self.link} and {self.obstacle} has a lower ' + 'value above its upper value') def limits(self, across): """Return (lower, upper) in radians at this angle of the other joint.""" @@ -125,8 +168,12 @@ def from_urdf(cls, urdf, table_z=0.0, clearance=0.01, self_clearance=0.002): if box is not None: half, radius = tuple(size / 2.0 for size in _vector(box, 'size')), None else: - radius = float(cylinder.get('radius', 0.0)) - half = (radius, radius, float(cylinder.get('length', 0.0)) / 2.0) + radius = _number(cylinder, 'radius') + half = (radius, radius, _number(cylinder, 'length') / 2.0) + if not all(math.isfinite(size) and size > 0.0 for size in half): + # A shape without a size would silently drop out of the checks. + raise ValueError('robot_description has a collision shape without a ' + f'positive finite size on {link.get("name")}') origin = collision.find('origin') shapes.setdefault(link.get('name'), []).append(( _vector(origin, 'xyz'), _rpy(*_vector(origin, 'rpy')), half, radius)) @@ -137,23 +184,47 @@ def from_urdf(cls, urdf, table_z=0.0, clearance=0.01, self_clearance=0.002): for joint in robot.findall('joint'): mimic = joint.find('mimic') origin = joint.find('origin') + axis = _vector(joint.find('axis'), 'xyz', (1.0, 0.0, 0.0)) + length = math.sqrt(_dot(axis, axis)) + if mimic is not None: + mimic = (mimic.get('joint'), _number(mimic, 'multiplier', 1.0), + _number(mimic, 'offset', 0.0)) + if length < 1e-9 or (mimic and not all(map(math.isfinite, mimic[1:]))): + raise ValueError(f'robot_description has joint {joint.get("name")} without an ' + 'axis, or with a mimic that is not two finite numbers') joints[joint.find('child').get('link')] = { 'name': joint.get('name'), 'type': joint.get('type'), 'parent': joint.find('parent').get('link'), 'xyz': _vector(origin, 'xyz'), 'rpy': _rpy(*_vector(origin, 'rpy')), - 'axis': _vector(joint.find('axis'), 'xyz', (1.0, 0.0, 0.0)), - 'mimic': None if mimic is None else ( - mimic.get('joint'), float(mimic.get('multiplier', 1.0)), - float(mimic.get('offset', 0.0)))} + 'axis': tuple(value / length for value in axis), 'mimic': mimic} children.add(joint.find('child').get('link')) roots = [link.get('name') for link in robot.findall('link') if link.get('name') not in children] if len(roots) != 1: raise ValueError(f'robot_description needs one root link, not {len(roots)}') - names = {joint['name'] for joint in joints.values()} - folds = [Fold(element, shapes, names) for element in robot.findall('waybionic_fold')] - checker = cls(shapes, joints, roots[0], table_z, clearance, self_clearance, folds) + checker = cls(shapes, joints, roots[0], table_z, clearance, self_clearance) checker.poses({}) + limits = {} + for joint in robot.findall('joint'): + limit = joint.find('limit') + if (joint.get('type') == 'revolute' and joint.find('mimic') is None + and limit is not None): + bounds = (_number(limit, 'lower'), _number(limit, 'upper')) + if all(math.isfinite(bound) for bound in bounds): + limits[joint.get('name')] = bounds + moved_by = {} + for link in shapes: + moved_by[link], child = set(), link + # poses() has checked that the joints form a tree, so this reaches the root. + while child in joints: + if joints[child]['name'] in limits: + moved_by[link].add(joints[child]['name']) + child = joints[child]['parent'] + folds = [Fold(element, moved_by, limits) for element in robot.findall('waybionic_fold')] + pairs = {(fold.link, fold.obstacle) for fold in folds} + if len(pairs) != len(folds): + raise ValueError('robot_description has two waybionic_fold tables for one pair') + checker.folds = {(fold.link, fold.obstacle): fold for fold in folds} return checker def poses(self, positions): From 2083c14a38618a0e793955fe1112c3fbd42809ea Mon Sep 17 00:00:00 2001 From: Yassin Soliman <108886216+yassinsolim@users.noreply.github.com> Date: Sat, 17 Oct 2026 13:07:23 -0600 Subject: [PATCH 06/12] Set the joint limits where the CAD parts touch or meet the ground scripts/cad/exact_limits.py turns each joint from the upright pose with exact triangle-mesh distances (FCL). The straight arm meets the ground under the base at 109.65 degrees of shoulder, the forearm meets the shoulder's motor mount at 148.93 degrees of elbow, and the tool mount meets the forearm's cap at 94.68 degrees of wrist pitch. Base yaw and wrist roll meet nothing over a full turn, so they turn 360 degrees either way. The elbow's fold tables now run to contact over the new shoulder range. Against the table, the teleop check now uses each moving link's convex hull from the CAD (waybionic_hull in the URDF) instead of its collision shapes, which reached up to 12 mm below the tool mount. The table and self-collision clearances default to 0, so the arm stops where its parts touch. --- BuildInstructions.md | 41 +-- scripts/cad/build_arm_description.py | 97 ++++--- scripts/cad/exact_limits.py | 273 ++++++++++++++++++ scripts/cad/joint_clearance.py | 220 ++------------ scripts/cad/link_hulls.json | 1 + .../test/test_arm_description.py | 31 ++ waybionic_description/urdf/waybionic_arm.urdf | 218 +++++++++++++- waybionic_teleop/config/xbox_teleop.yaml | 11 +- waybionic_teleop/package.xml | 2 + waybionic_teleop/test/test_collision.py | 121 ++++++-- waybionic_teleop/test/test_incision.py | 15 +- waybionic_teleop/test/test_kinematics.py | 12 +- .../test/test_sim_arm_drives_node.py | 7 +- .../test/test_xbox_teleop_node.py | 2 +- .../waybionic_teleop/collision.py | 40 ++- .../waybionic_teleop/xbox_teleop_node.py | 4 +- 16 files changed, 769 insertions(+), 326 deletions(-) create mode 100644 scripts/cad/exact_limits.py create mode 100644 scripts/cad/link_hulls.json diff --git a/BuildInstructions.md b/BuildInstructions.md index 7afb040d..8cf24e0c 100644 --- a/BuildInstructions.md +++ b/BuildInstructions.md @@ -434,14 +434,17 @@ the point moves onto the axis instead of the arm moving. Further away, the group rather than pull the tool back: press Y, withdraw the tool in another group, then select the incision group again to set a new incision point. -The arm URDF's joint limits come from the CAD: each pitch joint stops about 1 degree -before two parts touch, 135 degrees either way for the shoulder, 147 for the elbow and -93 for the wrist pitch (found with `scripts/cad/joint_clearance.py`). Base yaw and -wrist roll never touch another part, so they turn 180 degrees either way until their -cabling is measured. These limits and the collision checks below have been tested with -simulated drives only. The simulated CAN map is not a powered-arm safety case. Do not -operate powered motors until Mechanical confirms the signed travel of each joint from -upright zero on the built arm, including any cable or gear stop. +The arm URDF's joint limits are where the CAD parts touch, found by turning each joint +from the upright pose with exact triangle-mesh contacts (`scripts/cad/exact_limits.py`): +the straight arm meets the ground under the base at 109.65 degrees of shoulder either +way, the forearm meets the shoulder's motor mount at 148.93 degrees of elbow, and the +tool mount meets the cap on the forearm at 94.68 degrees of wrist pitch. Nothing meets +anything over a full turn of base yaw or wrist roll, so they turn a full turn (360 +degrees) either way; their cabling is not modelled. These limits and the collision +checks below have been tested with simulated drives only. The simulated CAN map is not +a powered-arm safety case. Do not operate powered motors until Mechanical confirms the +signed travel of each joint from upright zero on the built arm, including any cable or +gear stop. In simulation, a zero-velocity joint command (including B and controller timeout) sends an MKS F5 frame with zero speed and zero acceleration to each moving drive. @@ -454,26 +457,28 @@ up faster than the teleop speed limits. This checks simulated behavior only. Do not connect powered drives or treat it as a hardware E-stop test; drive identities, wiring, zeroing and electrical safety still need hardware verification. -Every group stops a move before any part of the arm comes within 10 mm of the -table or within 2 mm of the arm's own base and shoulder. The checks use a box +Every group stops a move where any part of the arm would go below the table or into +the arm's own base and shoulder. Against the table each link's lowest point comes from +the convex hull of its CAD parts (`waybionic_hull` in the URDF), so the arm stops where +its real parts reach the table. Against the base and shoulder the checks use a box around each CAD part, or a cylinder where a part, or one side of it, is round about a joint axis, such as the base's lid, the tool mount and the lower half of the wrist's housing, so they fit those parts however the joints turn. You can see them by ticking **Collision Enabled** on RViz's RobotModel display. They are too coarse where the forearm folds against the shoulder or the base, so there the elbow -follows tables of its limits against the shoulder angle, measured from the CAD -1 degree before the parts touch (`waybionic_fold` in the URDF); the base's table -holds at every yaw. +follows tables of its limits against the shoulder angle, measured from the CAD where +the parts touch (`waybionic_fold` in the URDF, `scripts/cad/joint_clearance.py`); the +base's table holds at every yaw. The tool's box is a placeholder around the RViz jaws, which reach 30 mm past `tool_link`, until the real tool is modelled; a longer tool needs a longer box. When a move stops, the diagnostics panel names the part, for example `At limit: forearm_link: table`. If the arm stands on a raised mount, set `table_height` in `waybionic_teleop/config/xbox_teleop.yaml` to the table's height -above the bottom of the base. `collision_clearance` in the same file sets the 10 mm -margin to the table, and `self_collision_clearance` the 2 mm margin to the base and -shoulder; the forearm's tables keep their 1 degree instead. If the arm is already -touching something, the only moves still allowed are the ones that back out of it: -a move that presses any contact further in is refused, even if it would ease +above the bottom of the base. `collision_clearance` in the same file keeps a gap to the +table, and `self_collision_clearance` to the base and shoulder; both are 0, so the arm +stops where its parts touch. Raise them for a margin on the real arm. If the arm is +already touching something, the only moves still allowed are the ones that back out of +it: a move that presses any contact further in is refused, even if it would ease another contact at the same time. The collision shapes are what make any of this work. A `robot_description` without diff --git a/scripts/cad/build_arm_description.py b/scripts/cad/build_arm_description.py index 45b7ef6e..b1c890bd 100644 --- a/scripts/cad/build_arm_description.py +++ b/scripts/cad/build_arm_description.py @@ -38,6 +38,8 @@ URDF_PATH = REPOSITORY / 'waybionic_description' / 'urdf' / 'waybionic_arm.urdf' MESH_DIRECTORY = REPOSITORY / 'waybionic_description' / 'meshes' / 'arm' MESH_URI = 'package://waybionic_description/meshes/arm/' +# Written by scripts/cad/exact_limits.py --hulls: each moving link's convex hull. +HULLS_PATH = Path(__file__).resolve().with_name('link_hulls.json') # Top-level components, including everything below them, for each rigid link. LINKS = { @@ -59,60 +61,59 @@ } # name, parent, child, axis mate, origin plane mate, SolidWorks rotor, limits in degrees. -# The pitch limits stop about 1 degree before two CAD parts touch, found with -# scripts/cad/joint_clearance.py; base yaw and wrist roll never touch, so cabling sets them. +# Each limit is where a joint, turning from the upright pose, first brings two CAD parts +# together or the arm down to the ground under the base (scripts/cad/exact_limits.py): the +# straight arm meets the ground at 109.65 degrees of shoulder, the forearm the shoulder's motor +# mount at 148.93 of elbow, and the tool mount the cap on the forearm at 94.68 of wrist pitch. +# Nothing meets over a full turn of base yaw or wrist roll, so they turn a full turn either way. +# In other poses the forearm's folds (ELBOW_FOLDS) and the ground stop the arm in teleop. JOINTS = ( ('joint_1', 'base_link', 'shoulder_link', 'Concentric124', 'Coincident70', - 'outer_ring_sweep_loose-1', (-180.0, 180.0)), + 'outer_ring_sweep_loose-1', (-360.0, 360.0)), ('joint_2', 'shoulder_link', 'upper_arm_link', 'Concentric112', 'Coincident57', - 'outer-ring-Nema23-1', (-135.0, 135.0)), + 'outer-ring-Nema23-1', (-109.65, 109.65)), ('joint_3', 'upper_arm_link', 'forearm_link', 'Concentric127', 'Coincident71', - 'outer_ring_sweep_loose-2', (-147.0, 147.0)), + 'outer_ring_sweep_loose-2', (-148.93, 148.93)), ('joint_4', 'forearm_link', 'wrist_pitch_link', 'Concentric139', None, - 'DifferentialHousing-1', (-93.0, 93.0)), + 'DifferentialHousing-1', (-94.68, 94.68)), ('joint_5', 'wrist_pitch_link', 'wrist_roll_link', 'Concentric143', None, - 'straight bevel pinion_iso-3', (-180.0, 180.0)), + 'straight bevel pinion_iso-3', (-360.0, 360.0)), ) # How far the elbow folds before the forearm meets the shoulder, or the base at any yaw, depends # on the shoulder angle: for each, shoulder angles from START in steps of STEP degrees, then the -# elbow's upper and lower limits there, 1 degree short of contact +# elbow's upper and lower limits there, where the parts touch, to 0.1 degree # (scripts/cad/joint_clearance.py). The collision shapes are too coarse for these pairs, so the # teleop collision check reads these tables instead. ELBOW_FOLDS = { 'shoulder_link': ( - -135.0, 5.0, - (147.3, 147.4, 147.4, 147.5, 147.6, 147.6, 147.6, 147.6, 147.6, 147.7, 147.7, 147.7, 147.7, - 147.7, 147.7, 147.7, 147.7, 147.7, 147.7, 147.7, 147.7, 147.7, 147.7, 147.6, 147.6, 147.6, - 147.6, 147.5, 147.5, 147.4, 147.4, 147.3, 147.2, 147.1, 147.0, 146.3, 144.8, 143.3, 141.6, - 139.9, 138.1, 136.4, 134.7, 133.1, 131.7, 130.2, 128.9, 127.6, 126.5, 125.6, 124.8, 124.3, - 121.9, 121.9, 122.6), - (-122.7, -121.9, -121.8, -124.3, -124.8, -125.6, -126.5, -127.6, -128.8, -130.1, -131.6, - -133.2, -134.7, -136.4, -138.1, -139.8, -141.6, -143.3, -144.8, -146.3, -147.0, -147.1, - -147.2, -147.3, -147.4, -147.4, -147.5, -147.5, -147.5, -147.6, -147.6, -147.6, -147.6, - -147.6, -147.7, -147.7, -147.7, -147.7, -147.7, -147.7, -147.7, -147.7, -147.7, -147.7, - -147.7, -147.6, -147.6, -147.6, -147.6, -147.6, -147.5, -147.5, -147.5, -147.4, -147.3), + -109.65, 4.984090909090909, + (148.7, 148.8, 148.8, 148.8, 148.8, 148.9, 148.8, 148.9, 148.9, 148.9, 148.9, 148.9, 148.9, + 148.9, 148.9, 148.9, 148.9, 148.8, 148.8, 148.8, 148.8, 148.7, 148.7, 148.7, 148.6, 148.5, + 148.5, 148.4, 148.3, 148.1, 147.5, 146.0, 144.5, 142.8, 141.0, 139.3, 137.6, 136.0, 134.4, + 132.9, 131.4, 130.1, 128.8, 127.8, 126.9), + (-126.8, -127.7, -128.8, -130.2, -131.4, -132.9, -134.3, -135.9, -137.6, -139.3, -141.0, + -142.8, -144.5, -146.0, -147.4, -148.1, -148.3, -148.4, -148.5, -148.5, -148.6, -148.7, + -148.7, -148.7, -148.8, -148.8, -148.8, -148.9, -148.8, -148.9, -148.9, -148.9, -148.9, + -148.9, -148.9, -148.9, -148.9, -148.9, -148.9, -148.9, -148.8, -148.9, -148.8, -148.8, + -148.8), ), 'base_link': ( - -135.0, 2.5, - (172.7, 176.0, 178.5, 180.0, 180.0, 180.0, 180.0, 180.0, 180.0, 180.0, 180.0, 180.0, 180.0, - 180.0, 180.0, 180.0, 180.0, 180.0, 180.0, 180.0, 180.0, 180.0, 180.0, 180.0, 180.0, 180.0, - 180.0, 180.0, 180.0, 180.0, 180.0, 180.0, 180.0, 178.7, 178.1, 177.4, 176.5, 175.5, 174.6, - 173.6, 172.7, 171.8, 170.8, 169.9, 168.8, 167.8, 166.9, 165.9, 164.9, 164.0, 163.0, 162.0, - 161.1, 160.1, 159.1, 158.1, 156.7, 155.3, 154.3, 152.0, 149.6, 147.4, 145.4, 143.4, 141.6, - 139.9, 138.2, 136.6, 135.0, 133.5, 132.0, 130.5, 128.9, 127.5, 125.9, 124.3, 121.7, 120.1, - 118.4, 116.8, 115.0, 113.2, 111.3, 109.3, 107.2, 105.1, 103.0, 100.9, 98.8, 96.5, 95.9, - 93.7, 91.2, 88.8, 86.2, 83.5, 80.8, 77.9, 74.9, 71.7, 68.3, 64.0, 59.4, 54.3, 49.1, 43.9, - 35.8, 24.6, 9.9), - (-9.9, -24.5, -35.8, -43.8, -49.1, -54.3, -59.4, -64.0, -68.3, -71.7, -74.9, -77.9, -80.8, - -83.5, -86.2, -88.8, -91.2, -93.6, -95.9, -96.5, -98.8, -100.9, -103.0, -105.1, -107.3, - -109.3, -111.3, -113.2, -115.0, -116.8, -118.4, -120.1, -121.7, -124.3, -125.9, -127.4, - -128.9, -130.5, -132.0, -133.5, -135.0, -136.6, -138.2, -139.9, -141.6, -143.4, -145.4, - -147.4, -149.6, -152.1, -154.3, -155.3, -156.7, -158.1, -159.1, -160.1, -161.0, -162.0, - -163.0, -164.0, -164.9, -165.9, -166.9, -167.9, -168.8, -169.8, -170.7, -171.8, -172.7, - -173.6, -174.6, -175.5, -176.5, -177.4, -178.1, -178.8, -180.0, -180.0, -180.0, -180.0, + -109.65, 2.4920454545454547, + (180.0, 180.0, 180.0, 180.0, 180.0, 180.0, 180.0, 180.0, 180.0, 180.0, 180.0, 180.0, 180.0, + 180.0, 180.0, 180.0, 180.0, 180.0, 180.0, 180.0, 180.0, 180.0, 180.0, 179.8, 179.2, 178.4, + 177.5, 176.6, 175.6, 174.7, 173.8, 172.8, 171.8, 170.9, 169.9, 169.0, 168.0, 167.0, 166.1, + 165.1, 164.1, 163.1, 162.1, 161.2, 160.1, 159.2, 158.1, 156.5, 155.5, 153.3, 150.8, 148.6, + 146.5, 144.6, 142.8, 141.0, 139.3, 137.7, 136.1, 134.6, 133.1, 131.6, 130.1, 128.6, 127.1, + 125.5, 122.9, 121.3, 119.7, 118.0, 116.3, 114.4, 112.5, 110.6, 108.6, 106.5, 104.3, 102.2, + 100.1, 97.9, 97.3, 95.0, 92.7, 90.2, 87.7, 85.1, 82.3, 79.4, 76.4), + (-76.5, -79.5, -82.3, -85.1, -87.7, -90.2, -92.7, -95.0, -97.3, -97.9, -100.1, -102.2, + -104.4, -106.5, -108.6, -110.6, -112.5, -114.4, -116.3, -118.0, -119.7, -121.3, -122.9, + -125.5, -127.1, -128.6, -130.1, -131.7, -133.1, -134.6, -136.1, -137.7, -139.3, -141.0, + -142.8, -144.6, -146.6, -148.6, -150.8, -153.3, -155.4, -156.5, -158.2, -159.2, -160.1, + -161.1, -162.1, -163.1, -164.1, -165.1, -166.0, -167.0, -168.0, -169.0, -169.9, -170.9, + -171.8, -172.8, -173.7, -174.7, -175.6, -176.5, -177.5, -178.4, -179.2, -179.8, -180.0, -180.0, -180.0, -180.0, -180.0, -180.0, -180.0, -180.0, -180.0, -180.0, -180.0, -180.0, - -180.0, -180.0, -180.0, -180.0, -180.0, -180.0, -180.0, -180.0, -180.0, -180.0, -180.0, - -180.0, -180.0, -180.0, -180.0, -178.5, -176.0, -172.7), + -180.0, -180.0, -180.0, -180.0, -180.0, -180.0, -180.0, -180.0, -180.0, -180.0, -180.0), ), } DESCRIPTIONS = { @@ -764,6 +765,10 @@ def collision_lines(name, center, size, radius=None, axis=2): def write_urdf(model, source, shapes): + if not HULLS_PATH.exists(): + raise ValueError(f'{HULLS_PATH.name} is missing; run scripts/cad/exact_limits.py with ' + f'--hulls {HULLS_PATH.relative_to(REPOSITORY).as_posix()}') + hulls = json.loads(HULLS_PATH.read_text(encoding='utf-8')) angles = ', '.join(f'{name}={math.degrees(model.cad_angles[name]):.2f}' for name, *_ in JOINTS) lines = [ '', @@ -771,7 +776,7 @@ def write_urdf(model, source, shapes): ' Do not edit by hand; re-export the SolidWorks assembly and re-run the script.', ' Joint zero is the upright pose from the mechanical fk.py (links along +Z,', f' pitch about +Y). Saved CAD pose in degrees {angles}.', - ' Each pitch joint stops about 1 degree before two parts touch. Each part has a', + ' Joint limits are where CAD parts touch (scripts/cad/exact_limits.py). Each part has a', ' collision box, or a cylinder where it is round about a joint axis, with a box for', ' any side of it that is not. Effort and velocity are placeholders for display. -->', ''] @@ -816,14 +821,24 @@ def write_urdf(model, source, shapes): f' ', ' ', ' '] for obstacle, (start, step, upper, lower) in ELBOW_FOLDS.items(): lines += [ f' '] + lines += [ + ' '] + for link, points in hulls.items(): + values = [f'{value:g}' for point in points for value in point] + rows = [' '.join(values[i:i + 36]) for i in range(0, len(values), 36)] + lines += [f' ' lines += ['', ''] URDF_PATH.write_text('\n'.join(lines), encoding='utf-8') diff --git a/scripts/cad/exact_limits.py b/scripts/cad/exact_limits.py new file mode 100644 index 00000000..0f504ecd --- /dev/null +++ b/scripts/cad/exact_limits.py @@ -0,0 +1,273 @@ +#!/usr/bin/env python3 +"""Find exactly where the arm's CAD parts touch, and where the arm meets the ground. + + python3 scripts/cad/exact_limits.py build/cad/arm_export.json [--hulls scripts/cad/link_hulls.json] + +This needs numpy, scipy and python-fcl (pip install python-fcl); the build script does not. +After a CAD change, run this, copy the joint limits it prints into JOINTS in +build_arm_description.py, run joint_clearance.py for the ELBOW_FOLDS, and rebuild the URDF. + +Every CAD part, gearbox internals excepted (they are enclosed, and static CAD cannot model their +eccentric motion), becomes an FCL triangle mesh in its link frame. A joint turns from the upright +pose, every other joint at zero, and the links it carries move against the rest of the arm. Each +step turns no point of the moving parts further than the smallest gap, so no contact is stepped +over, and the contact is then bisected to under 0.001 degree on exact triangle distances. Parts +that already touch upright, such as bearing rings on their seats and meshing gears, turn on the +joint's own axis and are left out. The ground is the plane under the base (z = 0 in base_link), +and the lowest vertex of the moving parts is exact. + +A limit that holds in every pose comes from the parts that only that joint moves against each +other; where a contact also depends on another joint, the teleop collision check stops the arm +instead (ELBOW_FOLDS for the forearm, and the ground). --hulls writes each moving link's convex +hull in its link frame, which the URDF carries so the teleop check finds the lowest point of the +real parts rather than of their collision shapes. +""" + +import argparse +import importlib.util +import json +import math +from pathlib import Path + +import fcl +import numpy as np +from scipy.spatial import ConvexHull + +spec = importlib.util.spec_from_file_location( + 'build_arm_description', Path(__file__).resolve().with_name('build_arm_description.py')) +arm = importlib.util.module_from_spec(spec) +spec.loader.exec_module(arm) + +INTERNAL = ('discs-sweep', 'disc-bearing', 'loose_disc', 'inner_bearing', 'shaft-sweep', + 'NEMA23SHAFT', 'outer_ball_bearing', 'outer-ring-bearing', 'bearing_brace', + 'updatednema23bearingbrace', 'top-sweep') +TOUCH = 1e-6 # m: a gap this small is contact +MATED = 5e-5 # m: parts this close in the upright pose are mated +# Links the teleop check keeps off the ground: all but the base and the yaw stage, which turns +# only about the vertical. +HULL_LINKS = ('upper_arm_link', 'forearm_link', 'wrist_pitch_link', 'wrist_left_gear_link', + 'wrist_right_gear_link', 'wrist_roll_link') + + +def rotation(axis, angle): + return np.array(arm.rotation_about(axis, angle)) + + +def rpy(roll, pitch, yaw): + return rotation((0, 0, 1), yaw) @ rotation((0, 1, 0), pitch) @ rotation((1, 0, 0), roll) + + +class Robot: + """CAD parts as FCL meshes in their link frames, and the joint tree.""" + + def __init__(self, export_path): + export = arm.Export(export_path) + self.model = arm.Model(export, arm.check_components(export)) + self.parts = [] # (link, name, hull vertices, FCL mesh) + self.points = {} # link -> every vertex in its link frame, internals included + for link, names in self.model.assigned.items(): + for name in sorted(names): + component = export.components[name] + pose = (self.model.frames[link].inverse() * self.model.to_base + * arm.solidworks_pose(component['transform'])) + turn, origin = np.array(pose.rotation), np.array(pose.origin) + vertices, triangles, offset = [], [], 0 + for face in component['faces']: + v, t = export.face_arrays(face) + v = np.frombuffer(v.tobytes(), dtype=np.float32).reshape(-1, 3).astype(float) + vertices.append(v) + triangles.append(np.frombuffer(t.tobytes(), dtype=np.int32).reshape(-1, 3) + + offset) + offset += len(v) + if not vertices: + continue + v = np.vstack(vertices) @ turn.T + origin + self.points.setdefault(link, []).append(v) + if name.split('/')[-1].startswith(INTERNAL): + continue + t = np.vstack(triangles) + mesh = fcl.BVHModel() + mesh.beginModel(len(v), len(t)) + mesh.addSubModel(v, t) + mesh.endModel() + self.parts.append((link, name, v[ConvexHull(v).vertices], mesh)) + self.joints = {joint['name']: joint for joint in self.model.joints} + + def poses(self, q): + poses = {'base_link': (np.eye(3), np.zeros(3))} + for joint in self.model.joints: + angle = q.get(joint['name'], 0.0) + if joint['mimic']: + angle = joint['mimic'][1] * q.get(joint['mimic'][0], 0.0) + r, o = poses[joint['parent']] + poses[joint['child']] = (r @ rpy(*joint['rpy']) @ rotation(joint['axis'], angle), + o + r @ np.array(joint['xyz'])) + return poses + + def subtree(self, link): + found = {link} + for joint in self.model.joints: + if joint['parent'] in found: + found.add(joint['child']) + return found + + def hull(self, link): + points = np.vstack(self.points[link]) + return points[ConvexHull(points).vertices] + + +class Sweep: + """One joint turning from the upright pose, some links against others.""" + + def __init__(self, robot, joint, moving=None, fixed=None): + self.robot, self.name = robot, joint + moving = moving or robot.subtree(robot.joints[joint]['child']) + self.moving = [part for part in robot.parts if part[0] in moving] + self.fixed = [part for part in robot.parts + if part[0] not in moving and (fixed is None or part[0] in fixed)] + self.objects = {id(part): fcl.CollisionObject(part[3], fcl.Transform()) + for part in robot.parts} + self.pairs = [(m, f) for m in self.moving for f in self.fixed] + self.place(0.0) + self.mated = [(m, f) for bound, m, f in self._candidates() + if bound <= MATED and self._distance(m, f) <= MATED] + mated = {(id(m), id(f)) for m, f in self.mated} + self.pairs = [(m, f) for m, f in self.pairs if (id(m), id(f)) not in mated] + info = robot.joints[joint] + r, o = robot.poses({})[info['parent']] + self.origin = o + r @ np.array(info['xyz']) + self.axis = r @ rpy(*info['rpy']) @ np.array(info['axis'], dtype=float) + # No moving point is further than this from the joint axis. + self.reach = max(float(np.linalg.norm( + (part[2] - self.origin) - np.outer((part[2] - self.origin) @ self.axis, self.axis), + axis=1).max()) for part in self.moving) + + def place(self, angle): + poses = self.robot.poses({self.name: angle}) + self.world, self.boxes = {}, {} + for part in self.robot.parts: + r, o = poses[part[0]] + self.objects[id(part)].setTransform(fcl.Transform(r, o)) + points = part[2] @ r.T + o + self.world[id(part)] = points + self.boxes[id(part)] = (points.min(axis=0), points.max(axis=0)) + + def _candidates(self): + """Pairs with a lower bound on their gap from their boxes, nearest first.""" + found = [] + for m, f in self.pairs: + (a0, a1), (b0, b1) = self.boxes[id(m)], self.boxes[id(f)] + found.append((float(np.linalg.norm(np.maximum(0.0, np.maximum(a0 - b1, b0 - a1)))), + m, f)) + found.sort(key=lambda item: item[0]) + return found + + def _distance(self, m, f): + return fcl.distance(self.objects[id(m)], self.objects[id(f)], fcl.DistanceRequest(), + fcl.DistanceResult()) + + def gap(self): + best, pair = math.inf, None + for bound, m, f in self._candidates(): + if bound >= best: + break + distance = self._distance(m, f) + if distance < best: + best, pair = distance, (m, f) + return best, pair + + def contact(self, sign, limit=360.0): + """Degrees turned before two parts touch, with the parts, or (None, None).""" + angle = clear = 0.0 + while angle < limit: + self.place(sign * math.radians(angle)) + gap, pair = self.gap() + if gap <= TOUCH: + break + clear = angle + angle += max(math.degrees(gap / self.reach), 0.002) + else: + return None, None + low, high = clear, angle + while high - low > 0.0005: + middle = (low + high) / 2 + self.place(sign * math.radians(middle)) + if self.gap()[0] <= TOUCH: + high = middle + else: + low = middle + self.place(sign * math.radians(high)) + m, f = self.gap()[1] + return low, f'{m[0]}: {m[1]} -> {f[0]}: {f[1]}' + + def lowest(self): + return min(float(self.world[id(part)][:, 2].min()) for part in self.moving) + + def ground(self, sign, limit=360.0, step=0.25): + """Degrees turned before the moving parts reach z = 0, or None.""" + angle = 0.0 + while angle < limit: + angle += step + self.place(sign * math.radians(angle)) + if self.lowest() <= 0.0: + low, high = angle - step, angle + while high - low > 0.0005: + middle = (low + high) / 2 + self.place(sign * math.radians(middle)) + if self.lowest() <= 0.0: + high = middle + else: + low = middle + return low + return None + + +def report(sweep, title): + print(title) + if sweep.mated: + print(' left out, mated upright: ' + '; '.join( + f'{m[1].split("/")[-1]} on {f[1].split("/")[-1]}' for m, f in sweep.mated)) + found = [] + for sign in (1, -1): + angle, parts = sweep.contact(sign) + floor = sweep.ground(sign) + side = '+' if sign > 0 else '-' + touch = 'nothing touches in a full turn' if angle is None else f'{sign * angle:+.3f}' + meets = '' if floor is None else f', the ground at {sign * floor:+.3f}' + print(f' {side}: {touch}{meets}') + if parts: + print(f' {parts}') + found.append((angle, floor)) + return found + + +def main(): + parser = argparse.ArgumentParser(description=__doc__.splitlines()[0]) + parser.add_argument('export', type=Path, help='JSON written by export_solidworks_assembly') + parser.add_argument('--hulls', type=Path, help='write the moving links\' hulls here') + args = parser.parse_args() + robot = Robot(args.export) + + print('Each joint from the upright pose, the links it carries against the rest of the arm:') + for name in ('joint_1', 'joint_2', 'joint_3', 'joint_4', 'joint_5'): + report(Sweep(robot, name), f'{name}:') + print('Contacts that no other joint changes:') + report(Sweep(robot, 'joint_2', moving={'upper_arm_link'}, + fixed={'base_link', 'shoulder_link'}), + 'joint_2, the upper arm against the base and the yaw stage:') + report(Sweep(robot, 'joint_3', fixed={'upper_arm_link'}), + 'joint_3, the forearm and wrist against the upper arm:') + stops = report(Sweep(robot, 'joint_4', fixed={'forearm_link'}), + 'joint_4, the wrist against the forearm:') + upper, lower = (math.floor(angle * 100) / 100 for angle, _ in stops) + print(f' wrist pitch limits ({-lower:.2f}, {upper:.2f})') + + if args.hulls: + hulls = {link: [[round(float(value), 5) for value in point] + for point in robot.hull(link)] for link in HULL_LINKS} + args.hulls.write_text(json.dumps(hulls, separators=(',', ':')) + '\n', encoding='utf-8') + print(f'Wrote {sum(map(len, hulls.values()))} hull points to {args.hulls}') + + +if __name__ == '__main__': + main() diff --git a/scripts/cad/joint_clearance.py b/scripts/cad/joint_clearance.py index 61077772..36018c27 100644 --- a/scripts/cad/joint_clearance.py +++ b/scripts/cad/joint_clearance.py @@ -1,26 +1,19 @@ #!/usr/bin/env python3 -"""Find how far the arm's pitch joints turn before two CAD parts touch. +"""Find how far the elbow folds before the forearm meets the shoulder or the base. python3 scripts/cad/joint_clearance.py build/cad/arm_export.json -After a CAD change, copy the printed limits into JOINTS and ELBOW_FOLDS in -build_arm_description.py and rebuild the URDF. This script needs numpy and -scipy; the build script does not. - -Each part's SolidWorks tessellation is sampled densely in its link frame, with -outward normals. For a joint, the links it carries turn as one body against -the rest of the arm. A sample that ends up more than PENETRATION inside a part -of the other body is a clash once a winding number and the exact distance to -that part's triangles confirm it. Samples already inside in the upright pose -are press fits and are ignored. Gearbox internals are skipped: they are -enclosed, and static CAD cannot model their eccentric motion. Base yaw and -wrist roll turn round parts in round housings, so cabling sets their range. - -How far the elbow folds before the forearm meets the shoulder or the base also -depends on the shoulder angle, so that is tabulated against it. The base is -round, so its gap is measured in distance from the yaw axis and height, which -is the gap at the nearest yaw. The collision shapes are too coarse for these -pairs, and the teleop collision check uses the tables. +After a CAD change, run scripts/cad/exact_limits.py for the joint limits first, then copy the +ELBOW_FOLDS this prints into build_arm_description.py and rebuild the URDF. This script needs +numpy and scipy; the build script does not. + +Each part's SolidWorks tessellation is sampled densely in its link frame. Gearbox internals are +skipped: they are enclosed, and static CAD cannot model their eccentric motion. How far the +elbow folds before the forearm meets the shoulder or the base depends on the shoulder angle, so +that is tabulated against it, up to the samples' first contact (CONTACT). The base is round, so +its gap is measured in distance from the yaw axis and height, which is the gap at the nearest +yaw. The collision shapes are too coarse for these pairs, and the teleop collision check uses +the tables. """ import argparse @@ -33,18 +26,13 @@ from scipy.spatial import cKDTree DENSITY = 2.0e6 # samples per square metre of surface -PENETRATION = 0.0005 # m inside another part that counts as a clash -GROWTH = 0.00025 # m deeper than in the upright pose -SEARCH = 0.004 # m -NEIGHBOURS = 6 -CONTACT = 0.001 # m between forearm and shoulder or base samples that counts as touching +CONTACT = 0.0005 # m between forearm and shoulder or base samples that counts as touching FAR = 0.25 # m beyond which a fold's gap is only bounded SPARSE = 0.004 # m cells of the samples that find a fold's closest region -MARGIN = 1.0 # degrees kept clear of contact +MARGIN = 0.0 # degrees kept clear of contact: the tables stop where the parts touch INTERNAL = ('discs-sweep', 'disc-bearing', 'loose_disc', 'inner_bearing', 'shaft-sweep', 'NEMA23SHAFT', 'outer_ball_bearing', 'outer-ring-bearing', 'bearing_brace', 'updatednema23bearingbrace', 'top-sweep') -PITCH_JOINTS = ('joint_2', 'joint_3', 'joint_4') # The link that folds, what it folds against, the joint tabulated, the joint across and its step # in degrees. The base's limit bends sharply near some shoulder angles, so it needs finer steps. FOLDS = (('forearm_link', 'shoulder_link', 'joint_3', 'joint_2', 5.0), @@ -137,162 +125,6 @@ def radial(points): return np.column_stack((np.hypot(points[:, 0], points[:, 1]), points[:, 2])) -def inside(point, solids): - """True if point is inside a closed body (generalized winding number above one half).""" - for tri in solids: - a, b, c = tri[:, 0] - point, tri[:, 1] - point, tri[:, 2] - point - la, lb, lc = (np.linalg.norm(x, axis=1) for x in (a, b, c)) - numerator = np.einsum('ij,ij->i', a, np.cross(b, c)) - denominator = (la * lb * lc + np.einsum('ij,ij->i', a, b) * lc - + np.einsum('ij,ij->i', a, c) * lb + np.einsum('ij,ij->i', b, c) * la) - if abs(np.arctan2(numerator, denominator).sum() / (2.0 * math.pi)) > 0.5: - return True - return False - - -def _segment(p, a, b): - ab = b - a - t = np.clip(np.einsum('ij,ij->i', p - a, ab) - / np.maximum(np.einsum('ij,ij->i', ab, ab), 1e-30), 0.0, 1.0) - return np.linalg.norm(p - (a + t[:, None] * ab), axis=1) - - -def depth(point, solids): - """How far point is inside the bodies (distance to the nearest triangle), or 0 outside.""" - if not inside(point, solids): - return 0.0 - best = math.inf - for tri in solids: - a, b, c = tri[:, 0], tri[:, 1], tri[:, 2] - n = np.cross(b - a, c - a) - length = np.linalg.norm(n, axis=1) - ok = length > 1e-15 - n = n / np.where(ok, length, 1.0)[:, None] - height = np.einsum('ij,ij->i', point - a, n) - v0, v1, v2 = c - a, b - a, point - height[:, None] * n - a - d00, d01, d11 = (np.einsum('ij,ij->i', x, y) for x, y in ((v0, v0), (v0, v1), (v1, v1))) - d02, d12 = np.einsum('ij,ij->i', v0, v2), np.einsum('ij,ij->i', v1, v2) - det = d00 * d11 - d01 * d01 - with np.errstate(divide='ignore', invalid='ignore'): - u = (d11 * d02 - d01 * d12) / det - v = (d00 * d12 - d01 * d02) / det - within = ok & (u >= 0) & (v >= 0) & (u + v <= 1) - p = np.broadcast_to(point, a.shape) - edges = np.minimum(np.minimum(_segment(p, a, b), _segment(p, b, c)), _segment(p, c, a)) - best = min(best, float(np.where(within, np.abs(height), edges).min())) - return best - - -def signed(tree, normals, points): - """Signed distance to the nearest samples (negative inside), and the nearest sample.""" - distance, index = tree.query(points, k=NEIGHBOURS, distance_upper_bound=SEARCH, workers=-1) - near = np.flatnonzero(np.isfinite(distance[:, NEIGHBOURS // 2])) - value = np.full(len(points), np.inf) - if len(near): - ok = np.isfinite(distance[near]) - safe = np.where(ok, index[near], 0) - s = np.einsum('ijk,ijk->ij', points[near][:, None, :] - tree.data[safe], normals[safe]) - inner = np.nanmedian(np.where(ok, s, np.nan), axis=1) < 0.0 - value[near] = np.where(inner, -distance[near, 0], distance[near, 0]) - return value, index[:, 0] - - -class Sweep: - """One joint turning from the upright pose, its links against the rest of the arm.""" - - def __init__(self, robot, name): - self.robot, self.joint = robot, robot.joint(name) - self.axis = np.array(self.joint['axis']) - moving = robot.subtree(self.joint['child']) - poses = robot.poses({}) - self.child0 = poses[self.joint['child']] - self.fixed = self._gather([link for link in robot.parts if link not in moving], poses, None) - # The moving links are kept in the child frame, where they never move. - self.moving = self._gather([link for link in robot.parts if link in moving], poses, - self.child0) - self.start = self._depths(0.0) - - def _gather(self, links, poses, frame): - """Points, normals, labels and bodies in the base frame, or in frame = (rotation, origin).""" - points, normals, labels, solids = [], [], [], {} - for link in links: - r, o = poses[link] - if frame is not None: - r, o = frame[0].T @ r, frame[0].T @ (o - frame[1]) - for name, local, n, bodies in self.robot.parts[link]: - points.append(local @ r.T + o) - normals.append(n @ r.T) - labels += [f'{link}: {name}'] * len(local) - solids[f'{link}: {name}'] = [tri @ r.T + o for tri in bodies] - points = np.vstack(points) - return {'points': points, 'normals': np.vstack(normals), 'labels': np.array(labels), - 'solids': solids, 'tree': cKDTree(points)} - - def child_pose(self, angle): - return self.robot.poses({self.joint['name']: angle})[self.joint['child']] - - def _depths(self, angle): - r, o = self.child_pose(angle) - moving_world = self.moving['points'] @ r.T + o - fixed_local = (self.fixed['points'] - o) @ r - into_fixed = signed(self.fixed['tree'], self.fixed['normals'], moving_world) - into_moving = signed(self.moving['tree'], self.moving['normals'], fixed_local) - return into_fixed, into_moving, moving_world, fixed_local - - def _radius(self, local): - """Distance of a point in the child frame from the joint axis.""" - return float(np.linalg.norm(local - self.axis * (local @ self.axis))) - - def clashes(self, angle): - """Return {(moving part, fixed part): (depth, radius)} at this angle, and the lowest - moving point. Radius is the clashing point's distance from the joint axis.""" - (into_fixed, fixed_index), (into_moving, moving_index), world, local = self._depths(angle) - r0, o0 = self.child0 - pairs = {} - - def add(pair, now, point): - if now > pairs.get(pair, (0.0, 0.0))[0]: - pairs[pair] = (now, self._radius(point)) - - for i in np.flatnonzero((into_fixed < -PENETRATION) & (self.start[0][0] >= -PENETRATION)): - pair = (self.moving['labels'][i], self.fixed['labels'][fixed_index[i]]) - solids = self.fixed['solids'][pair[1]] - now = depth(world[i], solids) - if now > PENETRATION and now - depth( - self.moving['points'][i] @ r0.T + o0, solids) > GROWTH: - add(pair, now, self.moving['points'][i]) - for i in np.flatnonzero((into_moving < -PENETRATION) & (self.start[1][0] >= -PENETRATION)): - pair = (self.moving['labels'][moving_index[i]], self.fixed['labels'][i]) - solids = self.moving['solids'][pair[0]] - now = depth(local[i], solids) - if now > PENETRATION and now - depth( - (self.fixed['points'][i] - o0) @ r0, solids) > GROWTH: - add(pair, now, local[i]) - return pairs, float(world[:, 2].min()) - - def first_contact(self, sign, step=1.0): - """Degrees turned in one direction when two parts first touch, the parts, and where - the arm meets the table (the plane under the base).""" - angle, table = 0.0, None - while angle < 181.0: - angle += step - pairs, lowest = self.clashes(sign * math.radians(angle)) - if table is None and lowest < 0.0: - table = angle - if pairs: - fine = angle - step - while fine < angle: - fine += 0.05 - pairs, _ = self.clashes(sign * math.radians(fine)) - if pairs: - break - # Back off by the angle that took the deepest point that far in. - touch = fine - max(math.degrees(inside_by / max(radius, 1e-3)) - for inside_by, radius in pairs.values()) - return touch, sorted(pairs), table - return None, [], table - - class Fold: """How far one link folds against another, for each angle of the joint between them.""" @@ -357,28 +189,16 @@ def main(): args = parser.parse_args() robot = Arm(args.export) - print('Pitch joints from the upright pose (base yaw and wrist roll do not touch):') - for name in PITCH_JOINTS: - sweep = Sweep(robot, name) - found = [] - for sign in (1, -1): - angle, pairs, table = sweep.first_contact(sign) - found.append(angle) - where = f'touches at {sign * angle:+.2f}' if angle is not None else 'clear to 181' - meets = f', meets the table at {sign * table:+.0f}' if table is not None else '' - print(f' {name} {"+-"[sign < 0]}: {where}{meets}', flush=True) - for moving, fixed in pairs[:3]: - print(f' {moving} -> {fixed}') - upper, lower = (math.floor(angle - MARGIN) if angle is not None else 180 for angle in found) - print(f' limits ({-lower:.1f}, {upper:.1f})') - tables = {} for link, obstacle, joint, across, step in FOLDS: fold = Fold(robot, link, obstacle, joint, across) low, high = robot.joint(across)['limits'] - print(f'Elbow fold against {obstacle}, {MARGIN:.0f} degree short of contact:') + # The table ends exactly at the other joint's limits, in steps no longer than step. + count = math.ceil((high - low) / step - 1e-9) + step = (high - low) / count + print(f'Elbow fold against {obstacle}, until contact:') upper, lower = [], [] - for index in range(int(round((high - low) / step)) + 1): + for index in range(count + 1): shoulder = low + index * step values = [] for sign in (1, -1): @@ -393,7 +213,7 @@ def main(): print('ELBOW_FOLDS = {') for obstacle, (low, step, upper, lower) in tables.items(): print(f" '{obstacle}': (") - print(f' {low:.1f}, {step:.1f},') + print(f' {low!r}, {step!r},') for values in (upper, lower): print(textwrap.fill(', '.join(f'{value:.1f}' for value in values) + '),', width=99, initial_indent=' (', subsequent_indent=' ')) diff --git a/scripts/cad/link_hulls.json b/scripts/cad/link_hulls.json new file mode 100644 index 00000000..1dfef24b --- /dev/null +++ b/scripts/cad/link_hulls.json @@ -0,0 +1 @@ +{"upper_arm_link":[[-0.02403,0.1001,-0.02024],[-0.02486,0.09987,-0.01984],[-0.02403,0.13273,0.01446],[-0.02486,0.10657,-0.01547],[-0.02486,0.11282,-0.01048],[-0.02403,0.10684,-0.01585],[-0.02403,0.11313,-0.01084],[-0.02403,0.11892,-0.00524],[-0.02486,0.12836,0.00771],[-0.02403,0.12414,0.00087],[-0.02486,0.13231,0.01467],[-0.02403,0.12876,0.00746],[-0.02309,0.11325,-0.01097],[-0.02309,0.11905,-0.00537],[-0.02309,0.12428,0.00076],[-0.02486,0.13544,0.02161],[-0.02486,0.13544,0.02162],[-0.02162,0.09317,-0.02592],[-0.02235,0.09316,-0.0254],[-0.01844,0.09398,-0.02742],[-0.01557,0.09323,-0.02939],[-0.01538,0.094,-0.02898],[-0.0122,0.09401,-0.03026],[-0.01025,0.09326,-0.03136],[-0.01012,0.09402,-0.03092],[-0.00686,0.09328,-0.03216],[-0.00678,0.09403,-0.03171],[-0.00345,0.09328,-0.03264],[-0.00341,0.09403,-0.03218],[-2e-05,0.09329,-0.0328],[-2e-05,0.09404,-0.03234],[0.00229,0.09404,-0.03227],[0.00231,0.09328,-0.03273],[0.0057,0.09403,-0.0319],[0.00577,0.09328,-0.03235],[0.00905,0.09402,-0.03121],[0.01232,0.09401,-0.03022],[0.01247,0.09325,-0.03065],[0.01423,0.09401,-0.02949],[0.01739,0.09399,-0.028],[0.0176,0.09321,-0.02839],[0.02062,0.09318,-0.0266],[-0.02351,0.09314,-0.02451],[-0.02486,0.09313,-0.02339],[0.02486,0.09313,-0.02339],[0.02349,0.09314,-0.02453],[0.02403,0.13273,0.01446],[0.02486,0.13231,0.01467],[0.02486,0.13544,0.02161],[0.02403,0.1001,-0.02024],[0.02486,0.09987,-0.01984],[0.02486,0.12377,0.00116],[0.02403,0.12876,0.00746],[0.02486,0.11858,-0.00492],[0.02403,0.12414,0.00087],[0.02403,0.11892,-0.00524],[0.02486,0.10657,-0.01547],[0.02403,0.11313,-0.01084],[0.02403,0.10684,-0.01585],[0.02309,0.11325,-0.01097],[0.02309,0.11905,-0.00537],[0.02309,0.12428,0.00076],[0.02486,0.09312,-0.02339],[-0.00036,0.1442,0.02067],[0.02162,0.13791,0.02158],[0.01861,0.13978,0.02155],[0.0184,0.1394,0.02071],[0.01548,0.14135,0.02152],[0.0153,0.14095,0.0207],[0.01368,0.14209,0.02151],[0.01208,0.14221,0.02069],[0.00999,0.1433,0.0215],[0.00988,0.14288,0.02068],[0.00832,0.14372,0.02149],[0.00649,0.14364,0.02067],[0.00656,0.14407,0.02148],[0.00311,0.14451,0.02148],[0.00307,0.14408,0.02067],[-0.00275,0.1441,0.02067],[-0.0062,0.14369,0.02067],[-0.00278,0.14454,0.02148],[-0.00958,0.14296,0.02068],[-0.01288,0.14193,0.02069],[-0.01492,0.14112,0.0207],[-0.01808,0.13958,0.02071],[-0.01509,0.14152,0.02152],[-0.01829,0.13996,0.02154],[-0.02132,0.13812,0.02157],[0.02486,0.13544,0.02162],[-0.03881,0.10712,0.01503],[-0.03881,0.11036,0.01977],[-0.03881,0.11316,0.02479],[-0.03881,0.11548,0.03004],[-0.03881,0.1173,0.03548],[-0.03881,0.11862,0.04108],[-0.03881,0.11941,0.04676],[-0.03881,0.11968,0.0525],[-0.03709,0.10296,0.00263],[-0.03709,0.10737,0.00704],[-0.03709,0.11135,0.01183],[-0.03709,0.11488,0.01697],[-0.03709,0.11791,0.02242],[-0.03709,0.12043,0.02812],[-0.03709,0.12241,0.03403],[-0.03709,0.12384,0.0401],[-0.03709,0.1247,0.04627],[-0.03709,0.12498,0.0525],[-0.03464,0.10119,-0.00536],[-0.03464,0.10634,-0.00108],[-0.03464,0.11108,0.00366],[-0.03464,0.11536,0.00881],[-0.03464,0.11914,0.01433],[-0.03464,0.1224,0.02018],[-0.03464,0.1251,0.02631],[-0.03464,0.12723,0.03266],[-0.03464,0.12877,0.03918],[-0.03464,0.12969,0.04581],[-0.03696,0.12531,0.0525],[-0.03464,0.13,0.0525],[-0.03152,0.0981,-0.01307],[-0.03152,0.10398,-0.00905],[-0.03152,0.10946,-0.0045],[-0.03152,0.1145,0.00054],[-0.03152,0.11905,0.00602],[-0.03152,0.12307,0.0119],[-0.03152,0.12654,0.01812],[-0.03152,0.12942,0.02464],[-0.03152,0.13168,0.03139],[-0.03152,0.13331,0.03833],[-0.03152,0.1343,0.04538],[-0.02779,0.09373,-0.02025],[-0.02779,0.10029,-0.0166],[-0.02779,0.10648,-0.01236],[-0.02779,0.11225,-0.00756],[-0.02779,0.11756,-0.00225],[-0.02779,0.12236,0.00352],[-0.02779,0.1266,0.00971],[-0.02779,0.13025,0.01627],[-0.02779,0.13329,0.02314],[-0.02779,0.13567,0.03026],[-0.02779,0.13739,0.03757],[-0.02779,0.13843,0.045],[-0.02779,0.13877,0.0525],[-0.02351,0.13663,0.02184],[-0.02351,0.13912,0.02928],[-0.02351,0.14092,0.03691],[-0.02351,0.142,0.04467],[-0.02351,0.14236,0.0525],[-0.01878,0.14197,0.02847],[-0.01878,0.14382,0.03636],[-0.01878,0.14494,0.0444],[-0.01368,0.09004,-0.0315],[-0.01368,0.14415,0.02785],[-0.01368,0.14605,0.03595],[-0.01368,0.1472,0.04419],[-0.01531,0.14696,0.0525],[-0.00832,0.0906,-0.03294],[-0.00832,0.14563,0.02743],[-0.00832,0.14757,0.03566],[-0.00832,0.14874,0.04405],[-0.00832,0.14913,0.0525],[-0.00279,0.09088,-0.03366],[-0.00279,0.14638,0.02721],[-0.00279,0.14833,0.03552],[-0.00279,0.14951,0.04397],[-0.0078,0.14923,0.0525],[0.00279,0.09088,-0.03366],[0.00279,0.14638,0.02721],[0.00279,0.14833,0.03552],[0.00279,0.14951,0.04397],[-0.0,0.15,0.0525],[0.00832,0.0906,-0.03294],[0.00832,0.14563,0.02743],[0.00832,0.14757,0.03566],[0.00832,0.14874,0.04405],[0.01368,0.09004,-0.0315],[0.01368,0.14415,0.02785],[0.01368,0.14605,0.03595],[0.01368,0.1472,0.04419],[0.01368,0.14759,0.0525],[0.01878,0.14197,0.02847],[0.01878,0.14382,0.03636],[0.01878,0.14494,0.0444],[0.01878,0.14532,0.0525],[0.02351,0.13912,0.02928],[0.02351,0.14092,0.03691],[0.02351,0.142,0.04467],[0.02222,0.14326,0.0525],[0.02779,0.13329,0.02314],[0.02779,0.13567,0.03026],[0.02779,0.13739,0.03757],[0.02779,0.13843,0.045],[0.02779,0.13877,0.0525],[0.02779,0.09373,-0.02025],[0.02779,0.10029,-0.0166],[0.03152,0.0981,-0.01307],[0.02779,0.10648,-0.01236],[0.03152,0.10398,-0.00905],[0.02779,0.11225,-0.00756],[0.03152,0.10946,-0.0045],[0.02779,0.11756,-0.00225],[0.03152,0.1145,0.00054],[0.02779,0.12236,0.00352],[0.03152,0.11905,0.00602],[0.02779,0.1266,0.00971],[0.03152,0.12307,0.0119],[0.02779,0.13025,0.01627],[0.03152,0.12654,0.01812],[0.03152,0.12942,0.02464],[0.03152,0.13168,0.03139],[0.03152,0.13331,0.03833],[0.03152,0.1343,0.04538],[0.02828,0.13828,0.0525],[0.03152,0.13463,0.0525],[0.03464,0.10119,-0.00536],[0.03464,0.10634,-0.00108],[0.03464,0.11108,0.00366],[0.03464,0.11536,0.00881],[0.03464,0.11914,0.01433],[0.03464,0.1224,0.02018],[0.03464,0.1251,0.02631],[0.03464,0.12723,0.03266],[0.03464,0.12877,0.03918],[0.03464,0.12969,0.04581],[0.03326,0.13222,0.0525],[0.03464,0.13,0.0525],[0.03709,0.10296,0.00263],[0.03709,0.10737,0.00704],[0.03709,0.11135,0.01183],[0.03709,0.11488,0.01697],[0.03709,0.11791,0.02242],[0.03709,0.12043,0.02812],[0.03709,0.12241,0.03403],[0.03709,0.12384,0.0401],[0.03709,0.1247,0.04627],[0.03709,0.12498,0.0525],[0.03881,0.10712,0.01503],[0.03881,0.11036,0.01977],[0.03881,0.11316,0.02479],[0.03881,0.11548,0.03004],[0.03881,0.1173,0.03548],[0.03881,0.11862,0.04108],[0.03881,0.11941,0.04676],[0.03923,0.1178,0.0525],[0.02486,0.11282,-0.01048],[0.02486,0.12836,0.00771],[0.02351,0.13663,0.02184],[0.02231,0.13743,0.02158],[-0.00037,0.14464,0.02148],[-0.00628,0.14412,0.02148],[-0.00832,0.14372,0.02149],[-0.00969,0.14338,0.02149],[-0.01303,0.14234,0.02151],[-0.02418,0.13601,0.02161],[-0.02486,0.12377,0.00116],[-0.02486,0.11858,-0.00492],[-0.02486,0.09312,-0.02339],[-0.01866,0.0932,-0.0278],[-0.01235,0.09325,-0.03069],[0.00916,0.09327,-0.03165],[0.0144,0.09324,-0.0299],[0.01222,0.14262,0.02151],[-0.01878,0.14532,0.0525],[-0.02222,0.14326,0.0525],[-0.03152,0.13463,0.0525],[-0.02828,0.13828,0.0525],[-0.03326,0.13222,0.0525],[-0.03923,0.1178,0.0525],[-0.01368,0.14759,0.0525],[-0.00279,0.1499,0.0525],[0.00279,0.1499,0.0525],[0.00832,0.14913,0.0525],[0.0078,0.14923,0.0525],[0.01531,0.14696,0.0525],[0.02351,0.14236,0.0525],[0.03696,0.12531,0.0525],[0.03881,0.11968,0.0525],[0.0525,0.0425,0.0],[-0.0525,0.0425,-0.0],[-0.0517,0.0425,-0.00912],[-0.0524,0.0425,-0.00323],[-0.05003,0.0425,-0.01592],[-0.04769,0.0425,-0.02194],[-0.0409,0.0425,-0.03291],[-0.04464,0.0425,-0.02764],[-0.04022,0.0425,-0.03375],[-0.02625,0.0425,-0.04547],[-0.03164,0.0425,-0.0419],[-0.00912,0.0425,-0.0517],[-0.00162,0.0425,-0.05248],[0.0,0.0425,-0.0525],[0.00912,0.0425,-0.0517],[0.00484,0.0425,-0.05228],[0.01123,0.0425,-0.05128],[0.02625,0.0425,-0.04547],[0.0234,0.0425,-0.047],[0.03375,0.0425,-0.04022],[0.03416,0.0425,-0.03987],[0.04547,0.0425,-0.02625],[0.04285,0.0425,-0.03033],[0.0517,0.0425,-0.00912],[0.05091,0.0425,-0.01281],[0.0525,0.0325,0.0],[-0.0525,0.0325,-0.0],[-0.0517,0.0325,-0.00912],[-0.04933,0.0325,-0.01796],[-0.04547,0.0325,-0.02625],[-0.01796,0.0325,-0.04933],[0.04547,0.0325,-0.02625],[0.04933,0.0325,-0.01796],[0.0517,0.0325,-0.00912],[-0.02625,0.0325,-0.04547],[0.03375,0.0325,-0.04022],[0.0,0.0325,-0.0525],[0.00912,0.0325,-0.0517],[0.04895,0.0425,-0.01897],[0.04933,0.0425,-0.01796],[0.04022,0.0325,-0.03375],[0.0388,0.0425,-0.03537],[0.04022,0.0425,-0.03375],[0.029,0.0425,-0.04376],[0.02625,0.0325,-0.04547],[0.01796,0.0325,-0.04933],[0.01745,0.0425,-0.04952],[0.01796,0.0425,-0.04933],[-0.00912,0.0325,-0.0517],[-0.01437,0.0425,-0.0505],[-0.02046,0.0425,-0.04835],[-0.01796,0.0425,-0.04933],[0.04625,0.0425,-0.02484],[-0.03375,0.0325,-0.04022],[-0.03375,0.0425,-0.04022],[-0.03655,0.0425,-0.03769],[-0.04022,0.0325,-0.03375],[-0.04547,0.0425,-0.02625],[-0.04933,0.0425,-0.01796],[-0.05161,0.0425,-0.00965],[0.00058,0.0401,-0.0525],[0.00109,0.0398,-0.05249],[0.00058,0.0369,-0.0525],[0.00109,0.0372,-0.05249],[0.00147,0.03765,-0.05248],[-0.00058,0.0369,-0.0525],[-0.00109,0.0372,-0.05249],[-0.00147,0.03765,-0.05248],[-0.00167,0.0382,-0.05247],[-0.00167,0.0388,-0.05247],[-0.00805,0.0425,-0.05188],[-0.00109,0.0398,-0.05249],[-0.00058,0.0401,-0.0525],[-0.00147,0.03935,-0.05248],[0.0521,0.0425,0.00645],[0.05249,0.0398,0.00109],[0.05248,0.03935,0.00147],[0.05247,0.0388,0.00167],[0.05247,0.0382,0.00167],[0.0525,0.0369,0.00058],[0.05249,0.0372,0.00109],[0.05248,0.03765,0.00147],[0.0525,0.0369,-0.00058],[0.05248,0.03765,-0.00147],[0.05247,0.0382,-0.00167],[0.05247,0.0388,-0.00167],[0.0521,0.0425,-0.00645],[0.0525,0.0401,-0.00058],[0.05248,0.03935,-0.00147],[-0.0525,0.0401,-0.00058],[-0.05248,0.03935,-0.00147],[-0.05249,0.0398,-0.00109],[-0.0525,0.0369,-0.00058],[-0.05249,0.0372,-0.00109],[-0.05248,0.03765,-0.00147],[-0.05249,0.0372,0.00109],[-0.05247,0.0382,0.00167],[-0.05247,0.0388,0.00167],[-0.0524,0.0425,0.00323],[-0.05248,0.03935,0.00147],[-0.05249,0.0398,0.00109],[-0.0525,0.0401,0.00058],[0.05249,0.0372,-0.00109],[0.05249,0.0398,-0.00109],[0.0525,0.0401,0.00058],[-0.0525,0.0369,0.00058],[-0.05248,0.03765,0.00147],[-0.05247,0.0388,-0.00167],[-0.05247,0.0382,-0.00167],[0.00147,0.03935,-0.05248],[0.00167,0.0388,-0.05247],[0.00167,0.0382,-0.05247],[-0.02204,0.12975,0.15893],[-0.02252,0.12913,0.15929],[-0.01962,0.13105,0.15964],[-0.02055,0.13078,0.15906],[-0.01958,0.13105,0.15967],[-0.01895,0.13111,0.16023],[0.02208,0.12992,0.15861],[0.02176,0.13019,0.15857],[0.02118,0.13057,0.15866],[0.02042,0.1309,0.15901],[0.01948,0.13109,0.15972],[0.01981,0.13105,0.15944],[0.01916,0.1311,0.16002],[0.03978,0.07345,0.16689],[0.03978,0.07832,0.16522],[0.03978,0.08302,0.16311],[0.03978,0.08751,0.16058],[0.03978,0.09176,0.15766],[0.03978,0.09572,0.15436],[0.03978,0.09936,0.15072],[0.03978,0.10266,0.14676],[0.03978,0.10558,0.14251],[0.03978,0.10811,0.13802],[0.03978,0.11022,0.13332],[0.00832,0.08328,0.20042],[0.00771,0.08604,0.1997],[0.01368,0.08285,0.19895],[0.00941,0.08603,0.19931],[0.01276,0.08602,0.19829],[0.01602,0.08601,0.19697],[0.01878,0.08221,0.19677],[0.01916,0.086,0.19535],[0.02351,0.08138,0.19393],[0.02098,0.08639,0.19409],[0.02005,0.08608,0.19479],[0.02351,0.08867,0.19143],[0.02268,0.08781,0.19239],[0.02312,0.08866,0.19173],[0.02228,0.08731,0.19287],[0.02328,0.08917,0.19141],[0.02351,0.09571,0.18827],[0.02351,0.10244,0.18449],[0.02351,0.10879,0.18011],[0.03978,0.11189,0.12845],[0.03978,0.11311,0.12344],[0.03978,0.11388,0.11835],[0.03881,0.0695,0.17351],[0.03881,0.07499,0.17216],[0.03881,0.08034,0.17033],[0.03881,0.0855,0.16802],[0.03881,0.09042,0.16524],[0.03881,0.09508,0.16204],[0.03881,0.09942,0.15842],[0.03881,0.10342,0.15442],[0.03881,0.10704,0.15008],[0.03881,0.11024,0.14542],[0.03881,0.11302,0.1405],[0.03881,0.11533,0.13534],[0.03881,0.11716,0.12999],[0.03881,0.11851,0.1245],[0.03881,0.11935,0.11891],[0.03709,0.06446,0.17962],[0.03709,0.07053,0.17871],[0.03709,0.07649,0.17726],[0.03709,0.08229,0.17527],[0.03709,0.08789,0.17276],[0.03709,0.09323,0.16975],[0.03709,0.09829,0.16626],[0.03709,0.103,0.16234],[0.03709,0.10734,0.158],[0.03709,0.11126,0.15329],[0.03709,0.11475,0.14823],[0.03709,0.11776,0.14289],[0.03709,0.12027,0.13729],[0.03709,0.12226,0.13149],[0.03709,0.12371,0.12553],[0.02351,0.11472,0.17517],[0.02351,0.12017,0.16972],[0.02351,0.12511,0.16379],[0.03881,0.11967,0.11327],[0.03709,0.12462,0.11946],[0.03464,0.06498,0.18461],[0.03464,0.0715,0.18364],[0.03464,0.0779,0.18207],[0.03464,0.08413,0.17993],[0.03464,0.09015,0.17723],[0.03464,0.09589,0.174],[0.03464,0.10132,0.17026],[0.03464,0.10638,0.16604],[0.03464,0.11104,0.16138],[0.03464,0.11526,0.15632],[0.03464,0.119,0.15089],[0.03464,0.12223,0.14515],[0.03464,0.12493,0.13913],[0.03464,0.12707,0.1329],[0.03464,0.12864,0.1265],[0.03709,0.12498,0.11334],[0.03464,0.12961,0.11998],[0.03152,0.06546,0.18921],[0.03152,0.07239,0.18818],[0.03152,0.0792,0.18651],[0.03152,0.08583,0.18423],[0.03152,0.09223,0.18136],[0.03152,0.09834,0.17793],[0.03152,0.10411,0.17395],[0.03152,0.1095,0.16946],[0.03152,0.11446,0.1645],[0.03152,0.11895,0.15911],[0.03152,0.12293,0.15334],[0.03152,0.12636,0.14723],[0.03152,0.12923,0.14083],[0.03152,0.13151,0.1342],[0.03152,0.13318,0.12739],[0.03464,0.12999,0.1134],[0.03152,0.13421,0.12046],[0.02779,0.06588,0.19334],[0.02779,0.07319,0.19224],[0.02779,0.08037,0.19049],[0.02779,0.08736,0.18809],[0.02779,0.0941,0.18507],[0.02779,0.10054,0.18144],[0.02779,0.10662,0.17725],[0.02779,0.1123,0.17252],[0.02779,0.11752,0.1673],[0.02779,0.12225,0.16162],[0.02779,0.12644,0.15554],[0.02779,0.13007,0.1491],[0.02779,0.13309,0.14236],[0.02779,0.13549,0.13537],[0.02779,0.13724,0.12819],[0.03152,0.13462,0.11346],[0.02779,0.13834,0.12088],[0.02351,0.06625,0.19691],[0.02351,0.07388,0.19576],[0.02351,0.12949,0.15744],[0.02351,0.13327,0.15071],[0.02351,0.13643,0.14367],[0.02351,0.13893,0.13638],[0.02351,0.14076,0.12888],[0.02779,0.13877,0.11351],[0.02351,0.14191,0.12125],[0.01878,0.06656,0.19985],[0.01878,0.07445,0.19867],[0.00832,0.05864,0.20412],[-0.00832,0.05864,0.20412],[-0.03923,0.1178,0.1125],[-0.03881,0.11967,0.11327],[-0.03881,0.11968,0.1125],[-0.03709,0.12498,0.1125],[-0.03464,0.12999,0.1134],[-0.03709,0.12498,0.11334],[-0.03152,0.13462,0.11346],[-0.03326,0.13222,0.1125],[-0.02779,0.13877,0.11351],[-0.02351,0.14236,0.1125],[-0.01878,0.14531,0.11359],[-0.02351,0.14235,0.11355],[-0.01878,0.14532,0.1125],[-0.01531,0.14696,0.1125],[-0.01368,0.14758,0.11362],[-0.01368,0.14759,0.1125],[-0.00279,0.1499,0.11365],[-0.0078,0.14923,0.1125],[-0.00832,0.14912,0.11364],[-0.00279,0.1499,0.1125],[-0.0,0.15,0.1125],[0.00279,0.1499,0.11365],[0.00832,0.14912,0.11364],[0.00832,0.14913,0.1125],[0.01878,0.14531,0.11359],[0.01531,0.14696,0.1125],[0.01368,0.14758,0.11362],[0.02351,0.14235,0.11355],[0.02779,0.13877,0.1125],[0.02828,0.13828,0.1125],[0.03152,0.13463,0.1125],[0.03326,0.13222,0.1125],[0.03696,0.12531,0.1125],[0.03709,0.12498,0.1125],[0.03881,0.11968,0.1125],[0.01878,0.132,0.159],[0.01878,0.13591,0.15204],[0.01878,0.13918,0.14476],[0.01878,0.14177,0.13721],[0.01878,0.14367,0.12945],[0.01878,0.14485,0.12156],[0.01368,0.06679,0.20211],[0.01368,0.07489,0.20089],[0.01368,0.13392,0.1602],[0.01368,0.13794,0.15307],[0.01368,0.14129,0.14559],[0.01368,0.14395,0.13785],[0.01368,0.14589,0.12989],[0.01368,0.14711,0.12179],[0.00832,0.06695,0.20364],[0.00832,0.07519,0.2024],[0.00832,0.13523,0.16102],[0.00832,0.13931,0.15376],[0.00832,0.14272,0.14616],[0.00832,0.14542,0.13828],[0.00832,0.1474,0.13019],[0.00832,0.14864,0.12195],[0.00279,0.06703,0.20441],[0.00279,0.07534,0.20316],[0.00279,0.13588,0.16143],[0.00279,0.14,0.15411],[0.00279,0.14344,0.14644],[0.00279,0.14617,0.1385],[0.00279,0.14816,0.13034],[0.00279,0.14941,0.12203],[-0.00279,0.06703,0.20441],[0.00279,0.0835,0.20117],[-0.00279,0.07534,0.20316],[-0.00279,0.13588,0.16143],[-0.00279,0.14,0.15411],[-0.00279,0.14344,0.14644],[-0.00279,0.14617,0.1385],[-0.00279,0.14816,0.13034],[-0.00279,0.14941,0.12203],[-0.00832,0.06695,0.20364],[-0.00279,0.0835,0.20117],[-0.00832,0.07519,0.2024],[-0.00832,0.13523,0.16102],[-0.00832,0.13931,0.15376],[-0.00832,0.14272,0.14616],[-0.00832,0.14542,0.13828],[-0.00832,0.1474,0.13019],[-0.00832,0.14864,0.12195],[-0.01368,0.06679,0.20211],[-0.00832,0.08328,0.20042],[-0.01368,0.07489,0.20089],[-0.01368,0.13392,0.1602],[-0.01368,0.13794,0.15307],[-0.01368,0.14129,0.14559],[-0.01368,0.14395,0.13785],[-0.01368,0.14589,0.12989],[-0.01368,0.14711,0.12179],[-0.01878,0.06656,0.19985],[-0.01368,0.08285,0.19895],[-0.01878,0.07445,0.19867],[-0.01878,0.132,0.159],[-0.01878,0.13591,0.15204],[-0.01878,0.13918,0.14476],[-0.01878,0.14177,0.13721],[-0.01878,0.14367,0.12945],[-0.01878,0.14485,0.12156],[-0.02351,0.06625,0.19691],[-0.01878,0.08221,0.19677],[-0.02351,0.07388,0.19576],[-0.02351,0.12949,0.15744],[-0.02351,0.13327,0.15071],[-0.02351,0.13643,0.14367],[-0.02351,0.13893,0.13638],[-0.02351,0.14076,0.12888],[-0.02351,0.14191,0.12125],[-0.02779,0.06588,0.19334],[-0.02351,0.08138,0.19393],[-0.02779,0.07319,0.19224],[-0.02351,0.08867,0.19143],[-0.02779,0.08037,0.19049],[-0.02351,0.09571,0.18827],[-0.02779,0.08736,0.18809],[-0.02351,0.10244,0.18449],[-0.02779,0.0941,0.18507],[-0.02351,0.10879,0.18011],[-0.02779,0.10054,0.18144],[-0.02351,0.11472,0.17517],[-0.02779,0.10662,0.17725],[-0.02351,0.12017,0.16972],[-0.02779,0.1123,0.17252],[-0.02351,0.12511,0.16379],[-0.02779,0.11752,0.1673],[-0.02779,0.12225,0.16162],[-0.02779,0.12644,0.15554],[-0.02779,0.13007,0.1491],[-0.02779,0.13309,0.14236],[-0.02779,0.13549,0.13537],[-0.02779,0.13724,0.12819],[-0.02779,0.13834,0.12088],[-0.03152,0.06546,0.18921],[-0.03152,0.07239,0.18818],[-0.03152,0.0792,0.18651],[-0.03152,0.08583,0.18423],[-0.03152,0.09223,0.18136],[-0.03152,0.09834,0.17793],[-0.03152,0.10411,0.17395],[-0.03152,0.1095,0.16946],[-0.03152,0.11446,0.1645],[-0.03152,0.11895,0.15911],[-0.03152,0.12293,0.15334],[-0.03152,0.12636,0.14723],[-0.03152,0.12923,0.14083],[-0.03152,0.13151,0.1342],[-0.03152,0.13318,0.12739],[-0.03152,0.13421,0.12046],[-0.03464,0.06498,0.18461],[-0.03464,0.0715,0.18364],[-0.03464,0.0779,0.18207],[-0.03464,0.08413,0.17993],[-0.03464,0.09015,0.17723],[-0.03464,0.09589,0.174],[-0.03464,0.10132,0.17026],[-0.03464,0.10638,0.16604],[-0.03464,0.11104,0.16138],[-0.03464,0.11526,0.15632],[-0.03464,0.119,0.15089],[-0.03464,0.12223,0.14515],[-0.03464,0.12493,0.13913],[-0.03464,0.12707,0.1329],[-0.03464,0.12864,0.1265],[-0.03464,0.12961,0.11998],[-0.03709,0.06446,0.17962],[-0.03709,0.07053,0.17871],[-0.03709,0.07649,0.17726],[-0.03709,0.08229,0.17527],[-0.03709,0.08789,0.17276],[-0.03709,0.09323,0.16975],[-0.03709,0.09829,0.16626],[-0.03709,0.103,0.16234],[-0.03709,0.10734,0.158],[-0.03709,0.11126,0.15329],[-0.03709,0.11475,0.14823],[-0.03709,0.11776,0.14289],[-0.03709,0.12027,0.13729],[-0.03709,0.12226,0.13149],[-0.03709,0.12371,0.12553],[-0.03709,0.12462,0.11946],[-0.03881,0.0695,0.17351],[-0.03881,0.07499,0.17216],[-0.03881,0.08034,0.17033],[-0.03881,0.0855,0.16802],[-0.03881,0.09042,0.16524],[-0.03881,0.09508,0.16204],[-0.03881,0.09942,0.15842],[-0.03881,0.10342,0.15442],[-0.03881,0.10704,0.15008],[-0.03881,0.11024,0.14542],[-0.03881,0.11302,0.1405],[-0.03881,0.11533,0.13534],[-0.03881,0.11716,0.12999],[-0.03881,0.11851,0.1245],[-0.03881,0.11935,0.11891],[-0.03978,0.07345,0.16689],[-0.03978,0.07832,0.16522],[-0.03978,0.08302,0.16311],[-0.03978,0.08751,0.16058],[-0.03978,0.09176,0.15766],[-0.03978,0.09572,0.15436],[-0.03978,0.09936,0.15072],[-0.03978,0.10266,0.14676],[-0.03978,0.10558,0.14251],[-0.03978,0.10811,0.13802],[-0.03978,0.11022,0.13332],[-0.03978,0.11189,0.12845],[-0.03978,0.11311,0.12344],[-0.03978,0.11388,0.11835],[-0.00145,0.08604,0.20046],[-0.00839,0.08603,0.19955],[-0.02291,0.08867,0.19189],[-0.02316,0.09005,0.19115],[-0.02316,0.09726,0.18775],[-0.02316,0.10413,0.1837],[-0.02316,0.12205,0.16797],[-0.00355,0.13122,0.16811],[0.00015,0.13122,0.16837],[0.00294,0.13122,0.16819],[0.00838,0.1312,0.16691],[0.02255,0.12939,0.15885],[0.02303,0.12858,0.15948],[0.02313,0.12833,0.15973],[0.02333,0.12752,0.16067],[0.01189,0.13118,0.16538],[-0.00081,0.13122,0.16835],[-0.00626,0.13121,0.16756],[-0.01194,0.13118,0.16535],[-0.02278,0.12865,0.15969],[-0.02308,0.12776,0.16064],[-0.02316,0.12696,0.16169],[-0.02119,0.13044,0.15885],[-0.02152,0.13021,0.15882],[-0.02313,0.08954,0.19138],[-0.02195,0.0872,0.19315],[-0.02157,0.08687,0.19353],[-0.02069,0.08636,0.19429],[-0.01993,0.0861,0.19486],[0.03923,0.1178,0.1125],[-0.00058,0.15,0.0901],[-0.00167,0.14996,0.0888],[-0.00147,0.14997,0.08765],[-0.00167,0.14996,0.0882],[-0.00058,0.15,0.0869],[-0.03464,0.13,0.1125],[-0.03696,0.12531,0.1125],[-0.03152,0.13463,0.1125],[-0.02779,0.13877,0.1125],[-0.02828,0.13828,0.1125],[-0.02222,0.14326,0.1125],[-0.00832,0.14913,0.1125],[0.01368,0.14759,0.1125],[0.0078,0.14923,0.1125],[0.01878,0.14532,0.1125],[0.02351,0.14236,0.1125],[0.02222,0.14326,0.1125],[0.00058,0.15,0.0901],[0.00279,0.1499,0.1125],[0.00147,0.14997,0.08765],[0.00109,0.14999,0.0872],[0.00147,0.14997,0.08935],[0.03464,0.13,0.1125],[0.003,0.13077,0.16862],[0.00569,0.13121,0.1677],[0.00016,0.13078,0.1688],[-0.00082,0.13078,0.16878],[-0.00361,0.13077,0.16853],[-0.00279,0.13122,0.16821],[-0.00637,0.13076,0.16797],[-0.00907,0.13075,0.1671],[-0.00832,0.1312,0.16693],[-0.00892,0.1312,0.16671],[-0.00931,0.1312,0.16656],[-0.00947,0.13075,0.16695],[-0.01213,0.13073,0.16571],[-0.01445,0.13116,0.16386],[-0.01684,0.13113,0.1621],[0.00578,0.13077,0.16812],[0.00852,0.13075,0.16731],[0.00935,0.13075,0.167],[0.00919,0.1312,0.16661],[0.01208,0.13073,0.16574],[0.01447,0.13116,0.16385],[0.01704,0.13113,0.16194],[0.02337,0.09727,0.18758],[0.02337,0.10414,0.18351],[0.02282,0.0974,0.18783],[0.02337,0.1106,0.17882],[0.02282,0.10429,0.18375],[0.02337,0.11659,0.17355],[0.02282,0.11077,0.17904],[0.02337,0.12206,0.16773],[0.02282,0.11678,0.17375],[0.02337,0.12696,0.16143],[0.02282,0.12227,0.16792],[-0.0226,0.12226,0.16815],[-0.02316,0.11658,0.17377],[-0.02316,0.11059,0.17903],[-0.0226,0.11677,0.17397],[-0.0226,0.11076,0.17925],[-0.0226,0.10428,0.18394],[-0.0226,0.09739,0.188],[0.02337,0.09005,0.19098],[0.02149,0.08666,0.19366],[0.01911,0.08634,0.19522],[0.01918,0.086,0.19534],[-0.01895,0.086,0.19547],[-0.02256,0.08796,0.19242],[-0.02316,0.08995,0.19119],[0.0159,0.08658,0.19672],[0.01909,0.08634,0.19523],[0.01267,0.08659,0.19803],[0.00934,0.08659,0.19904],[0.00765,0.0866,0.19942],[0.00425,0.08604,0.20025],[0.00421,0.0866,0.19997],[0.00208,0.08604,0.20043],[0.00207,0.0866,0.20015],[-0.00144,0.0866,0.20017],[-0.00491,0.0866,0.19988],[-0.00833,0.0866,0.19928],[-0.00495,0.08604,0.20016],[-0.01061,0.08659,0.19869],[-0.01394,0.08659,0.19755],[-0.01069,0.08603,0.19896],[-0.01404,0.08602,0.19781],[-0.01888,0.08634,0.19535],[-0.01727,0.08601,0.19637],[0.00058,0.15,0.0869],[0.00167,0.14996,0.0882],[0.00167,0.14996,0.0888],[0.00109,0.14999,0.0898],[-0.00109,0.14999,0.0898],[-0.00147,0.14997,0.08935],[-0.00109,0.14999,0.0872],[0.04447,-0.0,-0.01669],[0.03577,-0.0,-0.03125],[0.02962,-0.0,-0.03714],[0.01468,-0.0,-0.04518],[-0.00213,-0.0,-0.04745],[-0.01057,-0.0,-0.04631],[-0.04579,-0.0,-0.01264],[-0.04731,-0.0,-0.00426],[-0.04731,-0.0,0.00426],[0.0475,-0.0,0.0],[-0.01867,-0.0,-0.04368],[0.04674,-0.0,-0.00848],[-0.02617,-0.0,-0.03964],[-0.03283,-0.0,-0.03433],[0.02251,-0.0,-0.04183],[0.00638,-0.0,-0.04707],[-0.03843,-0.0,-0.02792],[0.04078,-0.0,-0.02436],[-0.0428,-0.0,-0.02061],[-0.04207,0.0175,0.17105],[-0.03681,0.0175,0.18625],[0.00404,0.0175,0.20731],[-0.01642,0.0175,0.2042],[0.04207,0.0175,0.17105],[0.04016,0.0175,0.1789],[-0.01197,0.0175,0.20578],[-0.00404,0.0175,0.20731],[-0.0,0.0175,0.2075],[-0.03212,0.0175,0.19283],[-0.02627,0.0175,0.19841],[-0.01719,0.0075,0.20387],[0.00404,0.0075,0.20731],[0.01947,0.0075,0.20278],[0.02627,0.0075,0.19841],[-0.00404,0.0075,0.20731],[0.03681,0.0075,0.18625],[0.04245,0.0075,0.16298],[-0.04207,0.0075,0.17105],[-0.02627,0.0075,0.19841],[-0.04016,0.0075,0.1789],[-0.01947,0.0075,0.20278],[-0.03212,0.0075,0.19283],[0.04207,0.0075,0.17105],[0.04016,0.0075,0.1789],[0.03681,0.0175,0.18625],[0.03212,0.0175,0.19283],[0.03212,0.0075,0.19283],[0.02627,0.0175,0.19841],[0.01947,0.0175,0.20278],[0.01197,0.0175,0.20578],[0.01197,0.0075,0.20578],[-0.0,0.0075,0.2075],[-0.01197,0.0075,0.20578],[-0.01947,0.0175,0.20278],[-0.03681,0.0075,0.18625],[-0.04016,0.0175,0.1789],[-0.04245,0.0075,0.16298],[-0.02801,-0.02505,0.17024],[-0.02685,-0.02505,0.17456],[-0.02351,-0.02505,0.1489],[-0.02071,-0.02505,0.14542],[-0.00079,-0.02505,0.13651],[0.02502,-0.02505,0.15136],[0.00805,-0.02505,0.13766],[0.00367,-0.02505,0.13674],[-0.02258,-0.02505,0.18239],[-0.0161,-0.02505,0.18851],[-0.01223,-0.02505,0.19074],[0.00524,-0.02505,0.19301],[0.00956,-0.02505,0.19185],[0.01739,-0.02505,0.18758],[0.02071,-0.02505,0.18458],[0.02826,-0.02505,0.16867],[0.02734,-0.02505,0.17305],[0.02801,-0.02505,0.15976],[0.02258,-0.02505,0.14761],[0.0161,-0.02505,0.14149],[-0.02826,-0.02505,0.16133],[-0.02849,-0.02505,0.16579],[-0.02734,-0.02505,0.15695],[-0.02574,-0.02505,0.15277],[0.02685,-0.02505,0.15544],[-0.00398,-0.02332,0.19562],[0.00085,-0.02402,0.19551],[0.00086,-0.02332,0.19587],[-0.00872,-0.02332,0.19462],[-0.00393,-0.02402,0.19527],[-0.01325,-0.02332,0.19289],[-0.00862,-0.02402,0.19428],[-0.01745,-0.02332,0.19048],[-0.01309,-0.02402,0.19257],[-0.02122,-0.02332,0.18743],[-0.01725,-0.02402,0.19018],[-0.02447,-0.02332,0.18384],[-0.02097,-0.02402,0.18717],[-0.02711,-0.02332,0.17978],[-0.02418,-0.02402,0.18362],[-0.02909,-0.02332,0.17536],[-0.0268,-0.02402,0.17961],[-0.03,-0.02402,0.17061],[-0.02823,-0.02457,0.17505],[-0.02875,-0.02402,0.17524],[-0.03051,-0.02402,0.16585],[-0.02946,-0.02457,0.17051],[-0.02996,-0.02457,0.16583],[-0.02972,-0.02457,0.16114],[0.03051,-0.02402,0.16415],[0.02946,-0.02457,0.15949],[0.03027,-0.02402,0.16893],[0.02996,-0.02457,0.16417],[0.02928,-0.02402,0.17362],[0.02972,-0.02457,0.16886],[0.02757,-0.02402,0.17809],[0.02875,-0.02457,0.17346],[0.02518,-0.02402,0.18225],[0.02707,-0.02457,0.17786],[0.02217,-0.02402,0.18597],[0.02473,-0.02457,0.18193],[0.01862,-0.02402,0.18918],[0.02177,-0.02457,0.18559],[0.01461,-0.02402,0.1918],[0.01828,-0.02457,0.18875],[0.01024,-0.02402,0.19375],[0.01434,-0.02457,0.19131],[0.00561,-0.02402,0.195],[0.01005,-0.02457,0.19323],[0.00551,-0.02457,0.19446],[0.00083,-0.02457,0.19496],[-0.00386,-0.02457,0.19472],[-0.00846,-0.02457,0.19375],[-0.01286,-0.02457,0.19207],[-0.01693,-0.02457,0.18973],[-0.02059,-0.02457,0.18677],[-0.02375,-0.02457,0.18328],[-0.02631,-0.02457,0.17934],[-0.02758,-0.02493,0.17482],[-0.02877,-0.02493,0.17038],[-0.02926,-0.02493,0.16581],[-0.02903,-0.02493,0.16123],[-0.02808,-0.02493,0.15673],[-0.02644,-0.02493,0.15244],[-0.02415,-0.02493,0.14846],[-0.02127,-0.02493,0.14489],[-0.01786,-0.02493,0.14181],[-0.01401,-0.02493,0.1393],[0.01654,-0.02493,0.14085],[0.02011,-0.02493,0.14373],[0.02319,-0.02493,0.14714],[0.0257,-0.02493,0.15099],[0.02758,-0.02493,0.15518],[0.02877,-0.02493,0.15962],[0.02926,-0.02493,0.16419],[0.02903,-0.02493,0.16877],[0.02808,-0.02493,0.17327],[0.02644,-0.02493,0.17756],[0.02415,-0.02493,0.18154],[0.02127,-0.02493,0.18511],[0.01786,-0.02493,0.18819],[0.01401,-0.02493,0.1907],[0.00982,-0.02493,0.19258],[0.00538,-0.02493,0.19377],[0.00081,-0.02493,0.19426],[-0.00377,-0.02493,0.19403],[-0.00827,-0.02493,0.19308],[-0.01256,-0.02493,0.19144],[-0.01654,-0.02493,0.18915],[-0.02011,-0.02493,0.18627],[-0.02319,-0.02493,0.18286],[-0.0257,-0.02493,0.17901],[-0.01739,-0.02505,0.14242],[-0.01364,-0.02505,0.13998],[-0.00956,-0.02505,0.13815],[-0.00524,-0.02505,0.13699],[0.01223,-0.02505,0.13926],[0.01958,-0.02505,0.14429],[0.02849,-0.02505,0.16421],[0.02574,-0.02505,0.17723],[0.02351,-0.02505,0.1811],[0.01364,-0.02505,0.19002],[0.00079,-0.02505,0.19349],[-0.00367,-0.02505,0.19326],[-0.00805,-0.02505,0.19234],[-0.01958,-0.02505,0.18571],[-0.02502,-0.02505,0.17864],[0.00568,-0.02332,0.19535],[0.01884,-0.02332,0.18947],[0.01478,-0.02332,0.19211],[0.02243,-0.02332,0.18622],[0.02548,-0.02332,0.18245],[0.02789,-0.02332,0.17825],[0.02962,-0.02332,0.17372],[0.03062,-0.02332,0.16898],[0.03087,-0.02332,0.16414],[-0.03087,-0.02332,0.16586],[-0.03035,-0.02332,0.17068],[0.01036,-0.02332,0.19409]],"forearm_link":[[0.03879,-0.08288,0.01208],[0.03705,-0.08284,0.00428],[0.03879,-0.07913,0.00806],[0.03879,-0.08626,0.01641],[0.03705,-0.08691,0.00864],[0.03879,-0.08924,0.02103],[0.03705,-0.09057,0.01335],[0.03879,-0.09181,0.02589],[0.03705,-0.09381,0.01836],[0.03879,-0.09393,0.03096],[0.03705,-0.09659,0.02363],[0.03705,-0.0989,0.02913],[0.03705,-0.10071,0.03481],[0.03705,-0.06857,-0.00643],[0.0346,-0.06529,-0.01367],[0.03705,-0.07363,-0.00328],[0.0346,-0.07101,-0.01079],[0.03705,-0.0784,0.0003],[0.0346,-0.07645,-0.00741],[0.0346,-0.08158,-0.00357],[0.0346,-0.08634,0.00071],[0.0346,-0.09071,0.0054],[0.0346,-0.09465,0.01045],[0.0346,-0.09812,0.01583],[0.0346,-0.10111,0.02149],[0.0346,-0.10359,0.0274],[0.0346,-0.10554,0.0335],[0.03148,-0.06719,-0.01788],[0.03148,-0.07327,-0.01481],[0.03148,-0.07906,-0.01122],[0.03148,-0.08451,-0.00713],[0.03148,-0.08957,-0.00258],[0.03148,-0.09422,0.00241],[0.03148,-0.09841,0.00778],[0.03148,-0.1021,0.0135],[0.03148,-0.10528,0.01952],[0.03148,-0.10792,0.02581],[0.03148,-0.10999,0.0323],[0.03148,-0.11148,0.03894],[0.02774,-0.06222,-0.0243],[0.02774,-0.06888,-0.02165],[0.02774,-0.07529,-0.01841],[0.02774,-0.08139,-0.01463],[0.02774,-0.08713,-0.01032],[0.02774,-0.09247,-0.00553],[0.02774,-0.09736,-0.00028],[0.02774,-0.10177,0.00538],[0.02774,-0.10567,0.01141],[0.02774,-0.10902,0.01776],[0.02774,-0.1118,0.02438],[0.02774,-0.11398,0.03121],[0.02774,-0.11555,0.03822],[0.02347,-0.06339,-0.02768],[0.02347,-0.07035,-0.02491],[0.02347,-0.07704,-0.02153],[0.02347,-0.08341,-0.01758],[0.02347,-0.0894,-0.01308],[0.02347,-0.09497,-0.00808],[0.02347,-0.10008,-0.0026],[0.02347,-0.10469,0.00331],[0.02347,-0.10876,0.00961],[0.02347,-0.11225,0.01623],[0.02347,-0.11515,0.02314],[0.02347,-0.11743,0.03028],[0.02347,-0.11907,0.03759],[0.01874,-0.06436,-0.03046],[0.01874,-0.07156,-0.02759],[0.01874,-0.07848,-0.0241],[0.01874,-0.08507,-0.02001],[0.01874,-0.09127,-0.01536],[0.01874,-0.09704,-0.01018],[0.01874,-0.10232,-0.00451],[0.01874,-0.10709,0.00161],[0.01874,-0.1113,0.00812],[0.01874,-0.11492,0.01497],[0.01874,-0.11792,0.02212],[0.01874,-0.12027,0.02951],[0.01874,-0.12197,0.03707],[0.01365,-0.0651,-0.0326],[0.01365,-0.07249,-0.02965],[0.01365,-0.07959,-0.02607],[0.01365,-0.08634,-0.02188],[0.01365,-0.0927,-0.01711],[0.01365,-0.09862,-0.01179],[0.01365,-0.10404,-0.00598],[0.01365,-0.10893,0.0003],[0.01365,-0.11325,0.00697],[0.01365,-0.11696,0.01401],[0.01365,-0.12004,0.02134],[0.01365,-0.12246,0.02891],[0.01365,-0.1242,0.03667],[0.0083,-0.05786,-0.03636],[0.0083,-0.0656,-0.03404],[0.0083,-0.07312,-0.03105],[0.0083,-0.08034,-0.02741],[0.0083,-0.08721,-0.02314],[0.0083,-0.09368,-0.01829],[0.0083,-0.09969,-0.01288],[0.0083,-0.10521,-0.00697],[0.0083,-0.11018,-0.00059],[0.0083,-0.11457,0.0062],[0.0083,-0.11835,0.01335],[0.0083,-0.12147,0.02081],[0.0083,-0.12393,0.02851],[0.0083,-0.1257,0.0364],[0.00278,-0.05804,-0.03711],[0.00278,-0.06586,-0.03477],[0.00278,-0.07344,-0.03176],[0.00278,-0.08072,-0.02808],[0.00278,-0.08765,-0.02378],[0.00278,-0.09417,-0.01889],[0.00278,-0.10024,-0.01344],[0.00278,-0.1058,-0.00747],[0.00278,-0.11081,-0.00104],[0.00278,-0.11524,0.00581],[0.00278,-0.11904,0.01302],[0.00278,-0.1222,0.02054],[0.00278,-0.12468,0.02831],[0.00278,-0.12647,0.03627],[-0.00278,-0.05804,-0.03711],[-0.00278,-0.06586,-0.03477],[-0.00278,-0.07344,-0.03176],[-0.00278,-0.08072,-0.02808],[-0.00278,-0.08765,-0.02378],[-0.00278,-0.09417,-0.01889],[-0.00278,-0.10024,-0.01344],[-0.00278,-0.1058,-0.00747],[-0.00278,-0.11081,-0.00104],[-0.00278,-0.11524,0.00581],[-0.00278,-0.11904,0.01302],[-0.00278,-0.1222,0.02054],[-0.00278,-0.12468,0.02831],[-0.00278,-0.12647,0.03627],[-0.0083,-0.05786,-0.03636],[-0.0083,-0.0656,-0.03404],[-0.0083,-0.07312,-0.03105],[-0.0083,-0.08034,-0.02741],[-0.0083,-0.08721,-0.02314],[-0.0083,-0.09368,-0.01829],[-0.0083,-0.09969,-0.01288],[-0.0083,-0.10521,-0.00697],[-0.0083,-0.11018,-0.00059],[-0.0083,-0.11457,0.0062],[-0.0083,-0.11835,0.01335],[-0.0083,-0.12147,0.02081],[-0.0083,-0.12393,0.02851],[-0.0083,-0.1257,0.0364],[-0.01365,-0.0651,-0.0326],[-0.01365,-0.07249,-0.02965],[-0.01365,-0.07959,-0.02607],[-0.01365,-0.08634,-0.02188],[-0.01365,-0.0927,-0.01711],[-0.01365,-0.09862,-0.01179],[-0.01365,-0.10404,-0.00598],[-0.01365,-0.10893,0.0003],[-0.01365,-0.11325,0.00697],[-0.01365,-0.11696,0.01401],[-0.01365,-0.12004,0.02134],[-0.01365,-0.12246,0.02891],[-0.01365,-0.1242,0.03667],[-0.01874,-0.06436,-0.03046],[-0.01874,-0.07156,-0.02759],[-0.01874,-0.07848,-0.0241],[-0.01874,-0.08507,-0.02001],[-0.01874,-0.09127,-0.01536],[-0.01874,-0.09704,-0.01018],[-0.01874,-0.10232,-0.00451],[-0.01874,-0.10709,0.00161],[-0.01874,-0.1113,0.00812],[-0.01874,-0.11492,0.01497],[-0.01874,-0.11792,0.02212],[-0.01874,-0.12027,0.02951],[-0.01874,-0.12197,0.03707],[-0.02347,-0.06339,-0.02768],[-0.02347,-0.07035,-0.02491],[-0.02347,-0.07704,-0.02153],[-0.02347,-0.08341,-0.01758],[-0.02347,-0.0894,-0.01308],[-0.02347,-0.09497,-0.00808],[-0.02347,-0.10008,-0.0026],[-0.02347,-0.10469,0.00331],[-0.02347,-0.10876,0.00961],[-0.02347,-0.11225,0.01623],[-0.02347,-0.11515,0.02314],[-0.02347,-0.11743,0.03028],[-0.02347,-0.11907,0.03759],[-0.02774,-0.06222,-0.0243],[-0.02774,-0.06888,-0.02165],[-0.02774,-0.07529,-0.01841],[-0.02774,-0.08139,-0.01463],[-0.02774,-0.08713,-0.01032],[-0.02774,-0.09247,-0.00553],[-0.02774,-0.09736,-0.00028],[-0.02774,-0.10177,0.00538],[-0.02774,-0.10567,0.01141],[-0.02774,-0.10902,0.01776],[-0.02774,-0.1118,0.02438],[-0.02774,-0.11398,0.03121],[-0.02774,-0.11555,0.03822],[-0.03148,-0.06719,-0.01788],[-0.03148,-0.07327,-0.01481],[-0.03148,-0.07906,-0.01122],[-0.03148,-0.08451,-0.00713],[-0.03148,-0.08957,-0.00258],[-0.03148,-0.09422,0.00241],[-0.03148,-0.09841,0.00778],[-0.03148,-0.1021,0.0135],[-0.03148,-0.10528,0.01952],[-0.03148,-0.10792,0.02581],[-0.03148,-0.10999,0.0323],[-0.03148,-0.11148,0.03894],[-0.0346,-0.06529,-0.01367],[-0.0346,-0.07101,-0.01079],[-0.0346,-0.07645,-0.00741],[-0.0346,-0.08158,-0.00357],[-0.0346,-0.08634,0.00071],[-0.0346,-0.09071,0.0054],[-0.0346,-0.09465,0.01045],[-0.0346,-0.09812,0.01583],[-0.0346,-0.10111,0.02149],[-0.0346,-0.10359,0.0274],[-0.0346,-0.10554,0.0335],[-0.03705,-0.06857,-0.00643],[-0.03705,-0.07363,-0.00328],[-0.03705,-0.0784,0.0003],[-0.03705,-0.08284,0.00428],[-0.03705,-0.08691,0.00864],[-0.03705,-0.09057,0.01335],[-0.03705,-0.09381,0.01836],[-0.03705,-0.09659,0.02363],[-0.03705,-0.0989,0.02913],[-0.03705,-0.10071,0.03481],[-0.03879,-0.07504,0.00439],[-0.03879,-0.07913,0.00806],[-0.03879,-0.08288,0.01208],[-0.03879,-0.08626,0.01641],[-0.03879,-0.08924,0.02103],[-0.03879,-0.09181,0.02589],[-0.03879,-0.09393,0.03096],[0.03879,-0.07504,0.00439],[0.03879,-0.07065,0.00109],[0.03977,-0.08179,0.01959],[0.03977,-0.07871,0.01564],[-0.04222,-0.0195,-0.0124],[-0.03911,-0.0195,-0.02016],[-0.02881,-0.0195,-0.03325],[-0.022,-0.0195,-0.03811],[-0.01439,-0.0195,-0.04158],[-0.00626,-0.0195,-0.04355],[0.00209,-0.0195,-0.04395],[0.01828,-0.0195,-0.04002],[0.02552,-0.0195,-0.03584],[0.03184,-0.0195,-0.03036],[0.03702,-0.0195,-0.02379],[0.044,-0.0195,-0.0],[-0.04085,-0.03373,-0.01635],[-0.03911,-0.03373,-0.02016],[-0.03459,-0.0195,-0.0272],[-0.03184,-0.03373,-0.03036],[-0.02881,-0.03373,-0.03325],[-0.02552,-0.03373,-0.03584],[-0.022,-0.03373,-0.03811],[-0.01828,-0.03373,-0.04002],[-0.01037,-0.03373,-0.04276],[-0.00626,-0.03373,-0.04355],[0.0013,-0.02859,-0.04398],[0.00209,-0.03373,-0.04395],[0.00085,-0.02897,-0.04399],[0.0016,-0.02808,-0.04397],[-0.00209,-0.03373,-0.04395],[-0.0016,-0.02808,-0.04397],[-0.0016,-0.02692,-0.04397],[-0.0003,-0.02583,-0.044],[0.0003,-0.02583,-0.044],[0.00085,-0.02603,-0.04399],[0.0013,-0.02641,-0.04398],[0.0016,-0.02692,-0.04397],[0.0017,-0.0275,-0.04397],[0.01037,-0.0195,-0.04276],[0.01828,-0.03373,-0.04002],[0.02881,-0.03373,-0.03325],[0.03184,-0.03373,-0.03036],[0.03459,-0.03373,-0.0272],[0.03702,-0.03373,-0.02379],[0.03911,-0.03373,-0.02016],[0.04085,-0.0195,-0.01635],[0.04085,-0.03373,-0.01635],[0.04222,-0.03373,-0.0124],[0.0432,-0.0195,-0.00833],[0.04399,-0.02897,-0.00085],[0.04397,-0.0275,-0.0017],[0.04397,-0.02692,-0.0016],[-0.04068,-0.03541,-0.01629],[-0.03895,-0.03541,-0.02008],[-0.03702,-0.03373,-0.02379],[-0.03686,-0.03541,-0.02369],[-0.03459,-0.03373,-0.0272],[-0.03445,-0.03541,-0.02709],[-0.03171,-0.03541,-0.03024],[-0.0287,-0.03541,-0.03312],[-0.02542,-0.03541,-0.0357],[-0.02191,-0.03541,-0.03795],[-0.0182,-0.03541,-0.03986],[-0.01439,-0.03373,-0.04158],[-0.01433,-0.03541,-0.04141],[-0.01033,-0.03541,-0.04259],[-0.00624,-0.03541,-0.04338],[-0.00209,-0.03541,-0.04377],[0.00209,-0.03541,-0.04377],[0.00626,-0.03373,-0.04355],[0.00624,-0.03541,-0.04338],[0.01037,-0.03373,-0.04276],[0.01033,-0.03541,-0.04259],[0.01439,-0.03373,-0.04158],[0.01433,-0.03541,-0.04141],[0.0182,-0.03541,-0.03986],[0.022,-0.03373,-0.03811],[0.02191,-0.03541,-0.03795],[0.02552,-0.03373,-0.03584],[0.02542,-0.03541,-0.0357],[0.0287,-0.03541,-0.03312],[0.03171,-0.03541,-0.03024],[0.03445,-0.03541,-0.02709],[0.03686,-0.03541,-0.02369],[0.03895,-0.03541,-0.02008],[0.04068,-0.03541,-0.01629],[0.04205,-0.03541,-0.01235],[0.0432,-0.03373,-0.00833],[0.04303,-0.03541,-0.00829],[0.0438,-0.03373,-0.00418],[0.04362,-0.03541,-0.00417],[0.044,-0.03373,-0.0],[0.04398,-0.02859,-0.0013],[0.04397,-0.02808,-0.0016],[0.04398,-0.02641,-0.0013],[0.04399,-0.02603,-0.00085],[-0.0013,-0.02641,-0.04398],[-0.00085,-0.02603,-0.04399],[0.0003,-0.02917,-0.044],[-0.0003,-0.02917,-0.044],[-0.00085,-0.02897,-0.04399],[-0.0013,-0.02859,-0.04398],[-0.0017,-0.0275,-0.04397],[0.01626,-0.12996,0.0825],[0.02006,-0.12828,0.0825],[0.02369,-0.12626,0.0825],[0.02712,-0.12391,0.0825],[0.03032,-0.12126,0.0825],[0.03326,-0.11832,0.0825],[0.03591,-0.11512,0.0825],[0.03826,-0.11169,0.0825],[0.04028,-0.10806,0.0825],[0.04328,-0.10031,0.0825],[0.04423,-0.09627,0.0825],[-0.04481,-0.09215,0.0825],[-0.04328,-0.10031,0.0825],[-0.03591,-0.11512,0.0825],[-0.03326,-0.11832,0.0825],[-0.03032,-0.12126,0.0825],[-0.01231,-0.13128,0.0825],[-0.00415,-0.13281,0.0825],[0.04196,-0.10426,0.0825],[0.00827,-0.13223,0.0825],[0.01231,-0.13128,0.0825],[-0.00827,-0.13223,0.0825],[-0.01626,-0.12996,0.0825],[-0.02369,-0.12626,0.0825],[-0.02006,-0.12828,0.0825],[-0.02712,-0.12391,0.0825],[-0.04028,-0.10806,0.0825],[-0.03826,-0.11169,0.0825],[-0.04196,-0.10426,0.0825],[0.00415,-0.13281,0.0825],[-0.0,-0.133,0.0825],[-0.04423,-0.09627,0.0825],[0.045,-0.088,0.0825],[0.04481,-0.09215,0.0825],[-0.04767,-0.09159,0.2515],[-0.04659,-0.09868,0.2515],[0.04767,-0.09159,0.2515],[0.04659,-0.07732,0.2515],[0.04659,-0.09868,0.2515],[-0.04767,-0.08441,0.2515],[-0.04778,-0.0867,0.23509],[-0.04777,-0.0897,0.234],[-0.04777,-0.0896,0.23458],[-0.0478,-0.0883,0.23567],[-0.0478,-0.0883,0.23233],[-0.04779,-0.08885,0.23253],[-0.0478,-0.0877,0.23233],[0.0478,-0.0883,0.23567],[0.04777,-0.0897,0.234],[0.04767,-0.09159,0.2265],[0.04777,-0.0896,0.23458],[0.04767,-0.08441,0.2515],[0.04778,-0.0867,0.23509],[0.04779,-0.08715,0.23547],[0.04777,-0.0864,0.23458],[0.0478,-0.0877,0.23567],[0.04777,-0.0896,0.23342],[0.0478,-0.088,0.2323],[0.04767,-0.08441,0.2265],[0.0478,-0.0877,0.23233],[0.04778,-0.0867,0.23291],[0.04659,-0.09868,0.2265],[0.04,-0.1359,0.2265],[-0.04659,-0.09868,0.2265],[-0.04767,-0.09159,0.2265],[-0.03923,-0.0401,0.2933],[-0.03696,-0.0401,0.30081],[0.04,-0.0401,0.2855],[0.01531,-0.0401,0.32246],[0.02222,-0.0401,0.31876],[-0.01531,-0.0401,0.32246],[0.0,-0.0401,0.3255],[-0.0078,-0.0401,0.32473],[-0.03326,-0.0401,0.30772],[0.02828,-0.0401,0.31378],[0.03923,-0.0401,0.2933],[0.0078,-0.0401,0.32473],[0.03326,-0.0401,0.30772],[0.03696,-0.0401,0.30081],[-0.02222,-0.0401,0.31876],[-0.02828,-0.0401,0.31378],[-0.04,-0.0401,0.2855],[-0.04,-0.1359,0.2265],[0.02828,-0.1359,0.31378],[-0.04,-0.1359,0.2855],[-0.03923,-0.1359,0.2933],[-0.02828,-0.1359,0.31378],[-0.02222,-0.1359,0.31876],[0.01531,-0.1359,0.32246],[-0.01531,-0.1359,0.32246],[0.03696,-0.1359,0.30081],[0.03923,-0.1359,0.2933],[-0.0078,-0.1359,0.32473],[0.0,-0.1359,0.3255],[0.04,-0.1359,0.2855],[-0.03696,-0.1359,0.30081],[-0.03326,-0.1359,0.30772],[0.0078,-0.1359,0.32473],[0.02222,-0.1359,0.31876],[0.03326,-0.1359,0.30772],[0.04779,-0.08715,0.23253],[0.04777,-0.0864,0.23342],[0.04777,-0.0863,0.234],[0.04779,-0.08885,0.23547],[0.04778,-0.0893,0.23509],[0.04778,-0.0893,0.23291],[0.04779,-0.08885,0.23253],[0.0478,-0.0883,0.23233],[-0.04779,-0.08715,0.23547],[-0.04779,-0.08715,0.23253],[-0.04778,-0.0893,0.23291],[-0.04777,-0.0896,0.23342],[-0.0478,-0.0877,0.23567],[-0.04779,-0.08885,0.23547],[-0.04778,-0.0893,0.23509],[0.00628,-0.1428,0.17091],[0.00745,-0.1428,0.17333],[-0.00338,-0.1428,0.16848],[-0.00079,-0.1428,0.16774],[0.00773,-0.1428,0.17601],[0.00707,-0.1428,0.17862],[0.00189,-0.1428,0.16793],[0.00435,-0.1428,0.16903],[-0.00556,-0.1428,0.17005],[-0.01538,-0.144,0.20233],[-0.02171,-0.144,0.19479],[-0.02038,-0.144,0.19367],[-0.01875,-0.144,0.19308],[-0.01538,-0.144,0.19367],[-0.01318,-0.144,0.19629],[-0.01288,-0.144,0.198],[-0.01318,-0.144,0.19971],[-0.02258,-0.144,0.19971],[-0.01875,-0.144,0.20292],[-0.01701,-0.144,0.19308],[-0.02038,-0.144,0.20233],[-0.02171,-0.144,0.20121],[-0.01405,-0.144,0.20121],[-0.02258,-0.144,0.19629],[-0.01405,-0.144,0.19479],[-0.02288,-0.144,0.198],[-0.01701,-0.144,0.20292],[-0.047,-0.0299,-0.001],[-0.047,-0.0261,-0.00219],[-0.047,-0.0249,0.00012],[-0.047,-0.02502,-0.00078],[-0.047,-0.02544,-0.00158],[-0.047,-0.02693,-0.00254],[-0.047,-0.02784,-0.00258],[-0.047,-0.02942,-0.00176],[-0.047,-0.0287,-0.00231],[-0.03923,0.0,0.0078],[-0.03696,0.0,0.01531],[-0.0078,0.0,0.03923],[0.03696,0.0,0.01531],[0.03923,0.0,0.0078],[0.03923,0.0,-0.0078],[0.03696,0.0,-0.01531],[0.03326,0.0,-0.02222],[0.02828,0.0,-0.02828],[0.02222,0.0,-0.03326],[0.0078,0.0,-0.03923],[-0.0078,0.0,-0.03923],[-0.02222,0.0,-0.03326],[-0.02828,0.0,-0.02828],[-0.03326,0.0,-0.02222],[-0.03696,0.0,-0.01531],[-0.03923,0.0,-0.0078],[-0.0,0.0,-0.04],[-0.0,0.0,0.04],[-0.04,0.0,-0.0],[0.04,0.0,-0.0],[0.02828,0.0,0.02828],[0.03326,0.0,0.02222],[-0.01531,0.0,-0.03696],[-0.02828,0.0,0.02828],[-0.03326,0.0,0.02222],[-0.02222,0.0,0.03326],[0.02222,0.0,0.03326],[-0.01531,0.0,0.03696],[0.0078,0.0,0.03923],[0.01531,0.0,0.03696],[0.01531,0.0,-0.03696]],"wrist_pitch_link":[[0.0287,-0.041,0.02786],[0.02275,-0.041,0.0329],[0.03356,-0.041,0.02177],[0.03714,-0.041,0.01485],[0.03932,-0.041,0.00737],[0.04,-0.041,-0.0004],[0.03916,-0.041,-0.00814],[0.00776,-0.041,-0.03924],[0.0,-0.041,-0.04],[-0.00776,-0.041,-0.03924],[-0.01522,-0.041,-0.03699],[-0.0221,-0.041,-0.03334],[-0.03312,-0.041,-0.02243],[-0.03684,-0.041,-0.01558],[-0.03916,-0.041,-0.00814],[-0.04,-0.041,-0.0004],[-0.03714,-0.041,0.01485],[-0.03356,-0.041,0.02177],[-0.0287,-0.041,0.02786],[-0.02275,-0.041,0.0329],[-0.0173,-0.041,0.03607],[-0.04,0.041,-0.0004],[-0.03916,0.041,-0.00814],[-0.0287,0.041,0.02786],[-0.01522,0.041,-0.03699],[-0.0173,0.041,0.03607],[-0.03684,0.041,-0.01558],[0.00776,0.041,-0.03924],[-0.03356,0.041,0.02177],[-0.03714,0.041,0.01485],[-0.0221,0.041,-0.03334],[0.0,0.041,-0.04],[0.03356,0.041,0.02177],[0.03932,0.041,0.00737],[-0.03312,0.041,-0.02243],[0.02814,0.041,-0.02842],[0.0287,0.041,0.02786],[0.01522,0.041,-0.03699],[0.03312,0.041,-0.02243],[0.0221,0.041,-0.03334],[0.03684,0.041,-0.01558],[0.04,0.041,-0.0004],[0.03916,0.041,-0.00814],[0.03714,0.041,0.01485],[0.02814,-0.041,-0.02842],[0.0221,-0.041,-0.03334],[0.01522,-0.041,-0.03699],[-0.02814,-0.041,-0.02842],[-0.03932,-0.041,0.00737],[0.03684,-0.041,-0.01558],[0.0173,-0.041,0.03607],[0.03312,-0.041,-0.02243],[-0.02275,0.041,0.0329],[0.02275,0.041,0.0329],[0.0173,0.041,0.03607],[-0.00776,0.041,-0.03924],[-0.02814,0.041,-0.02842],[-0.03932,0.041,0.00737],[-0.01302,0.02703,0.04307],[-0.0187,0.02345,0.04307],[-0.02345,0.0187,0.04307],[-0.02677,0.01353,0.04307],[-0.02361,0.01851,0.04307],[-0.02703,0.01302,0.04307],[-0.02925,0.00668,0.04307],[-0.03,-0.0,0.04307],[-0.02925,-0.00668,0.04307],[-0.02827,-0.01005,0.04307],[-0.00668,-0.02925,0.04307],[-0.02361,-0.01851,0.04307],[-0.01302,-0.02703,0.04307],[-0.0187,-0.02345,0.04307],[0.0,-0.03,0.04307],[0.0187,-0.02345,0.04307],[0.03,-0.0,0.04307],[0.02345,0.0187,0.04307],[0.01353,0.02677,0.04307],[0.01851,0.02361,0.04307],[0.0187,0.02345,0.04307],[-0.01851,0.02361,0.04307],[0.01302,0.02703,0.04307],[0.0,0.03,0.04307],[-0.00668,0.02925,0.04307],[-0.01005,0.02827,0.04307],[-0.02345,-0.0187,0.04307],[0.00668,-0.02925,0.04307],[0.01302,-0.02703,0.04307],[0.02703,0.01302,0.04307],[-0.02703,-0.01302,0.04307],[0.02703,-0.01302,0.04307],[0.02925,-0.00668,0.04307],[0.02925,0.00668,0.04307],[0.02345,-0.0187,0.04307],[0.00668,0.02925,0.04307]],"wrist_left_gear_link":[[2e-05,0.06505,0.0073],[0.00454,0.06505,0.00572],[-0.0045,0.06505,0.00575],[-0.00614,0.06505,0.00396],[-0.00709,0.06505,0.00173],[0.00241,0.06505,0.00689],[-0.00333,0.06505,-0.00649],[0.0014,0.06505,-0.00716],[0.00367,0.06505,-0.00631],[0.00554,0.06505,-0.00476],[0.00679,0.06505,-0.00268],[-0.00664,0.06505,-0.00304],[0.00616,0.06505,0.00392],[-0.00727,0.06505,-0.00069],[-0.00237,0.06505,0.0069],[-0.00102,0.06505,-0.00723],[-0.00528,0.06505,-0.00504],[0.00729,0.06505,-0.00031],[0.01,0.0635,0.0],[0.00174,0.0635,-0.00985],[-0.00173,0.0635,-0.00985],[-0.0094,0.0635,0.00342],[-0.005,0.0635,0.00866],[0.00766,0.0635,0.00643],[-0.0094,0.0635,-0.00342],[-0.005,0.0635,-0.00866],[-0.00766,0.0635,-0.00643],[-0.00766,0.0635,0.00643],[-0.00174,0.0635,0.00985],[0.005,0.0635,0.00866],[0.0094,0.0635,0.00342],[0.0094,0.0635,-0.00342],[0.00173,0.0635,0.00985],[-0.01,0.0635,-0.0],[0.00766,0.0635,-0.00643],[0.005,0.0635,-0.00866],[-0.00783,0.0576,-0.01841],[-0.0125,0.0576,-0.01561],[-0.01625,0.0576,-0.01166],[-0.01879,0.0576,-0.00684],[-0.01994,0.0576,-0.00152],[0.01955,0.0576,0.00422],[0.01996,0.0576,-0.00121],[0.0189,0.0576,-0.00655],[0.01643,0.0576,-0.01141],[0.01274,0.0576,-0.01542],[-0.00016,0.0576,0.02],[0.00525,0.0576,0.0193],[0.01879,0.0576,0.00684],[0.00288,0.0576,-0.01979],[-0.01783,0.0576,0.00906],[-0.01472,0.0576,0.01354],[-0.01052,0.0576,0.01701],[0.01026,0.0576,0.01717],[0.01451,0.0576,0.01376],[-0.00257,0.0576,-0.01983],[0.00811,0.0576,-0.01828],[0.01769,0.0576,0.00934],[-0.00555,0.0576,0.01922],[-0.01961,0.0576,0.00392],[-0.00291,0.01758,-0.01834],[-0.00738,0.01758,-0.01704],[-0.01138,0.01758,-0.01467],[-0.01844,0.01758,-0.00221],[-0.01834,0.01758,-0.0029],[-0.01707,0.01758,-0.00731],[-0.00405,0.01758,0.01812],[-0.00843,0.01758,0.01655],[-0.00774,0.01758,0.01688],[-0.01169,0.01758,0.01443],[0.00098,0.01758,-0.01854],[0.00979,0.01758,-0.01578],[0.01044,0.01758,-0.01536],[0.01618,0.01758,-0.00911],[0.00629,0.01758,-0.01747],[0.00556,0.01758,-0.01772],[-0.01491,0.01758,0.01107],[-0.01747,0.01758,0.00629],[-0.0172,0.01758,0.00701],[0.01812,0.01758,-0.00405],[0.01857,0.01758,-0.00019],[0.01783,0.01758,0.00518],[0.01803,0.01758,0.00444],[-0.01849,0.01758,0.00175],[-0.0184,0.01758,0.00251],[0.00592,0.01758,0.0176],[0.00135,0.01758,0.01852],[0.00945,0.01758,0.01598],[0.01011,0.01758,0.01558],[-0.02628,0.02459,0.00265],[-0.02617,0.02459,0.00358],[-0.0263,0.02459,0.00248],[-0.02446,0.02459,0.00997],[-0.02485,0.02459,0.00895],[-0.02121,0.02459,0.01574],[-0.02185,0.02459,0.01485],[-0.01663,0.02459,0.02052],[-0.01228,0.01758,0.01393],[-0.01747,0.02459,0.01981],[-0.01199,0.02459,0.02353],[-0.00468,0.02459,0.026],[-0.00329,0.01758,0.01828],[-0.00576,0.02459,0.02578],[0.00058,0.01758,0.01856],[0.00083,0.02459,0.0264],[0.00565,0.01758,0.01769],[0.00737,0.02459,0.02537],[0.00518,0.01758,0.01783],[0.00842,0.02459,0.02504],[0.01313,0.01758,0.01313],[0.01366,0.01758,0.01257],[0.01868,0.02459,0.01868],[0.01598,0.01758,0.00945],[0.01636,0.01758,0.00878],[0.02641,0.02459,-0.00027],[0.01856,0.01758,0.00058],[0.02552,0.02459,-0.00683],[0.01655,0.01758,-0.00843],[0.02302,0.02459,-0.01296],[0.02354,0.02459,-0.01199],[0.01374,0.01758,-0.01249],[0.01981,0.02459,-0.01747],[0.01907,0.02459,-0.01828],[0.01341,0.01758,-0.01285],[0.00791,0.02459,-0.0252],[0.00139,0.02459,-0.02638],[0.00175,0.01758,-0.01849],[0.00249,0.02459,-0.0263],[-0.00521,0.02459,-0.02589],[-0.00366,0.01758,-0.0182],[-0.01049,0.02459,-0.02424],[-0.00808,0.01758,-0.01672],[-0.01704,0.02459,-0.02018],[-0.01198,0.01758,-0.01419],[-0.01619,0.02459,-0.02087],[-0.02143,0.02459,-0.01544],[-0.01467,0.01758,-0.01138],[-0.02087,0.02459,-0.01619],[-0.0245,0.02459,-0.00987],[-0.01733,0.01758,-0.00666],[-0.02466,0.02459,-0.00947],[-0.02424,0.02459,-0.01049],[-0.01704,0.01758,-0.00737],[-0.02615,0.02459,-0.00371],[-0.02609,0.02459,-0.00413],[-0.02624,0.02459,-0.00304],[-0.01845,0.01758,-0.00214],[-0.01149,0.02459,-0.02378],[-0.00413,0.02459,-0.02609],[0.00895,0.02459,-0.02485],[0.01485,0.02459,-0.02185],[0.01392,0.02459,-0.02245],[0.0264,0.02459,0.00083],[0.02565,0.02459,0.00631],[0.02274,0.02459,0.01345],[0.01944,0.02459,0.01788],[0.01345,0.02459,0.02274],[0.01438,0.02459,0.02216],[0.00193,0.02459,0.02634],[-0.01513,0.01758,-0.01076],[-0.02153,0.02459,-0.01531],[0.01393,0.01758,-0.01228],[0.01794,0.01758,-0.0048],[0.02578,0.02459,-0.00576],[0.02537,0.02459,0.00737],[0.02328,0.02459,0.01249],[-0.011,0.02459,0.02401],[-0.01536,0.01758,0.01044]],"wrist_right_gear_link":[[0.00505,-0.06585,0.00527],[0.00716,-0.06585,-0.00142],[0.0065,-0.06585,0.00332],[-0.00211,-0.06585,-0.00699],[-0.00429,-0.06585,-0.00591],[-0.00702,-0.06585,-0.00199],[-0.00675,-0.06585,0.00279],[0.00029,-0.06585,-0.00729],[0.00071,-0.06585,0.00727],[-0.00729,-0.06585,0.00042],[0.00305,-0.06585,0.00663],[0.00723,-0.06585,0.00101],[-0.00599,-0.06585,-0.00418],[0.00267,-0.06585,-0.0068],[0.00475,-0.06585,-0.00555],[0.0063,-0.06585,-0.00369],[-0.00171,-0.06585,0.0071],[-0.00546,-0.06585,0.00484],[-0.00622,-0.0643,0.00783],[-0.00852,-0.0643,0.00523],[-0.00879,-0.0643,-0.00476],[-0.00663,-0.0643,-0.00748],[-0.00368,-0.0643,-0.0093],[0.00852,-0.0643,-0.00523],[0.00989,-0.0643,0.00147],[0.00027,-0.0643,0.01],[-0.00989,-0.0643,-0.00147],[0.00622,-0.0643,-0.00783],[0.0098,-0.0643,-0.00201],[0.00368,-0.0643,0.0093],[0.00663,-0.0643,0.00748],[-0.00027,-0.0643,-0.01],[-0.00316,-0.0643,0.00949],[0.00879,-0.0643,0.00476],[0.00316,-0.0643,-0.00949],[-0.0098,-0.0643,0.00201],[-0.01498,-0.0584,-0.01325],[-0.00055,-0.0584,-0.01999],[-0.00218,-0.0584,0.01988],[-0.01602,-0.0584,0.01198],[-0.01866,-0.0584,0.00721],[-0.018,-0.0584,-0.00871],[0.01902,-0.0584,0.00618],[0.01665,-0.0584,0.01108],[-0.01991,-0.0584,0.00191],[0.01424,-0.0584,-0.01405],[0.0175,-0.0584,-0.00968],[0.01946,-0.0584,-0.0046],[0.01998,-0.0584,0.00082],[0.00326,-0.0584,0.01973],[0.00847,-0.0584,0.01812],[-0.00592,-0.0584,-0.0191],[-0.01085,-0.0584,-0.0168],[-0.01969,-0.0584,-0.00353],[-0.01219,-0.0584,0.01585],[-0.00746,-0.0584,0.01856],[0.00055,-0.0584,0.01999],[0.01304,-0.0584,0.01516],[0.00992,-0.0584,-0.01737],[0.00487,-0.0584,-0.0194],[-0.00653,-0.01838,-0.01738],[-0.00124,-0.01838,-0.01853],[0.01173,-0.01838,-0.0144],[0.0072,-0.01838,-0.01712],[0.01506,-0.01838,0.01086],[0.01756,-0.01838,0.00605],[0.01729,-0.01838,0.00677],[0.01851,-0.01838,0.00149],[0.01843,-0.01838,0.00226],[-0.0141,-0.01838,-0.01209],[-0.01359,-0.01838,-0.01266],[-0.018,-0.01838,-0.00455],[-0.01776,-0.01838,0.00543],[-0.01856,-0.01838,0.00056],[-0.01631,-0.01838,-0.00888],[0.01694,-0.01838,-0.00761],[0.01724,-0.01838,-0.0069],[-0.01585,-0.01838,0.00967],[0.00714,-0.01838,-0.01714],[-0.01349,-0.01838,0.01276],[-0.00923,-0.01838,0.01611],[-0.00989,-0.01838,0.01572],[-0.00493,-0.01838,0.0179],[-0.00567,-0.01838,0.01768],[0.01451,-0.01838,-0.01158],[0.01498,-0.01838,-0.01097],[0.01247,-0.01838,0.01376],[0.00822,-0.01838,0.01665],[0.00784,-0.01838,-0.01683],[0.00866,-0.01838,0.01643],[0.01189,-0.01838,0.01426],[-0.00033,-0.01838,0.01857],[-0.0011,-0.01838,0.01854],[0.0043,-0.01838,0.01806],[0.02131,-0.02539,-0.01561],[0.02409,-0.02539,-0.01083],[0.02619,-0.02539,-0.00341],[0.0183,-0.01838,-0.00316],[0.02622,-0.02539,0.00321],[0.02633,-0.02539,0.00212],[0.0246,-0.02539,0.00963],[0.02143,-0.02539,0.01545],[0.0155,-0.01838,0.01022],[0.02205,-0.02539,0.01454],[0.01691,-0.02539,0.02029],[0.01774,-0.02539,0.01957],[0.01232,-0.02539,0.02337],[0.01134,-0.02539,0.02386],[0.00797,-0.01838,0.01677],[-0.00156,-0.02539,0.02637],[-0.00046,-0.02539,0.02641],[-0.00701,-0.02539,0.02547],[-0.01313,-0.02539,0.02292],[-0.01407,-0.02539,0.02235],[-0.01919,-0.02539,0.01815],[-0.01295,-0.01838,0.01331],[-0.01841,-0.02539,0.01894],[-0.0231,-0.02539,0.01281],[-0.02255,-0.02539,0.01376],[-0.01797,-0.01838,0.00469],[-0.02639,-0.02539,0.0012],[-0.01855,-0.01838,0.00084],[-0.02641,-0.02539,0.0001],[-0.01857,-0.01838,7e-05],[-0.02586,-0.02539,-0.0054],[-0.01666,-0.01838,-0.0082],[-0.0237,-0.02539,-0.01166],[-0.01932,-0.02539,-0.01801],[-0.01424,-0.02539,-0.02225],[-0.01515,-0.02539,-0.02164],[-0.01001,-0.01838,-0.01564],[-0.00929,-0.02539,-0.02473],[-0.00581,-0.01838,-0.01764],[-0.00826,-0.02539,-0.02509],[-0.00176,-0.02539,-0.02636],[0.00341,-0.01838,-0.01825],[0.00377,-0.02539,-0.02614],[0.01118,-0.01838,-0.01483],[0.01676,-0.02539,-0.02042],[0.01178,-0.01838,-0.01435],[-0.00285,-0.02539,-0.02626],[0.00469,-0.02539,-0.02599],[0.01077,-0.02539,-0.02412],[0.01623,-0.02539,-0.02084],[0.0159,-0.02539,-0.0211],[0.02075,-0.02539,-0.01635],[0.02064,-0.02539,-0.01648],[0.01116,-0.02539,-0.02394],[0.00485,-0.02539,-0.02596],[-0.02006,-0.02539,-0.01719],[-0.02319,-0.02539,-0.01264],[-0.02526,-0.02539,0.00772],[-0.02556,-0.02539,0.00666],[-0.00807,-0.02539,0.02515],[0.00612,-0.02539,0.02569],[0.00505,-0.02539,0.02593],[0.02498,-0.02539,0.0086],[0.02452,-0.02539,-0.00982],[0.01015,-0.02539,-0.02439],[0.00265,-0.01838,-0.01838],[-0.002,-0.01838,-0.01846],[-0.01065,-0.01838,-0.01521],[-0.02561,-0.02539,-0.00647],[-0.01818,-0.01838,-0.0038],[-0.01624,-0.01838,0.00901],[0.00355,-0.01838,0.01823],[0.01841,-0.01838,-0.0024],[0.02603,-0.02539,-0.0045]],"wrist_roll_link":[[-0.00193,-0.00704,0.01214],[-0.00422,-0.00595,0.01212],[-0.00664,-0.00304,0.01212],[-0.00124,0.00643,0.01212],[-0.00708,0.00043,0.01212],[-0.00707,0.00052,0.01212],[-0.00698,-0.00188,0.01212],[-0.00704,-0.00158,0.01212],[-0.00339,0.00577,0.01212],[-0.00321,0.00586,0.01212],[0.00303,-0.00627,0.01212],[-0.00146,-0.00709,0.01212],[-0.00505,0.00458,0.01212],[-0.00265,0.00609,0.01212],[0.00193,0.00619,0.01212],[-0.00616,0.00316,0.01212],[-0.00463,0.00496,0.01212],[2e-05,0.00649,0.01212],[0.00538,0.00363,0.01212],[0.00562,0.00324,0.01212],[-0.00601,-0.00415,0.01212],[-0.00701,0.00092,0.01212],[0.00051,0.00647,0.01212],[0.00262,0.00593,0.01212],[-0.00254,-0.00684,0.01212],[0.00444,0.00473,0.01212],[0.00388,0.0052,0.01212],[0.00628,0.00164,0.01212],[0.00638,-0.00177,0.01212],[0.00591,-0.00317,0.01212],[-0.00024,0.00648,0.01212],[-0.00527,0.00435,0.01212],[-0.00657,0.00236,0.01212],[-0.0071,-0.00109,0.01212],[0.00642,0.00092,0.01212],[0.00575,0.003,0.01212],[0.00223,0.00609,0.01212],[6e-05,-0.00715,0.01212],[0.00231,-0.00662,0.01212],[0.00085,-0.00705,0.01212],[0.00062,-0.00709,0.01212],[0.00425,-0.00541,0.01212],[0.00283,-0.00638,0.01212],[0.0048,-0.00487,0.01212],[0.00566,-0.00366,0.01212],[0.00647,-0.00121,0.01212],[0.00648,0.00024,0.01212],[0.00649,-0.00105,0.01212],[-0.03485,0.00327,0.06107],[-0.03485,0.00327,0.06607],[0.02089,-0.02808,0.06107],[0.01459,-0.03181,0.09337],[-0.01388,-0.03213,0.09337],[-0.02025,-0.02854,0.09337],[-0.02025,-0.02854,0.06107],[-0.02575,-0.02371,0.09337],[-0.02575,-0.02371,0.06107],[-0.03316,-0.01119,0.06107],[-0.03341,0.01044,0.06107],[-0.0305,0.01716,0.09337],[-0.0305,0.01716,0.06107],[-0.02089,0.02808,0.09337],[0.01388,0.03213,0.09337],[0.02025,0.02854,0.06107],[0.02575,0.02371,0.09337],[0.02575,0.02371,0.06107],[0.03011,0.01784,0.09337],[0.03011,0.01784,0.06107],[0.03316,0.01119,0.09337],[0.03341,-0.01044,0.06107],[0.0305,-0.01716,0.06107],[-0.00766,0.03415,0.06107],[-0.00985,0.03358,0.06607],[-0.00039,0.035,0.06607],[0.00552,0.03456,0.06607],[0.00552,0.03456,0.09337],[0.03362,0.00974,0.06607],[0.03477,0.00405,0.06607],[0.03485,-0.00327,0.06607],[0.03454,-0.00564,0.09337],[0.00766,-0.03415,0.06107],[0.00985,-0.03358,0.06607],[0.00766,-0.03415,0.06607],[-0.00689,-0.03431,0.09337],[-0.00552,-0.03456,0.06607],[-0.00552,-0.03456,0.09337],[-0.03477,-0.00405,0.06107],[-0.03477,-0.00405,0.06607],[-0.03341,0.01044,0.09337],[-0.00985,0.03358,0.09337],[0.03362,0.00974,0.09337],[0.00985,-0.03358,0.09337],[-0.03355,-0.00997,0.09337],[-0.03458,0.0054,0.09337],[-0.02627,0.02313,0.06107],[-0.03011,-0.01784,0.06107],[-0.01388,-0.03213,0.06107],[0.00039,-0.035,0.06107],[-0.00689,-0.03431,0.06107],[0.01459,-0.03181,0.06107],[0.02627,-0.02313,0.06107],[0.03485,-0.00327,0.06107],[0.03477,0.00405,0.06107],[0.03316,0.01119,0.06107],[-0.02089,0.02808,0.06107],[0.01388,0.03213,0.06107],[0.00689,0.03431,0.06107],[-0.00039,0.035,0.06107],[-0.01459,0.03181,0.06107],[0.03454,-0.00564,0.06607],[-0.00766,0.03415,0.06607],[-0.03458,0.0054,0.06607],[0.00039,-0.035,0.06607],[0.00689,0.03431,0.09337],[-0.03316,-0.01119,0.09337],[-0.03011,-0.01784,0.09337],[0.03341,-0.01044,0.09337],[-0.02627,0.02313,0.09337],[0.02089,-0.02808,0.09337],[0.0305,-0.01716,0.09337],[0.02025,0.02854,0.09337],[-0.01459,0.03181,0.09337],[0.02627,-0.02313,0.09337],[-0.03355,-0.00997,0.06607],[-0.01227,-0.01394,0.01765],[-0.01168,-0.01444,0.01765],[-0.00404,-0.01813,0.01765],[-0.00328,-0.01828,0.01765],[0.01006,-0.01561,0.01765],[0.00526,-0.01781,0.01765],[0.01654,0.00844,0.01765],[-0.0149,-0.01108,0.01765],[-0.0184,-0.00253,0.01765],[-0.01705,0.00736,0.01765],[-0.01734,0.00665,0.01765],[-0.01838,0.00261,0.01765],[-0.01834,0.00289,0.01765],[0.01784,-0.00517,0.01765],[0.01804,-0.00442,0.01765],[-0.01468,0.01137,0.01765],[0.0006,-0.01856,0.01765],[0.00137,-0.01852,0.01765],[-0.00739,0.01704,0.01765],[-0.00292,0.01834,0.01765],[-0.00368,0.0182,0.01765],[0.01001,0.01564,0.01765],[0.00978,0.01579,0.01765],[0.00173,0.01849,0.01765],[0.00628,0.01748,0.01765],[0.01367,-0.01256,0.01765],[0.02329,-0.01247,0.02465],[0.02566,-0.00629,0.02465],[0.02537,-0.00735,0.02465],[0.01856,-0.00057,0.01765],[0.01857,0.0002,0.01765],[0.0264,-0.00081,0.02465],[0.02551,0.00685,0.02465],[0.01812,0.00407,0.01765],[0.01793,0.00481,0.01765],[0.02353,0.01201,0.02465],[0.01905,0.01829,0.02465],[0.01392,0.01229,0.01765],[0.01483,0.02186,0.02465],[0.01391,0.02246,0.02465],[0.00789,0.02521,0.02465],[0.00096,0.01854,0.01765],[-0.00809,0.01671,0.01765],[-0.01051,0.02423,0.02465],[-0.01139,0.01466,0.01765],[-0.01621,0.02086,0.02465],[-0.02154,0.01529,0.02465],[-0.01514,0.01075,0.01765],[-0.02466,0.00945,0.02465],[-0.02624,0.00302,0.02465],[-0.01719,-0.00702,0.01765],[-0.01661,-0.02054,0.02465],[-0.01745,-0.01983,0.02465],[-0.01197,-0.02354,0.02465],[-0.00772,-0.01689,0.01765],[-0.00466,-0.026,0.02465],[-0.00574,-0.02578,0.02465],[0.00195,-0.02634,0.02465],[0.00804,-0.02516,0.02465],[0.00593,-0.0176,0.01765],[0.00739,-0.02536,0.02465],[0.00947,-0.01598,0.01765],[0.01383,-0.02251,0.02465],[0.01346,-0.02273,0.02465],[0.0144,-0.02214,0.02465],[0.01012,-0.01557,0.01765],[0.00178,-0.02635,0.02465],[0.00085,-0.0264,0.02465],[0.01881,-0.01854,0.02465],[0.01869,-0.01866,0.02465],[0.00844,-0.02503,0.02465],[-0.02184,-0.01486,0.02465],[-0.0212,-0.01576,0.02465],[-0.02485,-0.00897,0.02465],[-0.02445,-0.00999,0.02465],[-0.02617,-0.0036,0.02465],[-0.02609,0.00411,0.02465],[-0.02425,0.01047,0.02465],[-0.02088,0.01617,0.02465],[-0.01151,0.02377,0.02465],[-0.00415,0.02609,0.02465],[-0.00524,0.02589,0.02465],[0.00247,0.0263,0.02465],[0.00137,0.02638,0.02465],[0.00893,0.02486,0.02465],[0.0198,0.01748,0.02465],[0.02577,0.00578,0.02465],[0.01945,-0.01787,0.02465],[0.0052,-0.01783,0.01765],[-0.01098,-0.02402,0.02465],[-0.00842,-0.01655,0.01765],[-0.01535,-0.01045,0.01765],[-0.01747,-0.00631,0.01765],[-0.01849,-0.00176,0.01765],[-0.0263,-0.00251,0.02465],[-0.01845,0.00213,0.01765],[-0.01199,0.01418,0.01765],[-0.01706,0.02017,0.02465],[0.00554,0.01772,0.01765],[0.01042,0.01537,0.01765],[0.0134,0.01286,0.01765],[0.01617,0.00912,0.01765],[0.02301,0.01298,0.02465],[0.02641,0.00029,0.02465],[0.01637,-0.00877,0.01765],[0.01599,-0.00944,0.01765],[0.02275,-0.01343,0.02465],[0.01314,-0.01312,0.01765]]} diff --git a/waybionic_description/test/test_arm_description.py b/waybionic_description/test/test_arm_description.py index bea29c2e..128bc8bf 100644 --- a/waybionic_description/test/test_arm_description.py +++ b/waybionic_description/test/test_arm_description.py @@ -37,6 +37,37 @@ def test_joint_chain_matches_mechanical_fk(robot): assert float(limit.get('lower')) < 0.0 < float(limit.get('upper')) +def test_joint_limits_are_where_the_cad_parts_touch(robot): + # From the upright pose (scripts/cad/exact_limits.py), the straight arm meets the ground under + # the base at 109.65 degrees of shoulder, the forearm the shoulder's motor mount at 148.93 of + # elbow, and the tool mount the forearm's cap at 94.68 of wrist pitch. Nothing meets over a + # full turn of base yaw or wrist roll. + joints = {joint.get('name'): joint for joint in robot.findall('joint')} + for name, degrees in (('joint_1', 360.0), ('joint_2', 109.65), ('joint_3', 148.93), + ('joint_4', 94.68), ('joint_5', 360.0)): + limit = joints[name].find('limit') + assert math.degrees(float(limit.get('upper'))) == pytest.approx(degrees, abs=1e-4) + assert math.degrees(float(limit.get('lower'))) == pytest.approx(-degrees, abs=1e-4) + + +def test_moving_links_carry_the_hull_of_their_parts(robot): + hulls = {hull.get('link'): [float(value) for value in hull.get('points').split()] + for hull in robot.findall('waybionic_hull')} + assert sorted(hulls) == sorted([ + 'upper_arm_link', 'forearm_link', 'wrist_pitch_link', 'wrist_left_gear_link', + 'wrist_right_gear_link', 'wrist_roll_link']) + for link, values in hulls.items(): + assert len(values) % 3 == 0 and len(values) >= 12 + shapes = [collision_shape(collision) + for collision in robot.find(f"link[@name='{link}']").findall('collision')] + # In the link's own frame: the shapes hold the parts, so they hold the hull too, to + # within the 1 mm the visual meshes' tessellation leaves. + for point in zip(values[0::3], values[1::3], values[2::3]): + assert any(inside(point, center, [h + 0.001 for h in half], + None if radius is None else radius + 0.001, axis) + for center, half, radius, axis in shapes), (link, point) + + def test_differential_side_gears_follow_wrist_roll(robot): gears = {joint.get('name'): joint for joint in robot.findall('joint') if joint.find('mimic') is not None} diff --git a/waybionic_description/urdf/waybionic_arm.urdf b/waybionic_description/urdf/waybionic_arm.urdf index c9b7a1e6..ebeb08a3 100644 --- a/waybionic_description/urdf/waybionic_arm.urdf +++ b/waybionic_description/urdf/waybionic_arm.urdf @@ -3,7 +3,7 @@ Do not edit by hand; re-export the SolidWorks assembly and re-run the script. Joint zero is the upright pose from the mechanical fk.py (links along +Z, pitch about +Y). Saved CAD pose in degrees joint_1=-8.93, joint_2=-8.78, joint_3=45.14, joint_4=5.08, joint_5=0.00. - Each pitch joint stops about 1 degree before two parts touch. Each part has a + Joint limits are where CAD parts touch (scripts/cad/exact_limits.py). Each part has a collision box, or a cylinder where it is round about a joint axis, with a box for any side of it that is not. Effort and velocity are placeholders for display. --> @@ -276,7 +276,7 @@ - + @@ -284,7 +284,7 @@ - + @@ -292,7 +292,7 @@ - + @@ -300,7 +300,7 @@ - + @@ -308,7 +308,7 @@ - + @@ -332,12 +332,204 @@ - - + + + + + + + + + diff --git a/waybionic_teleop/config/xbox_teleop.yaml b/waybionic_teleop/config/xbox_teleop.yaml index 1999528e..bef94fb3 100644 --- a/waybionic_teleop/config/xbox_teleop.yaml +++ b/waybionic_teleop/config/xbox_teleop.yaml @@ -57,9 +57,10 @@ xbox_teleop: tool_open_axis: left_trigger tool_frame: tool_link base_frame: base_link - # Moves stop before any part's collision shape comes within collision_clearance (m) of the - # table, table_height (m) above the bottom of the base, or within self_collision_clearance - # (m) of the base and shoulder. + # Moves stop where a part would go below the table, table_height (m) above the bottom of the + # base, or into the base or shoulder: the joint limits and the forearm's folds are where the + # CAD parts touch, and the table check uses each link's real parts. collision_clearance (m) + # and self_collision_clearance (m) keep a gap to the table and to the base and shoulder. table_height: 0.0 - collision_clearance: 0.01 - self_collision_clearance: 0.002 + collision_clearance: 0.0 + self_collision_clearance: 0.0 diff --git a/waybionic_teleop/package.xml b/waybionic_teleop/package.xml index 7ad14a25..416a0c60 100644 --- a/waybionic_teleop/package.xml +++ b/waybionic_teleop/package.xml @@ -16,6 +16,8 @@ visualization_msgs python3-can + + python3-numpy python3-serial diff --git a/waybionic_teleop/test/test_collision.py b/waybionic_teleop/test/test_collision.py index e9496c03..1a4b9c63 100644 --- a/waybionic_teleop/test/test_collision.py +++ b/waybionic_teleop/test/test_collision.py @@ -49,13 +49,60 @@ def test_folding_back_into_the_base_is_caught_past_todays_joint_limits(check): assert not any('table' in hit for hit in hits) -def test_the_elbow_folds_until_the_forearm_almost_touches_the_shoulder(check): - # The forearm's boxes would stop this near 134 degrees; the CAD fold table allows 147. - assert check.hits(pose(0, 146, 0)) == [] and check.hits(pose(0, -146, 0)) == [] +def test_the_elbow_folds_until_the_forearm_touches_the_shoulder(check): + # The forearm's boxes would stop this near 134 degrees; the CAD fold table allows 148.7. + assert check.hits(pose(0, 148.6, 0)) == [] and check.hits(pose(0, -148.6, 0)) == [] assert check.hits(pose(0, 149, 0)) == ['forearm_link: shoulder_link'] assert check.hits(pose(0, -149, 0)) == ['forearm_link: shoulder_link'] +@pytest.mark.parametrize('group, axis, joint, stop, why', [ + # The straight arm reaches the ground under the base, where the shoulder's limit is. + (0, 'left_y', 'joint_2', 109.65, None), + # The forearm reaches the shoulder's motor mount: the fold table at an upright shoulder. + (0, 'right_y', 'joint_3', 148.7, 'forearm_link: shoulder_link'), + # The tool mount reaches the cap on the forearm, where the wrist's limit is. + (1, 'right_y', 'joint_4', 94.68, None), +]) +def test_each_joint_turned_from_upright_stops_where_its_cad_parts_touch( + parameters, check, group, axis, joint, stop, why): + teleop = ArmTeleop(config_from_parameters({**parameters('xbox_teleop.yaml', 'xbox_teleop'), + 'initial_speed_level': 3}), + LIMITS, ArmKinematics.from_urdf(URDF), check) + upright = pose(0, 0, 0) + for button in ('start',) + ('y',) * group: + teleop.update(*sample(button), upright, DT) + teleop.update(*sample(), upright, DT) + for _ in range(round(4.0 / DT)): + teleop.update(*sample(**{axis: 1.0}), dict(teleop.targets), DT) + assert abs(math.degrees(teleop.targets[joint])) == pytest.approx(stop, abs=0.05) + assert check.hits(teleop.targets) == [] + if why: + assert teleop.blocked == [why] + if joint == 'joint_2': + # Where the shoulder stops, the tool mount is within 0.1 mm of the ground. + assert ArmCollision.from_urdf(URDF, clearance=0.0001).hits(teleop.targets) == [ + 'wrist_roll_link: table'] + + +def test_base_yaw_and_wrist_roll_turn_on_past_half_a_turn(parameters, check): + teleop = ArmTeleop(config_from_parameters({**parameters('xbox_teleop.yaml', 'xbox_teleop'), + 'initial_speed_level': 3}), + LIMITS, ArmKinematics.from_urdf(URDF), check) + upright = pose(0, 0, 0) + teleop.update(*sample('start'), upright, DT) + teleop.update(*sample(), upright, DT) + for _ in range(round(4.0 / DT)): + teleop.update(*sample(left_x=1.0), dict(teleop.targets), DT) + teleop.update(*sample('y'), dict(teleop.targets), DT) + teleop.update(*sample(), dict(teleop.targets), DT) + for _ in range(round(4.0 / DT)): + teleop.update(*sample(right_x=1.0), dict(teleop.targets), DT) + assert abs(math.degrees(teleop.targets['joint_1'])) > 200.0 + assert abs(math.degrees(teleop.targets['joint_5'])) > 200.0 + assert teleop.blocked == [] + + def test_the_fold_limit_follows_the_shoulder_angle(): # With the shoulder tilted, the forearm meets the shoulder sooner on that side. away = ArmCollision.from_urdf(URDF, table_z=-10.0) @@ -65,17 +112,17 @@ def test_the_fold_limit_follows_the_shoulder_angle(): @pytest.mark.parametrize('yaw', [0.0, math.radians(45)]) -def test_the_forearm_folds_onto_the_base_until_just_before_its_parts_touch(yaw): +def test_the_forearm_folds_onto_the_base_until_its_parts_touch(yaw): # With the table out of the way, the CAD parts touch at these elbow angles at either yaw. away = ArmCollision.from_urdf(URDF, table_z=-10.0) for shoulder, touch in ((45, 130.2), (90, 97.2)): - assert away.hits(pose(shoulder, touch - 1.4, 0, yaw)) == [] + assert away.hits(pose(shoulder, touch - 0.3, 0, yaw)) == [] assert 'forearm_link: base_link' in away.hits(pose(shoulder, touch + 0.3, 0, yaw)) - # Folded back to the shoulder's limit, the forearm clears the base with the elbow bent up; - # bent down, it touches the base at -11 degrees. - for elbow in (60, 90, -9.5): - assert away.hits(pose(-135, elbow, 0, yaw)) == [] - assert away.hits(pose(-135, -11.5, 0, yaw)) == ['forearm_link: base_link'] + # At the shoulder's limit, the forearm clears the base with the elbow bent up; bent down, it + # touches the base at -76.5 degrees. + for elbow in (60, 90, -76): + assert away.hits(pose(-109.65, elbow, 0, yaw)) == [] + assert away.hits(pose(-109.65, -77, 0, yaw)) == ['forearm_link: base_link'] @pytest.mark.parametrize('yaw', [0.0, math.radians(45)]) @@ -92,18 +139,21 @@ def test_the_wrist_and_tool_stop_just_before_their_parts_touch_the_base(yaw): @pytest.mark.parametrize('old, new', [ - ('across="joint_2"', 'across="joint_9"'), ('start="-135"', 'start="nan"'), - ('step="5"', 'step="0"'), ('upper="147.3 ', 'upper="'), ('lower="-122.7', 'lower="inf'), + ('across="joint_2"', 'across="joint_9"'), ('start="-109.65"', 'start="nan"'), + ('step="4.984090909"', 'step="0"'), ('upper="148.7 ', 'upper="'), + ('lower="-126.8', 'lower="inf'), # Each table replaces the shapes for its pair, so it must fit the joint tree. ('obstacle="shoulder_link"', 'obstacle="upper_arm_link"'), ('link="forearm_link" obstacle="base_link"', 'link="upper_arm_link" obstacle="base_link"'), - ('joint="joint_3" across="joint_2" start="-135" step="5"', - 'joint="joint_1" across="joint_2" start="-135" step="5"'), - ('across="joint_2" start="-135" step="5"', 'across="joint_3" start="-135" step="5"'), - ('across="joint_2" start="-135" step="5"', 'across="joint_4" start="-135" step="5"'), - ('start="-135" step="5"', 'start="-130" step="5"'), - ('start="-135" step="2.5"', 'start="-135" step="2"'), - ('upper="147.3 ', 'upper="-130 '), + ('joint="joint_3" across="joint_2" start="-109.65" step="4.984090909"', + 'joint="joint_1" across="joint_2" start="-109.65" step="4.984090909"'), + ('across="joint_2" start="-109.65" step="4.984090909"', + 'across="joint_3" start="-109.65" step="4.984090909"'), + ('across="joint_2" start="-109.65" step="4.984090909"', + 'across="joint_4" start="-109.65" step="4.984090909"'), + ('start="-109.65" step="4.984090909"', 'start="-104.65" step="4.984090909"'), + ('start="-109.65" step="2.492045455"', 'start="-109.65" step="2"'), + ('upper="148.7 ', 'upper="-130 '), ]) def test_an_unusable_fold_table_is_refused(old, new): assert old in URDF @@ -144,6 +194,35 @@ def test_table_height_and_clearance_are_configurable(): assert ArmCollision.from_urdf(URDF, table_z=0.1, clearance=0.1).hits(joints) +def test_the_table_check_follows_the_real_parts_rather_than_their_shapes(): + # With the tool tilted back, the tool mount's cylinder reaches 12 mm below the mount itself, + # whose lowest point, from the URDF's convex hull of its CAD parts, is 650.42 mm up. + joints = pose(0, 20, -60) + contact = 'wrist_roll_link: table' + assert contact not in ArmCollision.from_urdf(URDF, table_z=0.6503).hits(joints) + assert contact in ArmCollision.from_urdf(URDF, table_z=0.6505).hits(joints) + shapes_only = re.sub(r'', '', URDF, flags=re.S) + assert contact in ArmCollision.from_urdf(shapes_only, table_z=0.645).hits(joints) + assert contact not in ArmCollision.from_urdf(URDF, table_z=0.645).hits(joints) + + +ROLL_HULL = re.search(r'', URDF, re.S).group(0) + + +@pytest.mark.parametrize('hull', [ + ROLL_HULL.replace('points="', 'points="nan '), + ROLL_HULL.replace('points="', 'points="0.1 '), + '', + ROLL_HULL.replace('link="wrist_roll_link"', 'link="base_link"'), + ROLL_HULL.replace('link="wrist_roll_link"', 'link="stray_link"'), + ROLL_HULL.replace('link="wrist_roll_link"', 'link="forearm_link"'), +]) +def test_a_hull_that_is_not_one_whole_set_of_points_is_refused(hull): + # A hull short of the link's parts would let them below the table. + with pytest.raises(ValueError, match='waybionic_hull'): + ArmCollision.from_urdf(URDF.replace(ROLL_HULL, hull)) + + def test_the_base_and_shoulder_have_their_own_smaller_clearance(): # The tool is between 2 and 10 mm from the base's lid here. joints = pose(30, 121.5, 90, math.radians(45)) @@ -255,7 +334,7 @@ def test_teleop_refuses_a_step_that_presses_one_contact_deeper(parameters, check for _ in range(round(0.5 / DT)): teleop.update(*sample(left_y=-1.0), dict(teleop.targets), DT) assert teleop.targets['joint_3'] == start['joint_3'] - assert teleop.blocked == ['tool_link: table'] + assert 'tool_link: table' in teleop.blocked def test_the_intrusion_is_the_volume_inside_the_grown_obstacle(): @@ -271,7 +350,7 @@ def test_the_intrusion_is_the_volume_inside_the_grown_obstacle(): @pytest.mark.parametrize('start, contact', [ - (pose(45, 129.5, 0), 'forearm_link: base_link'), + (pose(45, 130.1, 0), 'forearm_link: base_link'), (pose(45, 121.0, 60), 'wrist_roll_link: base_link'), ]) def test_teleop_never_presses_the_arm_further_into_the_base(parameters, start, contact): diff --git a/waybionic_teleop/test/test_incision.py b/waybionic_teleop/test/test_incision.py index 9900a150..f3d64692 100644 --- a/waybionic_teleop/test/test_incision.py +++ b/waybionic_teleop/test/test_incision.py @@ -161,21 +161,22 @@ def test_moving_into_a_joint_limit_sends_targets_within_the_urdf_limits( assert through(arm, teleop.targets, teleop.incision)[0] < 1e-6 -@pytest.mark.parametrize('into, back, contact', [ - ({'left_y': 1.0}, {'left_y': -1.0}, 'tool_link: table'), - ({'right_y': -1.0}, {'right_y': 1.0}, 'tool_link: table'), - ({'right_y': 1.0}, {'right_y': -1.0}, 'forearm_link: table'), +@pytest.mark.parametrize('inserted, into, back, contact', [ + (1.0, {'left_y': 1.0}, {'left_y': -1.0}, 'tool_link: table'), + (1.6, {'right_y': -1.0}, {'right_y': 1.0}, 'tool_link: table'), + (1.0, {'right_y': 1.0}, {'right_y': -1.0}, 'wrist_pitch_link: table'), ], ids=['insert', 'pivot_tool_down', 'pivot_forearm_down']) def test_an_incision_move_into_the_table_is_refused_but_backing_out_is_not( - parameters, arm, into, back, contact): + parameters, arm, inserted, into, back, contact): check = ArmCollision.from_urdf(URDF) teleop = ArmTeleop(config_from_parameters(parameters('xbox_teleop.yaml', 'xbox_teleop')), LIMITS, arm, check) for button in ('start', 'y', 'y', 'y'): teleop.update(*sample(button), NEAR_TABLE, DT) teleop.update(*sample(), NEAR_TABLE, DT) - # With the tool 25 mm in, inserting further or pivoting either way reaches the table. - run(teleop, 1.0, left_y=1.0) + # With the tool 25 mm in, inserting further or pivoting the forearm down reaches the table; + # 40 mm in, so does pivoting the tool down, whose jaws reach about 55 mm past the incision. + run(teleop, inserted, left_y=1.0) run(teleop, 0.3) first = teleop.incision stopped = False diff --git a/waybionic_teleop/test/test_kinematics.py b/waybionic_teleop/test/test_kinematics.py index 4a1b9061..7df5c213 100644 --- a/waybionic_teleop/test/test_kinematics.py +++ b/waybionic_teleop/test/test_kinematics.py @@ -204,18 +204,18 @@ def test_other_arm_layouts_are_rejected(change): def test_joint_limits_match_the_model_and_allow_only_explicit_missing_placeholders(): assert joint_limits(URDF, ['joint_1', 'joint_2']) == { - 'joint_1': (-3.141593, 3.141593), - 'joint_2': (-2.356194, 2.356194)} + 'joint_1': (-6.283185, 6.283185), + 'joint_2': (-1.913754, 1.913754)} assert joint_limits(URDF, ['tool_grip'], required=False) == {} with pytest.raises(ValueError, match='tool_grip'): joint_limits(URDF, ['tool_grip']) @pytest.mark.parametrize('bad', [ - URDF.replace('lower="-2.356194"', 'lower="nan"', 1), - URDF.replace('upper="2.356194"', 'upper="inf"', 1), - URDF.replace('upper="2.356194"', 'upper="-3"', 1), - URDF.replace('lower="-2.356194" ', '', 1), + URDF.replace('lower="-1.913754"', 'lower="nan"', 1), + URDF.replace('upper="1.913754"', 'upper="inf"', 1), + URDF.replace('upper="1.913754"', 'upper="-3"', 1), + URDF.replace('lower="-1.913754" ', '', 1), URDF.replace('', ''), ]) def test_invalid_or_duplicate_urdf_joint_bounds_are_rejected(bad): diff --git a/waybionic_teleop/test/test_sim_arm_drives_node.py b/waybionic_teleop/test/test_sim_arm_drives_node.py index cbee2c6b..8daf70c2 100644 --- a/waybionic_teleop/test/test_sim_arm_drives_node.py +++ b/waybionic_teleop/test/test_sim_arm_drives_node.py @@ -264,14 +264,15 @@ def test_malformed_commands_stop_all_drives_instead_of_partially_updating(node, elif fault == 'nonfinite_speed': bad.velocity[-1] = math.inf else: - bad.position[0] = 4.0 + # Base yaw turns a full turn either way. + bad.position[0] = 7.0 node.on_command(bad) assert node.rejected == 1 assert_stopped(node) @pytest.mark.parametrize('bad', [ - URDF.replace('upper="2.356194"', 'upper="nan"', 1), + URDF.replace('upper="1.913754"', 'upper="nan"', 1), URDF.replace('name="joint_2" type="revolute"', 'name="other" type="revolute"', 1), ]) def test_invalid_or_missing_model_limit_requires_repair_and_new_enable(node, bad): @@ -336,7 +337,7 @@ def test_int24_overflow_rejects_the_entire_coordinated_move(node): def test_encoder_outside_a_provisional_limit_may_move_only_toward_it(node): start = dict.fromkeys(node.map.joints, 0.0) - start['joint_4'] = 1.65 + start['joint_4'] = 1.67 for drive, count in zip(node.map.drives, node.map.to_counts(start)): node.bus.drives[drive.can_id].axis = float(count) ready(node) diff --git a/waybionic_teleop/test/test_xbox_teleop_node.py b/waybionic_teleop/test/test_xbox_teleop_node.py index 523775e2..68e1d766 100644 --- a/waybionic_teleop/test/test_xbox_teleop_node.py +++ b/waybionic_teleop/test/test_xbox_teleop_node.py @@ -168,7 +168,7 @@ def test_stale_joint_feedback_cannot_be_used_to_enable(node): def test_bad_description_and_mismatched_joint_map_fail_closed(node): - node.load(String(data=URDF.replace('upper="2.356194"', 'upper="nan"', 1))) + node.load(String(data=URDF.replace('upper="1.913754"', 'upper="nan"', 1))) assert node.teleop is None and 'invalid limits' in node.problem node.config.groups[2].joints.reverse() node.load(String(data=URDF)) diff --git a/waybionic_teleop/waybionic_teleop/collision.py b/waybionic_teleop/waybionic_teleop/collision.py index 2274d1ba..f90c28d1 100644 --- a/waybionic_teleop/waybionic_teleop/collision.py +++ b/waybionic_teleop/waybionic_teleop/collision.py @@ -5,16 +5,19 @@ round about a joint axis, such as the base's lid or the tool mount, a cylinder and a box for a part round on one side, such as the wrist's differential housing, and otherwise a box. Every check happens in the base frame. The moving links must stay above the table, and the forearm, -wrist and tool must stay out of the base and shoulder, the parts they can fold into. Adjacent -links overlap at their joints, so those pairs are never compared; the joint limits keep them -apart. Where the URDF has a fold table for a pair (waybionic_fold, measured from the CAD), the -table replaces the shapes for it: the elbow may fold until the forearm is about to touch the -shoulder or the base. +wrist and tool must stay out of the base and shoulder, the parts they can fold into. Against the +table a link's convex hull (waybionic_hull, the CAD parts' own) gives its exact lowest point; +links without one use their shapes. Adjacent links overlap at their joints, so those pairs are +never compared; the joint limits keep them apart. Where the URDF has a fold table for a pair +(waybionic_fold, measured from the CAD), the table replaces the shapes for it: the elbow may fold +until the forearm touches the shoulder or the base. """ import math import xml.etree.ElementTree as ET +import numpy as np + # The fixed base and the yaw stage, and what may never touch them. BODY = ('base_link', 'shoulder_link') FOLDING = ('forearm_link', 'wrist_pitch_link', 'wrist_left_gear_link', 'wrist_right_gear_link', @@ -145,14 +148,16 @@ def excess(self, positions): class ArmCollision: """Collision shapes and joint tree read from a URDF.""" - def __init__(self, shapes, joints, root, table_z=0.0, clearance=0.01, self_clearance=0.002, - folds=()): + def __init__(self, shapes, joints, root, table_z=0.0, clearance=0.0, self_clearance=0.0, + folds=(), hulls=None): self.shapes, self.joints, self.root = shapes, joints, root self.table_z, self.clearance, self.self_clearance = table_z, clearance, self_clearance self.folds = {(fold.link, fold.obstacle): fold for fold in folds} + # link -> (N, 3) points in the link frame whose lowest is the link's lowest point. + self.hulls = dict(hulls or {}) @classmethod - def from_urdf(cls, urdf, table_z=0.0, clearance=0.01, self_clearance=0.002): + def from_urdf(cls, urdf, table_z=0.0, clearance=0.0, self_clearance=0.0): """Read shapes and joints; raise ValueError if a required link has no shapes.""" try: robot = ET.fromstring(urdf) @@ -225,6 +230,19 @@ def from_urdf(cls, urdf, table_z=0.0, clearance=0.01, self_clearance=0.002): if len(pairs) != len(folds): raise ValueError('robot_description has two waybionic_fold tables for one pair') checker.folds = {(fold.link, fold.obstacle): fold for fold in folds} + for element in robot.findall('waybionic_hull'): + link = element.get('link') + try: + values = [float(value) for value in (element.get('points') or '').split()] + except ValueError: + values = [] + if (link not in shapes or link in BODY or link in checker.hulls + or len(values) < 12 or len(values) % 3 + or not all(math.isfinite(value) for value in values)): + # A hull that is not whole would let the link's real parts below the table. + raise ValueError(f'robot_description has a waybionic_hull for {link} that is not ' + 'one set of at least four finite points of a moving link') + checker.hulls[link] = np.array(values).reshape(-1, 3) return checker def poses(self, positions): @@ -285,7 +303,11 @@ def check(self, positions): for link, placed in world.items(): if link in BODY: continue - lowest = min(_lowest(shape) for shape, _ in placed) + if link in self.hulls: + rotation, origin = poses[link] + lowest = float((self.hulls[link] @ np.array(rotation[2])).min()) + origin[2] + else: + lowest = min(_lowest(shape) for shape, _ in placed) if lowest < self.table_z + self.clearance: found[f'{link}: table'] = self.table_z + self.clearance - lowest margin = self.self_clearance diff --git a/waybionic_teleop/waybionic_teleop/xbox_teleop_node.py b/waybionic_teleop/waybionic_teleop/xbox_teleop_node.py index 79f36f6e..c7de8235 100644 --- a/waybionic_teleop/waybionic_teleop/xbox_teleop_node.py +++ b/waybionic_teleop/waybionic_teleop/xbox_teleop_node.py @@ -66,8 +66,8 @@ def __init__(self, **kwargs): self.tool_frame = params['tool_frame'] self.base_frame = params['base_frame'] self.table_height = float(params.get('table_height', 0.0)) - self.clearance = float(params.get('collision_clearance', 0.01)) - self.self_clearance = float(params.get('self_collision_clearance', 0.002)) + self.clearance = float(params.get('collision_clearance', 0.0)) + self.self_clearance = float(params.get('self_collision_clearance', 0.0)) if not (math.isfinite(self.table_height) and 0 <= self.clearance < math.inf and 0 <= self.self_clearance < math.inf): raise ValueError('table_height must be finite, and collision_clearance and ' From c3fe49f56660026ee243fb71549d342f1711ac5b Mon Sep 17 00:00:00 2001 From: Yassin Soliman <108886216+yassinsolim@users.noreply.github.com> Date: Sat, 17 Oct 2026 14:14:34 -0600 Subject: [PATCH 07/12] Stop the joint sliders where the arm's parts would touch The sliders now go through joint_state_guard, which moves the arm toward the requested pose with the teleop collision check, stops at the last pose before any part touches, and sends the sliders back there. The wrist limit is now the lowest contact over a full turn of roll (94.67 degrees), and scripts/cad/check_collision_model.py checks the collision model against the CAD meshes. --- BuildInstructions.md | 30 ++- scripts/cad/build_arm_description.py | 5 +- scripts/cad/check_collision_model.py | 173 ++++++++++++++++++ scripts/cad/exact_limits.py | 58 ++++-- waybionic_bringup/CMakeLists.txt | 1 + waybionic_bringup/README.md | 2 +- .../launch/ground_station.launch.py | 26 ++- waybionic_bringup/test/test_launch_options.py | 10 + .../test/test_slider_guard_launch.py | 78 ++++++++ .../test/test_arm_description.py | 6 +- waybionic_description/urdf/waybionic_arm.urdf | 2 +- waybionic_teleop/setup.py | 1 + waybionic_teleop/test/test_collision.py | 35 +++- .../test/test_joint_state_guard.py | 106 +++++++++++ .../waybionic_teleop/collision.py | 32 ++++ .../waybionic_teleop/joint_state_guard.py | 118 ++++++++++++ 16 files changed, 648 insertions(+), 35 deletions(-) create mode 100644 scripts/cad/check_collision_model.py create mode 100644 waybionic_bringup/test/test_slider_guard_launch.py create mode 100644 waybionic_teleop/test/test_joint_state_guard.py create mode 100644 waybionic_teleop/waybionic_teleop/joint_state_guard.py diff --git a/BuildInstructions.md b/BuildInstructions.md index 8cf24e0c..f32d2557 100644 --- a/BuildInstructions.md +++ b/BuildInstructions.md @@ -270,9 +270,10 @@ a terminal with an outdated `PATH`: ``` RViz and the Joint State Publisher GUI open as separate windows. Move the -`joint_1` to `joint_5` sliders to move the arm, and use the diagnostics panel's -mock controls to try normal and fault states. This demo uses simulated data, not -a physical arm. Press **Ctrl+C** in PowerShell to stop it. +`joint_1` to `joint_5` sliders to move the arm; it stops where it would hit +itself or the ground, and the sliders jump back to where it stopped. Use the +diagnostics panel's mock controls to try normal and fault states. This demo uses +simulated data, not a physical arm. Press **Ctrl+C** in PowerShell to stop it. To sweep each joint in turn instead, put the launch command after `wslg`: @@ -438,9 +439,10 @@ The arm URDF's joint limits are where the CAD parts touch, found by turning each from the upright pose with exact triangle-mesh contacts (`scripts/cad/exact_limits.py`): the straight arm meets the ground under the base at 109.65 degrees of shoulder either way, the forearm meets the shoulder's motor mount at 148.93 degrees of elbow, and the -tool mount meets the cap on the forearm at 94.68 degrees of wrist pitch. Nothing meets -anything over a full turn of base yaw or wrist roll, so they turn a full turn (360 -degrees) either way; their cabling is not modelled. These limits and the collision +tool mount meets the cap on the forearm at 94.67 degrees of wrist pitch, at the wrist +roll that turns its facets closest to the cap. Nothing meets anything over a full turn +of base yaw or wrist roll, so they turn a full turn (360 degrees) either way; their +cabling is not modelled. These limits and the collision checks below have been tested with simulated drives only. The simulated CAN map is not a powered-arm safety case. Do not operate powered motors until Mechanical confirms the signed travel of each joint from upright zero on the built arm, including any cable or @@ -481,6 +483,16 @@ already touching something, the only moves still allowed are the ones that back it: a move that presses any contact further in is refused, even if it would ease another contact at the same time. +The joint sliders use the same check. `joint_state_guard` moves the arm from where it +is toward the sliders' pose, checking at least every half degree of each joint, stops +at the last pose before any part would touch, and moves the sliders back to it. + +`scripts/cad/check_collision_model.py` checks all of this against the exact CAD +meshes: at about 300,000 poses that the check calls clear (random poses, poses with +a joint at a limit, and the poses where moves stop), no two parts, nor the tool's box, +intersect, and no part is below the ground. Run it after any change to the CAD, +the limits or the collision shapes. + The collision shapes are what make any of this work. A `robot_description` without collision shapes for the base, shoulder, upper arm, forearm, wrist, wrist roll or tool leaves teleop disabled, and the diagnostics panel names the missing links. @@ -916,7 +928,7 @@ ros2 launch waybionic_bringup ground_station.launch.py ``` - **RViz** and **Joint State Publisher GUI** (separate small window) will pop up after the last command - RViz opens pre-configured with `base_link` fixed frame, `RobotModel`, and `TF` displays already loaded -- Move the `joint_1` to `joint_5` sliders in the Joint State Publisher GUI (small window) to move the arm: base yaw, shoulder, elbow, wrist pitch, and wrist roll +- Move the `joint_1` to `joint_5` sliders in the Joint State Publisher GUI (small window) to move the arm: base yaw, shoulder, elbow, wrist pitch, and wrist roll. The arm stops where it would hit itself or the ground, and the sliders jump back to where it stopped - Joint demo: `ros2 launch waybionic_bringup ground_station.launch.py demo_mode:=true` sweeps each joint in turn (simulated, no hardware) and shows a pass/fail row per joint in the diagnostics panel; `demo_speed:=60` changes the speed in degrees per second For mock and live diagnostics checks, continue with the @@ -992,7 +1004,8 @@ Keep this Terminal window open. Within a few seconds: - `DiagnosticsPanel` displays **WayBionic Engineering Monitor** and **Current State: NORMAL**. - Joint State Publisher displays the `joint_1` to `joint_5` sliders. Move them - to check base yaw, shoulder, elbow, wrist pitch, and wrist roll. + to check base yaw, shoulder, elbow, wrist pitch, and wrist roll. The arm stops + where it would hit itself or the ground. To stop the application, return to the launch Terminal and press Control+C. @@ -1017,6 +1030,7 @@ RMW_IMPLEMENTATION=rmw_cyclonedds_cpp ./scripts/macos.sh run ros2 node list The output must include: ```text +/joint_state_guard /joint_state_publisher /robot_state_publisher /rviz2 diff --git a/scripts/cad/build_arm_description.py b/scripts/cad/build_arm_description.py index b1c890bd..93931004 100644 --- a/scripts/cad/build_arm_description.py +++ b/scripts/cad/build_arm_description.py @@ -64,7 +64,8 @@ # Each limit is where a joint, turning from the upright pose, first brings two CAD parts # together or the arm down to the ground under the base (scripts/cad/exact_limits.py): the # straight arm meets the ground at 109.65 degrees of shoulder, the forearm the shoulder's motor -# mount at 148.93 of elbow, and the tool mount the cap on the forearm at 94.68 of wrist pitch. +# mount at 148.93 of elbow, and the tool mount the cap on the forearm at 94.67 of wrist pitch, +# at the roll that turns its facets closest to the cap. # Nothing meets over a full turn of base yaw or wrist roll, so they turn a full turn either way. # In other poses the forearm's folds (ELBOW_FOLDS) and the ground stop the arm in teleop. JOINTS = ( @@ -75,7 +76,7 @@ ('joint_3', 'upper_arm_link', 'forearm_link', 'Concentric127', 'Coincident71', 'outer_ring_sweep_loose-2', (-148.93, 148.93)), ('joint_4', 'forearm_link', 'wrist_pitch_link', 'Concentric139', None, - 'DifferentialHousing-1', (-94.68, 94.68)), + 'DifferentialHousing-1', (-94.67, 94.67)), ('joint_5', 'wrist_pitch_link', 'wrist_roll_link', 'Concentric143', None, 'straight bevel pinion_iso-3', (-360.0, 360.0)), ) diff --git a/scripts/cad/check_collision_model.py b/scripts/cad/check_collision_model.py new file mode 100644 index 00000000..3cfe1bea --- /dev/null +++ b/scripts/cad/check_collision_model.py @@ -0,0 +1,173 @@ +#!/usr/bin/env python3 +"""Check the teleop collision model against the exact CAD at random poses. + + python3 scripts/cad/check_collision_model.py build/cad/arm_export.json [--poses 320000] + +This needs numpy, scipy and python-fcl, like exact_limits.py. The model is what teleop and the +joint sliders stop at: the URDF's joint limits, collision shapes, fold tables and hulls, read by +waybionic_teleop.collision. It must never call a pose clear where two CAD parts on different +links, or a part and the tool's placeholder box, intersect, or where a part reaches below the +ground under the base. Poses are drawn uniformly within the joint limits, then with one joint at +a limit, then at the ends of straight moves from clear poses, where the model or a joint limit +first stops them. FCL checks each pose the model calls clear on the triangle meshes. Parts that +already touch upright, such as bearings on their seats and meshing gears, are left out, as in +exact_limits.py. The script exits with status 1 if any pose clashes. +""" + +import argparse +import collections +import importlib.util +import math +import multiprocessing +from pathlib import Path +import random +import sys +import xml.etree.ElementTree as ET + +import fcl +import numpy as np + +ROOT = Path(__file__).resolve().parents[2] +sys.path.insert(0, str(ROOT / 'waybionic_teleop')) +from waybionic_teleop.collision import ArmCollision # noqa: E402 +from waybionic_teleop.kinematics import joint_limits # noqa: E402 + +spec = importlib.util.spec_from_file_location( + 'exact_limits', Path(__file__).resolve().with_name('exact_limits.py')) +exact = importlib.util.module_from_spec(spec) +spec.loader.exec_module(exact) + +URDF = (ROOT / 'waybionic_description' / 'urdf' / 'waybionic_arm.urdf').read_text( + encoding='utf-8') +JOINTS = ['joint_1', 'joint_2', 'joint_3', 'joint_4', 'joint_5'] +BODY = {'base_link', 'shoulder_link'} +STEP = math.radians(0.25) + + +class Truth: + """Every CAD part as a triangle mesh, and the tool's box, posed by the joint angles.""" + + def __init__(self, export): + self.robot = exact.Robot(export) + # (link, name, hull points in the link frame, FCL object, its centre in the link frame) + self.items = [(link, name.split('/')[-1], hull, + fcl.CollisionObject(mesh, fcl.Transform()), np.zeros(3)) + for link, name, hull, mesh in self.robot.parts] + box = ET.fromstring(URDF).find("link[@name='tool_link']/collision") + centre = np.array([float(v) for v in box.find('origin').get('xyz').split()]) + size = np.array([float(v) for v in box.find('geometry/box').get('size').split()]) + corners = np.array([[x, y, z] for x in (-1, 1) for y in (-1, 1) for z in (-1, 1)]) + self.items.append(('tool_link', 'tool box', corners * size / 2 + centre, + fcl.CollisionObject(fcl.Box(*size), fcl.Transform()), centre)) + tool = ET.fromstring(URDF).find("joint[@name='tool_joint']/origin") + self.tool = np.array([float(v) for v in tool.get('xyz').split()]) + self.place({}) + self.pairs = [(a, b) for i, a in enumerate(self.items) for b in self.items[i + 1:] + if a[0] != b[0] and fcl.distance(a[3], b[3], fcl.DistanceRequest(), + fcl.DistanceResult()) > exact.MATED] + + def place(self, q): + poses = self.robot.poses(q) + r, o = poses['wrist_roll_link'] + poses['tool_link'] = (r, o + r @ self.tool) + self.boxes, self.lowest = {}, (math.inf, None) + for link, name, points, obj, centre in self.items: + r, o = poses[link] + obj.setTransform(fcl.Transform(r, o + r @ centre)) + world = points @ r.T + o + self.boxes[id(obj)] = (world.min(axis=0), world.max(axis=0)) + if link not in BODY and world[:, 2].min() < self.lowest[0]: + self.lowest = (float(world[:, 2].min()), link) + + def clashes(self, q): + """Return what clashes at these joint angles: ('ground', link) or (link, link) pairs.""" + self.place(q) + found = [] + if self.lowest[0] < -1e-6: + found.append(('ground', self.lowest[1])) + for a, b in self.pairs: + (a0, a1), (b0, b1) = self.boxes[id(a[3])], self.boxes[id(b[3])] + if np.any(a0 > b1 + 1e-9) or np.any(b0 > a1 + 1e-9): + continue + if fcl.collide(a[3], b[3], fcl.CollisionRequest(), fcl.CollisionResult()): + found.append((f'{a[0]}: {a[1]}', f'{b[0]}: {b[1]}')) + return found + + +_TRUTH = None + + +def check(task): + seed, count = task + rng = random.Random(seed) + model = ArmCollision.from_urdf(URDF) + limits = joint_limits(URDF, JOINTS) + clear, kinds, examples = 0, collections.Counter(), [] + + def pose(): + return {joint: rng.uniform(*limits[joint]) for joint in JOINTS} + + def judge(q): + nonlocal clear + clear += 1 + found = _TRUTH.clashes(q) + if found: + at = [joint for joint in JOINTS + if min(abs(q[joint] - bound) for bound in limits[joint]) < 1e-9] + links = sorted({' and '.join(sorted(item.split(':')[0] for item in pair)) + for pair in found}) + kinds['; '.join(links) + (' at the limit of ' + ', '.join(at) if at else '')] += 1 + if len(examples) < 3: + examples.append((', '.join(f'{joint} {math.degrees(q[joint]):.2f}' + for joint in JOINTS), found[:2])) + + for _ in range(count): + q = pose() + if not model.hits(q): + judge(q) + for _ in range(count // 4): + q = pose() + joint = rng.choice(JOINTS) + q[joint] = limits[joint][rng.randrange(2)] + if not model.hits(q): + judge(q) + for _ in range(count // 20): + q = pose() + if model.hits(q): + continue + direction = [rng.gauss(0.0, 1.0) for _ in JOINTS] + norm = math.sqrt(sum(value * value for value in direction)) + while True: + step = {joint: q[joint] + STEP * value / norm + for joint, value in zip(JOINTS, direction)} + if (any(not limits[j][0] <= step[j] <= limits[j][1] for j in JOINTS) + or model.hits(step)): + judge(q) + break + q = step + return clear, kinds, examples + + +def main(): + parser = argparse.ArgumentParser(description=__doc__.splitlines()[0]) + parser.add_argument('export', type=Path, help='JSON written by export_solidworks_assembly') + parser.add_argument('--poses', type=int, default=320000, help='random poses to draw') + args = parser.parse_args() + global _TRUTH + _TRUTH = Truth(args.export) + workers = multiprocessing.cpu_count() + with multiprocessing.get_context('fork').Pool(workers) as pool: + results = pool.map(check, [(seed, args.poses // workers) for seed in range(workers)]) + clear = sum(result[0] for result in results) + kinds = sum((result[1] for result in results), collections.Counter()) + print(f'{clear} poses the model calls clear; {sum(kinds.values())} of them clash in the CAD') + for kind, count in kinds.most_common(): + print(f' {count}: {kind}') + for _, _, examples in results: + for q, found in examples: + print(f' for example {q}: {found}') + return 1 if kinds else 0 + + +if __name__ == '__main__': + sys.exit(main()) diff --git a/scripts/cad/exact_limits.py b/scripts/cad/exact_limits.py index 0f504ecd..36999893 100644 --- a/scripts/cad/exact_limits.py +++ b/scripts/cad/exact_limits.py @@ -5,7 +5,8 @@ This needs numpy, scipy and python-fcl (pip install python-fcl); the build script does not. After a CAD change, run this, copy the joint limits it prints into JOINTS in -build_arm_description.py, run joint_clearance.py for the ELBOW_FOLDS, and rebuild the URDF. +build_arm_description.py, run joint_clearance.py for the ELBOW_FOLDS, rebuild the URDF, and +check it with check_collision_model.py. Every CAD part, gearbox internals excepted (they are enclosed, and static CAD cannot model their eccentric motion), becomes an FCL triangle mesh in its link frame. A joint turns from the upright @@ -17,16 +18,18 @@ and the lowest vertex of the moving parts is exact. A limit that holds in every pose comes from the parts that only that joint moves against each -other; where a contact also depends on another joint, the teleop collision check stops the arm -instead (ELBOW_FOLDS for the forearm, and the ground). --hulls writes each moving link's convex -hull in its link frame, which the URDF carries so the teleop check finds the lowest point of the -real parts rather than of their collision shapes. +other, over a full turn of any joint that turns them too (the wrist's roll turns the tool mount +against the forearm's cap); where a contact also depends on another joint, the teleop collision +check stops the arm instead (ELBOW_FOLDS for the forearm, and the ground). --hulls writes each +moving link's convex hull in its link frame, which the URDF carries so the teleop check finds +the lowest point of the real parts rather than of their collision shapes. """ import argparse import importlib.util import json import math +import multiprocessing from pathlib import Path import fcl @@ -119,8 +122,10 @@ def hull(self, link): class Sweep: """One joint turning from the upright pose, some links against others.""" - def __init__(self, robot, joint, moving=None, fixed=None): + def __init__(self, robot, joint, moving=None, fixed=None, held=None): self.robot, self.name = robot, joint + # Other joints held at these angles (radians) while this one turns. + self.held = held or {} moving = moving or robot.subtree(robot.joints[joint]['child']) self.moving = [part for part in robot.parts if part[0] in moving] self.fixed = [part for part in robot.parts @@ -134,16 +139,17 @@ def __init__(self, robot, joint, moving=None, fixed=None): mated = {(id(m), id(f)) for m, f in self.mated} self.pairs = [(m, f) for m, f in self.pairs if (id(m), id(f)) not in mated] info = robot.joints[joint] - r, o = robot.poses({})[info['parent']] + r, o = robot.poses(self.held)[info['parent']] self.origin = o + r @ np.array(info['xyz']) self.axis = r @ rpy(*info['rpy']) @ np.array(info['axis'], dtype=float) # No moving point is further than this from the joint axis. self.reach = max(float(np.linalg.norm( - (part[2] - self.origin) - np.outer((part[2] - self.origin) @ self.axis, self.axis), + (self.world[id(part)] - self.origin) + - np.outer((self.world[id(part)] - self.origin) @ self.axis, self.axis), axis=1).max()) for part in self.moving) def place(self, angle): - poses = self.robot.poses({self.name: angle}) + poses = self.robot.poses({**self.held, self.name: angle}) self.world, self.boxes = {}, {} for part in self.robot.parts: r, o = poses[part[0]] @@ -222,6 +228,32 @@ def ground(self, sign, limit=360.0, step=0.25): return None +# The robot for the roll scan's worker processes, which fork with it. +_ROBOT = None + + +def _wrist_contacts(roll): + sweep = Sweep(_ROBOT, 'joint_4', fixed={'forearm_link'}, + held={'joint_5': math.radians(roll)}) + return [sweep.contact(sign, 120.0)[0] for sign in (1, -1)] + + +def wrist_stops(robot, step=0.1): + """ + Return the wrist pitch (degrees) either way where the wrist first touches the forearm. + + Rolling the wrist turns the tool mount's facets against the forearm's cap, so the contact + is found every step degrees over a full turn of roll and the lowest kept. It changes by + under 0.1 degree of pitch per degree of roll, so between two steps it is at most 0.005 + degree lower than the lowest found. + """ + global _ROBOT + _ROBOT = robot + with multiprocessing.get_context('fork').Pool() as pool: + found = pool.map(_wrist_contacts, np.arange(0.0, 360.0, step)) + return tuple(min(contacts[side] for contacts in found) for side in (0, 1)) + + def report(sweep, title): print(title) if sweep.mated: @@ -257,10 +289,10 @@ def main(): 'joint_2, the upper arm against the base and the yaw stage:') report(Sweep(robot, 'joint_3', fixed={'upper_arm_link'}), 'joint_3, the forearm and wrist against the upper arm:') - stops = report(Sweep(robot, 'joint_4', fixed={'forearm_link'}), - 'joint_4, the wrist against the forearm:') - upper, lower = (math.floor(angle * 100) / 100 for angle, _ in stops) - print(f' wrist pitch limits ({-lower:.2f}, {upper:.2f})') + report(Sweep(robot, 'joint_4', fixed={'forearm_link'}), + 'joint_4, the wrist against the forearm, roll at zero:') + upper, lower = (math.floor((angle - 0.005) * 100) / 100 for angle in wrist_stops(robot)) + print(f' over a full turn of roll, wrist pitch limits ({-lower:.2f}, {upper:.2f})') if args.hulls: hulls = {link: [[round(float(value), 5) for value in point] diff --git a/waybionic_bringup/CMakeLists.txt b/waybionic_bringup/CMakeLists.txt index 4529bc24..bbbef60a 100644 --- a/waybionic_bringup/CMakeLists.txt +++ b/waybionic_bringup/CMakeLists.txt @@ -26,6 +26,7 @@ if(BUILD_TESTING) add_launch_test(test/test_cartesian_launch.py ${isolated}) add_launch_test(test/test_joint_demo_launch.py ${isolated}) add_launch_test(test/test_teleop_launch.py ${isolated}) + add_launch_test(test/test_slider_guard_launch.py ${isolated}) add_launch_test(test/test_autoplay_launch.py ${isolated}) add_launch_test(test/test_old_arm_launch.py ${isolated}) add_launch_test(test/test_old_arm_arduino_launch.py ${isolated}) diff --git a/waybionic_bringup/README.md b/waybionic_bringup/README.md index 9895b31b..c037c42b 100644 --- a/waybionic_bringup/README.md +++ b/waybionic_bringup/README.md @@ -12,7 +12,7 @@ RViz using `waybionic_unified.rviz` with its internal mock diagnostics panel. | Argument | Default | Purpose | | --- | --- | --- | | `launch_rviz` | `true` | Start RViz. | -| `use_joint_state_publisher_gui` | `true` | Start the separate joint-state GUI. | +| `use_joint_state_publisher_gui` | `true` | Start the separate joint-state GUI. Its sliders go through `joint_state_guard`, which stops the arm where it would hit itself or the ground and moves the sliders back there. | | `use_diagnostics` | `true` | Enable the RViz diagnostics panel and permit the demo publisher. | | `use_mock_diagnostics` | `true` | Select internal mock data rather than live topics in the panel; demo mode, teleop and the camera always use live topics. | | `start_temporary_diagnostics_publisher` | `false` | Start a demo publisher when diagnostics are enabled. | diff --git a/waybionic_bringup/launch/ground_station.launch.py b/waybionic_bringup/launch/ground_station.launch.py index dfb8c58f..a1bf6f06 100644 --- a/waybionic_bringup/launch/ground_station.launch.py +++ b/waybionic_bringup/launch/ground_station.launch.py @@ -247,12 +247,26 @@ def generate_launch_description(): sim_time = {'use_sim_time': LaunchConfiguration('use_sim_time')} # Demo mode and teleop publish joint states themselves. simulated_joints = OrSubstitution(demo_mode, teleop) + sliders = AndSubstitution(LaunchConfiguration('use_joint_state_publisher_gui'), + NotSubstitution(simulated_joints)) + # The sliders ask for a pose; the guard moves the arm only as far as it goes without + # hitting itself or the table, with teleop's collision settings, and sends the sliders back + # to where it stopped. jsp_gui_node = Node( package='joint_state_publisher_gui', executable='joint_state_publisher_gui', - condition=IfCondition(AndSubstitution( - LaunchConfiguration('use_joint_state_publisher_gui'), - NotSubstitution(simulated_joints))) + condition=IfCondition(sliders), + parameters=[{'source_list': ['joint_state_guard/accepted']}], + remappings=[('joint_states', 'joint_states_requested')] + ) + + with open(os.path.join(teleop_config_dir, 'xbox_teleop.yaml'), encoding='utf-8') as source: + teleop_config = yaml.safe_load(source)['xbox_teleop']['ros__parameters'] + guard_node = Node( + package='waybionic_teleop', executable='joint_state_guard', name='joint_state_guard', + output='screen', condition=IfCondition(sliders), + parameters=[{name: float(teleop_config[name]) for name in ( + 'table_height', 'collision_clearance', 'self_collision_clearance')}, sim_time] ) # With autoplay, the controller goes through the autoplay node before it reaches teleop. @@ -366,7 +380,7 @@ def generate_launch_description(): drive_interface_arg, drive_channel_arg, joy_source_arg, autoplay_arg, joy_udp_bind_arg, joy_udp_port_arg, follow_camera_arg, use_sim_time_arg, camera_arg, camera_bind_arg, camera_log_arg, - launch_rviz_arg, rviz_config_arg, file_check, rsp_node, jsp_gui_node, joint_demo_node, - joy_node, joy_udp_node, autoplay_node, teleop_node, drives_node, camera_follower_node, - temp_diag_pub_node, camera_launch, rviz_node + launch_rviz_arg, rviz_config_arg, file_check, rsp_node, jsp_gui_node, guard_node, + joint_demo_node, joy_node, joy_udp_node, autoplay_node, teleop_node, drives_node, + camera_follower_node, temp_diag_pub_node, camera_launch, rviz_node ]) diff --git a/waybionic_bringup/test/test_launch_options.py b/waybionic_bringup/test/test_launch_options.py index df2263f4..e704f38c 100644 --- a/waybionic_bringup/test/test_launch_options.py +++ b/waybionic_bringup/test/test_launch_options.py @@ -132,6 +132,16 @@ def test_demo_and_teleop_are_rejected_together(context): MODULE.check_files_exist(context) +@pytest.mark.parametrize('options, sliders', [ + ({}, True), ({'teleop': 'true'}, False), ({'demo_mode': 'true'}, False), + ({'use_joint_state_publisher_gui': 'false'}, False)]) +def test_the_collision_guard_runs_whenever_the_sliders_do(context, options, sliders): + context.launch_configurations.update(options) + guard = next(action for action in nodes() if action.node_executable == 'joint_state_guard') + assert node('joint_state_publisher_gui').condition.evaluate(context) is sliders + assert guard.condition.evaluate(context) is sliders + + def test_diagnostics_disabled(context): context.launch_configurations.update({ 'use_diagnostics': 'false', 'start_temporary_diagnostics_publisher': 'true', diff --git a/waybionic_bringup/test/test_slider_guard_launch.py b/waybionic_bringup/test/test_slider_guard_launch.py new file mode 100644 index 00000000..05a4b99d --- /dev/null +++ b/waybionic_bringup/test/test_slider_guard_launch.py @@ -0,0 +1,78 @@ +"""Joint sliders asking for a pose that clashes stop the arm where its parts meet.""" + +import os +import time +import unittest + +from ament_index_python.packages import get_package_share_directory +import launch +from launch.actions import IncludeLaunchDescription, SetEnvironmentVariable +from launch.launch_description_sources import PythonLaunchDescriptionSource +import launch_testing +import launch_testing.actions +import pytest +import rclpy +from sensor_msgs.msg import JointState + +from waybionic_teleop.collision import ArmCollision + +# The elbow folded back through the base: a pose the sliders used to allow. +FOLDED = {'joint_1': 0.0, 'joint_2': 0.921, 'joint_3': 2.599, 'joint_4': 1.652, + 'joint_5': -6.283} + + +@pytest.mark.launch_test +def generate_test_description(): + launch_file = os.path.join( + get_package_share_directory('waybionic_bringup'), 'launch', 'ground_station.launch.py') + return launch.LaunchDescription([ + # The slider window runs without a display. + SetEnvironmentVariable('QT_QPA_PLATFORM', 'offscreen'), + IncludeLaunchDescription( + PythonLaunchDescriptionSource(launch_file), + launch_arguments={'launch_rviz': 'false', 'use_diagnostics': 'false', + 'follow_camera': 'false'}.items()), + launch_testing.actions.ReadyToTest(), + ]) + + +class TestSliderGuard(unittest.TestCase): + + def test_the_sliders_stop_where_the_parts_meet(self): + urdf = os.path.join(get_package_share_directory('waybionic_description'), 'urdf', + 'waybionic_arm.urdf') + with open(urdf, encoding='utf-8') as source: + check = ArmCollision.from_urdf(source.read()) + self.assertTrue(check.hits(FOLDED)) + rclpy.init() + node = rclpy.create_node('slider_guard_test') + states, requests = {}, {} + node.create_subscription( + JointState, '/joint_states', + lambda message: states.update(zip(message.name, message.position)), 10) + node.create_subscription( + JointState, '/joint_states_requested', + lambda message: requests.update(zip(message.name, message.position)), 10) + sliders = node.create_publisher(JointState, '/joint_states_requested', 10) + + def spin(seconds, until=lambda: False): + end = time.monotonic() + seconds + while time.monotonic() < end and not until(): + rclpy.spin_once(node, timeout_sec=0.05) + + try: + # The slider window publishes, and the guard has the model and passes it on. + spin(30.0, lambda: 'joint_3' in requests and 'joint_3' in states) + self.assertIn('joint_3', requests, 'the slider window never published') + self.assertIn('joint_3', states, 'the guard never passed the sliders on') + # Ask for the clashing pose as the sliders would. + sliders.publish(JointState(name=list(FOLDED), position=list(FOLDED.values()))) + spin(3.0) + self.assertEqual(check.hits(states), []) + self.assertGreater(states['joint_3'], 1.0, 'the arm did not move toward the pose') + # The slider window was sent back to where the arm stopped and now asks for that. + for joint in FOLDED: + self.assertAlmostEqual(requests[joint], states[joint], delta=0.002, msg=joint) + finally: + node.destroy_node() + rclpy.shutdown() diff --git a/waybionic_description/test/test_arm_description.py b/waybionic_description/test/test_arm_description.py index 128bc8bf..c644d4f7 100644 --- a/waybionic_description/test/test_arm_description.py +++ b/waybionic_description/test/test_arm_description.py @@ -40,11 +40,11 @@ def test_joint_chain_matches_mechanical_fk(robot): def test_joint_limits_are_where_the_cad_parts_touch(robot): # From the upright pose (scripts/cad/exact_limits.py), the straight arm meets the ground under # the base at 109.65 degrees of shoulder, the forearm the shoulder's motor mount at 148.93 of - # elbow, and the tool mount the forearm's cap at 94.68 of wrist pitch. Nothing meets over a - # full turn of base yaw or wrist roll. + # elbow, and the tool mount the forearm's cap at 94.67 of wrist pitch, at the closest roll. + # Nothing meets over a full turn of base yaw or wrist roll. joints = {joint.get('name'): joint for joint in robot.findall('joint')} for name, degrees in (('joint_1', 360.0), ('joint_2', 109.65), ('joint_3', 148.93), - ('joint_4', 94.68), ('joint_5', 360.0)): + ('joint_4', 94.67), ('joint_5', 360.0)): limit = joints[name].find('limit') assert math.degrees(float(limit.get('upper'))) == pytest.approx(degrees, abs=1e-4) assert math.degrees(float(limit.get('lower'))) == pytest.approx(-degrees, abs=1e-4) diff --git a/waybionic_description/urdf/waybionic_arm.urdf b/waybionic_description/urdf/waybionic_arm.urdf index ebeb08a3..8a1c073a 100644 --- a/waybionic_description/urdf/waybionic_arm.urdf +++ b/waybionic_description/urdf/waybionic_arm.urdf @@ -300,7 +300,7 @@ - + diff --git a/waybionic_teleop/setup.py b/waybionic_teleop/setup.py index a5943eff..6136de85 100644 --- a/waybionic_teleop/setup.py +++ b/waybionic_teleop/setup.py @@ -32,6 +32,7 @@ 'mks_setup = waybionic_teleop.mks_setup:main', 'autoplay = waybionic_teleop.autoplay_node:main', 'joy_udp_receiver = waybionic_teleop.joy_udp_receiver:main', + 'joint_state_guard = waybionic_teleop.joint_state_guard:main', ], }, ) diff --git a/waybionic_teleop/test/test_collision.py b/waybionic_teleop/test/test_collision.py index 1a4b9c63..185dbef8 100644 --- a/waybionic_teleop/test/test_collision.py +++ b/waybionic_teleop/test/test_collision.py @@ -56,13 +56,46 @@ def test_the_elbow_folds_until_the_forearm_touches_the_shoulder(check): assert check.hits(pose(0, -149, 0)) == ['forearm_link: shoulder_link'] +def test_a_move_stops_at_the_last_pose_before_parts_touch(check): + reached, blocked = check.reach(pose(0, 0, 0), pose(0, 160, 0), math.radians(0.5)) + assert 148.6 < math.degrees(reached['joint_3']) < 149 + assert check.hits(reached) == [] and blocked == ['forearm_link: shoulder_link'] + # A clear move goes all the way. + assert check.reach(pose(0, 0, 0), pose(30, 60, 60), math.radians(0.5)) == ( + pytest.approx(pose(30, 60, 60)), []) + # From inside a collision the arm moves only to a clear pose. + inside = pose(0, 150, 0) + stay, blocked = check.reach(inside, pose(0, 155, 0), 0.01) + assert stay == inside and 'forearm_link: shoulder_link' in blocked + assert check.reach(inside, pose(0, 0, 0), 0.01) == (pose(0, 0, 0), []) + + +@pytest.mark.parametrize('goal', [ + # Two poses the joint sliders allowed: the elbow folded back through the base... + {'joint_1': 0.0, 'joint_2': 0.921, 'joint_3': 2.599, 'joint_4': 1.652, 'joint_5': -6.283}, + # ...and the wrist under the ground. + {'joint_1': 0.0, 'joint_2': 1.9137, 'joint_3': 0.829, 'joint_4': 1.652, 'joint_5': -6.283}, +]) +def test_a_move_toward_a_pose_that_clashes_stops_just_before_it(check, goal): + assert check.hits(goal) + start = dict.fromkeys(goal, 0.0) + reached, blocked = check.reach(start, goal, math.radians(0.5)) + assert check.hits(reached) == [] and blocked + # A hair further along the move the parts touch. + fraction = reached['joint_2'] / goal['joint_2'] + 1e-4 + assert check.hits({joint: goal[joint] * fraction for joint in goal}) + # Asking again moves it no further. + again, _ = check.reach(reached, goal, math.radians(0.5)) + assert again == pytest.approx(reached, abs=1e-5) + + @pytest.mark.parametrize('group, axis, joint, stop, why', [ # The straight arm reaches the ground under the base, where the shoulder's limit is. (0, 'left_y', 'joint_2', 109.65, None), # The forearm reaches the shoulder's motor mount: the fold table at an upright shoulder. (0, 'right_y', 'joint_3', 148.7, 'forearm_link: shoulder_link'), # The tool mount reaches the cap on the forearm, where the wrist's limit is. - (1, 'right_y', 'joint_4', 94.68, None), + (1, 'right_y', 'joint_4', 94.67, None), ]) def test_each_joint_turned_from_upright_stops_where_its_cad_parts_touch( parameters, check, group, axis, joint, stop, why): diff --git a/waybionic_teleop/test/test_joint_state_guard.py b/waybionic_teleop/test/test_joint_state_guard.py new file mode 100644 index 00000000..2c15e19a --- /dev/null +++ b/waybionic_teleop/test/test_joint_state_guard.py @@ -0,0 +1,106 @@ +"""The joint sliders move the arm only as far as it goes without hitting itself or the table.""" + +from pathlib import Path + +import pytest +import rclpy +from rclpy.parameter import Parameter +from sensor_msgs.msg import JointState +from std_msgs.msg import String + +from waybionic_teleop.collision import ArmCollision +from waybionic_teleop.joint_state_guard import JointStateGuard +from waybionic_teleop.kinematics import joint_limits + +DESCRIPTION = Path(__file__).resolve().parents[2] / 'waybionic_description' / 'urdf' +URDF = (DESCRIPTION / 'waybionic_arm.urdf').read_text(encoding='utf-8') +JOINTS = ['joint_1', 'joint_2', 'joint_3', 'joint_4', 'joint_5'] +SETTINGS = ('table_height', 'collision_clearance', 'self_collision_clearance') + + +@pytest.fixture +def settings(parameters): + teleop = parameters('xbox_teleop.yaml', 'xbox_teleop') + return {name: float(teleop[name]) for name in SETTINGS} + + +@pytest.fixture +def guard(monkeypatch, settings): + # Keep this node out of other tests' discovery. + monkeypatch.setenv('ROS_AUTOMATIC_DISCOVERY_RANGE', 'OFF') + context = rclpy.Context() + rclpy.init(context=context) + node = JointStateGuard(context=context, parameter_overrides=[ + Parameter(name, value=value) for name, value in settings.items()]) + node.states, node.sent_back = [], [] + monkeypatch.setattr(node.state_publisher, 'publish', node.states.append) + monkeypatch.setattr(node.accepted_publisher, 'publish', node.sent_back.append) + yield node + node.destroy_node() + rclpy.try_shutdown(context=context) + + +def sliders(**positions): + """Return what joint_state_publisher_gui publishes: every joint, the gears that mimic roll.""" + pose = {joint: positions.get(joint, 0.0) for joint in JOINTS} + pose.update(wrist_left_gear_joint=-pose['joint_5'], wrist_right_gear_joint=pose['joint_5']) + return JointState(name=list(pose), position=list(pose.values())) + + +def pose(message): + return dict(zip(message.name, message.position)) + + +def test_nothing_moves_before_the_arm_model_arrives(guard): + guard.on_request(sliders(joint_2=0.5)) + assert guard.states == [] and guard.sent_back == [] + + +def test_a_clear_slider_pose_passes_unchanged(guard): + guard.load(String(data=URDF)) + wanted = {'joint_1': 1.0, 'joint_2': 0.5, 'joint_3': 1.0, 'joint_4': -0.5, 'joint_5': 2.0} + guard.on_request(sliders(**wanted)) + # robot_state_publisher works out the gears from roll itself. + assert pose(guard.states[-1]) == pytest.approx(wanted) + assert guard.sent_back == [] + + +@pytest.mark.parametrize('wanted', [ + # Two poses the sliders used to allow: the elbow folded back through the base... + {'joint_2': 0.921, 'joint_3': 2.599, 'joint_4': 1.652, 'joint_5': -6.283}, + # ...and the wrist under the ground. + {'joint_2': 1.913, 'joint_3': 0.829, 'joint_4': 1.652, 'joint_5': -6.283}, +]) +def test_a_slider_pose_that_clashes_stops_where_the_parts_meet(guard, settings, wanted): + check = ArmCollision.from_urdf(URDF, settings['table_height'], + settings['collision_clearance'], + settings['self_collision_clearance']) + goal = {joint: wanted.get(joint, 0.0) for joint in JOINTS} + assert check.hits(goal) + guard.load(String(data=URDF)) + guard.on_request(sliders(**wanted)) + stopped = pose(guard.states[-1]) + assert check.hits(stopped) == [] + # It went as far as it could: a hair further along the move, the parts touch. + fraction = stopped['joint_2'] / goal['joint_2'] + 1e-4 + assert check.hits({joint: goal[joint] * fraction for joint in JOINTS}) + # The sliders are sent back to where the arm stopped, and asking again moves it no further. + assert pose(guard.sent_back[-1]) == stopped + guard.on_request(sliders(**wanted)) + assert pose(guard.states[-1]) == pytest.approx(stopped, abs=1e-5) + + +def test_a_slider_past_a_joint_limit_is_held_at_the_limit(guard): + guard.load(String(data=URDF)) + guard.on_request(sliders(joint_4=2.0)) + limit = joint_limits(URDF, ['joint_4'])['joint_4'][1] + assert pose(guard.states[-1])['joint_4'] == pytest.approx(limit) + assert pose(guard.sent_back[-1])['joint_4'] == pytest.approx(limit) + + +def test_a_model_without_the_arms_collision_shapes_passes_the_sliders_through(guard): + guard.load(String(data=(DESCRIPTION / 'waybionic_placeholder.urdf').read_text( + encoding='utf-8'))) + message = sliders(joint_2=3.0) + guard.on_request(message) + assert guard.states == [message] and guard.sent_back == [] diff --git a/waybionic_teleop/waybionic_teleop/collision.py b/waybionic_teleop/waybionic_teleop/collision.py index f90c28d1..840b30a1 100644 --- a/waybionic_teleop/waybionic_teleop/collision.py +++ b/waybionic_teleop/waybionic_teleop/collision.py @@ -331,6 +331,38 @@ def check(self, positions): found[f'{link}: {body}'] = volume return found + def reach(self, start, goal, step): + """ + Move in a straight line in joint space from start toward goal, checking every step. + + start and goal map the same joints to radians, and step is the most any joint turns + between two checks. Return the furthest pose along the line before anything would + collide, to within 1e-6 of the move, and what would collide just past it ([] when the + whole move is clear). A start that already collides moves only to a clear goal. + """ + def along(fraction): + return {joint: start[joint] + (goal[joint] - start[joint]) * fraction + for joint in goal} + + if self.hits(start): + blocked = self.hits(goal) + return (dict(start), blocked) if blocked else (dict(goal), []) + span = max((abs(goal[joint] - start[joint]) for joint in goal), default=0.0) + count = max(1, math.ceil(span / step)) + clear = 0.0 + for index in range(1, count + 1): + if self.hits(along(index / count)): + blocked = index / count + while blocked - clear > 1e-6: + middle = (clear + blocked) / 2.0 + if self.hits(along(middle)): + blocked = middle + else: + clear = middle + return along(clear), self.hits(along(blocked)) + clear = index / count + return along(1.0), [] + def _squared_distance(a, b): return sum((x - y) ** 2 for x, y in zip(a, b)) diff --git a/waybionic_teleop/waybionic_teleop/joint_state_guard.py b/waybionic_teleop/waybionic_teleop/joint_state_guard.py new file mode 100644 index 00000000..48ed7e2b --- /dev/null +++ b/waybionic_teleop/waybionic_teleop/joint_state_guard.py @@ -0,0 +1,118 @@ +""" +Let the joint sliders move the arm only as far as it can go without hitting itself or the table. + +joint_state_publisher_gui publishes the pose its sliders ask for on /joint_states_requested. +This node moves the arm from where it is toward that pose in steps of at most max_step_deg, +with the collision check that teleop uses, and publishes on /joint_states the furthest pose +before any part would touch the table (table_height m above the bottom of the base) or fold into +the base or shoulder. When it stops short of the sliders, or a slider is past a joint limit, it +publishes the pose on /joint_state_guard/accepted too, which the slider window reads back so +that its sliders show where the arm stopped. A model without the arm's collision shapes, such as +the old arm, has nothing to check, so its slider poses pass through unchanged. +""" + +import math + +import rclpy +from rclpy._rclpy_pybind11 import RCLError +from rclpy.executors import ExternalShutdownException +from rclpy.node import Node +from rclpy.qos import DurabilityPolicy, QoSProfile +from sensor_msgs.msg import JointState +from std_msgs.msg import String + +from waybionic_teleop.collision import ArmCollision +from waybionic_teleop.kinematics import joint_limits + +MOVING = ('revolute', 'continuous', 'prismatic') + + +class JointStateGuard(Node): + """Pass on slider poses up to where the arm would collide.""" + + def __init__(self, **kwargs): + super().__init__('joint_state_guard', **kwargs) + self.table_height = float(self.declare_parameter('table_height', 0.0).value) + self.clearance = float(self.declare_parameter('collision_clearance', 0.0).value) + self.self_clearance = float( + self.declare_parameter('self_collision_clearance', 0.0).value) + self.step = math.radians(float(self.declare_parameter('max_step_deg', 0.5).value)) + if not (math.isfinite(self.table_height) and 0 <= self.clearance < math.inf + and 0 <= self.self_clearance < math.inf and 0 < self.step < math.inf): + raise ValueError('table_height must be finite, collision_clearance and ' + 'self_collision_clearance zero or more and finite, and ' + 'max_step_deg positive and finite') + # None until a description with the arm's collision shapes arrives. + self.collision = None + self.unchecked = False + self.limits = {} + self.pose = {} + latched = QoSProfile(depth=1, durability=DurabilityPolicy.TRANSIENT_LOCAL) + self.create_subscription(String, 'robot_description', self.load, latched) + # Only the newest slider pose matters, so a long check never queues old ones. + self.create_subscription(JointState, 'joint_states_requested', self.on_request, 1) + self.state_publisher = self.create_publisher(JointState, 'joint_states', 10) + self.accepted_publisher = self.create_publisher( + JointState, 'joint_state_guard/accepted', 10) + + def load(self, message): + try: + collision = ArmCollision.from_urdf(message.data, self.table_height, self.clearance, + self.self_clearance) + # robot_state_publisher works out the mimic joints from the joints they follow. + joints = [joint['name'] for joint in collision.joints.values() + if joint['type'] in MOVING and not joint['mimic']] + limits = joint_limits(message.data, joints) + except ValueError as error: + self.collision, self.unchecked = None, True + self.get_logger().warning(f'Joint sliders are not collision checked: {error}') + return + self.collision, self.limits, self.unchecked = collision, limits, False + # A new description keeps the arm where it was, inside the new limits. + self.pose = {joint: min(max(self.pose.get(joint, 0.0), low), high) + for joint, (low, high) in limits.items()} + self.get_logger().info('Joint sliders stop where the arm would hit itself or the table') + + def on_request(self, message): + if self.unchecked: + self.state_publisher.publish(message) + if self.collision is None: + return + requested = {name: position for name, position in zip(message.name, message.position) + if name in self.limits and math.isfinite(position)} + goal = {joint: min(max(requested.get(joint, self.pose[joint]), low), high) + for joint, (low, high) in self.limits.items()} + self.pose, blocked = self.collision.reach(self.pose, goal, self.step) + state = JointState(name=list(self.pose), position=list(self.pose.values())) + state.header.stamp = self.get_clock().now().to_msg() + self.state_publisher.publish(state) + if any(abs(requested[joint] - self.pose[joint]) > 1e-9 for joint in requested): + self.accepted_publisher.publish(state) + if blocked: + self.get_logger().info('Sliders stopped before ' + ', '.join(blocked), + throttle_duration_sec=1.0) + + +def main(): + rclpy.init() + node = JointStateGuard() + try: + rclpy.spin(node) + except (KeyboardInterrupt, ExternalShutdownException): + pass + except RCLError as error: + # SIGINT can shut down the context before spin recreates its wait set. + if rclpy.ok() or 'the given context is not valid' not in str(error): + raise + except RuntimeError as error: + # Jazzy may surface this binding error when SIGINT invalidates a subscription. + if (rclpy.ok() or not str(error).startswith( + "Unable to convert call argument '0' to Python object")): + raise + finally: + node.destroy_node() + rclpy.try_shutdown() + + +if __name__ == '__main__': + main() From e8e211cd2e2f469a4fac30d75a9e33606c14eb34 Mon Sep 17 00:00:00 2001 From: Ovilikaris Date: Sat, 24 Oct 2026 15:57:23 -0600 Subject: [PATCH 08/12] Make slider guard launch test tolerate GUI request races --- .../test/test_slider_guard_launch.py | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/waybionic_bringup/test/test_slider_guard_launch.py b/waybionic_bringup/test/test_slider_guard_launch.py index 05a4b99d..b689478b 100644 --- a/waybionic_bringup/test/test_slider_guard_launch.py +++ b/waybionic_bringup/test/test_slider_guard_launch.py @@ -46,13 +46,16 @@ def test_the_sliders_stop_where_the_parts_meet(self): self.assertTrue(check.hits(FOLDED)) rclpy.init() node = rclpy.create_node('slider_guard_test') - states, requests = {}, {} + states, requests, accepted = {}, {}, {} node.create_subscription( JointState, '/joint_states', lambda message: states.update(zip(message.name, message.position)), 10) node.create_subscription( JointState, '/joint_states_requested', lambda message: requests.update(zip(message.name, message.position)), 10) + node.create_subscription( + JointState, '/joint_state_guard/accepted', + lambda message: accepted.update(zip(message.name, message.position)), 10) sliders = node.create_publisher(JointState, '/joint_states_requested', 10) def spin(seconds, until=lambda: False): @@ -65,9 +68,20 @@ def spin(seconds, until=lambda: False): spin(30.0, lambda: 'joint_3' in requests and 'joint_3' in states) self.assertIn('joint_3', requests, 'the slider window never published') self.assertIn('joint_3', states, 'the guard never passed the sliders on') - # Ask for the clashing pose as the sliders would. - sliders.publish(JointState(name=list(FOLDED), position=list(FOLDED.values()))) - spin(3.0) + # The real slider window also publishes on this topic at 10 Hz. Retry until + # the guard acknowledges our pose; a single request can be replaced by a + # newer GUI message while the guard is checking collisions. + folded = JointState(name=list(FOLDED), position=list(FOLDED.values())) + deadline = time.monotonic() + 15.0 + while time.monotonic() < deadline and accepted.get('joint_3', 0.0) <= 1.0: + sliders.publish(folded) + spin(0.1) + self.assertGreater(accepted.get('joint_3', 0.0), 1.0, + 'the guard did not accept the clashing request') + # Once the test stops publishing, the GUI should adopt the accepted pose. + spin(3.0, lambda: 'joint_3' in states and all( + abs(requests.get(joint, float('inf')) - states.get(joint, 0.0)) < 0.002 + for joint in FOLDED)) self.assertEqual(check.hits(states), []) self.assertGreater(states['joint_3'], 1.0, 'the arm did not move toward the pose') # The slider window was sent back to where the arm stopped and now asks for that. From 80528694c7ee27e7e2c86163f0213257a56262cf Mon Sep 17 00:00:00 2001 From: Yassin Soliman <108886216+yassinsolim@users.noreply.github.com> Date: Sat, 14 Nov 2026 05:02:50 -0600 Subject: [PATCH 09/12] Block the joint sliders when the arm's collision data cannot be used joint_state_guard took any ValueError from loading the description as "this model has nothing to check" and published every slider pose unchanged. A hull or fold table that failed to load therefore switched the check off: a joint_3 request of 99.0 reached /joint_states untouched. Only the models in UNCHECKED_MODELS (the old arm and the placeholder, which have no collision shapes by design) pass through now, matched by robot name. Any other description whose collision data or joint limits cannot be used blocks the sliders: nothing is published, the load logs an error, and each slider request logs it again (at most every 5 s) until a usable description arrives. A malformed description that replaces a good one blocks as well, and a good one after it resumes the check. The tests load the arm with a bad hull, a hull for a missing link, two fold tables for one pair, its collision shapes lost, a joint without limits and a description cut short, then send joint_3 = 99.0. They fail on the old guard. --- docs/operator_guide.md | 5 +- .../test/test_joint_state_guard.py | 72 +++++++++++++++++-- .../waybionic_teleop/joint_state_guard.py | 40 +++++++++-- 3 files changed, 108 insertions(+), 9 deletions(-) diff --git a/docs/operator_guide.md b/docs/operator_guide.md index 3c57b24d..c3ac0a50 100644 --- a/docs/operator_guide.md +++ b/docs/operator_guide.md @@ -280,7 +280,10 @@ the arm's own base and shoulder. `tool_link`, until the real tool is modelled; a longer tool needs a longer box. - The joint sliders use the same check. `joint_state_guard` moves the arm toward the sliders' pose, checking at least every half degree of each joint, stops at the - last pose before any part would touch, and moves the sliders back to it. + last pose before any part would touch, and moves the sliders back to it. If the arm's + description has collision data it cannot use (a malformed hull or fold table, or lost + shapes), the sliders do nothing and the guard logs an error; only the old arm and the + placeholder, which have no collision shapes by design, pass through unchecked. - When a move stops, the diagnostics panel names the part, for example `At limit: forearm_link: table`. - If the arm stands on a raised mount, set `table_height` in diff --git a/waybionic_teleop/test/test_joint_state_guard.py b/waybionic_teleop/test/test_joint_state_guard.py index 2c15e19a..e9e64dd9 100644 --- a/waybionic_teleop/test/test_joint_state_guard.py +++ b/waybionic_teleop/test/test_joint_state_guard.py @@ -1,6 +1,7 @@ """The joint sliders move the arm only as far as it goes without hitting itself or the table.""" from pathlib import Path +import re import pytest import rclpy @@ -16,6 +17,20 @@ URDF = (DESCRIPTION / 'waybionic_arm.urdf').read_text(encoding='utf-8') JOINTS = ['joint_1', 'joint_2', 'joint_3', 'joint_4', 'joint_5'] SETTINGS = ('table_height', 'collision_clearance', 'self_collision_clearance') +ROLL_HULL = re.search(r'', URDF, re.S).group(0) +FOLD = re.search(r'', URDF, re.S).group(0) +MALFORMED = { + 'a hull with a point that is not a number': + URDF.replace(ROLL_HULL, ROLL_HULL.replace('points="', 'points="nan ')), + 'a hull for a link the arm does not have': + URDF.replace(ROLL_HULL, ROLL_HULL.replace('link="wrist_roll_link"', 'link="stray_link"')), + 'two fold tables for one pair': URDF.replace('', FOLD + '\n'), + 'the arm with its collision shapes lost': + re.sub(r'', '', URDF, flags=re.S), + 'a joint without limits': + re.sub(r'(]*/>', r'\1', URDF, count=1, flags=re.S), + 'a description cut short': URDF[:len(URDF) // 2], +} @pytest.fixture @@ -40,6 +55,28 @@ def guard(monkeypatch, settings): rclpy.try_shutdown(context=context) +class Log: + """Stand in for the node's logger and keep what it says as an error.""" + + def __init__(self): + self.errors = [] + + def error(self, message, **kwargs): + self.errors.append(message) + + def info(self, *args, **kwargs): + pass + + warning = info + + +@pytest.fixture +def log(guard, monkeypatch): + logger = Log() + monkeypatch.setattr(guard, 'get_logger', lambda: logger) + return logger + + def sliders(**positions): """Return what joint_state_publisher_gui publishes: every joint, the gears that mimic roll.""" pose = {joint: positions.get(joint, 0.0) for joint in JOINTS} @@ -98,9 +135,36 @@ def test_a_slider_past_a_joint_limit_is_held_at_the_limit(guard): assert pose(guard.sent_back[-1])['joint_4'] == pytest.approx(limit) -def test_a_model_without_the_arms_collision_shapes_passes_the_sliders_through(guard): - guard.load(String(data=(DESCRIPTION / 'waybionic_placeholder.urdf').read_text( - encoding='utf-8'))) +@pytest.mark.parametrize( + 'model', ['waybionic_placeholder.urdf', 'waybionic_old_arm.expanded.urdf']) +def test_a_model_without_the_arms_collision_shapes_passes_the_sliders_through( + guard, log, model): + guard.load(String(data=(DESCRIPTION / model).read_text(encoding='utf-8'))) message = sliders(joint_2=3.0) guard.on_request(message) - assert guard.states == [message] and guard.sent_back == [] + assert guard.states == [message] and guard.sent_back == [] and log.errors == [] + + +@pytest.mark.parametrize('broken', MALFORMED.values(), ids=MALFORMED.keys()) +def test_a_malformed_arm_model_blocks_the_sliders_and_says_so(guard, log, broken): + assert broken != URDF + guard.load(String(data=broken)) + assert len(log.errors) == 1 and 'blocked' in log.errors[0] + # A request far past the elbow's limit was once published unchanged after such a load. + guard.on_request(sliders(joint_3=99.0)) + assert guard.states == [] and guard.sent_back == [] + assert len(log.errors) == 2 and 'ignored' in log.errors[1] + + +def test_a_malformed_model_replacing_a_good_one_blocks_the_sliders_until_a_good_one_comes( + guard, log): + guard.load(String(data=URDF)) + guard.on_request(sliders(joint_2=0.1)) + assert len(guard.states) == 1 + guard.load(String(data=MALFORMED['two fold tables for one pair'])) + guard.on_request(sliders(joint_3=99.0)) + assert len(guard.states) == 1 + guard.load(String(data=URDF)) + guard.on_request(sliders(joint_3=99.0)) + limit = joint_limits(URDF, ['joint_3'])['joint_3'][1] + assert len(guard.states) == 2 and pose(guard.states[-1])['joint_3'] <= limit + 1e-9 diff --git a/waybionic_teleop/waybionic_teleop/joint_state_guard.py b/waybionic_teleop/waybionic_teleop/joint_state_guard.py index 48ed7e2b..babec5ed 100644 --- a/waybionic_teleop/waybionic_teleop/joint_state_guard.py +++ b/waybionic_teleop/waybionic_teleop/joint_state_guard.py @@ -7,11 +7,15 @@ before any part would touch the table (table_height m above the bottom of the base) or fold into the base or shoulder. When it stops short of the sliders, or a slider is past a joint limit, it publishes the pose on /joint_state_guard/accepted too, which the slider window reads back so -that its sliders show where the arm stopped. A model without the arm's collision shapes, such as -the old arm, has nothing to check, so its slider poses pass through unchanged. +that its sliders show where the arm stopped. + +Only the models in UNCHECKED_MODELS, which have no collision shapes by design, pass their +slider poses through unchanged. For any other description whose collision data cannot be used, +nothing is published and an error is logged until a usable description arrives. """ import math +import xml.etree.ElementTree as ET import rclpy from rclpy._rclpy_pybind11 import RCLError @@ -25,6 +29,18 @@ from waybionic_teleop.kinematics import joint_limits MOVING = ('revolute', 'continuous', 'prismatic') +# Robot names of the models drawn without collision shapes: the old arm and the placeholder. A +# description of the arm that has lost its shapes or hulls must block the sliders, not pass for +# one of these. +UNCHECKED_MODELS = frozenset({'waybionic_old_arm_visualization', 'waybionic_placeholder'}) + + +def robot_name(urdf): + """Return the name of the robot in a URDF string, or None if it is not XML.""" + try: + return ET.fromstring(urdf).get('name') + except ET.ParseError: + return None class JointStateGuard(Node): @@ -44,7 +60,10 @@ def __init__(self, **kwargs): 'max_step_deg positive and finite') # None until a description with the arm's collision shapes arrives. self.collision = None + # Set for a model in UNCHECKED_MODELS, whose poses pass through. self.unchecked = False + # Why a description that cannot be checked blocks the sliders. + self.blocked_by = '' self.limits = {} self.pose = {} latched = QoSProfile(depth=1, durability=DurabilityPolicy.TRANSIENT_LOCAL) @@ -56,6 +75,12 @@ def __init__(self, **kwargs): JointState, 'joint_state_guard/accepted', 10) def load(self, message): + name = robot_name(message.data) + if name in UNCHECKED_MODELS: + self.collision, self.limits, self.unchecked, self.blocked_by = None, {}, True, '' + self.get_logger().warning( + f'Joint sliders are not collision checked: {name} has no collision shapes') + return try: collision = ArmCollision.from_urdf(message.data, self.table_height, self.clearance, self.self_clearance) @@ -64,10 +89,14 @@ def load(self, message): if joint['type'] in MOVING and not joint['mimic']] limits = joint_limits(message.data, joints) except ValueError as error: - self.collision, self.unchecked = None, True - self.get_logger().warning(f'Joint sliders are not collision checked: {error}') + # An arm whose collision data cannot be used must not move unchecked. + self.collision, self.limits, self.unchecked = None, {}, False + self.blocked_by = str(error) + self.get_logger().error( + f'Joint sliders are blocked, the arm cannot be checked: {error}') return self.collision, self.limits, self.unchecked = collision, limits, False + self.blocked_by = '' # A new description keeps the arm where it was, inside the new limits. self.pose = {joint: min(max(self.pose.get(joint, 0.0), low), high) for joint, (low, high) in limits.items()} @@ -77,6 +106,9 @@ def on_request(self, message): if self.unchecked: self.state_publisher.publish(message) if self.collision is None: + if self.blocked_by: + self.get_logger().error(f'Joint slider request ignored, the arm cannot be ' + f'checked: {self.blocked_by}', throttle_duration_sec=5.0) return requested = {name: position for name, position in zip(message.name, message.position) if name in self.limits and math.isfinite(position)} From 41a50c85460b911bc3a2742befed1719d75e0c77 Mon Sep 17 00:00:00 2001 From: Yassin Soliman <108886216+yassinsolim@users.noreply.github.com> Date: Sat, 14 Nov 2026 05:02:50 -0600 Subject: [PATCH 10/12] Use the shared shutdown check in the joint state guard The guard decided for itself whether a spin error came from SIGINT, looking at rclpy.ok() at once. rclpy's signal thread wakes the executor before it shuts the context down, so ok() can still be true and the guard exited with code 1: the race #55 fixed in the other nodes with ros_shutdown. The guard runs in the ground station launch tests, so this can fail them at random, as in the ARM64 autoplay launch test. --- waybionic_teleop/waybionic_teleop/joint_state_guard.py | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/waybionic_teleop/waybionic_teleop/joint_state_guard.py b/waybionic_teleop/waybionic_teleop/joint_state_guard.py index babec5ed..c74855a8 100644 --- a/waybionic_teleop/waybionic_teleop/joint_state_guard.py +++ b/waybionic_teleop/waybionic_teleop/joint_state_guard.py @@ -18,7 +18,6 @@ import xml.etree.ElementTree as ET import rclpy -from rclpy._rclpy_pybind11 import RCLError from rclpy.executors import ExternalShutdownException from rclpy.node import Node from rclpy.qos import DurabilityPolicy, QoSProfile @@ -27,6 +26,7 @@ from waybionic_teleop.collision import ArmCollision from waybionic_teleop.kinematics import joint_limits +from waybionic_teleop.ros_shutdown import is_shutdown_error MOVING = ('revolute', 'continuous', 'prismatic') # Robot names of the models drawn without collision shapes: the old arm and the placeholder. A @@ -132,14 +132,8 @@ def main(): rclpy.spin(node) except (KeyboardInterrupt, ExternalShutdownException): pass - except RCLError as error: - # SIGINT can shut down the context before spin recreates its wait set. - if rclpy.ok() or 'the given context is not valid' not in str(error): - raise except RuntimeError as error: - # Jazzy may surface this binding error when SIGINT invalidates a subscription. - if (rclpy.ok() or not str(error).startswith( - "Unable to convert call argument '0' to Python object")): + if not is_shutdown_error(error): raise finally: node.destroy_node() From 771fc456534ef99e1caf6793161ddc58e2bae6a1 Mon Sep 17 00:00:00 2001 From: Yassin Soliman <108886216+yassinsolim@users.noreply.github.com> Date: Sat, 14 Nov 2026 05:02:50 -0600 Subject: [PATCH 11/12] Say that the base clearance test adds no clearance The test builds the check with the default self-clearance of 0, so the 1.3 degrees it stays clear of the sampled contact angles is not a 2 mm margin. --- waybionic_teleop/test/test_collision.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/waybionic_teleop/test/test_collision.py b/waybionic_teleop/test/test_collision.py index 8fba94fd..e41f7c74 100644 --- a/waybionic_teleop/test/test_collision.py +++ b/waybionic_teleop/test/test_collision.py @@ -162,7 +162,8 @@ def test_the_forearm_folds_onto_the_base_until_its_parts_touch(yaw): def test_the_wrist_and_tool_stop_just_before_their_parts_touch_the_base(yaw): # With the table out of the way, the CAD parts come within 1 mm of the base at these elbow # angles at either yaw: the tool mount, the tool and the wrist's differential housing. The - # 2 mm clearance stops the elbow up to 1.3 degrees before them. + # check adds no clearance (self_clearance is 0): it is clear 1.3 degrees before each + # sampled contact angle and reports the contact 0.3 degrees after it. away = ArmCollision.from_urdf(URDF, table_z=-10.0) for shoulder, wrist, touch, link in ((45, 60, 120.5, 'wrist_roll_link'), (30, 90, 122.85, 'tool_link'), From 6de0e01ce90ffba7cbcc69196696122198134bc6 Mon Sep 17 00:00:00 2001 From: Yassin Soliman <108886216+yassinsolim@users.noreply.github.com> Date: Sat, 14 Nov 2026 05:03:51 -0600 Subject: [PATCH 12/12] Describe how to check the new joint limits on the powered arm The limits come from the CAD, where parts touch; the cabling, the drives' own travel and the tolerances of the assembled arm are not modelled, and no one has moved the powered arm to them. The guide already says not to power the motors until Mechanical confirms each joint's travel. It now also says how to check the limits once the arm is powered: lowest speed, one joint at a time, stop short of each limit and creep up to it, and what to do where the real arm has less room. --- docs/operator_guide.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/docs/operator_guide.md b/docs/operator_guide.md index c3ac0a50..ca32bbf1 100644 --- a/docs/operator_guide.md +++ b/docs/operator_guide.md @@ -262,6 +262,14 @@ joint from the upright pose and checking the exact meshes Don't power the motors until Mechanical confirms each joint's signed travel from upright zero on the built arm, including any cable or gear stop. +Then check each limit with the arm powered, before the real arm runs with them. Set the +lowest speed (D-pad down twice), keep the emergency stop within reach, and move one joint +at a time toward each limit: stop about 5 degrees short of it, then creep up to it. Stop at +once if a part touches, a cable pulls tight or a drive reports a following error. Where the +real arm has less room than the table says, write the angle down and lower that limit +before the arm is used. Yaw and roll are 360 degrees because nothing models the cabling: +check that the cables allow a full turn each way. + Every group stops a move where any part of the arm would go below the table or into the arm's own base and shoulder.