Swerve Autonomous Going in the Wrong Direction

Hi. I’m trying out swerve autonomous for off-season. I’m not using pathweaver, and just using the Trajectory class from WPILIB. I’ve noticed 2 issues:

  1. When I want to set it to 1 meter, it goes 4 times (or more) that distance.
  2. When I input an x-coordinate into the trajectory generator, the robot moves in the y direction. When I input a y-coordinate, the robot moves in the -x direction. I honestly have no idea why.
    Below is the autonomous code I use:
    https://github.com/u24ielfen/2022_Offseason/blob/main/src/main/java/frc/robot/RobotContainer.java

Any suggestions?

My initial thought is ur gear ratio is incorrect. For the other issue, I suspect ur gyro is rotated vs what u consider the front and you’ll need to just offset the angle.

What are you considering ‘wrong’ for x and y. Understand that the FRC coordinate system is x+ away from the driver station and y + to the left. Most people expect x+ to be away from the driver station and y+ to be to the right, but the FRC Coordinates are x and y as viewed from the right side of the field not from the driver station perspective.

4 Likes
  1. When I want to set it to 1 meter, it goes 4 times (or more) that distance.

I would check if your kinematic constants are accurate. It could also be the wheel circumference.

1 Like

Make sure X+ is forwards, and Y+ is left as viewing from the driver station. This makes Z+ up and is the standard right hand coordinate axis system assumed.

So, what that means is you should check that the “drive” function of your swerve goes forwards when given a +x value and left when given a +y value. Then make sure your swerve drive kinematics is defined with the module locations in the same coordinate system.

Module positions FL, FR, BL, BR would be the following (assuming center of robot is 0,0)

FL (+,+)
FR (+,-)
BL (-,+)
BR (-,-)

Also, just a heads up because joystick input can get confusing, XboxController analog sticks give their values in a different coordinate axis, we usually fix this by changing those before they are fed into the drivetrain’s “drive” function.

IE on XboxController getLeftY() is actually negative X and getLeftX() is actually negative Y in field coordinates.

1 Like

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