diff --git a/pathplannerlib/src/main/native/cpp/pathplanner/lib/auto/AutoBuilder.cpp b/pathplannerlib/src/main/native/cpp/pathplanner/lib/auto/AutoBuilder.cpp index 56a7ecf4..b4d7cb55 100644 --- a/pathplannerlib/src/main/native/cpp/pathplanner/lib/auto/AutoBuilder.cpp +++ b/pathplannerlib/src/main/native/cpp/pathplanner/lib/auto/AutoBuilder.cpp @@ -13,7 +13,7 @@ #include #include #include -#include +#include using namespace pathplanner; @@ -267,14 +267,14 @@ frc2::CommandPtr AutoBuilder::buildAuto(std::string autoName) { + "/pathplanner/autos/" + autoName + ".auto"; std::error_code error_code; - wpi::raw_fd_istream input { filePath, error_code }; + std::unique_ptr < wpi::MemoryBuffer > fileBuffer = + wpi::MemoryBuffer::GetFile(filePath, error_code); - if (error_code) { + if (fileBuffer == nullptr || error_code) { throw std::runtime_error("Cannot open file: " + filePath); } - wpi::json json; - input >> json; + wpi::json json = wpi::json::parse(fileBuffer->begin(), fileBuffer->end()); return getAutoCommandFromJson(json); } diff --git a/pathplannerlib/src/main/native/cpp/pathplanner/lib/commands/PathPlannerAuto.cpp b/pathplannerlib/src/main/native/cpp/pathplanner/lib/commands/PathPlannerAuto.cpp index 775cf36e..de273880 100644 --- a/pathplannerlib/src/main/native/cpp/pathplanner/lib/commands/PathPlannerAuto.cpp +++ b/pathplannerlib/src/main/native/cpp/pathplanner/lib/commands/PathPlannerAuto.cpp @@ -2,7 +2,7 @@ #include "pathplanner/lib/auto/AutoBuilder.h" #include "pathplanner/lib/util/PPLibTelemetry.h" #include -#include +#include using namespace pathplanner; @@ -22,14 +22,14 @@ std::vector> PathPlannerAuto::getPathGroupFromA + "/pathplanner/autos/" + autoName + ".auto"; std::error_code error_code; - wpi::raw_fd_istream input { filePath, error_code }; + std::unique_ptr < wpi::MemoryBuffer > fileBuffer = + wpi::MemoryBuffer::GetFile(filePath, error_code); - if (error_code) { + if (fileBuffer == nullptr || error_code) { throw std::runtime_error("Cannot open file: " + filePath); } - wpi::json json; - input >> json; + wpi::json json = wpi::json::parse(fileBuffer->begin(), fileBuffer->end()); return pathsFromCommandJson(json.at("command")); } @@ -39,14 +39,14 @@ frc::Pose2d PathPlannerAuto::getStartingPoseFromAutoFile(std::string autoName) { + "/pathplanner/autos/" + autoName + ".auto"; std::error_code error_code; - wpi::raw_fd_istream input { filePath, error_code }; + std::unique_ptr < wpi::MemoryBuffer > fileBuffer = + wpi::MemoryBuffer::GetFile(filePath, error_code); - if (error_code) { + if (fileBuffer == nullptr || error_code) { throw std::runtime_error("Cannot open file: " + filePath); } - wpi::json json; - input >> json; + wpi::json json = wpi::json::parse(fileBuffer->begin(), fileBuffer->end()); return AutoBuilder::getStartingPoseFromJson(json.at("startingPose")); } diff --git a/pathplannerlib/src/main/native/cpp/pathplanner/lib/path/PathPlannerPath.cpp b/pathplannerlib/src/main/native/cpp/pathplanner/lib/path/PathPlannerPath.cpp index 107c1cd0..f1fa13fa 100644 --- a/pathplannerlib/src/main/native/cpp/pathplanner/lib/path/PathPlannerPath.cpp +++ b/pathplannerlib/src/main/native/cpp/pathplanner/lib/path/PathPlannerPath.cpp @@ -2,7 +2,7 @@ #include "pathplanner/lib/util/GeometryUtil.h" #include "pathplanner/lib/util/PPLibTelemetry.h" #include -#include +#include #include #include @@ -87,14 +87,14 @@ std::shared_ptr PathPlannerPath::fromPathFile( + "/pathplanner/paths/" + pathName + ".path"; std::error_code error_code; - wpi::raw_fd_istream input { filePath, error_code }; + std::unique_ptr < wpi::MemoryBuffer > fileBuffer = + wpi::MemoryBuffer::GetFile(filePath, error_code); - if (error_code) { + if (fileBuffer == nullptr || error_code) { throw std::runtime_error("Cannot open file: " + filePath); } - wpi::json json; - input >> json; + wpi::json json = wpi::json::parse(fileBuffer->begin(), fileBuffer->end()); std::shared_ptr < PathPlannerPath > path = std::make_shared < PathPlannerPath > (PathPlannerPath::fromJson(json)); diff --git a/pathplannerlib/src/main/native/cpp/pathplanner/lib/pathfinding/LocalADStar.cpp b/pathplannerlib/src/main/native/cpp/pathplanner/lib/pathfinding/LocalADStar.cpp index e927162c..3ff230c7 100644 --- a/pathplannerlib/src/main/native/cpp/pathplanner/lib/pathfinding/LocalADStar.cpp +++ b/pathplannerlib/src/main/native/cpp/pathplanner/lib/pathfinding/LocalADStar.cpp @@ -1,7 +1,7 @@ #include "pathplanner/lib/pathfinding/LocalADStar.h" #include #include -#include +#include #include #include #include @@ -26,12 +26,13 @@ LocalADStar::LocalADStar() : fieldLength(16.54), fieldWidth(8.02), nodeSize( + "/pathplanner/navgrid.json"; std::error_code error_code; - wpi::raw_fd_istream input { filePath, error_code }; + std::unique_ptr < wpi::MemoryBuffer > fileBuffer = + wpi::MemoryBuffer::GetFile(filePath, error_code); if (!error_code) { try { - wpi::json json; - input >> json; + wpi::json json = wpi::json::parse(fileBuffer->begin(), + fileBuffer->end()); nodeSize = json.at("nodeSizeMeters").get(); wpi::json::const_reference grid = json.at("grid");