Hi, it is our teams first time using java for our swerve drive, we are having some issues and were wondering if anyone could give us some pointers of how to fix it.
Our main issue is that when we enable the robot the setpoints keep changing from something like -45 to -135. Which just causes the wheels to move back and forth. However if we simulate our robot, it works perfectly fine.
Another issue we are having is in the module folder there is a setting called “absoluteEncoderOffset” and we are struggling to find any information on what it is and or what we need to set it to.
Absolute encoder offset from 0 in degrees. May need to be a negative number.
You use it to indicate the position of the magnet in your swerve module encoder. When you first set it up, when the wheels are pointed straight forward (0°) the encoder will not read 0°. You need to read the value of the encoder with the wheel in this position and configure the offset.
For example, if you point the left-front wheel straight forward and the encoder reads 46°, you need to configure an offset of -46° for that module (46° + -46° = 0°).
Get the offsets set up first, it might also solve your main problem. That could be a problem where the code is trying to “optimize” the rotation of the wheel, but it’s confused by the offset.
I have added this to the code, and I amAndyMark still getting the same issue. I now have a Video of it now. Also would I need to change the Offset value every time I start the robot or just for the first time?
the setpoints keep changing from something like -45 to -135.
I checked while it was running the setpoints keep changing from -45 to 135.
You are using a slightly out of date YAGSL library. I don’t know that updating alone would fix the issue but you can try adding swervedrive.pushOffsetsToControllers() it could fix this issue, but it’s only in the newest version of YAGSL
The offsets are a physical characteristic of the robot, so you should only need to set it once unless your module changes. But by asking you are indicating you don’t understand this setting.
You should make sure to set the offsets correctly. You need to have the encoder offset set to zero, align the wheels forward, and read the value. After configuring the offset, you need to confirm that each wheel is reading 0° when it is pointed forward.
Not related to your issue, but I see in your swervedrive.json you have configured your IMU as navx_usb, but in your README you linked the NavX MXP. It’s more likely you have an MXP, you might want to check that.
For magnets we have made sure they are glued correctly. We have been setting the offset value so that is good. And we also updated the YAGSL to the newest version yet the problem is still happening.
Some of the wheels get close to the setpoint of 45 but they don’t stay.
Watching the video, I’m guessing your motor and encoder are not “in phase”. This means the motor and encoder’s inversion are not configured the same.
Here’s a way to troubleshoot:
Put the motor’s encoder on SmartDashboard as well as the CANCoder’s value. If you do this in your subsystem period() method, you can get readings with the robot disabled, so you can safely move the wheels by hand.
Choose a wheel and turn it in the counter-clockwise (left) direction, when viewed from the top.
Both the motor encoder’s value and the CANCoder’s value should get larger. Invert the motor and/or the encoder so the value gets larger when you rotate counter-clockwise.
Here’s more detail on why you would see this behavior when something is out of phase. There is code built in to optimize the direction of the wheel so it never has to rotate more than 90-degrees. For example, consider a scenario where the robot is driving straight forward and you want to switch to backward. A non-optimized way to do this would be to keep the wheel driving in the same direction and spin the steering around 180° to point backwards. An optimized way to do this is to keep the steering pointed forward and drive the wheel in reverse.
This optimization is always looking at where the wheel is now, and where you’re asking it to go, and finding the best option. When the wheel rotates the wrong direction, this optimization keeps flipping between 45° (pointing forward and to the right) and -135°, which are 180° apart. It’s deciding it’s quicker to go the other way and reverse the drive instead of rotating more than 90°.
So I have the encoders so where when I turn them left their value increases, now as for the Motors I am currently struggling to figure out how to add their values to the dashbaord.
You’re using Neo motors with Spark Max controllers, right? A shortcut you could take would be to connect the REV Hardware client and just look at the position value for that motor. For the CANCoder and/or Talon FX controllers, you could use Pheonix Tuner X.
To get it onto the dashboard, you’ll have to go into SparkMaxSwerve and expose the encoder value, maybe with a method like this:
public double getSteerMotorPosition() {
return encoder.getPosition();
}
How could I view the position value in the REV Hardware Client, I have looked around for a bit now and I see somethings that might be it but when I try I am not getting anything for values.