Skip to content

Commit

Permalink
renamed diffy to differential
Browse files Browse the repository at this point in the history
  • Loading branch information
r4stered committed Sep 24, 2024
1 parent f7fc012 commit 62f1c1c
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 38 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright (c) Choreo contributors

#include "choreo/trajectory/DiffySample.h"
#include "choreo/trajectory/DifferentialSample.h"

#include <wpi/MathExtras.h>
#include <wpi/json.h>
Expand All @@ -10,15 +10,15 @@

using namespace choreo::trajectory;

units::second_t DiffySample::GetTimestamp() const {
units::second_t DifferentialSample::GetTimestamp() const {
return timestamp;
}

frc::Pose2d DiffySample::GetPose() const {
frc::Pose2d DifferentialSample::GetPose() const {
return frc::Pose2d{x, y, frc::Rotation2d{heading}};
}

frc::ChassisSpeeds DiffySample::GetChassisSpeeds() const {
frc::ChassisSpeeds DifferentialSample::GetChassisSpeeds() const {
return frc::ChassisSpeeds{
(vl + vr) / 2.0, 0.0_mps,
(vr - vl) /
Expand All @@ -27,18 +27,18 @@ frc::ChassisSpeeds DiffySample::GetChassisSpeeds() const {
1_rad};
}

DiffySample DiffySample::OffsetBy(units::second_t timeStampOffset) const {
return DiffySample{
DifferentialSample DifferentialSample::OffsetBy(units::second_t timeStampOffset) const {
return DifferentialSample{
timestamp + timeStampOffset, x, y, heading, vl, vr, al, ar, fl, fr};
}

DiffySample DiffySample::Interpolate(const DiffySample& endValue,
DifferentialSample DifferentialSample::Interpolate(const DifferentialSample& endValue,
units::second_t t) const {
units::scalar_t scale = (t - timestamp) / (endValue.timestamp - timestamp);
frc::Pose2d interpolatedPose =
frc::Interpolate(GetPose(), endValue.GetPose(), scale.value());

return DiffySample{
return DifferentialSample{
wpi::Lerp(timestamp, endValue.timestamp, scale),
interpolatedPose.X(),
interpolatedPose.Y(),
Expand All @@ -53,7 +53,7 @@ DiffySample DiffySample::Interpolate(const DiffySample& endValue,
}

void choreo::trajectory::to_json(wpi::json& json,
const DiffySample& trajSample) {
const DifferentialSample& trajSample) {
json = wpi::json{{"t", trajSample.timestamp.value()},
{"x", trajSample.x.value()},
{"y", trajSample.y.value()},
Expand All @@ -67,7 +67,7 @@ void choreo::trajectory::to_json(wpi::json& json,
}

void choreo::trajectory::from_json(const wpi::json& json,
DiffySample& trajSample) {
DifferentialSample& trajSample) {
trajSample.timestamp = units::second_t{json.at("t").get<double>()};
trajSample.x = units::meter_t{json.at("x").get<double>()};
trajSample.y = units::meter_t{json.at("y").get<double>()};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@ void choreo::trajectory::from_json(const wpi::json& json,
}

void choreo::trajectory::to_json(wpi::json& json,
const Trajectory<DiffySample>& traj) {
const Trajectory<DifferentialSample>& traj) {
json = wpi::json{{"name", traj.name},
{"samples", traj.samples},
{"splits", traj.splits},
{"events", traj.events}};
}

void choreo::trajectory::from_json(const wpi::json& json,
Trajectory<DiffySample>& traj) {
traj.samples = json.at("traj").at("samples").get<std::vector<DiffySample>>();
Trajectory<DifferentialSample>& traj) {
traj.samples = json.at("traj").at("samples").get<std::vector<DifferentialSample>>();
traj.splits = json.at("traj").at("splits").get<std::vector<int>>();
traj.events = json.at("events").get<std::vector<EventMarker>>();
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright (c) Choreo contributors

#include "choreo/trajectory/struct/DiffySampleStruct.h"
#include "choreo/trajectory/struct/DifferentialSampleStruct.h"

namespace {
constexpr size_t kTimestampOff = 0;
Expand All @@ -15,11 +15,11 @@ constexpr size_t kFlOff = kArOff + 8;
constexpr size_t kFrOff = kFlOff + 8;
} // namespace

using StructType = wpi::Struct<choreo::trajectory::DiffySample>;
using StructType = wpi::Struct<choreo::trajectory::DifferentialSample>;

choreo::trajectory::DiffySample StructType::Unpack(
choreo::trajectory::DifferentialSample StructType::Unpack(
std::span<const uint8_t> data) {
return choreo::trajectory::DiffySample{
return choreo::trajectory::DifferentialSample{
units::second_t{wpi::UnpackStruct<double, kTimestampOff>(data)},
units::meter_t{wpi::UnpackStruct<double, kXOff>(data)},
units::meter_t{wpi::UnpackStruct<double, kYOff>(data)},
Expand All @@ -35,7 +35,7 @@ choreo::trajectory::DiffySample StructType::Unpack(
}

void StructType::Pack(std::span<uint8_t> data,
const choreo::trajectory::DiffySample& value) {
const choreo::trajectory::DifferentialSample& value) {
wpi::PackStruct<kTimestampOff>(data, value.timestamp.value());
wpi::PackStruct<kXOff>(data, value.x.value());
wpi::PackStruct<kYOff>(data, value.y.value());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@

namespace choreo {
namespace trajectory {
class DiffySample {
class DifferentialSample {
public:
DiffySample() = default;
DiffySample(units::second_t timestamp, units::meter_t x, units::meter_t y,
DifferentialSample() = default;
DifferentialSample(units::second_t timestamp, units::meter_t x, units::meter_t y,
units::radian_t heading, units::meters_per_second_t vl,
units::meters_per_second_t vr,
units::meters_per_second_squared_t al,
Expand All @@ -42,10 +42,10 @@ class DiffySample {
frc::Pose2d GetPose() const;
frc::ChassisSpeeds GetChassisSpeeds() const;
template <int Year>
DiffySample Flipped() const {
DifferentialSample Flipped() const {
static constexpr auto flipper = choreo::util::GetFlipperForYear<Year>();
if constexpr (flipper.isMirrored) {
return DiffySample(timestamp,
return DifferentialSample(timestamp,
flipper.FlipX(x),
y,
flipper.FlipHeading(heading),
Expand All @@ -56,7 +56,7 @@ class DiffySample {
fl,
fr);
} else {
return DiffySample(timestamp,
return DifferentialSample(timestamp,
flipper.FlipX(x),
flipper.FlipY(y),
flipper.FlipHeading(heading),
Expand All @@ -68,8 +68,8 @@ class DiffySample {
fl);
}
}
DiffySample OffsetBy(units::second_t timeStampOffset) const;
DiffySample Interpolate(const DiffySample& endValue, units::second_t t) const;
DifferentialSample OffsetBy(units::second_t timeStampOffset) const;
DifferentialSample Interpolate(const DifferentialSample& endValue, units::second_t t) const;

units::second_t timestamp = 0_s;
units::meter_t x = 0_m;
Expand All @@ -83,9 +83,9 @@ class DiffySample {
units::newton_t fr = 0_N;
};

void to_json(wpi::json& json, const DiffySample& trajSample);
void from_json(const wpi::json& json, DiffySample& trajSample);
void to_json(wpi::json& json, const DifferentialSample& trajSample);
void from_json(const wpi::json& json, DifferentialSample& trajSample);
} // namespace trajectory
} // namespace choreo

#include "choreo/trajectory/struct/DiffySampleStruct.h"
#include "choreo/trajectory/struct/DifferentialSampleStruct.h"
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

#include <wpi/json_fwd.h>

#include "choreo/trajectory/DiffySample.h"
#include "choreo/trajectory/DifferentialSample.h"
#include "choreo/trajectory/EventMarker.h"
#include "choreo/trajectory/SwerveSample.h"
#include "choreo/trajectory/TrajSample.h"
Expand Down Expand Up @@ -182,7 +182,7 @@ class Trajectory {
void to_json(wpi::json& json, const Trajectory<SwerveSample>& traj);
void from_json(const wpi::json& json, Trajectory<SwerveSample>& traj);

void to_json(wpi::json& json, const Trajectory<DiffySample>& traj);
void from_json(const wpi::json& json, Trajectory<DiffySample>& traj);
void to_json(wpi::json& json, const Trajectory<DifferentialSample>& traj);
void from_json(const wpi::json& json, Trajectory<DifferentialSample>& traj);
} // namespace trajectory
} // namespace choreo
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@
#include <wpi/SymbolExports.h>
#include <wpi/struct/Struct.h>

#include "choreo/trajectory/DiffySample.h"
#include "choreo/trajectory/DifferentialSample.h"

template <>
struct wpi::Struct<choreo::trajectory::DiffySample> {
static constexpr std::string_view GetTypeName() { return "DiffySample"; }
struct wpi::Struct<choreo::trajectory::DifferentialSample> {
static constexpr std::string_view GetTypeName() { return "DifferentialSample"; }
static constexpr size_t GetSize() { return 80; }
static constexpr std::string_view GetSchema() {
return "double timestamp;double x;double y;double heading;double vl;double "
"vr;double al;double ar;double fl;double fr;";
}

static choreo::trajectory::DiffySample Unpack(std::span<const uint8_t> data);
static choreo::trajectory::DifferentialSample Unpack(std::span<const uint8_t> data);
static void Pack(std::span<uint8_t> data,
const choreo::trajectory::DiffySample& value);
const choreo::trajectory::DifferentialSample& value);
};

static_assert(wpi::StructSerializable<choreo::trajectory::DiffySample>);
static_assert(wpi::StructSerializable<choreo::trajectory::DifferentialSample>);

0 comments on commit 62f1c1c

Please sign in to comment.