Skip to content
This repository has been archived by the owner on Jul 8, 2024. It is now read-only.

Commit

Permalink
Remove JSON serialization (#88)
Browse files Browse the repository at this point in the history
The Rust library build is broken by the JSON library's test folder
having files whose names are too long on Windows; CI can't even clone
the dependency's Git repo. We don't use the JSON serialization for
anything anymore, so we can just remove it.
  • Loading branch information
calcmogul authored Feb 17, 2024
1 parent 54b910b commit 524714c
Show file tree
Hide file tree
Showing 30 changed files with 9 additions and 468 deletions.
15 changes: 0 additions & 15 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -104,21 +104,6 @@ endif()

target_link_libraries(TrajoptLib PUBLIC fmt::fmt)

# json dependency
set(BUILD_SHARED_LIBS_SAVE ${BUILD_SHARED_LIBS})
set(BUILD_SHARED_LIBS OFF)
set(JSON_BuildTests OFF)
set(JSON_Install ON)
fetchcontent_declare(
nlohmann_json
GIT_REPOSITORY https://github.com/nlohmann/json
GIT_TAG v3.11.2
)
fetchcontent_makeavailable(nlohmann_json)
set(BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS_SAVE})

target_link_libraries(TrajoptLib PUBLIC nlohmann_json::nlohmann_json)

set(OPTIMIZER_BACKEND "casadi" CACHE STRING "Optimizer backend")
set_property(CACHE OPTIMIZER_BACKEND PROPERTY STRINGS casadi sleipnir)

Expand Down
8 changes: 0 additions & 8 deletions include/trajopt/constraint/AngularVelocityConstraint.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,9 @@

#include <optional>

#include <nlohmann/json.hpp>

#include "trajopt/SymbolExports.h"
#include "trajopt/set/IntervalSet1d.h"
#include "trajopt/solution/SolutionChecking.h"
#include "trajopt/util/JsonFmtFormatter.h"

namespace trajopt {

Expand All @@ -31,9 +28,4 @@ struct TRAJOPT_DLLEXPORT AngularVelocityConstraint {
const SolutionTolerances& tolerances) const noexcept;
};

NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(AngularVelocityConstraint,
angularVelocityBound)

} // namespace trajopt

_JSON_FMT_FORMATTER(trajopt::AngularVelocityConstraint)
52 changes: 0 additions & 52 deletions include/trajopt/constraint/Constraint.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
#include <optional>
#include <variant>

#include <fmt/format.h>

#include "trajopt/SymbolExports.h"
#include "trajopt/constraint/AngularVelocityConstraint.h"
#include "trajopt/constraint/HeadingConstraint.h"
Expand Down Expand Up @@ -66,54 +64,4 @@ std::optional<SolutionError> CheckState(
const Constraint& constraint, double x, double y, double heading,
const SolutionTolerances& tolerances) noexcept;

NLOHMANN_JSON_SERIALIZE_ENUM(CoordinateSystem,
{
{CoordinateSystem::kField, "field"},
{CoordinateSystem::kRobot, "robot"},
})

} // namespace trajopt

/**
* Formatter for Constraint.
*/
//! @cond Doxygen_Suppress
template <>
struct fmt::formatter<trajopt::Constraint> {
//! @endcond
/**
* Format string parser.
*
* @param ctx Format string context.
*/
constexpr auto parse(fmt::format_parse_context& ctx) { return ctx.begin(); }

/**
* Writes out a formatted Constraint.
*
* @param constraint Constraint instance.
* @param ctx Format string context.
*/
auto format(const trajopt::Constraint& constraint,
fmt::format_context& ctx) const {
using namespace trajopt;
if (std::holds_alternative<TranslationConstraint>(constraint)) {
return fmt::format_to(ctx.out(), "constraint: {}",
std::get<TranslationConstraint>(constraint));
} else if (std::holds_alternative<HeadingConstraint>(constraint)) {
return fmt::format_to(ctx.out(), "constraint: {}",
std::get<HeadingConstraint>(constraint));
} else if (std::holds_alternative<LinePointConstraint>(constraint)) {
return fmt::format_to(ctx.out(), "constraint: {}",
std::get<LinePointConstraint>(constraint));
} else if (std::holds_alternative<PointLineConstraint>(constraint)) {
return fmt::format_to(ctx.out(), "constraint: {}",
std::get<PointLineConstraint>(constraint));
} else if (std::holds_alternative<PointPointConstraint>(constraint)) {
return fmt::format_to(ctx.out(), "constraint: {}",
std::get<PointPointConstraint>(constraint));
} else {
return ctx.out();
}
}
};
7 changes: 0 additions & 7 deletions include/trajopt/constraint/HeadingConstraint.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,9 @@

