Problem Programming Swerve

Hi, as I have posted before my team decided to build a swerve drive this off-season. (you can find the swerve CAD and specs here)

Due to covid-19 we have only finished building our swerve drive train recently (about two weeks ago). We are now trying to program and have unfortunately run into a problem. No matter what we do the swerve just won’t swerve, It keeps moving just like a tank drive. We have been working on it for the past two weeks to no avail and are getting stressed due to the season starting in less than a month.

A video of the problem: https://youtu.be/wYYAaD-JcoU

We think it’s either PID or mechanical issue but we are not completely convinced that’s the cause.
If you have any idea as to what could cause this problem, please help us solve it!

That is indeed a problem. I’m interpreting this to mean you’re unable to strafe side-to-side?

I could think of a couple root causes, but I think I’d need more info to help narrow it down.

As long as you can move the module by hand to the expected “go-sideways” position. Then, try running your motors with a thrifty throttle or some test code to ensure they all can rotate freely. As long as this is the case, I’d tend to say it’s probably not a mechanical problem.

Can you post code? That would help quite a bit in the analysis.

Additionally, pick one of the modules and plot its desired and actual azimuth angle. Check two things:

  1. When transitioning from fwd/rev motion to side-to-side strafe motion, the desired module angle changes by 90 degrees
  2. The actual module angle follows the desired module angle.

And, one final question, since I can’t quite see from the video - what does happen when you command a strafe side to side on a joystick? does it just not move? or does it rotate?

Hi here is a link for our github repository. swerve repo 5987

Quick early thought, looks like you may need an absolute value sign here:

Looks like joystick values would be capped to be always positive?

Otherwise not seeing anything else immediately problematic, though my ability to read the vector math and guess the results without running is limited.

I see you have some unit tests in place - Do your tests currently pass? especially - if you command strafing in a test, do you get module commands and motion that corresponds with strafing?

1 Like

So, I have watched the video you posted, but can’t really tell from that video what the control inputs are and what the modules are actually doing in response to those control inputs. Some of the motions that are shown wouldn’t be easy to do if the modules were not rotating correctly in response to the command inputs. I can see that the robot does not demonstrate the ability to translate in the strafing directions, but would need more understanding of what the actual control inputs are and the module responses to debug why it is not able to strafe or make other swervy motions.

One of the tests that we always run before we actually put the robot on the floor and drive it is to have the robot laying on its side so that the driver can see the wheels. Then the driver manipulates the controls in various directions to verify that all the modules respond in the correct direction. You can run this in field oriented mode or robot oriented mode since the robot does not move during the test and therefore the gyro heading does not change. Assuming that you have one joystick for translation and one joystick for rotation, you want to test the translation joystick first by moving it through a full circle from forward, through sideways and backward direction and you should see all the modules pointed in the same direction as the joystick is pointed as you move it around. Assuming that is working correctly, then you can test the rotation joystick while leaving the translation joystick centered and you should see all the modules turn perpendicular to the center of the robot. In addition to the module pointing angles you want to verify that the wheel speed and direction of wheel rotation is correct. Once you have run those simple tests, you can exercise both joysticks at the same time and verify that the more complex motions and the various speeds are producing the expects module rotation angles and speeds. Try not to just move the sticks around randomly, but instead move the sticks to produce a particular motion like spinning while translating forward or moving from forward motion to strafing motion to a spin while strafing.

If you can take a video of how the robot is behaving when running this test, it would help to verify that the modules are, in fact, not responding to certain control inputs and which ones. That would be a big help in debugging the root cause here. Having the joysticks in the video or narrating the joystick inputs as you make them would be very helpful as well.

4 Likes

This.

Well said and written. Important step when turning on a swerve for the first time.

2 Likes