If you have the module sims working, you can use the toTwist2d
method on SwerveDriveKinematics
to convert a set of module positions deltas into a Twist2d
. This includes components for the position deltas in X, Y, and theta based purely on the modules. That method is what SwerveDriveOdometry
uses internally, except it would normally just use the X and Y components since the rotation comes from the gyro. However, you can use the theta value to update a Rotation2d
to track the rotation without a gyro. That rotation can then be passed to the normal odometry or pose estimator object. It would look something like this:
SwerveDriveKinematics kinematics = ...;
SwerveDriveOdometry odometry = ...;
Rotation2d simRotation = new Rotation2d();
periodic() {
SwerveModulePosition[] wheelDeltas = ...;
var twist = kinematics.toTwist2d(wheelDeltas);
simRotation = simRotation.plus(new Rotation2d(twist.dtheta));
odometry.update(simRotation, ...);
}