Hello,
We are having an issue with our Swerve code. When we enable Teleop, the motors move on their own. In RobotContainer.cpp and DriveSubsystem.cpp, it shows that it should be only move the motors when a joystick is going, but when i unplug the joystick or make sure it is all 0.00, it still moves the motors. The motors are both turning the swerve&steer turning motors and running the drive motors. The motors still react to the joystick like they should, but they shouldn’t be moving on their own. Our motor controllers are all wired with CAN into the rio, and all of our encoders are plugged into the rio directly. Our code The WPILib Example we used
One theory I have is maybe the AutoConstants in constants.h and also the DriveConstants values ks, kv, ka, kPFrontLeftVel, kPRearLeftVel, kPFrontRightVel, kPRearRightVel.
Thank you very much as we are tight on time to get swerve working for our drivers to get practicing.
Check the value of the velocity of the driving motors. Make sure that when they are expected to be positive, they are positive and vice versa.
Edit:
If the issue is that the speed of the modules oscillates, consider adding a SimpleMotorFeedForward.
Hello, thanks for the response. Here is a video of the check, I was only able to do a check of the MotorOutputVoltage, MotorOutputPercent, and OutputCurrent (which is in amps)
When I move the joystick the bot still reacts like it should but the motors keep moving on their own. I have updated the code too so that the joystick is multiplied by a number defined in Constants.h, but the issue still happens.
I am unsure how to implement the SimpleMotorFeedForward into my code and am unsure how it would help me.
For the simple motor feedforward implementation, consider taking a look at this WPILib example project(swerve in timed robot), that has it implemented. It would help if you could also include a video of the swerve itself so I can see what it is actually doing, it’s a bit hard to infer from the dashboard.
To see more about velocity control with feedforward, take a look at this flywheel simulation, and this article about combining the PID and FF.
Edit:
Also, consider putting the encoder readings onto the dashboard, those are very important to PID control.
Hello, thanks for your response, we made a new branch on our code for the example you provided with PID, and it makes the problem a little less. the X axis does not make the wheels spin like before, but the Y axis is much slower and still causes the wheels to spin. The Z axis also has some issues. I added the encoder readings into the smartdashboard and here is a video if it, sorry about the things not being organized like before. Here is a video of the actual wheels when I am moving the joystick (both of these were recorded at the same time).
We really appreciate your support as we are short on time. If you know how to fix this it would be awesome or if you can help us find other examples that might work too that would help.
Based on your code and your encoder readings, here’s what it looks like the issue may be:
- The number you are putting on the dashboard for the module angle reading is different from what you use in your calculations(you use
.Get()
for your dashboard and.GetDistance()
for your swerve modules). - Make sure the value you are reading from your module rotation encoder is in radians when you do your PID calculations. (It appears to be degrees)
- Make sure the drive encoder has it’s output converted to M/S for the driving PID calculation(It appears to be in an abitrary unit).
It is very important that the units from these encoders match the units for the PID controllers or they will give you an unexpected output.
Hello, thanks for your reply, and sorry for the late reply
We decided that since 3 of the encoders are broken we will just work on other code for the time being, but now we are going to have the encoders working soon.
To address your findings individually:
- We have since changed it to .GetDistance(), thank you.
2 and 3. I am unsure how to convert it into the correct unit… If you could help me I would greatly appreciate it.
Thanks so much as you have helped us greatly so far.
That really depends on your encoder. For the M/S part of things, you need to first figure out what the encoder outputs natively (it may be rotations per second, per minute, or anything else). This then needs to be adjusted accordingly to rotations per second, then multiplied by the gear ratio( 1/6.75 for the MK4I L2 ratio for example), and then multiplied by the circumfrence of the wheel in meters. The angle of the module can be done much in the same way, except for position instead of speed.
Hello,
The GetDistance() uses meter_t for DriveEncoder and radian_t for
TurningEncoder (SwerveModule.cpp line 45)
And we use GetPosition() (which uses GetDistance()) in Drivetrain.h line 61.
The Drive command uses meters_per_second_t for xSpeed and ySpeed, and uses radians_per_second_t for zSpeed (rot). (Drivetrain.h line 26)
For the part about encoder output * circumfrence of wheel in meters, where do we do this? We set the wheel diameter and radius (they are correct values)
Diameter is in Constants.h line 127, and Radius is in SwerveModule.h line 41
I would like to say that I am unsure if our ks, kv, ka, kPFrontLeftVel, kPRearLeftVel, kPFrontRightVel, kPRearRightVel, kMaxSpeed, kMaxAcceleration, kMaxAngularSpeed, and kMaxAngularAcceleration are correct (all set in Constants.h), and if the distanceperpulse stuff is correct.
We know that the encoder diameter, radius, and CPR are correct but are unsure about the things listed above and the encoderresolution.
Also, I am wondering if I should do fieldrelative true or false.
Also, I am wondering if I should update odometry in teleopperioidic like it is in autonomousperiodic
Thanks
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.