Programming Swerve Drive

Hello Everyone,

We are attempting a swerve drive and could really use some help programming it. We have MA3 Miniature Absolute Magnetic Shaft Encoders on each wheel that measures the angle it has been turned. We need help writing it into the program. We’ve seen a couple of examples using PID logic, and would love to go that rout, but still are not fully understanding exactly what a PID does or how to implement it into our program. If we have four wheels and four encoders, how do we program PID logic for all four? Is it separate for each wheel? Then how does tele-op work?

Any help or tips would by much appreciated! :slight_smile:
Thank you!

what motor controller are you using?

i just programmed my team’s swerve this season

i’ll be glad to help you after work :wink:

I never worked with labview but i guess you only need the logic here

Watch this video.

Download, install, and experiment with this program.

Ether, thank you for the links! I’ve watched the video and downloaded the program. If I follow the steps for finding KVP that were shown in the video, what would the value of KVP in the example shown for a 6-1 PID controller in ModelQ? What should a “sustained and stable oscillation” look like? I’m having trouble defining what is a stable oscillation in ModelQ.

MaGiC_PiKaChU, we are using Talon motor controllers. If you could help us figure out this swerve drive, that would be fantastic! Our biggest problem in trying to figure out how to implement the PID vi supplied by labVIEW. We don’t know what to put in the ports. For example, what do we put in for process variable?

if you are using absolute shaft magnetic encoders you have to get it trough an analog channel(how it’s called in java)

I dont think you can use one PID subsystem for all your wheels, we used Talon SRX controllers so we could use their PID closed loop and put our swerve drive in a regular subsystem. Correct me if i’m wrong, but you have to use 4 subsystems only for wheels rotation

I recommend you control each wheel’s angle individually so they will get to their setpoint no matter what. (each wheel has it’s own PID, so you don’t send all motors the same command that would mess with synchronization with time.)

if you have any questions on that, feel free to send me an email

I assume since you are talking about a swerve drive and you have an encoder on each wheel that you want to steer each wheel independently.

If that is the case, then you will need separate angle controller code for each wheel (PID or whatever).

We’ve managed to get the robot moving without the use of encoders, but as suspected, the wheels do not turn at the same rate when turning due to the different ages of the motor controllers and the wheels initial starting positions. Now we just need to figure out how to implement the encoders to make the wheels turn simultaneously. We are not particularly worried about making the robot make an angled turn or pivot on a wheel at this moment, so I believe it would be alright to use only one PID since two wheels would be set to the setpoint and the other two would be the same but opposite.

I still need help setting up PID in labVIEW. I believe the MA3 uses analog signal, but I don’t know how to set that up in labVIEW.

Thanks for the help! :slight_smile:

Do you have a picture of the code so I could see it?

We still need help programming the encoders. As a clarification, they are 10-bit analog encoders. Any guidance building this code in labVIEW would be great! :slight_smile:

It would help if you would explain what further info you need, beyond what was provided here:

What vi’s to use in labVIEW. Do we use the vi meant for obtaining voltage, or something related to timing?

Ok, so we just need to use the get voltage vi then. What about in the begin vi? Is it going to be an encoder vi or an analog vi that we use?

The programming depends on what it does, not on what it is called. It produces an analog voltage. Treat it the same way you would treat any other analog signal.