I was looking into learning how to program field oriented swerve drive in Java. Does anybody know any good examples that are in Java command based.
We did this this year. Link is https://github.com/SaintsRobotics/frc2020
We did this on the periodic method of our swerve drivetrain subsystem
Have you programed robot relative swerve yet?
If so you just need to add this statement, with the appropriate variables plugged in.
if (_isFieldRelative) {
swerveModuleStates = _kinematics.toSwerveModuleStates(
ChassisSpeeds.fromFieldRelativeSpeeds(_x, _y, _theta, new Rotation2d(2 * Math.PI
- Math.toRadians(((m_gyro.getAngle() % 360) + 360) % 360))));
Thanks this is really helpfull but do you know anyother good examples that are in command base
WPILib has examples projects for both non-command based (swervebot) and command-based with the trajectory tracking with swervecontrollercommand.
While both intend to show more of a general way of getting it working that a full robot example, both can be useful. You can either get them with the project creation tool or at
swervebot and swervecontrollercommand respectively.
Edit: Also if you already have a working not FoD swerve and are using WPILib’s kinematics you can see in the examples its as easy as doing ChassisSpeeds.fromFieldRelativeSpeeds(xSpeed, ySpeed, rot, getAngle())
instead of a new ChassisSpeeds(xSpeed, ySpeed, rot)
, you can also just use that to get the xSpeed, ySpeed, and rotation from the field relative chassis speeds
Thanks this is all very helpful
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.