Skip to content

Commit

Permalink
Add structured binding support for wpimath objects
Browse files Browse the repository at this point in the history
  • Loading branch information
virtuald committed Dec 29, 2023
1 parent bc0a559 commit b43c0ef
Show file tree
Hide file tree
Showing 21 changed files with 98 additions and 5 deletions.
6 changes: 6 additions & 0 deletions subprojects/robotpy-wpimath/gen/controls/ArmFeedforward.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,9 @@ classes:
MinAchievableVelocity:
MaxAchievableAcceleration:
MinAchievableAcceleration:

extra_includes:
- wpystruct.h

inline_code: |
SetupWPyStruct<frc::ArmFeedforward>(cls_ArmFeedforward);
6 changes: 6 additions & 0 deletions subprojects/robotpy-wpimath/gen/controls/DCMotor.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
---

extra_includes:
- wpystruct.h

classes:
DCMotor:
shared_ptr: true
Expand Down Expand Up @@ -36,3 +39,6 @@ classes:
KrakenX60:
KrakenX60FOC:
NeoVortex:

inline_code: |
SetupWPyStruct<frc::DCMotor>(cls_DCMotor);
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ classes:
left:
right:

extra_includes:
- wpystruct.h

inline_code:
cls_DifferentialDriveWheelVoltages
.def(py::init<units::volt_t, units::volt_t>(),
Expand All @@ -17,4 +20,6 @@ inline_code:
"left=" + std::to_string(self->left()) + ","
"right=" + std::to_string(self->right()) + ")";
})
;
;

SetupWPyStruct<frc::DifferentialDriveWheelVoltages>(cls_DifferentialDriveWheelVoltages);
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,9 @@ classes:
MinAchievableVelocity:
MaxAchievableAcceleration:
MinAchievableAcceleration:

extra_includes:
- wpystruct.h

inline_code: |
SetupWPyStruct<frc::ElevatorFeedforward>(cls_ElevatorFeedforward);
3 changes: 3 additions & 0 deletions subprojects/robotpy-wpimath/gen/geometry/Pose2d.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
extra_includes:
- rpy/geometryToString.h
- wpystruct.h

functions:
to_json:
Expand Down Expand Up @@ -62,3 +63,5 @@ inline_code: |
return self->Y();
})
.def("__repr__", py::overload_cast<const Pose2d&>(&rpy::toString));
SetupWPyStruct<frc::Pose2d>(cls_Pose2d);
3 changes: 3 additions & 0 deletions subprojects/robotpy-wpimath/gen/geometry/Pose3d.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
extra_includes:
- rpy/geometryToString.h
- wpystruct.h

functions:
to_json:
Expand Down Expand Up @@ -53,3 +54,5 @@ inline_code: |
return self->Z();
})
.def("__repr__", py::overload_cast<const Pose3d&>(&rpy::toString));
SetupWPyStruct<frc::Pose3d>(cls_Pose3d);
5 changes: 4 additions & 1 deletion subprojects/robotpy-wpimath/gen/geometry/Quaternion.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
extra_includes:
- rpy/geometryToString.h
- wpystruct.h

functions:
to_json:
Expand Down Expand Up @@ -44,4 +45,6 @@ classes:

inline_code: |
cls_Quaternion
.def("__repr__", py::overload_cast<const Quaternion&>(&rpy::toString));
.def("__repr__", py::overload_cast<const Quaternion&>(&rpy::toString));
SetupWPyStruct<frc::Quaternion>(cls_Quaternion);
3 changes: 3 additions & 0 deletions subprojects/robotpy-wpimath/gen/geometry/Rotation2d.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
extra_includes:
- rpy/geometryToString.h
- wpystruct.h

functions:
to_json:
Expand Down Expand Up @@ -42,3 +43,5 @@ inline_code: |
return std::make_unique<Rotation2d>(value);
}, py::arg("value"))
.def("__repr__", py::overload_cast<const Rotation2d&>(&rpy::toString));
SetupWPyStruct<frc::Rotation2d>(cls_Rotation2d);
5 changes: 4 additions & 1 deletion subprojects/robotpy-wpimath/gen/geometry/Rotation3d.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
extra_includes:
- rpy/geometryToString.h
- wpystruct.h

functions:
to_json:
Expand Down Expand Up @@ -59,4 +60,6 @@ inline_code: |
.def_property_readonly("angle_degrees", [](const Rotation3d * self) -> units::degree_t {
return self->Angle();
})
.def("__repr__", py::overload_cast<const Rotation3d&>(&rpy::toString));
.def("__repr__", py::overload_cast<const Rotation3d&>(&rpy::toString));
SetupWPyStruct<frc::Rotation3d>(cls_Rotation3d);
3 changes: 3 additions & 0 deletions subprojects/robotpy-wpimath/gen/geometry/Transform2d.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
extra_includes:
- frc/geometry/Pose2d.h
- rpy/geometryToString.h
- wpystruct.h

