"""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("lookAheadDis", lookAheadDis);': ' nh->declare_parameter("pathInMapFrame", pathInMapFrame);\n' ' nh->declare_parameter("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()))