Skip to content

Commit

Permalink
Add dt to SimpleMotorFeedforward serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
KangarooKoala committed Jul 21, 2024
1 parent e7d18a1 commit a812c07
Show file tree
Hide file tree
Showing 11 changed files with 134 additions and 40 deletions.
135 changes: 108 additions & 27 deletions wpimath/src/generated/main/java/edu/wpi/first/math/proto/Controller.java

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ public ProtobufSimpleMotorFeedforward createMessage() {

@Override
public SimpleMotorFeedforward unpack(ProtobufSimpleMotorFeedforward msg) {
return new SimpleMotorFeedforward(msg.getKs(), msg.getKv(), msg.getKa());
return new SimpleMotorFeedforward(msg.getKs(), msg.getKv(), msg.getKa(), msg.getDt());
}

@Override
public void pack(ProtobufSimpleMotorFeedforward msg, SimpleMotorFeedforward value) {
msg.setKs(value.getKs()).setKv(value.getKv()).setKa(value.getKa());
msg.setKs(value.getKs()).setKv(value.getKv()).setKa(value.getKa()).setDt(value.getDt());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,28 @@ public String getTypeString() {

@Override
public int getSize() {
return kSizeDouble * 3;
return kSizeDouble * 4;
}

@Override
public String getSchema() {
return "double ks;double kv;double ka";
return "double ks;double kv;double ka;double dt";
}

@Override
public SimpleMotorFeedforward unpack(ByteBuffer bb) {
double ks = bb.getDouble();
double kv = bb.getDouble();
double ka = bb.getDouble();
return new SimpleMotorFeedforward(ks, kv, ka);
double dt = bb.getDouble();
return new SimpleMotorFeedforward(ks, kv, ka, dt);
}

@Override
public void pack(ByteBuffer bb, SimpleMotorFeedforward value) {
bb.putDouble(value.getKs());
bb.putDouble(value.getKv());
bb.putDouble(value.getKa());
bb.putDouble(value.getDt());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ wpi::Protobuf<frc::SimpleMotorFeedforward<Distance>>::Unpack(
units::unit_t<frc::SimpleMotorFeedforward<units::meters>::kv_unit>{
m->kv()},
units::unit_t<frc::SimpleMotorFeedforward<units::meters>::ka_unit>{
m->ka()}};
m->ka()},
units::second_t{m->dt()}};
}

template <class Distance>
Expand All @@ -40,4 +41,5 @@ void wpi::Protobuf<frc::SimpleMotorFeedforward<Distance>>::Pack(
m->set_ka(units::unit_t<frc::SimpleMotorFeedforward<units::meters>::ka_unit>{
value.GetKa()}
.value());
m->set_dt(units::second_t{value.GetDt()}.value());
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ struct wpi::Struct<frc::SimpleMotorFeedforward<Distance>> {
static constexpr std::string_view GetTypeString() {
return "struct:SimpleMotorFeedforward";
}
static constexpr size_t GetSize() { return 24; }
static constexpr size_t GetSize() { return 32; }
static constexpr std::string_view GetSchema() {
return "double ks;double kv;double ka";
return "double ks;double kv;double ka;double dt";
}

static frc::SimpleMotorFeedforward<Distance> Unpack(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ wpi::Struct<frc::SimpleMotorFeedforward<Distance>>::Unpack(
constexpr size_t kKsOff = 0;
constexpr size_t kKvOff = kKsOff + 8;
constexpr size_t kKaOff = kKvOff + 8;
constexpr size_t kDtOff = kKaOff + 8;
return {units::volt_t{wpi::UnpackStruct<double, kKsOff>(data)},
units::unit_t<frc::SimpleMotorFeedforward<units::meters>::kv_unit>{
wpi::UnpackStruct<double, kKvOff>(data)},
units::unit_t<frc::SimpleMotorFeedforward<units::meters>::ka_unit>{
wpi::UnpackStruct<double, kKaOff>(data)}};
wpi::UnpackStruct<double, kKaOff>(data)},
units::second_t{wpi::UnpackStruct<double, kDtOff>(data)}};
}

template <class Distance>
Expand All @@ -27,6 +29,7 @@ void wpi::Struct<frc::SimpleMotorFeedforward<Distance>>::Pack(
constexpr size_t kKsOff = 0;
constexpr size_t kKvOff = kKsOff + 8;
constexpr size_t kKaOff = kKvOff + 8;
constexpr size_t kDtOff = kKaOff + 8;
wpi::PackStruct<kKsOff>(data, value.GetKs().value());
wpi::PackStruct<kKvOff>(
data,
Expand All @@ -38,4 +41,5 @@ void wpi::Struct<frc::SimpleMotorFeedforward<Distance>>::Pack(
units::unit_t<frc::SimpleMotorFeedforward<units::meters>::ka_unit>{
value.GetKa()}
.value());
wpi::PackStruct<kDtOff>(data, units::second_t{value.GetDt()}.value());
}
1 change: 1 addition & 0 deletions wpimath/src/main/proto/controller.proto
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ message ProtobufSimpleMotorFeedforward {
double ks = 1;
double kv = 2;
double ka = 3;
double dt = 4;
}

message ProtobufDifferentialDriveWheelVoltages {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@
class SimpleMotorFeedforwardProtoTest
extends ProtoTestBase<SimpleMotorFeedforward, ProtobufSimpleMotorFeedforward> {
SimpleMotorFeedforwardProtoTest() {
super(new SimpleMotorFeedforward(0.4, 4.0, 0.7), SimpleMotorFeedforward.proto);
super(new SimpleMotorFeedforward(0.4, 4.0, 0.7, 0.025), SimpleMotorFeedforward.proto);
}

@Override
public void checkEquals(SimpleMotorFeedforward testData, SimpleMotorFeedforward data) {
assertEquals(testData.getKs(), data.getKs());
assertEquals(testData.getKv(), data.getKv());
assertEquals(testData.getKa(), data.getKa());
assertEquals(testData.getDt(), data.getDt());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@
@SuppressWarnings("PMD.TestClassWithoutTestCases")
class SimpleMotorFeedforwardStructTest extends StructTestBase<SimpleMotorFeedforward> {
SimpleMotorFeedforwardStructTest() {
super(new SimpleMotorFeedforward(0.4, 4.0, 0.7), SimpleMotorFeedforward.struct);
super(new SimpleMotorFeedforward(0.4, 4.0, 0.7, 0.025), SimpleMotorFeedforward.struct);
}

@Override
public void checkEquals(SimpleMotorFeedforward testData, SimpleMotorFeedforward data) {
assertEquals(testData.getKs(), data.getKs());
assertEquals(testData.getKv(), data.getKv());
assertEquals(testData.getKa(), data.getKa());
assertEquals(testData.getDt(), data.getDt());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@ struct SimpleMotorFeedforwardProtoTestData {

inline static const Type kTestData = {units::volt_t{0.4},
units::volt_t{4.0} / 1_mps,
units::volt_t{0.7} / 1_mps_sq};
units::volt_t{0.7} / 1_mps_sq, 25_ms};

static void CheckEq(const Type& testData, const Type& data) {
EXPECT_EQ(testData.GetKs().value(), data.GetKs().value());
EXPECT_EQ(testData.GetKv().value(), data.GetKv().value());
EXPECT_EQ(testData.GetKa().value(), data.GetKa().value());
EXPECT_EQ(testData.GetDt().value(), data.GetDt().value());
}
};

Expand Down
Loading

0 comments on commit a812c07

Please sign in to comment.