Separate forbidden ground from body collision and retain capture phase
This commit is contained in:
@@ -30,6 +30,7 @@ class ContinuousControl:
|
||||
clock=time.monotonic, body_top_m=math.inf, native_only=False):
|
||||
self.monitor, self.support = monitor, support_policy
|
||||
self.detections = DetectionObstacles(monitor)
|
||||
self.ground_monitor = monitor.ground_envelope()
|
||||
self.publish_pose, self.publish_path, self.native_command = (
|
||||
publish_pose, publish_path, native_command)
|
||||
self.clock, self.lock = clock, threading.Lock()
|
||||
@@ -61,7 +62,7 @@ class ContinuousControl:
|
||||
self.geometry = (self.clock() - age, points)
|
||||
self.range_sequence = sequence
|
||||
|
||||
def accept(self, value, result, terrain, *, detections=None):
|
||||
def accept(self, value, result, terrain, *, detections=None, collision_terrain=None):
|
||||
candidates = self.detections.observed(value)
|
||||
if detections is None:
|
||||
detections = candidates
|
||||
@@ -69,8 +70,18 @@ class ContinuousControl:
|
||||
detections = np.asarray(detections, dtype=float).reshape(-1, 3).copy()
|
||||
if not set(map(tuple, detections)) <= set(map(tuple, candidates)):
|
||||
raise ValueError("Refined detection is not an original associated range return")
|
||||
terrain = np.asarray(terrain, dtype=float).reshape(-1, 4).copy()
|
||||
collision = (terrain.copy() if collision_terrain is None else
|
||||
np.asarray(collision_terrain, dtype=float).reshape(-1, 4).copy())
|
||||
if (collision.shape != terrain.shape or not np.isfinite([terrain, collision]).all()
|
||||
or not np.array_equal(collision[:, :3], terrain[:, :3])
|
||||
or np.any(collision[:, 3] > terrain[:, 3])):
|
||||
raise ValueError("Collision and surface layers must share the measured terrain")
|
||||
# Only costs added by the semantic overlay belong to ground exclusion.
|
||||
# Physical terrain and detected solids retain the complete body envelope.
|
||||
floor = terrain[terrain[:, 3] > collision[:, 3]].copy()
|
||||
record = dict(value=value, result=result, detections=detections,
|
||||
terrain=np.asarray(terrain, dtype=float).reshape(-1, 4).copy(),
|
||||
terrain=terrain, collision_terrain=collision, forbidden_ground=floor,
|
||||
received_at=self.clock())
|
||||
with self.lock:
|
||||
self.plans[value["observation_id"]] = record
|
||||
@@ -84,7 +95,9 @@ class ContinuousControl:
|
||||
return None
|
||||
identity, plan = next(reversed(self.plans.items()))
|
||||
return dict(observation_id=identity, request=copy.deepcopy(plan["value"]),
|
||||
result=copy.deepcopy(plan["result"]), terrain=plan["terrain"].tolist())
|
||||
result=copy.deepcopy(plan["result"]), terrain=plan["terrain"].tolist(),
|
||||
collision_terrain=plan["collision_terrain"].tolist(),
|
||||
forbidden_ground=plan["forbidden_ground"].tolist())
|
||||
|
||||
def tick(self, value):
|
||||
started = self.clock()
|
||||
@@ -147,6 +160,7 @@ class ContinuousControl:
|
||||
raised = (height > self.monitor.max_step + 1e-4) & (height <= self.body_top_m)
|
||||
hazards = np.column_stack((points[raised], np.ones(int(raised.sum()))))
|
||||
terrain = np.concatenate((plan["terrain"], hazards))
|
||||
collision = np.concatenate((plan["collision_terrain"], hazards))
|
||||
def admit(command):
|
||||
speed, angular = map(float, command)
|
||||
if not all(math.isfinite(x) for x in (speed, angular)):
|
||||
@@ -162,12 +176,16 @@ class ContinuousControl:
|
||||
min(self.support.partial_yaw_rps, angular)) if stationary else 0.0
|
||||
if (reverse and (speed > 0 or abs(angular) > 0.15)) or (not reverse and speed < 0):
|
||||
return output(reason="direction")
|
||||
speed, angular, obstacle_scale = self.monitor.regulate_command(speed, angular, terrain, pose)
|
||||
speed, angular, obstacle_scale = self.monitor.regulate_command(speed, angular, collision, pose)
|
||||
if obstacle_scale == 0:
|
||||
return output(reason="obstacle")
|
||||
speed, angular, ground_scale = self.ground_monitor.regulate_command(
|
||||
speed, angular, plan["forbidden_ground"], pose)
|
||||
if ground_scale == 0:
|
||||
return output(reason="forbidden-ground-sweep")
|
||||
speed, angular, support_scale, support = self.support.regulate(
|
||||
speed, angular, terrain, pose, request["body_contact_height_m"],
|
||||
current_points=points,
|
||||
current_points=points, collision_terrain=collision,
|
||||
observed_retreat=bool(reverse and request.get("continuous")),
|
||||
)
|
||||
evidence = dict(support_policy=support["policy"]["reason"],
|
||||
|
||||
@@ -45,6 +45,22 @@ class Footprint:
|
||||
else None
|
||||
)
|
||||
|
||||
def ground_envelope(self):
|
||||
"""Conservative origin-centred enclosure of all validated contact bands.
|
||||
|
||||
Surface exclusions constrain ground contacts, not mounted overhangs.
|
||||
Keep the gap between tracks and the same reserve, braking and motion
|
||||
discrepancy bounds. Legacy geometry retains the full collision body.
|
||||
"""
|
||||
if self.contacts is None:
|
||||
return self
|
||||
extent = np.max([np.maximum(np.abs(low), np.abs(high))
|
||||
for low, high in self.contacts.bands], axis=0)
|
||||
return Footprint(dict(length_m=float(2*extent[0]), width_m=float(2*extent[1]),
|
||||
max_step_m=self.max_step,
|
||||
max_slope_degrees=math.degrees(math.atan(self.max_slope))),
|
||||
deceleration=self.deceleration, clearance_m=self.clearance_m)
|
||||
|
||||
def classify_contacts(self, surface, offsets):
|
||||
if self.contacts is None:
|
||||
return surface.classify(offsets)
|
||||
|
||||
@@ -110,8 +110,9 @@ class SupportPolicy:
|
||||
)
|
||||
|
||||
def regulate(self, speed, yaw_rate, terrain, pose, contact_height_m, *, current_points,
|
||||
observed_retreat=False):
|
||||
observed_retreat=False, collision_terrain=None):
|
||||
m = self.monitor
|
||||
collision = terrain if collision_terrain is None else collision_terrain
|
||||
requested = [speed, yaw_rate]
|
||||
pivot_scale = 1.0
|
||||
requested_support = None
|
||||
@@ -151,7 +152,7 @@ class SupportPolicy:
|
||||
narrow_fresh = live_sweep(speed * lower, yaw_rate * lower)
|
||||
if (narrow["admitted"] and fresh_clear(narrow_fresh)
|
||||
and m.command_footprint_clear(
|
||||
speed * lower, yaw_rate * lower, terrain, pose)):
|
||||
speed * lower, yaw_rate * lower, collision, pose)):
|
||||
upper = 1.0
|
||||
original = requested_support = support
|
||||
for _ in range(7):
|
||||
@@ -161,7 +162,7 @@ class SupportPolicy:
|
||||
candidate_fresh = live_sweep(speed * middle, yaw_rate * middle)
|
||||
if (candidate["admitted"] and fresh_clear(candidate_fresh)
|
||||
and m.command_footprint_clear(
|
||||
speed * middle, yaw_rate * middle, terrain, pose)):
|
||||
speed * middle, yaw_rate * middle, collision, pose)):
|
||||
lower, narrow, narrow_fresh = middle, candidate, candidate_fresh
|
||||
else:
|
||||
upper = middle
|
||||
@@ -180,7 +181,7 @@ class SupportPolicy:
|
||||
narrow_fresh = live_sweep(speed * lower, yaw_rate * lower)
|
||||
if ((support["unsafe_samples"] or not fresh_clear(fresh_sweep))
|
||||
and not narrow["unsafe_samples"] and fresh_clear(narrow_fresh)
|
||||
and m.command_footprint_clear(speed * lower, yaw_rate * lower, terrain, pose)):
|
||||
and m.command_footprint_clear(speed * lower, yaw_rate * lower, collision, pose)):
|
||||
# Apply the existing partial-observation policy to the actual
|
||||
# shorter stopping sweep, not to the discarded fast proposal.
|
||||
# This grants at most crawl speed and still requires both fresh
|
||||
@@ -208,7 +209,7 @@ class SupportPolicy:
|
||||
narrow = m.assess_command_support(0, slower, terrain, pose, contact_height_m)
|
||||
narrow_fresh = live_sweep(0, slower)
|
||||
if (narrow["admitted"] and fresh_clear(narrow_fresh)
|
||||
and m.command_footprint_clear(0, slower, terrain, pose)):
|
||||
and m.command_footprint_clear(0, slower, collision, pose)):
|
||||
narrow["requested_pivot_support"] = {
|
||||
key: support[key]
|
||||
for key in ("status", "unknown_samples", "unsafe_samples", "bounds")
|
||||
|
||||
Reference in New Issue
Block a user