Plan translation before choosing motion toward a local goal
This commit is contained in:
@@ -1,66 +0,0 @@
|
||||
"""Choose a native in-place turn before translation when the body sweep fits.
|
||||
|
||||
This is action selection, not a path or velocity controller. Nav2 Spin owns
|
||||
rotation; the live range, support, detector and freshness gates admit each tick.
|
||||
"""
|
||||
import math
|
||||
|
||||
import numpy as np
|
||||
from navigation.detection_obstacles import DetectionObstacles
|
||||
from navigation.support_surface import SupportSurface
|
||||
|
||||
|
||||
def observed_turn_support(angle, terrain, pose, monitor, contact_height):
|
||||
"""Test the complete newly entered contact area before choosing Spin.
|
||||
|
||||
Use the existing contact-cell geometry and support classifier. Retain the
|
||||
per-command discrepancy envelope at every orientation; no floor is filled
|
||||
under the current body and no positive motor permission is returned.
|
||||
"""
|
||||
bounds = monitor.command_bounds(0., math.copysign(.15, angle))
|
||||
bounds['horizon_seconds'] = abs(angle)/.15
|
||||
if monitor.contacts is not None:
|
||||
local, _ = monitor.contacts.cells(bounds, math.copysign(.15, angle))
|
||||
else:
|
||||
# Legacy geometry has no contact bands: conservatively inspect the
|
||||
# whole rotational disk on the existing fixed support-cell lattice.
|
||||
radius = math.hypot(monitor.half_length, monitor.half_width)
|
||||
radius += max(bounds['discrepancy_xy_m'])
|
||||
cells = math.ceil(radius/.1)
|
||||
local = np.array([[i*.1,j*.1] for i in range(-cells,cells+1)
|
||||
for j in range(-cells,cells+1) if math.hypot(i*.1,j*.1)<=radius+.1])
|
||||
required = (np.abs(local[:,0])>monitor.half_length) | (np.abs(local[:,1])>monitor.half_width)
|
||||
x, y, z, w = pose[3:]
|
||||
yaw = math.atan2(2*(w*z+x*y), 1-2*(y*y+z*z))
|
||||
axes = np.array([[math.cos(yaw),-math.sin(yaw)],[math.sin(yaw),math.cos(yaw)]])
|
||||
surface = SupportSurface(terrain, pose, contact_height, monitor.max_step, monitor.max_slope,
|
||||
anchor_radius_m=math.hypot(monitor.half_length,monitor.half_width))
|
||||
states, _ = monitor.classify_contacts(surface,local[required]@axes.T)
|
||||
return bool(np.all(states=='observed-supported'))
|
||||
|
||||
|
||||
def alignment_angle(pose, goal, terrain, detected, monitor, contact_height, *,
|
||||
collision_terrain=None):
|
||||
delta = np.asarray(goal[:2]) - np.asarray(pose[:2])
|
||||
if np.linalg.norm(delta) <= .4:
|
||||
return None
|
||||
x, y, z, w = pose[3:]
|
||||
yaw = math.atan2(2*(w*z+x*y), 1-2*(y*y+z*z))
|
||||
bearing = math.atan2(delta[1], delta[0]) - yaw
|
||||
angle = math.atan2(math.sin(bearing), math.cos(bearing))
|
||||
if abs(angle) < math.pi/6:
|
||||
return None
|
||||
collision = terrain if collision_terrain is None else collision_terrain
|
||||
if not monitor.rotation_clear(angle, collision, pose):
|
||||
return None
|
||||
if collision_terrain is not None:
|
||||
forbidden = terrain[terrain[:, 3] > collision[:, 3]]
|
||||
if not monitor.ground_envelope().rotation_clear(angle, forbidden, pose):
|
||||
return None
|
||||
objects = DetectionObstacles(monitor)
|
||||
hazards = np.column_stack((detected, np.full(len(detected), objects.cost)))
|
||||
if not objects.monitor.rotation_clear(angle, hazards, pose):
|
||||
return None
|
||||
if not observed_turn_support(angle, terrain, pose, monitor, contact_height):
|
||||
return None
|
||||
return angle
|
||||
@@ -19,7 +19,6 @@ import rclpy
|
||||
import yaml
|
||||
from action_msgs.msg import GoalStatus
|
||||
from configuration import observed_configuration
|
||||
from differential_motion import alignment_angle
|
||||
from navigation.arrival_approach import validate_orientation, orientation_identity
|
||||
from navigation.continuous_control import ContinuousControl
|
||||
from navigation.footprint import Footprint
|
||||
@@ -49,7 +48,6 @@ class Navigation:
|
||||
self.command_generation = 0
|
||||
self.path_context = None
|
||||
self.completed_orientation = None
|
||||
self.attempted_alignment = None
|
||||
self.path = None
|
||||
self.path_planned_at = float('-inf')
|
||||
self.active, self.failure = False, None
|
||||
@@ -205,50 +203,30 @@ class Navigation:
|
||||
and self.node.terminal is not None and self.node.terminal.done()
|
||||
and self.node.terminal.result().status == GoalStatus.STATUS_SUCCEEDED):
|
||||
self.completed_orientation = orientation_key
|
||||
# The tracked rover can change heading without translating. Consider
|
||||
# a native Spin before a large direction change, only if the complete
|
||||
# rectangular body turn fits the obstacle/detector reserve and its
|
||||
# complete newly entered track sweep has measured support.
|
||||
# Unsafe turns leave Smac/DWB free to find an arc. Support and all live
|
||||
# command gates still apply during Spin; completion grants no motion.
|
||||
alignment_key = ('align', tuple(goal[:2]), limit)
|
||||
aligning = (not reverse and value['translation_allowed']
|
||||
and self.action_key == alignment_key and self.node.terminal is not None
|
||||
and not self.node.terminal.done())
|
||||
# A changing local endpoint is still a FollowPath task. Let Smac/DWB
|
||||
# choose its curve; facing the endpoint directly is not a prerequisite
|
||||
# for following that curve. Preempting a live path with Spin on every
|
||||
# >30 degree bearing change creates stop/turn/advance oscillations.
|
||||
# A completed/aborted path and explicit mission recovery may still
|
||||
# select a fully observed in-place turn before starting translation.
|
||||
# Smac plans from the measured heading. A destination bearing is not
|
||||
# a path tangent or evidence of reachability, including after a failed
|
||||
# action. Never turn toward an unplanned translation goal. DWB retains
|
||||
# differential steering/pivots while following a feasible native path;
|
||||
# separate Spin is reserved for an explicit non-translating survey.
|
||||
following = (self.action_key is not None and self.action_key[0] == 'path'
|
||||
and self.node.terminal is not None and not self.node.terminal.done())
|
||||
turn = None
|
||||
if (not reverse and value['translation_allowed'] and not aligning and not following
|
||||
and alignment_key != self.attempted_alignment):
|
||||
turn = alignment_angle(pose, goal, terrain, observed['detected'], self.monitor,
|
||||
value['body_contact_height_m'],
|
||||
collision_terrain=observed['collision_terrain'])
|
||||
orienting = aligning or turn is not None or (not reverse and orientation is not None
|
||||
orienting = (not reverse and orientation is not None
|
||||
and orientation_key != self.completed_orientation
|
||||
and not value['translation_allowed'])
|
||||
if not value['translation_allowed'] and not orienting:
|
||||
self.stop()
|
||||
return self.reply('no-permitted-goal', status='blocked', route_observation=route)
|
||||
if orienting:
|
||||
automatic = aligning or turn is not None
|
||||
delta = (goal[:2] if automatic else np.asarray(orientation['xy']))-pose[:2]
|
||||
delta = np.asarray(orientation['xy'])-pose[:2]
|
||||
heading = math.atan2(delta[1], delta[0])
|
||||
angle = math.atan2(math.sin(heading-yaw_of(pose)), math.cos(heading-yaw_of(pose)))
|
||||
key = alignment_key if automatic else orientation_key
|
||||
key = orientation_key
|
||||
if key != self.action_key:
|
||||
self.revoke_command()
|
||||
# Existing mission budgets use simulation time. Do not invent
|
||||
# a second wall-clock maneuver budget in a slower simulation.
|
||||
# The unchanged command/data leases still gate every output.
|
||||
self.node.spin(angle, 0.)
|
||||
if automatic:
|
||||
self.attempted_alignment = alignment_key
|
||||
local_path = [[0.,0.,0.],[0.,0.,0.]]
|
||||
elif reverse:
|
||||
key = ('backup', tuple(goal[:2]), limit)
|
||||
|
||||
Reference in New Issue
Block a user