"""Opt-in curvature tracking in the pinned CMU follower, for both control loops. CMU's heading-proportional angular command is independent of speed. On a slow tracked robot it asks for a much tighter arc than the selected primitive and can be vetoed forever beside a safe corridor. Use the pure-pursuit curvature of its existing look-ahead point during translation. Keep the original separate large-heading rotation, direction grant, speed ramp and all subsequent stops. """ from pathlib import Path def patch(source): if "usePurePursuit" in source or "missioncorePursuitYaw" in source: raise ValueError("Pursuit adapter already present") edits = { "bool pathInit = false;": '#include "missioncore_pursuit.hpp"\n' 'bool usePurePursuit = false;\nbool pathInit = false;', ' nh->declare_parameter("lookAheadDis", lookAheadDis);': ' nh->declare_parameter("usePurePursuit", usePurePursuit);\n' ' nh->declare_parameter("lookAheadDis", lookAheadDis);', ' nh->get_parameter("lookAheadDis", lookAheadDis);': ' nh->get_parameter("usePurePursuit", usePurePursuit);\n' ' nh->get_parameter("lookAheadDis", lookAheadDis);', ' if (odomTime < stopInitTime + stopTime && stopInitTime > 0) {': ''' if (usePurePursuit && autonomyMode && pathSize > 1 && fabs(dirDiff) < dirDiffThre && dis > stopDisThre) { const double heading = vehicleYaw - vehicleYawRec; const double lateral = -sin(heading) * disX + cos(heading) * disY; vehicleYawRate = missioncorePursuitYaw(vehicleSpeed, lateral, dis, maxYawRate * PI / 180.0); } if (odomTime < stopInitTime + stopTime && stopInitTime > 0) {''', } for anchor, replacement in edits.items(): if source.count(anchor) != 1: raise ValueError("Unexpected pinned CMU pursuit anchor: " + anchor) source = source.replace(anchor, replacement) return source if __name__ == "__main__": path = Path("/opt/cmu/src/local_planner/src/pathFollower.cpp") path.write_text(patch(path.read_text()))