Skip to content
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

Merged
merged 50 commits into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
8ad459c
Add remaining struct and protobuf implementations
KangarooKoala Nov 10, 2023
3084032
Fix @param names
KangarooKoala Nov 23, 2023
b94afec
Fix docs (NFC)
KangarooKoala Nov 23, 2023
61b7f6f
Don't include protobuf implementations for template classes
KangarooKoala Nov 23, 2023
9937b34
const -> constexpr in Struct
KangarooKoala Nov 23, 2023
0353dfe
Export DifferentialDriveFeedforwardStruct and SimpleMotorFeedforwardS…
KangarooKoala Nov 24, 2023
957c7b7
Specify all template parameters
KangarooKoala Nov 29, 2023
5b1873d
Merge branch 'main' into more-serialization
KangarooKoala Dec 5, 2023
32fc284
Merge branch 'main' into more-serialization
KangarooKoala Jan 1, 2024
80483b1
Add marker interfaces
KangarooKoala Jan 1, 2024
9141517
Fix formatting
KangarooKoala Jan 1, 2024
de80169
Merge branch 'main' into more-serialization
KangarooKoala Apr 27, 2024
b386a55
Add doc comments to static struct and proto members
KangarooKoala Apr 27, 2024
0f06603
Remove method chaining in protobuf impl for consistency
KangarooKoala Apr 27, 2024
8363047
Use offset constants in C++ struct impls
KangarooKoala Apr 28, 2024
5a2b1d1
Manually export protobuf library symbols for templated classes
KangarooKoala Apr 28, 2024
8e54736
Fix docs errors
KangarooKoala Apr 28, 2024
9c51752
Merge branch 'main' into more-serialization
KangarooKoala May 4, 2024
4d8d655
Add struct serializable static assert
KangarooKoala May 4, 2024
4ccfb6f
Merge branch 'main' into more-serialization
KangarooKoala May 30, 2024
c74fb40
Fix import order
KangarooKoala May 30, 2024
e44caab
Merge branch 'main' into more-serialization
KangarooKoala Jun 8, 2024
89bbfd0
Fix doc comment
KangarooKoala Jun 8, 2024
754d8ff
Fix formatting
KangarooKoala Jun 8, 2024
6c54d97
Merge branch 'main' into more-serialization
KangarooKoala Jul 8, 2024
0468c09
Use wpi::CreateMessage
KangarooKoala Jul 8, 2024
69dfd4f
Only report Matrix proto once in LinearSystemProto.getNested()
KangarooKoala Jul 8, 2024
e448d80
Merge branch 'main' into more-serialization
KangarooKoala Jul 8, 2024
e65dc1d
Remove getNested()
KangarooKoala Jul 8, 2024
006b69c
Remove DLL_EXPORT from templated struct and protobuf definitions
KangarooKoala Jul 9, 2024
c38565c
Add struct implementations for Matrix and Vector
KangarooKoala Jul 9, 2024
cc6df45
Add struct implementations for matrix and vector in Java
KangarooKoala Jul 9, 2024
08bc678
Fix formatting
KangarooKoala Jul 9, 2024
59d9a16
Fix docs
KangarooKoala Jul 9, 2024
42999b9
Fix order of packages in docs
KangarooKoala Jul 10, 2024
af09a74
Add struct implementations for SwerveDriveKinematics
KangarooKoala Jul 11, 2024
c8dfb43
Add struct implementations for LinearSystem
KangarooKoala Jul 13, 2024
c9c1126
Fix usage of namespace {} in .inc files
KangarooKoala Jul 16, 2024
aa6a14c
Merge branch 'main' into more-serialization
KangarooKoala Jul 16, 2024
2cc2818
Fix docs
KangarooKoala Jul 16, 2024
5fa7e8b
Add StructSerializable tags to Matrix, Vector, and LinearSystem
KangarooKoala Jul 16, 2024
dacb18f
Formatting
KangarooKoala Jul 16, 2024
f14a3ae
Stores int's in VectorStruct and LinearSystemStruct
KangarooKoala Jul 16, 2024
e342773
Throw in C++ in case of mismatch between proto type and message
KangarooKoala Jul 16, 2024
0607cfd
Merge branch 'main' into more-serialization
KangarooKoala Jul 17, 2024
d1b955f
Add missing units includes
KangarooKoala Jul 18, 2024
e7d18a1
Merge branch 'main' into more-serialization
KangarooKoala Jul 21, 2024
a812c07
Add dt to SimpleMotorFeedforward serialization
KangarooKoala Jul 21, 2024
557ebb1
Implement nested behavior for C++ structs
KangarooKoala Jul 21, 2024
47b98d9
Merge branch 'main' into more-serialization
KangarooKoala Jul 29, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -221,12 +221,17 @@ task generateJavaDocs(type: Javadoc) {
"-edu.wpi.first.hal.simulation," +
// TODO: ^ Document these, then remove them from the list
"-edu.wpi.first.math.proto," +
"-edu.wpi.first.math.struct," +
"-edu.wpi.first.math.controller.proto," +
"-edu.wpi.first.math.controller.struct," +
"-edu.wpi.first.math.geometry.proto," +
"-edu.wpi.first.math.geometry.struct," +
"-edu.wpi.first.math.kinematics.proto," +
"-edu.wpi.first.math.kinematics.struct," +
"-edu.wpi.first.math.spline.proto," +
"-edu.wpi.first.math.spline.struct," +
"-edu.wpi.first.math.system.proto," +
"-edu.wpi.first.math.system.struct," +
"-edu.wpi.first.math.system.plant.proto," +
"-edu.wpi.first.math.system.plant.struct," +
"-edu.wpi.first.math.trajectory.proto", true)
Expand Down
4 changes: 4 additions & 0 deletions wpimath/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ target_compile_definitions(wpimath PRIVATE WPILIB_EXPORTS SLEIPNIR_EXPORTS)
target_compile_features(wpimath PUBLIC cxx_std_20)
if(MSVC)
target_compile_options(wpimath PUBLIC /utf-8 /bigobj)
target_link_options(
wpimath
PRIVATE /DEF:$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/main/native/exports.def>
)
endif()
wpilib_target_warnings(wpimath)
target_link_libraries(wpimath wpiutil)
Expand Down

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

