Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions pathplannerlib-python/pathplannerlib/path.py
Original file line number Diff line number Diff line change
Expand Up @@ -520,13 +520,18 @@ def _loadChoreoTrajectoryIntoCache(trajectory_name: str) -> None:
with open(filePath, 'r') as f:
fJson = json.loads(f.read())

version = str(fJson['version'])
versions = version.split('.')
version = 0

try:
version = int(fJson['version'])
except ValueError:
# Assume version 0
pass

if len(versions) < 2 or versions[0] != 'v2025' or versions[1] != '0':
if version > 1:
raise RuntimeError("Incompatible file version for '" + trajectory_name
+ ".traj'. Actual: '" + version
+ "' Expected: 'v2025.0.X'")
+ ".traj'. Actual: '" + str(version)
+ "' Expected: <= 1")

trajJson = fJson['trajectory']

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -349,11 +349,16 @@ private static void loadChoreoTrajectoryIntoCache(String trajectoryName)
String fileContent = fileContentBuilder.toString();
JSONObject json = (JSONObject) new JSONParser().parse(fileContent);

String version = json.get("version").toString();
String[] versions = version.split("\\.");
int version = 0;

try {
version = ((Number) json.get("version")).intValue();
} catch (Exception ignored) {
// Assume version 0
}

if (versions.length < 2 || !versions[0].equals("v2025") || !versions[1].equals("0")) {
throw new FileVersionException(version, "v2025.0.X", trajectoryName + ".traj");
if (version > 1) {
throw new FileVersionException(Integer.toString(version), "<= 1", trajectoryName + ".traj");
}

JSONObject trajJson = (JSONObject) json.get("trajectory");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,16 +155,16 @@ void PathPlannerPath::loadChoreoTrajectoryIntoCache(

wpi::json json = wpi::json::parse(fileBuffer.value()->GetCharBuffer());

std::string version = "1.0";
if (json.at("version").is_string()) {
version = json.at("version").get<std::string>();
int version = 0;
if (json.at("version").is_number_integer()) {
version = json.at("version").get<int>();
}

if (version != "v2025.0.0") {
if (version > 1) {
throw std::runtime_error(
"Incompatible file version for '" + trajectoryName
+ ".traj'. Actual: '" + version
+ "' Expected: 'v2025.0.0'");
+ ".traj'. Actual: '" + std::to_string(version)
+ "' Expected: <= 1");
}

auto trajJson = json.at("trajectory");
Expand Down
Loading