mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-07-02 02:51:42 +00:00
SCRIPT namespace replacements
This commit is contained in:
committed by
Peter Johnson
parent
ae6c043632
commit
9aca8e0fd6
@@ -148,7 +148,7 @@ static bool EmitEntryTarget(int tag_id, std::string& file) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
void saveCalibration(wpi::json& field, std::string& output_directory,
|
||||
void saveCalibration(wpi::util::json& field, std::string& output_directory,
|
||||
std::string output_name, bool& isCalibrating) {
|
||||
if (!field.empty() && !output_directory.empty()) {
|
||||
std::cout << "Saving calibration to " << output_directory << std::endl;
|
||||
@@ -198,8 +198,8 @@ static void DisplayGui() {
|
||||
field_calibration_directory_selector;
|
||||
static std::unique_ptr<pfd::select_folder> download_directory_selector;
|
||||
|
||||
static wpi::json field_calibration_json;
|
||||
static wpi::json field_combination_json;
|
||||
static wpi::util::json field_calibration_json;
|
||||
static wpi::util::json field_combination_json;
|
||||
|
||||
static std::string selected_camera_intrinsics;
|
||||
static std::string selected_field_map;
|
||||
@@ -534,8 +534,8 @@ static void DisplayGui() {
|
||||
std::ifstream calJson(output_calibration_json_path);
|
||||
std::ifstream refJson(selected_field_map);
|
||||
|
||||
currentCalibrationMap = Fieldmap(wpi::json::parse(calJson));
|
||||
currentReferenceMap = Fieldmap(wpi::json::parse(refJson));
|
||||
currentCalibrationMap = Fieldmap(wpi::util::json::parse(calJson));
|
||||
currentReferenceMap = Fieldmap(wpi::util::json::parse(refJson));
|
||||
|
||||
if (currentCalibrationMap.getNumTags() !=
|
||||
currentReferenceMap.getNumTags()) {
|
||||
@@ -616,7 +616,7 @@ static void DisplayGui() {
|
||||
if (!selected_field_map.empty()) {
|
||||
drawCheck();
|
||||
std::ifstream json(selected_field_map);
|
||||
currentReferenceMap = Fieldmap(wpi::json::parse(json));
|
||||
currentReferenceMap = Fieldmap(wpi::util::json::parse(json));
|
||||
currentCombinerMap = currentReferenceMap;
|
||||
}
|
||||
openFilesButton("Select Field Calibrations",
|
||||
@@ -660,7 +660,7 @@ static void DisplayGui() {
|
||||
if (ImGui::Button("Download", ImVec2(0, 0))) {
|
||||
for (auto& [key, val] : combiner_map) {
|
||||
std::ifstream json(val);
|
||||
Fieldmap map(wpi::json::parse(json));
|
||||
Fieldmap map(wpi::util::json::parse(json));
|
||||
currentCombinerMap.replaceTag(key, map.getTag(key));
|
||||
}
|
||||
field_combination_json = currentCombinerMap.toJson();
|
||||
|
||||
@@ -96,11 +96,11 @@ inline cameracalibration::CameraModel load_camera_model(std::string path) {
|
||||
|
||||
std::ifstream file(path);
|
||||
|
||||
wpi::json json_data;
|
||||
wpi::util::json json_data;
|
||||
|
||||
try {
|
||||
json_data = wpi::json::parse(file);
|
||||
} catch (const wpi::json::parse_error& e) {
|
||||
json_data = wpi::util::json::parse(file);
|
||||
} catch (const wpi::util::json::parse_error& e) {
|
||||
std::cout << e.what() << std::endl;
|
||||
}
|
||||
|
||||
@@ -150,7 +150,7 @@ inline cameracalibration::CameraModel load_camera_model(std::string path) {
|
||||
return camera_model;
|
||||
}
|
||||
|
||||
inline cameracalibration::CameraModel load_camera_model(wpi::json json_data) {
|
||||
inline cameracalibration::CameraModel load_camera_model(wpi::util::json json_data) {
|
||||
// Camera matrix
|
||||
Eigen::Matrix<double, 3, 3> camera_matrix;
|
||||
|
||||
@@ -176,10 +176,10 @@ inline cameracalibration::CameraModel load_camera_model(wpi::json json_data) {
|
||||
return camera_model;
|
||||
}
|
||||
|
||||
inline std::map<int, wpi::json> load_ideal_map(std::string path) {
|
||||
inline std::map<int, wpi::util::json> load_ideal_map(std::string path) {
|
||||
std::ifstream file(path);
|
||||
wpi::json json_data = wpi::json::parse(file);
|
||||
std::map<int, wpi::json> ideal_map;
|
||||
wpi::util::json json_data = wpi::util::json::parse(file);
|
||||
std::map<int, wpi::util::json> ideal_map;
|
||||
|
||||
for (const auto& element : json_data["tags"]) {
|
||||
ideal_map[element["ID"]] = element;
|
||||
@@ -189,7 +189,7 @@ inline std::map<int, wpi::json> load_ideal_map(std::string path) {
|
||||
}
|
||||
|
||||
Eigen::Matrix<double, 4, 4> get_tag_transform(
|
||||
std::map<int, wpi::json>& ideal_map, int tag_id) {
|
||||
std::map<int, wpi::util::json>& ideal_map, int tag_id) {
|
||||
Eigen::Matrix<double, 4, 4> transform =
|
||||
Eigen::Matrix<double, 4, 4>::Identity();
|
||||
|
||||
@@ -432,7 +432,7 @@ inline bool process_video_file(
|
||||
}
|
||||
|
||||
int fieldcalibration::calibrate(std::string input_dir_path,
|
||||
wpi::json& output_json,
|
||||
wpi::util::json& output_json,
|
||||
std::string camera_model_path,
|
||||
std::string ideal_map_path, int pinned_tag_id,
|
||||
bool show_debug_window) {
|
||||
@@ -452,13 +452,13 @@ int fieldcalibration::calibrate(std::string input_dir_path,
|
||||
return 1;
|
||||
}
|
||||
|
||||
wpi::json json = wpi::json::parse(std::ifstream(ideal_map_path));
|
||||
wpi::util::json json = wpi::util::json::parse(std::ifstream(ideal_map_path));
|
||||
if (!json.contains("tags")) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Load ideal field map
|
||||
std::map<int, wpi::json> ideal_map;
|
||||
std::map<int, wpi::util::json> ideal_map;
|
||||
try {
|
||||
ideal_map = load_ideal_map(ideal_map_path);
|
||||
} catch (...) {
|
||||
@@ -552,7 +552,7 @@ int fieldcalibration::calibrate(std::string input_dir_path,
|
||||
std::cout << summary.BriefReport() << std::endl;
|
||||
|
||||
// Output
|
||||
std::map<int, wpi::json> observed_map = ideal_map;
|
||||
std::map<int, wpi::util::json> observed_map = ideal_map;
|
||||
|
||||
Eigen::Matrix<double, 4, 4> correction_a;
|
||||
correction_a << 0, 0, -1, 0, 1, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, 1;
|
||||
@@ -594,7 +594,7 @@ int fieldcalibration::calibrate(std::string input_dir_path,
|
||||
corrected_transform_q.w();
|
||||
}
|
||||
|
||||
wpi::json observed_map_json;
|
||||
wpi::util::json observed_map_json;
|
||||
|
||||
for (const auto& [tag_id, tag_json] : observed_map) {
|
||||
observed_map_json["tags"].push_back(tag_json);
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
wpi::json fmap::singleTag(int tag, const tag::Pose& tagpose) {
|
||||
wpi::util::json fmap::singleTag(int tag, const tag::Pose& tagpose) {
|
||||
std::vector<double> transform = {};
|
||||
for (int i = 0; i < 4; i++) {
|
||||
for (int j = 0; j < 4; j++) {
|
||||
@@ -22,7 +22,7 @@ wpi::json fmap::singleTag(int tag, const tag::Pose& tagpose) {
|
||||
{"unique", true}};
|
||||
}
|
||||
|
||||
wpi::json fmap::convertfmap(const wpi::json& json) {
|
||||
wpi::util::json fmap::convertfmap(const wpi::util::json& json) {
|
||||
std::string fmapstart = "{\"fiducials\":[";
|
||||
|
||||
std::string fmapend = "],\"type\":\"frc\"}";
|
||||
@@ -36,5 +36,5 @@ wpi::json fmap::convertfmap(const wpi::json& json) {
|
||||
}
|
||||
}
|
||||
|
||||
return wpi::json::parse(fmapstart.append(fmapend));
|
||||
return wpi::util::json::parse(fmapstart.append(fmapend));
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ Pose::Pose(int tag_id, double xpos, double ypos, double zpos, double w,
|
||||
yawRot = eulerAngles[2];
|
||||
}
|
||||
|
||||
wpi::json Pose::toJson() {
|
||||
wpi::util::json Pose::toJson() {
|
||||
return {{"ID", tagId},
|
||||
{"pose",
|
||||
{{"translation", {{"x", xPos}, {"y", yPos}, {"z", zPos}}},
|
||||
|
||||
@@ -40,7 +40,7 @@ static void dumpJson(CameraModel& camera_model,
|
||||
camera_model.distortion_coefficients.data() +
|
||||
camera_model.distortion_coefficients.size());
|
||||
|
||||
wpi::json result = {
|
||||
wpi::util::json result = {
|
||||
{"camera_matrix", camera_matrix},
|
||||
{"distortion_coefficients", distortion_coefficients},
|
||||
{"avg_reprojection_error", camera_model.avg_reprojection_error}};
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
#include "wpi/util/json.hpp"
|
||||
|
||||
namespace fieldcalibration {
|
||||
int calibrate(std::string input_dir_path, wpi::json& output_json,
|
||||
int calibrate(std::string input_dir_path, wpi::util::json& output_json,
|
||||
std::string camera_model_path, std::string ideal_map_path,
|
||||
int pinned_tag_id, bool show_debug_window);
|
||||
} // namespace fieldcalibration
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
class Fieldmap {
|
||||
public:
|
||||
Fieldmap() = default;
|
||||
explicit Fieldmap(const wpi::json& json) {
|
||||
explicit Fieldmap(const wpi::util::json& json) {
|
||||
double field_length_meters =
|
||||
static_cast<double>(json.at("field").at("length"));
|
||||
double field_width_meters =
|
||||
@@ -50,8 +50,8 @@ class Fieldmap {
|
||||
|
||||
bool hasTag(int tag) { return tagMap.find(tag) != tagMap.end(); }
|
||||
|
||||
wpi::json toJson() {
|
||||
wpi::json json;
|
||||
wpi::util::json toJson() {
|
||||
wpi::util::json json;
|
||||
for (auto& [key, val] : tagMap) {
|
||||
json["tags"].push_back(val.toJson());
|
||||
}
|
||||
|
||||
@@ -9,6 +9,6 @@
|
||||
#include "wpi/util/json.hpp"
|
||||
|
||||
namespace fmap {
|
||||
wpi::json singleTag(int tag, const tag::Pose& tagpose);
|
||||
wpi::json convertfmap(const wpi::json& json);
|
||||
wpi::util::json singleTag(int tag, const tag::Pose& tagpose);
|
||||
wpi::util::json convertfmap(const wpi::util::json& json);
|
||||
} // namespace fmap
|
||||
|
||||
@@ -20,6 +20,6 @@ class Pose {
|
||||
Eigen::Quaterniond quaternion;
|
||||
Eigen::Matrix3d rotationMatrix;
|
||||
Eigen::Matrix4d transformMatrixFmap;
|
||||
wpi::json toJson();
|
||||
wpi::util::json toJson();
|
||||
};
|
||||
} // namespace tag
|
||||
|
||||
@@ -288,7 +288,7 @@ compose_r_core(// output
|
||||
|
||||
Described here:
|
||||
|
||||
Altmann, Simon L. "Hamilton, Rodrigues, and the Quaternion Scandal."
|
||||
Altmann, Simon L. "Hamilton, Rodrigues, and the wpi::math::Quaternion Scandal."
|
||||
Mathematics Magazine, vol. 62, no. 5, 1989, pp. 291–308
|
||||
|
||||
Available here:
|
||||
|
||||
Reference in New Issue
Block a user