37 changes: 36 additions & 1 deletion wpimath/src/main/java/edu/wpi/first/math/Matrix.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@

import edu.wpi.first.math.jni.EigenJNI;
import edu.wpi.first.math.numbers.N1;
import edu.wpi.first.math.proto.MatrixProto;
import edu.wpi.first.math.struct.MatrixStruct;
import edu.wpi.first.util.protobuf.Protobuf;
import edu.wpi.first.util.protobuf.ProtobufSerializable;
import edu.wpi.first.util.struct.Struct;
import edu.wpi.first.util.struct.StructSerializable;
import java.util.Objects;
import org.ejml.MatrixDimensionException;
import org.ejml.data.DMatrixRMaj;
Expand All @@ -24,7 +30,8 @@
* @param <R> The number of rows in this matrix.
* @param <C> The number of columns in this matrix.
*/
public class Matrix<R extends Num, C extends Num> {
public class Matrix<R extends Num, C extends Num>
implements ProtobufSerializable, StructSerializable {
/** Storage for underlying EJML matrix. */
protected final SimpleMatrix m_storage;

Expand Down Expand Up @@ -738,4 +745,32 @@ public boolean equals(Object other) {
public int hashCode() {
return Objects.hash(m_storage);
}

/**
* Creates an implementation of the {@link Protobuf} interface for matrices.
*
* @param <R> The number of rows of the matrices this serializer processes.
* @param <C> The number of cols of the matrices this serializer processes.
* @param rows The number of rows of the matrices this serializer processes.
* @param cols The number of cols of the matrices this serializer processes.
* @return The protobuf implementation.
*/
public static <R extends Num, C extends Num> MatrixProto<R, C> getProto(
Nat<R> rows, Nat<C> cols) {
return new MatrixProto<>(rows, cols);
}
KangarooKoala marked this conversation as resolved.
Show resolved Hide resolved

/**
* Creates an implementation of the {@link Struct} interfaces for matrices.
*
* @param <R> The number of rows of the matrices this serializer processes.
* @param <C> The number of cols of the matrices this serializer processes.
* @param rows The number of rows of the matrices this serializer processes.
* @param cols The number of cols of the matrices this serializer processes.
* @return The struct implementation.
*/
public static <R extends Num, C extends Num> MatrixStruct<R, C> getStruct(
Nat<R> rows, Nat<C> cols) {
return new MatrixStruct<>(rows, cols);
}
}
31 changes: 30 additions & 1 deletion wpimath/src/main/java/edu/wpi/first/math/Vector.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@

import edu.wpi.first.math.numbers.N1;
import edu.wpi.first.math.numbers.N3;
import edu.wpi.first.math.proto.VectorProto;
import edu.wpi.first.math.struct.VectorStruct;
import edu.wpi.first.util.protobuf.Protobuf;
import edu.wpi.first.util.protobuf.ProtobufSerializable;
import edu.wpi.first.util.struct.Struct;
import edu.wpi.first.util.struct.StructSerializable;
import java.util.Objects;
import org.ejml.simple.SimpleMatrix;

Expand All @@ -16,7 +22,8 @@
*
* @param <R> The number of rows in this matrix.
*/
public class Vector<R extends Num> extends Matrix<R, N1> {
public class Vector<R extends Num> extends Matrix<R, N1>
implements ProtobufSerializable, StructSerializable {
/**
* Constructs an empty zero vector of the given dimensions.
*
Expand Down Expand Up @@ -151,4 +158,26 @@ public static Vector<N3> cross(Vector<N3> a, Vector<N3> b) {
a.get(2) * b.get(0) - a.get(0) * b.get(2),
a.get(0) * b.get(1) - a.get(1) * b.get(0));
}

/**
* Creates an implementation of the {@link Protobuf} interface for vectors.
*
* @param <R> The number of rows of the vectors this serializer processes.
* @param rows The number of rows of the vectors this serializer processes.
* @return The protobuf implementation.
*/
public static final <R extends Num> VectorProto<R> getProto(Nat<R> rows) {
return new VectorProto<>(rows);
}

/**
* Creates an implementation of the {@link Struct} interface for vectors.
*
* @param <R> The number of rows of the vectors this serializer processes.
* @param rows The number of rows of the vectors this serializer processes.
* @return The struct implementation.
*/
public static final <R extends Num> VectorStruct<R> getStruct(Nat<R> rows) {
return new VectorStruct<>(rows);
}
}
Loading
Loading