-
Notifications
You must be signed in to change notification settings - Fork 614
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[wpimath] Add remaining struct and protobuf implementations #5953
[wpimath] Add remaining struct and protobuf implementations #5953
Conversation
I think the right answer where you need to pull the protobuf headers in is to make those .h files that the user has to explicitly pull in if they want that functionality. Compile times are already bad enough. |
Sounds good, though now there's the question of whether or not all of the protobuf headers should be like that for consistency. I could potentially see people getting tripped up over when they need to include the protobuf headers and when they don't, though documentation could help with that. |
Potentially, but we've put in a bunch of work to make sure it's cheap in those other cases. |
Also undos changes to shared/jni/setupBuild.gradle
I decided to remove the declaration includes from the main header files so that it would be a compilation error instead of a linkage error. I don't understanding what's going on with the Windows error or the clang-tidy error. |
Weird that Windows didn't recognize |
Eigen types have a lot of defaulted template arguments. GCC and Clang use those default values for overload resolution, but MSVC usually requires that you list them explicitly, even if that's just a variadic template as a catch-all. Our fmtlib formatter specialization used to do that, but then we started using concepts instead: https://github.com/wpilibsuite/allwpilib/blob/main/wpimath/src/main/native/include/frc/fmt/Eigen.h. |
Thanks for that advice! I don't know how long it would've taken me to figure that out otherwise, though now I need to figure out why it can't find the protobuf method definitions for the templated types when linking. (I did some testing on a separate branch, with this failure, even after making sure to merge the protobuf build fixes) |
It may have to do with DLL export. We don't use the export attribute on template classes because the user is going to be generating their own instantiation anyway, and MSVC doesn't like exporting template classes for some reason. |
I tried removing the export in KangarooKoala@79d01c8 (on the other branch) and the error message stayed the exact same... Curious that the methods it can't find are defined by the protobuf library, even though it is able to find other methods:
|
We've updated the build on main to export all wpimath protobuf symbols (#5957). Is this branch up to date with main? |
The branch I've been testing on should be up to date on main (https://github.com/KangarooKoala/allwpilib/tree/tmp-more-serialization), though I could try updating this one as well if you'd like. |
Merge conflicts are because of the changes to Spline, but I can't implement |
Struct implementations will need updating due to #5992. re: ControlVector, inlining seems like the correct approach. I don’t think anyone will want to directly serialize just the ControlVector. |
The cmake windows build is failing because cmake doesn't have the same export implementation that gradle does to export all symbols in the protobuf implementation files. |
diff --git a/wpimath/CMakeLists.txt b/wpimath/CMakeLists.txt
index a22ffc0b8..b341313a2 100644
--- a/wpimath/CMakeLists.txt
+++ b/wpimath/CMakeLists.txt
@@ -151,9 +151,7 @@ endif()
file(GLOB_RECURSE wpimath_native_src src/main/native/cpp/*.cpp)
list(REMOVE_ITEM wpimath_native_src ${wpimath_jni_src})
-set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS FALSE)
add_library(wpimath ${wpimath_native_src} ${WPIMATH_PROTO_SRCS})
-set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS TRUE)
set_target_properties(wpimath PROPERTIES DEBUG_POSTFIX "d")
set_property(TARGET wpimath PROPERTY FOLDER "libraries")
If the problem is symbol exporting, it looks symbols are explicitly prevented from being exported. This patch might fix that (you might have to do it manually). |
wpimath/src/main/java/edu/wpi/first/math/kinematics/SwerveDriveKinematics.java
Show resolved
Hide resolved
wpimath/src/main/java/edu/wpi/first/math/system/proto/LinearSystemProto.java
Show resolved
Hide resolved
|
||
/** The control vector for the final point in the y dimension. DO NOT MODIFY THIS ARRAY! */ | ||
public final double[] yFinalControlVector; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we make these package-private instead of public? I guess the problem is the struct/protobuf stuff is in a different package, ugh...
// TODO Error | ||
} | ||
if (m->data_size() != Rows * Cols) { | ||
// TODO Error |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think these should just ignore the incoming data if it's incorrectly sized. Either that or throw.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know what ignoring the incoming data looks like, since we have to return a result, so I guess we throw. Should we define a custom exception type to throw or use a standard exception type?
To make life easier, I added |
If we want that, it needs to be a function as well. It might be nice to have for nested use, sure. Agreed it should be a separate PR to do it broadly. |
Reminder so I don't forget- Add period to |
They were transitively included before, but those includes got removed
Now that #6872 has been merged, this should be updated. |
Closes #5888.
Implements struct and protobuf for all of the
wpimath/src/main/proto
classes except for those implemented in #5391 or #5935.Notes:
shared/jni/setupBuilder.gradle
to more precisely fit what's needed. (Specifically, adds protobuf dependencies to JNIShared because that was needed forMatrixd
andVectord
, and removes a protobuf dependency onDev
that doesn't seem necessary (especially considering that there isn't a src dir dependency).SwerveDriveKinematics
,Vector
,Matrix
,LinearSystem
are protobuf-only because of their repeated members.DifferentialDriveFeedforward
to aid recover of the constructor arguments.CubicHermiteSpline
andQuinticHermiteSpline
. I'm not sure what to do about the mutability of the arrays- We could make them private and add a getter that copies them, but that would be computationally expensive.SwerveDriveKinematics
. As the PMD warning indicates, this allows users to mutate the internal array. Like the control vectors for the splines, we could make this getter copy them, but that would be computationally expensive.LinearSystem.getNested()
is implemented correctly- Is there one element for each defined protobuf class or for each different implementation instance?MecanumDriveMotorVoltages
is only in Java, so there are no C++ implementations. Given the discussion in that issue, it might be removed anyways, but it's in this PR for now.ProtoTestBase
andStructTestBase
. The C++ versions are implemented a little oddly- I considered a macro, which would allow adding tests within the same group, but that felt like it would be a little too black-magic-y.