Swerve Autonomous Field Oriented Reset

3467 is finally getting around to writing autonomous modes that don’t just go in straight lines, and we have an issue where once we transition to teleop, the field-oriented controls aren’t pointed the correct direction.
Here’s the auto in question: https://drive.google.com/file/d/1Ck3jXEszof3UBJRjiqLdVMN3LKN8vdJL/view?usp=sharing

We are using Pathfinder and PPSwerveControllerCommand. Code is located here.

l think you should add a gyro offset.

This post may help you. Field-Oriented Driving Question - Technical / Java - Chief Delphi

I tried doing this in the initialize of the auto code where I config the mount yaw of the pigeon to be that of the offset of path planner but then forward for pathplanner is different and the whole path will be offset. Specifically the issue is the switch from autonomous to teleop where field forward in teleop is the direction we turned the robot on which is against the hub.

Easiest place to fix this is here: https://github.com/WHS-FRC-3467/Skip-5.12/blob/1022fed72c977639085574e18a59a05612a20e44/src/main/java/frc/robot/subsystems/Drive/SwerveDrive.java#L30

If I had to guess, you are using 0 degrees is forward on the field, which is the convention for most WPILib stuff. Now, when you make the joystick go forward, you have x=0 and y=1, which is 90 degrees. So currently forward on your joystick should make the robot go to the right. This means you just have to do some simple math to correct this. We can do new_x=y and new_y=-x, which will make it so that 90 degrees on the joystick gets transformed to be 0 degrees.

So, you can flip the x and y lines then negate the new y line.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.