MAXSwerve Python Template originally from: https://github.com/edubu/MAXSwerve-Python-Template
The python implementation of REV Robotics MAXSwerve Modules as adapted from the REV Robotics CPP Template for use in an environment using RobotPy. Suitable for FIRST Robotics Teams that want to utilize swerve drive and are using Python for their robot code. As Python is now officially supported by FRC as of 2024, a python adaptation is necessary.
Windows is only necessary for programming the CAN IDs using the REV Hardware Client
Follow the FRC Installation Guide for step by step instructions to get the environment setup for python in FRC.
The commands below will download this repository and install all of the necessary packages to your environment which will then be transferred over to the RoboRio
user@user:~$ git clone https://github.com/edubu/MAXSwerve-Python-Template.git
user@user~$ py -3 -m robotpy sync
The SparkMAX require the use of CAN to communicate with the encoders. If seeking guidance wiring with CAN, checkout this guide to help through the process.
After the wiring has been completed, you will need to connected to each SparkMax using the REV Hardware Client
Follow this guide to program the SparkMax controllers to their unique CAN IDs
The swerve drive parameters are located in constants.py and will be used to communicate with the SparkMax controllers and setup the kinematics of the chassis.
constants.py
# SPARK MAX CAN IDs
kFrontLeftDrivingCanId = 2
kRearLeftDrivingCanId = 8
kFrontRightDrivingCanId = 4
kRearRightDrivingCanId = 6
kFrontLeftTurningCanId = 3
kRearLeftTurningCanId = 1
kFrontRightTurningCanId = 5
kRearRightTurningCanId = 7
constants.py
# Chassis configuration
kTrackWidth = 0.6953 # Distance between centers of right and left wheels on robot METERS
kWheelBase = 0.6953 # Distance between centers of front and back wheels on robot METERS
constants.py
# The MaxSwerve module can be configured with one of the three pinion gears: 12T, 13T, or 14T.
# This changes the drive speed of the module ( a pinion gear with more teeth will result in a robot that drives faster)
kDrivingMotorPinionTeeth = 13
No, the NavX gyroscope was simply used because we had it available. You can use any gyro by simply changing the following to connect to your available hardware
# NavX Gyroscope
self.gyro = navx.AHRS(wpilib.SerialPort.Port.kUSB)
# Example Analog Gyroscope
self.gyro = wpilib.AnalogGyro(analogChannel)
In this template, an XboxController class is utilized to control the robot. The axis are predefined to control it and utilize SlewRateLimiters as well as a Deadband to facilitate smooth driving.
REV Robotics MAXSwerve Module
REV Robotics MAXSwerve Docs
REV Robotics MAXSwerve CPP Template
RobotPy Docs