My team’s been building a swervedrive during the offseason and we’re having trouble figuring out the wheel alignment. We’re able to drive the robot in the robot oriented way perfectly (meaning no on-place rotation, just movement up-down-left-right). The wheels align when we do that.
When we try to make the robot rotate in place, two of the wheels go in one direction, and the other two go in the other. My code is similar to this one:
What can I do to make both swivelling and normal driving work?
Check that all of your modules are in the correct order. The order should match for your kinematics, odometry, and the order you set them. i.e. FL, FR, BL, BR for all. Make sure your order matches the hardware as well, so the CAN IDs for the FL module for example are actually for the physical FL module.
what swerve do you use?
if you are using the mk4i you need to invert the steer motors
Depending on what you mean by this, this might actually be the intended behavior. If you are trying to rotate in place, the wheels should form a diamond shape - ie, your front left and rear right wheel should be oriented like this: / and the other two should be like this: \
So if looking at it from top down, the wheels should look like this:
Then if each wheel is spinning in the “same” direction, it will rotate. “Same” is in quotes here because it’s subtle what this means: for example, the front right wheel should be spinning such that it is delivering force towards the front left, whereas the rear left wheel should be spinning force such that it is delivering forces toward the rear right.
Yes, that’s true. But I know it’s going in the wrong direction because two of the wheel are spinning in a way that stops the rotation of the drivetrain. So you’d have to inverse them to make it work, but then the normal driving doesn’t work.
But then won’t the normal (non spining) driving be wrong because the wheels won’t point in the same direction?
This is what we have for our Mk4i chassis. We first decided which way the wheels would be set at startup, then set the drive directions when driving straight followed by the turn directions when strafing.
public static final boolean kFrontLeftTurningMotorReversed = true;
public static final boolean kBackLeftTurningMotorReversed = true;
public static final boolean kFrontRightTurningMotorReversed = true;
public static final boolean kBackRightTurningMotorReversed = true;
public static final boolean kFrontLeftDriveMotorReversed = false;
public static final boolean kBackLeftDriveMotorReversed = false;
public static final boolean kFrontRightDriveMotorReversed = true;
public static final boolean kBackRightDriveMotorReversed = true;
The code you are using is a code for mk3 if you are using mk4i the motor are upside down so you need to invert them
And if the driving wheel is pointing to the wrong direction just invert them
We wanted all 4 wheels to look “the same” when setting down on the field. This means one side is 180 degrees off from the other, hence the drive inversion on one side. Rotation isn’t affected.
I have a strong suspicion as to what your issue is, then, based on your description of the problem. If everything seems to be pointing in the correct direction and spinning in the correct direction when translating only, but some of them seem to be doing the backwards drive when rotating only, then I suspect that you have two of your modules physically in different corners than what your code is configured for.
Somewhere in your code you will have defined for each module, where it is in relation to your center of rotation. Check to make sure that code matches your physical setup, and be mindful of the positives/negatives in there to make sure they mean what you think they mean.
Each module had it’s own position, but I experimented with the values in the kinematics (either make them positive or negative). Now it works, so thanks!
Worth checking to be sure you are following this: Coordinate Systems — FIRST Robotics Competition documentation.
Strictly speaking, you can deviate from this – provided you do it consistently, or do not use parts of WPILib which rely on these conventions.
The kinematics signs indicate the positions of the modules with the center of the robot on the X 0, Y 0 coordinate and shouldn’t be changed.
The X values are 1/2 the length and Y values half the width of the robot
Front left is X+Y+
Front right is + -
Rear left is - +
Rear right is - -
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.