First year attempting Swerve Drive...Help!

This is my teams first year trying to use swerve drive. We bought the Swerve and Steer modules that AndyMark sells opting for NEO drive motors, PG motors, PG Encoders and MA3 Encoders. I wasn’t sure where to find example code for something at least similar to our configuration. I ultimately ended up using code from the SwerveBot and SwerveControllerCommand example projects and modifying it. After a few days of modifying and reading documentation I would really appreciate the help! I am mainly having issues with the drive encoders but due to my lack of experience I am sure there is bound to be other issues in there I have yet to come across. The problem I am looking to solve is setting the DistancePerPulse on a Relative Encoder. The example code I found creates two instances of the type ‘Encoder’, however, after reading the documentation on our swerve modules the drive encoder must be a RelativeEncoder. The methods that exist for ‘Encoders’ do not exist for the type ‘RelativeEncoders’. Are there any methods inside of the RelativeEncoders type that would set the DistancePerPulse, or is the issue I am running into the fact that they are fundamentally different? I would use the MA3 Encoders that came with our modules, however, they shipped separately and we are waiting on them to arrive.

Here is the link to what I have so far: GitHub - caleb-wells/SwerveBot-Test

2 Likes

First off, congrats on the progress you have made so far! Swerve is a big step forward for any team.

A couple of suggestions for potentially modifying your question so that you might be more likely to get helpful input from the community:

Upload your code to GitHub or a similar VCS provider.

Uploading your code to a online/public version control allows others to easily view your code without having to download and unpack ZIP files. It might seem like a small difference, but the smaller you can make the barrier to entry for people wanting to look at your code, the better. A version control system would also allow others to not only see your code, but to see the history of your code, which can also be very helpful.

There are also innumerable benefits to using version control in the first place, but I won’t cover that here. GitHub is a great place to start though: About Git - GitHub Docs

Give prospective reviewers (helpers) as much information as possible

The more information you can give to the people trying to help you, the better. Currently, your question doesn’t include a lot of information about what exactly is actually going wrong, or what it is you’re having trouble with. Open-ended questions, in general, tend to receive fewer and less helpful answers.

Detailing things like:

  • …what you are specifically trying to accomplish (more specific than ‘I want swerve drive to work’).
  • …what concepts you are struggling to understand.
  • …what specific issues you are encountering in your code, including error messages (and even full stack traces!) if at all possible.

Communicate what you have already done to attempt to fix the problem

This includes what fixes you have attempted in the code, or even what other resources you may have found and looked in to prior to asking your question here. Establishing a baseline for where exactly you are at in the overall progression of problem solving can help minimize the chances that contributors offer solutions that you have already ruled out.

Hopefully, after making some or all of the outlined changes to your question, we can get you and your team where you need to go!

2 Likes

IMHO you should just wait for the MA3 encoders; with them you don’t really need the PG encoder at all.

Thank you for the feedback! I’ve added the GitHub Repository for the project, as well as some more information about the problems I am running into, hopefully that helps!

I also don’t have experience with the AndyMark modules. But, let me see if I can help.

You will need two encoders per swerve module:

The drive encoder will be relative, you can use the built in Neo encoder. This encoder will tell you how far you’ve driven, and how fast your wheels are spinning. After a quick look, your code seems OK, except you have encoder resolution wrong for a Neo, it should be 42.

You will also need a steer encoder so you know the direction of your wheels. You will want this to be an absolute encoder so you know the angle of your wheels when the robot powers up. The only way to use the PG encoder is if you know the starting position of your wheels, as noted on the AndyMark product page: “This encoder can be used to determine the steering angle provided that all the modules start facing forward.” However, you have the PG encoder resolution wrong in your code. I’ve never used it, but I think it is 21 (7 pulses per revolution = 21 counts per revolution).

I’m a mentor for the DiscoBots team.
The team has an SDS Mk4i swerve developed over the summer.
It was a long build process and the testing has been quite a process.
Even with this Swerve testing, the DiscoBots are still uncertain if they will pursue Swerve in 2023.

Swerve takes a long time to build and test. If you haven’t put in this work over the summer.

Jumping into Swerve for 2023 might be too much of a leap.

1 Like

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