Prevent goal oscillation and unintended differential drive arcs

This commit is contained in:
DCCONSTRUCTIONS
2026-10-08 21:14:12 +03:00
parent 012286e972
commit 2e85d95c71
7 changed files with 120 additions and 20 deletions
@@ -21,6 +21,17 @@ PHASES = (
("resume", 3, 1, 0),
("final-hold", 3, 0, 0),
)
# Direct transitions intentionally omit an intervening safety-zero command.
# This isolates recovery from opposed tracks into straight translation.
TRANSITION_PHASES = (
("hold", 3, 0, 0),
("pivot-left", 8, 0, 0.35),
("exit-left", 6, 1, 0),
("hold-left", 3, 0, 0),
("pivot-right", 8, 0, -0.35),
("exit-right", 6, 1, 0),
("final-hold", 3, 0, 0),
)
CRITERIA = {
"translation_fraction_min": 0.5,
"turn_fraction_min": 0.45,
+16 -16
View File
@@ -96,23 +96,23 @@ class ChassisSpeedFeedback:
# requested yaw differential is retained. Safety zero stays zero.
pivot_room = abs(yaw_rate) * self.track_centres / 2
correction = max(-pivot_room, min(pivot_room, correction))
corrected = velocity + correction
# Feedback may reduce translation to zero, but cannot request an
# unplanned reversal. A pivot retains its opposed side directions.
if velocity * corrected < 0:
corrected = 0.0
nominal = SideSpeeds.from_twist(velocity, yaw_rate, self.track_centres)
proposed = SideSpeeds.from_twist(corrected, yaw_rate, self.track_centres)
# The nominal envelope owns each side's reversal through zero. A
# common correction must also respect a stationary/turning inner belt.
target = SideSpeeds(
*(
value if intent * value > 0 else 0.0
for intent, value in zip(
vars(nominal).values(), vars(proposed).values(), strict=True
)
)
).bounded(self.max_side)
# Limit the common correction before applying it to either belt.
# Clipping each side independently changes their difference and can
# amplify yaw when one nominal belt is near zero after a pivot.
for intent in vars(nominal).values():
if intent > 0:
correction = max(correction, -intent)
elif intent < 0:
correction = min(correction, -intent)
else:
correction = 0.0
corrected = velocity + correction
if velocity * corrected < 0:
corrected, correction = 0.0, -velocity
target = SideSpeeds.from_twist(corrected, yaw_rate, self.track_centres).bounded(
self.max_side
)
applied = target.twist(self.track_centres)
self.metrics = dict(
nominal_twist=[velocity, yaw_rate],
@@ -258,7 +258,18 @@ class ObservedGoals:
and (candidate_mask is None or candidate_mask(before[None])[0])
and supported(before)):
return before.tolist()
distance_to_target = np.linalg.norm(candidates[:, :2] - target, axis=1)
# Score the task direction at the existing 3.5 m observation horizon.
# Distance to a remote endpoint mostly rewards longitudinal advance:
# slightly farther side returns can beat a clear straight destination
# and make successive measured goals oscillate across the corridor.
# This reference only ranks actual permitted returns. It is never a
# generated drive goal, a straight-line route or a clearance receipt.
horizon = min(remaining, 3.5)
reference = pose[:2] + forward * horizon
# A smooth local attraction, normalized to metres like boundary_cost.
# Its gradient diminishes near the reference so centimetres of extra
# advance cannot outweigh clearance from an observed corridor edge.
distance_to_target = np.sum((candidates[:, :2] - reference)**2, axis=1) / horizon
# The declared task, not the selected lens, owns the preferred direction.
x,y,z,w = pose[3:7]
heading = math.atan2(2*(w*z+x*y),1-2*(y*y+z*z))
@@ -15,7 +15,7 @@ parser = argparse.ArgumentParser()
parser.add_argument("--output", type=Path, required=True)
parser.add_argument("--reservation", type=Path, required=True)
parser.add_argument("--case", action="append", dest="case_ids")
parser.add_argument("--profile", choices=("control", "sweep"), default="control")
parser.add_argument("--profile", choices=("control", "sweep", "transition"), default="control")
parser.add_argument("--contact-sample-hz", type=int, default=0, choices=(0, 1, 5, 10, 60))
args = parser.parse_args()
receipt = json.loads(args.reservation.read_text(encoding="utf-8-sig"))
@@ -40,6 +40,9 @@ from k1link.simulation.ai_polygon.robots import select_robot # noqa: E402
from k1link.simulation.ai_polygon.run_inputs import legacy_run_inputs # noqa: E402
from k1link.simulation.ai_polygon.run_robot import configure_robot # noqa: E402
if args.profile == "transition":
from control_qualification import TRANSITION_PHASES as PHASES
if args.profile == "sweep":
from sweep_qualification import CRITERIA, PHASES, SCHEMA
from sweep_qualification import phase_metrics as sweep_metrics