classes:
Transform2d:
Expand Down Expand Up @@ -47,3 +48,5 @@ inline_code: |
})
.def("__repr__", py::overload_cast<const Transform2d&>(&rpy::toString));
;
SetupWPyStruct<frc::Transform2d>(cls_Transform2d);
3 changes: 3 additions & 0 deletions subprojects/robotpy-wpimath/gen/geometry/Transform3d.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
extra_includes:
- rpy/geometryToString.h
- wpystruct.h

functions:
to_json:
Expand Down Expand Up @@ -45,3 +46,5 @@ inline_code: |
return self->Z();
})
.def("__repr__", py::overload_cast<const Transform3d&>(&rpy::toString));
SetupWPyStruct<frc::Transform3d>(cls_Transform3d);
3 changes: 3 additions & 0 deletions subprojects/robotpy-wpimath/gen/geometry/Translation2d.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
extra_includes:
- rpy/geometryToString.h
- wpystruct.h

functions:
to_json:
Expand Down Expand Up @@ -73,3 +74,5 @@ inline_code: |
}
})
.def("__repr__", py::overload_cast<const Translation2d&>(&rpy::toString));
SetupWPyStruct<frc::Translation2d>(cls_Translation2d);
3 changes: 3 additions & 0 deletions subprojects/robotpy-wpimath/gen/geometry/Translation3d.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
extra_includes:
- rpy/geometryToString.h
- wpystruct.h

functions:
to_json:
Expand Down Expand Up @@ -71,3 +72,5 @@ inline_code: |
}
})
.def("__repr__", py::overload_cast<const Translation3d&>(&rpy::toString));
SetupWPyStruct<frc::Translation3d>(cls_Translation3d);
5 changes: 5 additions & 0 deletions subprojects/robotpy-wpimath/gen/geometry/Twist2d.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
---

extra_includes:
- wpystruct.h

classes:
Twist2d:
force_no_default_constructor: true
Expand Down Expand Up @@ -53,3 +56,5 @@ inline_code: |
"dtheta=" + std::to_string(tw.dtheta()) + ")";
})
;
SetupWPyStruct<frc::Twist2d>(cls_Twist2d);
5 changes: 5 additions & 0 deletions subprojects/robotpy-wpimath/gen/kinematics/ChassisSpeeds.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
---

extra_includes:
- wpystruct.h

classes:
ChassisSpeeds:
force_no_default_constructor: true
Expand Down Expand Up @@ -71,3 +74,5 @@ inline_code: |
"omega=" + std::to_string(cs.omega()) + ")";
})
;
SetupWPyStruct<frc::ChassisSpeeds>(cls_ChassisSpeeds);
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
---

extra_includes:
- wpystruct.h

classes:
DifferentialDriveKinematics:
attributes:
Expand All @@ -9,3 +12,6 @@ classes:
ToChassisSpeeds:
ToWheelSpeeds:
ToTwist2d:

inline_code: |
SetupWPyStruct<frc::DifferentialDriveKinematics>(cls_DifferentialDriveKinematics);
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
---

extra_includes:
- wpystruct.h

classes:
DifferentialDriveWheelSpeeds:
force_no_default_constructor: true
Expand Down Expand Up @@ -50,3 +53,5 @@ inline_code: |
})
;
SetupWPyStruct<frc::DifferentialDriveWheelSpeeds>(cls_DifferentialDriveWheelSpeeds);
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
---

extra_includes:
- wpystruct.h

classes:
MecanumDriveKinematics:
methods:
Expand Down Expand Up @@ -37,3 +40,6 @@ classes:
GetFrontRightWheel:
GetRearLeftWheel:
GetRearRightWheel:

inline_code: |
SetupWPyStruct<frc::MecanumDriveKinematics>(cls_MecanumDriveKinematics);
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
---

extra_includes:
- wpystruct.h

classes:
MecanumDriveWheelSpeeds:
force_no_default_constructor: true
Expand Down Expand Up @@ -77,4 +80,6 @@ inline_code: |
"rearLeft=" + std::to_string(ms.rearLeft()) + ", "
"rearRight=" + std::to_string(ms.rearRight()) + ")";
})
;
;
SetupWPyStruct<frc::MecanumDriveWheelSpeeds>(cls_MecanumDriveWheelSpeeds);
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
---

extra_includes:
- wpystruct.h

classes:
SwerveModulePosition:
force_no_default_constructor: true
Expand Down Expand Up @@ -27,4 +30,7 @@ classes:
.def("__repr__", [](const SwerveModulePosition &ss) -> std::string {
return "SwerveModulePosition(distance=" + std::to_string(ss.distance()) + ", "
"angle=" + std::to_string(ss.angle.Radians()()) + ")";
})
})
inline_code: |
SetupWPyStruct<frc::SwerveModulePosition>(cls_SwerveModulePosition);
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
---

extra_includes:
- wpystruct.h

classes:
SwerveModuleState:
force_no_default_constructor: true
Expand Down Expand Up @@ -32,3 +35,5 @@ inline_code: |
"angle=" + std::to_string(ss.angle.Radians()()) + ")";
})
;
SetupWPyStruct<frc::SwerveModuleState>(cls_SwerveModuleState);

0 comments on commit b43c0ef

Please sign in to comment.