Skip to content

Commit

Permalink
Add C++
Browse files Browse the repository at this point in the history
  • Loading branch information
KangarooKoala committed Feb 1, 2024
1 parent d092fe8 commit 21bdc4f
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 46 deletions.
34 changes: 34 additions & 0 deletions apriltag/src/main/native/cpp/AprilTagFieldLayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,37 @@ void frc::from_json(const wpi::json& json, AprilTagFieldLayout& layout) {
layout.m_fieldWidth =
units::meter_t{json.at("field").at("width").get<double>()};
}

// Use namespace declaration for forward declaration
namespace frc {

// C++ generated from resource files
std::string_view GetResource_2022_rapidreact_json();
std::string_view GetResource_2023_chargedup_json();
std::string_view GetResource_2024_crescendo_json();

} // namespace frc

AprilTagFieldLayout AprilTagFieldLayout::LoadField(AprilTagField field) {
std::string_view fieldString;
switch (field) {
case AprilTagField::k2022RapidReact:
fieldString = GetResource_2022_rapidreact_json();
break;
case AprilTagField::k2023ChargedUp:
fieldString = GetResource_2023_chargedup_json();
break;
case AprilTagField::k2024Crescendo:
fieldString = GetResource_2024_crescendo_json();
break;
case AprilTagField::kNumFields:
throw std::invalid_argument("Invalid Field");
}

wpi::json json = wpi::json::parse(fieldString);
return json.get<AprilTagFieldLayout>();
}

AprilTagFieldLayout frc::LoadAprilTagLayoutField(AprilTagField field) {
return AprilTagFieldLayout::LoadField(field);
}
36 changes: 0 additions & 36 deletions apriltag/src/main/native/cpp/AprilTagFields.cpp

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <wpi/json_fwd.h>

#include "frc/apriltag/AprilTag.h"
#include "frc/apriltag/AprilTagFields.h"
#include "frc/geometry/Pose3d.h"

namespace frc {
Expand Down Expand Up @@ -48,6 +49,14 @@ class WPILIB_DLLEXPORT AprilTagFieldLayout {
kRedAllianceWallRightSide,
};

/**
* Loads an AprilTagFieldLayout from a predefined field
*
* @param field The predefined field
* @return AprilTagFieldLayout of the field
*/
static AprilTagFieldLayout LoadField(AprilTagField field);

AprilTagFieldLayout() = default;

/**
Expand Down Expand Up @@ -152,4 +161,13 @@ void to_json(wpi::json& json, const AprilTagFieldLayout& layout);
WPILIB_DLLEXPORT
void from_json(const wpi::json& json, AprilTagFieldLayout& layout);

/**
* Loads an AprilTagFieldLayout from a predefined field
*
* @param field The predefined field
* @return AprilTagFieldLayout of the field
*/
WPILIB_DLLEXPORT AprilTagFieldLayout
LoadAprilTagLayoutField(AprilTagField field);

} // namespace frc
10 changes: 0 additions & 10 deletions apriltag/src/main/native/include/frc/apriltag/AprilTagFields.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

#include <wpi/SymbolExports.h>

#include "frc/apriltag/AprilTagFieldLayout.h"

namespace frc {

/**
Expand All @@ -28,12 +26,4 @@ enum class AprilTagField {
kNumFields,
};

/**
* Loads an AprilTagFieldLayout from a predefined field
*
* @param field The predefined field
*/
WPILIB_DLLEXPORT AprilTagFieldLayout
LoadAprilTagLayoutField(AprilTagField field);

} // namespace frc
1 change: 1 addition & 0 deletions apriltag/src/test/native/cpp/LoadConfigTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include <gtest/gtest.h>

#include "frc/apriltag/AprilTagFieldLayout.h"
#include "frc/apriltag/AprilTagFields.h"

namespace frc {
Expand Down

0 comments on commit 21bdc4f

Please sign in to comment.