#include <optional>

#include <nlohmann/json.hpp>

#include "trajopt/SymbolExports.h"
#include "trajopt/set/IntervalSet1d.h"
#include "trajopt/solution/SolutionChecking.h"
#include "trajopt/util/JsonFmtFormatter.h"

namespace trajopt {

Expand All @@ -30,8 +27,4 @@ struct TRAJOPT_DLLEXPORT HeadingConstraint {
double theta, const SolutionTolerances& tolerances) const noexcept;
};

NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(HeadingConstraint, headingBound)

} // namespace trajopt

_JSON_FMT_FORMATTER(trajopt::HeadingConstraint)
10 changes: 0 additions & 10 deletions include/trajopt/constraint/LinePointConstraint.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@

#pragma once

#include <nlohmann/json.hpp>

#include "trajopt/set/IntervalSet1d.h"
#include "trajopt/util/JsonFmtFormatter.h"

namespace trajopt {

Expand All @@ -30,11 +27,4 @@ struct LinePointConstraint {
IntervalSet1d distance;
};

NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(LinePointConstraint, robotLineStartX,
robotLineStartY, robotLineEndX,
robotLineEndY, fieldPointX, fieldPointY,
distance)

} // namespace trajopt

_JSON_FMT_FORMATTER(trajopt::LinePointConstraint)
10 changes: 0 additions & 10 deletions include/trajopt/constraint/PointLineConstraint.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@

#pragma once

#include <nlohmann/json.hpp>

#include "trajopt/set/IntervalSet1d.h"
#include "trajopt/util/JsonFmtFormatter.h"

namespace trajopt {

Expand All @@ -30,11 +27,4 @@ struct PointLineConstraint {
IntervalSet1d distance;
};

NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(PointLineConstraint, robotPointX,
robotPointY, fieldLineStartX,
fieldLineStartY, fieldLineEndX,
fieldLineEndY, distance)

} // namespace trajopt

_JSON_FMT_FORMATTER(trajopt::PointLineConstraint)
9 changes: 0 additions & 9 deletions include/trajopt/constraint/PointPointConstraint.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@

#pragma once

#include <nlohmann/json.hpp>

#include "trajopt/set/IntervalSet1d.h"
#include "trajopt/util/JsonFmtFormatter.h"

namespace trajopt {

Expand All @@ -26,10 +23,4 @@ struct PointPointConstraint {
IntervalSet1d distance;
};

NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(PointPointConstraint, robotPointX,
robotPointY, fieldPointX, fieldPointY,
distance)

} // namespace trajopt

_JSON_FMT_FORMATTER(trajopt::PointPointConstraint)
7 changes: 0 additions & 7 deletions include/trajopt/constraint/TranslationConstraint.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,9 @@

#include <optional>

#include <nlohmann/json.hpp>

#include "trajopt/SymbolExports.h"
#include "trajopt/set/Set2d.h"
#include "trajopt/solution/SolutionChecking.h"
#include "trajopt/util/JsonFmtFormatter.h"

namespace trajopt {

Expand All @@ -31,8 +28,4 @@ struct TRAJOPT_DLLEXPORT TranslationConstraint {
double x, double y, const SolutionTolerances& tolerances) const noexcept;
};

NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(TranslationConstraint, translationBound)

} // namespace trajopt

_JSON_FMT_FORMATTER(trajopt::TranslationConstraint)
44 changes: 0 additions & 44 deletions include/trajopt/constraint/differential/DifferentialConstraint.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

#include <variant>

#include <fmt/format.h>

#include "trajopt/SymbolExports.h"
#include "trajopt/constraint/AngularVelocityConstraint.h"
#include "trajopt/constraint/Constraint.h"
Expand All @@ -21,45 +19,3 @@ using DifferentialConstraint =
DifferentialTangentialVelocityConstraint{},
DifferentialCentripetalAccelerationConstraint{}));
} // namespace trajopt

