Help starting up swerve

Hello. I am trying to create a working swerve drive code for my swerve drive bot. I am using this example from WPILib as a base. https://github.com/wpilibsuite/allwpilib/tree/main/wpilibcExamples/src/main/cpp/examples/SwerveControllerCommand
I have changed some things like changing the motors to frc::Talon in SwerveModule.h
I am using Talon SRX motorcontrollers and each one has a Talon SRX Breakout board on it
I don’t know how to find the values for Constants.h line 65-73
I don’t know how to find what ports are the correct ports for all of the CAN stuff
Each wheel has two motors (drive and turn), both having an encoder for speed and position, and a completely seperate encoder (not in a motor) for angle.
Each motor has its own motor controller (8 total)
The drive motors are am-0255 and the turning motors are andymark gear motor am-3651 gear box PG-26.9K shaft 0.375 Motor RS-775
there is a ADXRS450 gyro on it
I updated all of the motors using phoenix tuner x to talonsrx 22.1 2023
We are using CAN for all of this
if anyone can look at my code and tell me how to make it actually work, it would be so appreciated.
I can either use a 3 axis joystick, 2 axis joystick, or xbox controller.

You answered this question yourself sort of

You can do this by

And selecting one TalonSRX at a time. There is an option to blink the LEDs on the motor controllers, this also applies to PDP, PCM and the other CTRE can devices. It will be a rapid blink and obviously different from the standard on blink they normally do. When you find the ID number (if they all updated they have unique IDs which is good), label the MC with the ID number even if it’s just duct tape and a sharpie for now.

I’m not an expert on swerve code so I will leave that to others.

Swerve is a large project and it’s best to start with getting basics like controller input, then controlling one module, then moving onto all 4 in manual mode, then implement the Gyro for field oriented controls. Take it in steps instead of one large project.

It sounds like you have plenty of hardware, but haven’t run code for any of the individual parts. Maybe start with sample code for just reading the joystick, then the ADS gyro which will be different than many teams using Pigeon IMU. Then move onto motor control and calibration.

WpiLib documentation has a good list of links for CTRE devices and documents here Third-Party CAN Devices — FIRST Robotics Competition documentation including guides for the TalonSRX motor controllers which should have the same CAN id information and more about how to use the breakout board.

No expert here, but one resource that helped me understand how swerve drive works as well as some simple example code to get it to work was the “0 to Autonomous” series of videos created by 6814. Unfortunately the examples are in Java and I see you are writing in C++, but the ideas are the same. The first half of #6 Swerve Drive Auto will be helpful. Good luck!

1 Like

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