Files
DCCONSTRUCTIONS d0e5f90952 Preserve installed operator workspace before consolidation
Local preservation snapshot, not a new deployment or simulation acceptance.
2026-10-08 09:59:51 +03:00

39 lines
1.6 KiB
Python

"""Opt-in world-frame paths for CMU's existing live-odometry path follower."""
from pathlib import Path
def patch(source):
edits = {
"bool pathInit = false;": "bool pathInit = false;\nbool pathInMapFrame = false;",
' nh->declare_parameter<double>("lookAheadDis", lookAheadDis);':
' nh->declare_parameter<bool>("pathInMapFrame", pathInMapFrame);\n'
' nh->declare_parameter<double>("lookAheadDis", lookAheadDis);',
' nh->get_parameter("lookAheadDis", lookAheadDis);':
' nh->get_parameter("pathInMapFrame", pathInMapFrame);\n'
' nh->get_parameter("lookAheadDis", lookAheadDis);',
" vehicleXRec = vehicleX;": """ if (pathInMapFrame) {
if (pathIn->header.frame_id != "map") { pathInit = false; return; }
const double c = cos(vehicleYaw), s = sin(vehicleYaw);
for (int i = 0; i < pathSize; i++) {
const double x = path.poses[i].pose.position.x - vehicleX;
const double y = path.poses[i].pose.position.y - vehicleY;
path.poses[i].pose.position.x = c * x + s * y;
path.poses[i].pose.position.y = -s * x + c * y;
path.poses[i].pose.position.z -= vehicleZ;
}
}
vehicleXRec = vehicleX;""",
}
for anchor, replacement in edits.items():
if source.count(anchor) != 1:
raise ValueError("Unexpected pinned CMU continuous 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()))