/**
* Formatter for HolonomicConstraint.
*/
//! @cond Doxygen_Suppress
template <>
struct fmt::formatter<trajopt::DifferentialConstraint> {
//! @endcond
/**
* Format string parser.
*
* @param ctx Format string context.
*/
constexpr auto parse(fmt::format_parse_context& ctx) { return ctx.begin(); }

/**
* Writes out a formatted HolonomicConstraint.
*
* @param constraint HolonomicConstraint instance.
* @param ctx Format string context.
*/
auto format(const trajopt::DifferentialConstraint& constraint,
fmt::format_context& ctx) const {
using namespace trajopt;
if (std::holds_alternative<AngularVelocityConstraint>(constraint)) {
return fmt::format_to(ctx.out(), "constraint: {}",
std::get<AngularVelocityConstraint>(constraint));
} else if (std::holds_alternative<DifferentialTangentialVelocityConstraint>(
constraint)) {
return fmt::format_to(
ctx.out(), "constraint: {}",
std::get<DifferentialTangentialVelocityConstraint>(constraint));
} else if (std::holds_alternative<
DifferentialCentripetalAccelerationConstraint>(constraint)) {
return fmt::format_to(
ctx.out(), "constraint: {}",
std::get<DifferentialCentripetalAccelerationConstraint>(constraint));
} else {
return ctx.out();
}
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

#include <optional>

#include <fmt/format.h>

#include "trajopt/SymbolExports.h"
#include "trajopt/constraint/Constraint.h"
#include "trajopt/set/IntervalSet1d.h"
Expand All @@ -21,31 +19,3 @@ struct TRAJOPT_DLLEXPORT DifferentialTangentialVelocityConstraint {
IntervalSet1d velocityBound;
};
} // namespace trajopt

/**
* Formatter for VelocityConstraint.
*/
//! @cond Doxygen_Suppress
template <>
struct fmt::formatter<trajopt::DifferentialTangentialVelocityConstraint> {
//! @endcond
/**
* Format string parser.
*
* @param ctx Format string context.
*/
constexpr auto parse(fmt::format_parse_context& ctx) { return ctx.begin(); }

/**
* Writes out a formatted VelocityConstraint.
*
* @param constraint VelocityConstraint instance.
* @param ctx Format string context.
*/
auto format(
const trajopt::DifferentialTangentialVelocityConstraint& constraint,
fmt::format_context& ctx) const {
return fmt::format_to(ctx.out(), "diff velocity magnitude {}",
constraint.velocityBound);
}
};
22 changes: 0 additions & 22 deletions include/trajopt/constraint/holonomic/HolonomicConstraint.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,11 @@

#include <variant>

#include <nlohmann/json.hpp>

#include "trajopt/SymbolExports.h"
#include "trajopt/constraint/AngularVelocityConstraint.h"
#include "trajopt/constraint/holonomic/HolonomicVelocityConstraint.h"
#include "trajopt/solution/SolutionChecking.h"
#include "trajopt/util/AppendVariant.h"
#include "trajopt/util/JsonFmtFormatter.h"

namespace trajopt {

Expand Down Expand Up @@ -39,22 +36,3 @@ std::optional<SolutionError> CheckState(
const SolutionTolerances& tolerances) noexcept;

} // namespace trajopt

// For the serialization functions of HolonomicConstraint, we want to use the
// serialization functions of the various constraint types
// (TranslationConstraint, HeadingConstraint, etc.), but the implicit
// conversion from each of those types to HolonomicConstraint (because of
// std::variant) requires using this style of serialization that avoids that
// issue.
//! @cond Doxygen_Suppress
namespace nlohmann {
template <>
struct adl_serializer<trajopt::HolonomicConstraint> {
static void to_json(json& j, const trajopt::HolonomicConstraint& constraint);
static void from_json(const json& j,
trajopt::HolonomicConstraint& constraint);
};
} // namespace nlohmann
//! @endcond

_JSON_FMT_FORMATTER(trajopt::HolonomicConstraint)
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,10 @@

#include <optional>

#include <nlohmann/json.hpp>

#include "trajopt/SymbolExports.h"
#include "trajopt/constraint/Constraint.h"
#include "trajopt/set/Set2d.h"
#include "trajopt/solution/SolutionChecking.h"
#include "trajopt/util/JsonFmtFormatter.h"

namespace trajopt {

Expand All @@ -36,9 +33,4 @@ struct TRAJOPT_DLLEXPORT HolonomicVelocityConstraint {
const SolutionTolerances& tolerances) const noexcept;
};

NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(HolonomicVelocityConstraint, velocityBound,
coordinateSystem)

} // namespace trajopt

_JSON_FMT_FORMATTER(trajopt::HolonomicVelocityConstraint)
Loading

0 comments on commit 524714c

Please sign in to comment.