2023-02-13 17:21:24 -06:00
|
|
|
package swervelib.parser.json;
|
2023-02-13 14:37:05 -06:00
|
|
|
|
2024-02-12 18:59:40 -06:00
|
|
|
import static swervelib.telemetry.SwerveDriveTelemetry.canIdWarning;
|
|
|
|
|
import static swervelib.telemetry.SwerveDriveTelemetry.i2cLockupWarning;
|
|
|
|
|
import static swervelib.telemetry.SwerveDriveTelemetry.serialCommsIssueWarning;
|
|
|
|
|
|
2024-12-09 23:26:04 +00:00
|
|
|
import com.ctre.phoenix.motorcontrol.FeedbackDevice;
|
|
|
|
|
import com.studica.frc.AHRS.NavXComType;
|
|
|
|
|
import edu.wpi.first.math.system.plant.DCMotor;
|
2023-09-01 00:21:16 -05:00
|
|
|
import edu.wpi.first.wpilibj.DriverStation;
|
2023-02-21 22:38:14 -06:00
|
|
|
import swervelib.encoders.AnalogAbsoluteEncoderSwerve;
|
2023-02-13 17:21:24 -06:00
|
|
|
import swervelib.encoders.CANCoderSwerve;
|
2024-09-03 14:46:24 -05:00
|
|
|
import swervelib.encoders.CanAndMagSwerve;
|
2025-02-22 06:15:56 +00:00
|
|
|
import swervelib.encoders.DIODutyCycleEncoderSwerve;
|
|
|
|
|
import swervelib.encoders.SparkFlexEncoderSwerve;
|
2023-12-05 16:25:42 -06:00
|
|
|
import swervelib.encoders.SparkMaxAnalogEncoderSwerve;
|
2023-02-13 17:21:24 -06:00
|
|
|
import swervelib.encoders.SparkMaxEncoderSwerve;
|
|
|
|
|
import swervelib.encoders.SwerveAbsoluteEncoder;
|
2024-12-09 23:26:04 +00:00
|
|
|
import swervelib.encoders.TalonSRXEncoderSwerve;
|
2025-01-06 15:44:15 +00:00
|
|
|
import swervelib.encoders.ThriftyNovaEncoderSwerve;
|
2023-02-15 22:18:27 -06:00
|
|
|
import swervelib.imu.ADIS16448Swerve;
|
|
|
|
|
import swervelib.imu.ADIS16470Swerve;
|
|
|
|
|
import swervelib.imu.ADXRS450Swerve;
|
|
|
|
|
import swervelib.imu.AnalogGyroSwerve;
|
2024-10-20 09:14:32 -05:00
|
|
|
import swervelib.imu.CanandgyroSwerve;
|
2023-02-13 17:21:24 -06:00
|
|
|
import swervelib.imu.NavXSwerve;
|
|
|
|
|
import swervelib.imu.Pigeon2Swerve;
|
|
|
|
|
import swervelib.imu.PigeonSwerve;
|
2025-02-22 06:15:56 +00:00
|
|
|
import swervelib.imu.PigeonViaTalonSRXSwerve;
|
2023-02-13 17:21:24 -06:00
|
|
|
import swervelib.imu.SwerveIMU;
|
2024-01-15 14:37:13 -06:00
|
|
|
import swervelib.motors.SparkFlexSwerve;
|
2023-02-24 19:11:05 -06:00
|
|
|
import swervelib.motors.SparkMaxBrushedMotorSwerve;
|
2024-12-09 23:26:04 +00:00
|
|
|
import swervelib.motors.SparkMaxBrushedMotorSwerve.Type;
|
2023-02-13 17:21:24 -06:00
|
|
|
import swervelib.motors.SparkMaxSwerve;
|
|
|
|
|
import swervelib.motors.SwerveMotor;
|
2025-02-22 06:15:56 +00:00
|
|
|
import swervelib.motors.TalonFXSSwerve;
|
2023-02-13 17:21:24 -06:00
|
|
|
import swervelib.motors.TalonFXSwerve;
|
|
|
|
|
import swervelib.motors.TalonSRXSwerve;
|
2025-01-06 15:44:15 +00:00
|
|
|
import swervelib.motors.ThriftyNovaSwerve;
|
2023-02-13 14:37:05 -06:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Device JSON parsed class. Used to access the JSON data.
|
|
|
|
|
*/
|
|
|
|
|
public class DeviceJson
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The device type, e.g. pigeon/pigeon2/sparkmax/talonfx/navx
|
|
|
|
|
*/
|
2024-02-12 18:59:40 -06:00
|
|
|
public String type;
|
2023-02-13 14:37:05 -06:00
|
|
|
/**
|
|
|
|
|
* The CAN ID or pin ID of the device.
|
|
|
|
|
*/
|
2024-02-12 18:59:40 -06:00
|
|
|
public int id;
|
2023-02-13 14:37:05 -06:00
|
|
|
/**
|
|
|
|
|
* The CAN bus name which the device resides on if using CAN.
|
|
|
|
|
*/
|
2024-02-12 18:59:40 -06:00
|
|
|
public String canbus = "";
|
2023-02-13 14:37:05 -06:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Create a {@link SwerveAbsoluteEncoder} from the current configuration.
|
|
|
|
|
*
|
2023-08-09 13:15:02 -05:00
|
|
|
* @param motor {@link SwerveMotor} of which attached encoders will be created from, only used when the type is
|
|
|
|
|
* "attached" or "canandencoder".
|
2023-02-13 14:37:05 -06:00
|
|
|
* @return {@link SwerveAbsoluteEncoder} given.
|
|
|
|
|
*/
|
2023-08-09 13:15:02 -05:00
|
|
|
public SwerveAbsoluteEncoder createEncoder(SwerveMotor motor)
|
2023-02-13 14:37:05 -06:00
|
|
|
{
|
2023-11-09 20:53:40 -06:00
|
|
|
if (id > 40)
|
|
|
|
|
{
|
2024-01-17 09:17:39 -06:00
|
|
|
canIdWarning.set(true);
|
2023-11-09 20:53:40 -06:00
|
|
|
}
|
2023-02-13 14:37:05 -06:00
|
|
|
switch (type)
|
|
|
|
|
{
|
2023-02-16 21:21:26 -06:00
|
|
|
case "none":
|
2023-12-05 16:25:42 -06:00
|
|
|
return null;
|
2023-02-13 14:37:05 -06:00
|
|
|
case "integrated":
|
|
|
|
|
case "attached":
|
2024-09-03 14:46:24 -05:00
|
|
|
case "canandmag":
|
2023-08-09 13:15:02 -05:00
|
|
|
case "canandcoder":
|
2023-08-09 15:05:33 -05:00
|
|
|
return new SparkMaxEncoderSwerve(motor, 360);
|
2024-08-24 17:48:05 -05:00
|
|
|
case "sparkmax_analog":
|
|
|
|
|
return new SparkMaxAnalogEncoderSwerve(motor, 3.3);
|
2024-10-14 13:22:11 -05:00
|
|
|
case "sparkmax_analog5v":
|
|
|
|
|
return new SparkMaxAnalogEncoderSwerve(motor, 5);
|
2025-02-22 06:15:56 +00:00
|
|
|
case "sparkflex_integrated":
|
|
|
|
|
case "sparkflex_attached":
|
|
|
|
|
case "sparkflex_canandmag":
|
|
|
|
|
case "sparkflex_canandcoder":
|
|
|
|
|
return new SparkFlexEncoderSwerve(motor, 360);
|
2023-08-09 15:05:33 -05:00
|
|
|
case "canandcoder_can":
|
2024-09-03 14:46:24 -05:00
|
|
|
case "canandmag_can":
|
|
|
|
|
return new CanAndMagSwerve(id);
|
2023-09-01 00:21:16 -05:00
|
|
|
case "ctre_mag":
|
|
|
|
|
case "rev_hex":
|
2023-11-29 16:48:33 -06:00
|
|
|
case "throughbore":
|
2023-09-01 00:21:16 -05:00
|
|
|
case "am_mag":
|
|
|
|
|
case "dutycycle":
|
2025-02-22 06:15:56 +00:00
|
|
|
return new DIODutyCycleEncoderSwerve(id);
|
2023-02-21 22:38:14 -06:00
|
|
|
case "thrifty":
|
2024-01-18 10:43:29 -06:00
|
|
|
case "ma3":
|
2023-02-21 22:38:14 -06:00
|
|
|
case "analog":
|
|
|
|
|
return new AnalogAbsoluteEncoderSwerve(id);
|
2023-02-13 14:37:05 -06:00
|
|
|
case "cancoder":
|
|
|
|
|
return new CANCoderSwerve(id, canbus != null ? canbus : "");
|
2025-02-22 06:15:56 +00:00
|
|
|
case "srxmag_standalone":
|
|
|
|
|
return new TalonSRXEncoderSwerve(new TalonSRXSwerve(id, false, DCMotor.getCIM(1)),
|
|
|
|
|
FeedbackDevice.PulseWidthEncodedPosition);
|
2024-12-09 23:26:04 +00:00
|
|
|
case "talonsrx_pwm":
|
|
|
|
|
return new TalonSRXEncoderSwerve(motor, FeedbackDevice.PulseWidthEncodedPosition);
|
|
|
|
|
case "talonsrx_analog":
|
|
|
|
|
return new TalonSRXEncoderSwerve(motor, FeedbackDevice.Analog);
|
2025-01-06 15:44:15 +00:00
|
|
|
case "thrifty_nova":
|
|
|
|
|
return new ThriftyNovaEncoderSwerve(motor);
|
2023-02-13 14:37:05 -06:00
|
|
|
default:
|
|
|
|
|
throw new RuntimeException(type + " is not a recognized absolute encoder type.");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Create a {@link SwerveIMU} from the given configuration.
|
|
|
|
|
*
|
|
|
|
|
* @return {@link SwerveIMU} given.
|
|
|
|
|
*/
|
|
|
|
|
public SwerveIMU createIMU()
|
|
|
|
|
{
|
2023-11-09 20:53:40 -06:00
|
|
|
if (id > 40)
|
|
|
|
|
{
|
2024-01-17 09:17:39 -06:00
|
|
|
canIdWarning.set(true);
|
2023-11-09 20:53:40 -06:00
|
|
|
}
|
2023-02-13 14:37:05 -06:00
|
|
|
switch (type)
|
|
|
|
|
{
|
2023-02-15 22:18:27 -06:00
|
|
|
case "adis16448":
|
|
|
|
|
return new ADIS16448Swerve();
|
|
|
|
|
case "adis16470":
|
|
|
|
|
return new ADIS16470Swerve();
|
|
|
|
|
case "adxrs450":
|
|
|
|
|
return new ADXRS450Swerve();
|
|
|
|
|
case "analog":
|
|
|
|
|
return new AnalogGyroSwerve(id);
|
2024-10-20 09:14:32 -05:00
|
|
|
case "canandgyro":
|
|
|
|
|
return new CanandgyroSwerve(id);
|
2023-11-29 16:48:33 -06:00
|
|
|
case "navx":
|
2023-09-01 00:21:16 -05:00
|
|
|
case "navx_spi":
|
2024-12-09 23:26:04 +00:00
|
|
|
return new NavXSwerve(NavXComType.kMXP_SPI);
|
2023-09-01 00:21:16 -05:00
|
|
|
case "navx_i2c":
|
|
|
|
|
DriverStation.reportWarning(
|
|
|
|
|
"WARNING: There exists an I2C lockup issue on the roboRIO that could occur, more information here: " +
|
|
|
|
|
"\nhttps://docs.wpilib.org/en/stable/docs/yearly-overview/known-issues" +
|
|
|
|
|
".html#onboard-i2c-causing-system-lockups",
|
|
|
|
|
false);
|
2024-01-17 09:17:39 -06:00
|
|
|
i2cLockupWarning.set(true);
|
2024-12-09 23:26:04 +00:00
|
|
|
return new NavXSwerve(NavXComType.kI2C);
|
2023-02-22 23:10:57 -06:00
|
|
|
case "navx_usb":
|
2024-01-22 17:27:37 -06:00
|
|
|
DriverStation.reportWarning("WARNING: There is issues when using USB camera's and the NavX like this!\n" +
|
|
|
|
|
"https://pdocs.kauailabs.com/navx-mxp/guidance/selecting-an-interface/", false);
|
|
|
|
|
serialCommsIssueWarning.set(true);
|
2024-12-09 23:26:04 +00:00
|
|
|
return new NavXSwerve(NavXComType.kUSB1);
|
2024-01-22 15:11:18 -06:00
|
|
|
case "navx_mxp_serial":
|
2024-01-22 17:27:37 -06:00
|
|
|
serialCommsIssueWarning.set(true);
|
2024-12-09 23:26:04 +00:00
|
|
|
return new NavXSwerve(NavXComType.kMXP_UART);
|
2023-02-13 14:37:05 -06:00
|
|
|
case "pigeon":
|
|
|
|
|
return new PigeonSwerve(id);
|
2025-02-22 06:15:56 +00:00
|
|
|
case "pigeon_via_talonsrx":
|
|
|
|
|
return new PigeonViaTalonSRXSwerve(id);
|
2023-02-13 14:37:05 -06:00
|
|
|
case "pigeon2":
|
|
|
|
|
return new Pigeon2Swerve(id, canbus != null ? canbus : "");
|
|
|
|
|
default:
|
2023-12-12 10:48:54 -06:00
|
|
|
throw new RuntimeException(type + " is not a recognized imu/gyroscope type.");
|
2023-02-13 14:37:05 -06:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Create a {@link SwerveMotor} from the given configuration.
|
|
|
|
|
*
|
|
|
|
|
* @param isDriveMotor If the motor being generated is a drive motor.
|
|
|
|
|
* @return {@link SwerveMotor} given.
|
|
|
|
|
*/
|
|
|
|
|
public SwerveMotor createMotor(boolean isDriveMotor)
|
|
|
|
|
{
|
2023-11-09 20:53:40 -06:00
|
|
|
if (id > 40)
|
|
|
|
|
{
|
2024-01-17 09:17:39 -06:00
|
|
|
canIdWarning.set(true);
|
2023-11-09 20:53:40 -06:00
|
|
|
}
|
2023-02-13 17:21:24 -06:00
|
|
|
switch (type)
|
2023-02-13 14:37:05 -06:00
|
|
|
{
|
2025-02-22 06:15:56 +00:00
|
|
|
case "talonfxs_neo":
|
|
|
|
|
return new TalonFXSSwerve(id, canbus != null ? canbus : "", isDriveMotor, DCMotor.getNEO(1));
|
|
|
|
|
case "talonfxs_neo550":
|
|
|
|
|
return new TalonFXSSwerve(id, canbus != null ? canbus : "", isDriveMotor, DCMotor.getNeo550(1));
|
|
|
|
|
case "talonfxs_vortex":
|
|
|
|
|
return new TalonFXSSwerve(id, canbus != null ? canbus : "", isDriveMotor, DCMotor.getNeoVortex(1));
|
|
|
|
|
case "talonfxs_minion":
|
|
|
|
|
throw new UnsupportedOperationException("Cannot create minion combination yet"); //new TalonFXSSwerve(id, canbus != null ? canbus : "", isDriveMotor, DCMotor.getNeoVortex(1));
|
2024-12-09 23:26:04 +00:00
|
|
|
case "sparkmax_neo":
|
|
|
|
|
case "neo":
|
|
|
|
|
case "sparkmax":
|
|
|
|
|
return new SparkMaxSwerve(id, isDriveMotor, DCMotor.getNEO(1));
|
2025-02-22 06:15:56 +00:00
|
|
|
case "sparkmax_vortex":
|
|
|
|
|
return new SparkMaxSwerve(id, isDriveMotor, DCMotor.getNeoVortex(1));
|
|
|
|
|
case "sparkmax_minion":
|
|
|
|
|
throw new UnsupportedOperationException("Cannot create minion combination yet");
|
2024-12-09 23:26:04 +00:00
|
|
|
case "sparkmax_neo550":
|
|
|
|
|
case "neo550":
|
|
|
|
|
return new SparkMaxSwerve(id, isDriveMotor, DCMotor.getNeo550(1));
|
|
|
|
|
case "sparkflex_vortex":
|
|
|
|
|
case "vortex":
|
|
|
|
|
case "sparkflex":
|
|
|
|
|
return new SparkFlexSwerve(id, isDriveMotor, DCMotor.getNeoVortex(1));
|
|
|
|
|
case "sparkflex_neo":
|
|
|
|
|
return new SparkFlexSwerve(id, isDriveMotor, DCMotor.getNEO(1));
|
|
|
|
|
case "sparkflex_neo550":
|
|
|
|
|
return new SparkFlexSwerve(id, isDriveMotor, DCMotor.getNeo550(1));
|
2025-02-22 06:15:56 +00:00
|
|
|
case "sparkflex_minion":
|
|
|
|
|
throw new UnsupportedOperationException("Cannot create minion combination yet");
|
2024-12-09 23:26:04 +00:00
|
|
|
case "falcon500":
|
|
|
|
|
case "falcon":
|
|
|
|
|
return new TalonFXSwerve(id, canbus != null ? canbus : "", isDriveMotor, DCMotor.getFalcon500(1));
|
|
|
|
|
case "falcon500foc":
|
|
|
|
|
return new TalonFXSwerve(id, canbus != null ? canbus : "", isDriveMotor, DCMotor.getFalcon500Foc(1));
|
|
|
|
|
case "krakenx60":
|
|
|
|
|
case "talonfx":
|
|
|
|
|
return new TalonFXSwerve(id, canbus != null ? canbus : "", isDriveMotor, DCMotor.getKrakenX60(1));
|
|
|
|
|
case "krakenx60foc":
|
|
|
|
|
return new TalonFXSwerve(id, canbus != null ? canbus : "", isDriveMotor, DCMotor.getKrakenX60Foc(1));
|
|
|
|
|
case "talonsrx":
|
|
|
|
|
return new TalonSRXSwerve(id, isDriveMotor, DCMotor.getCIM(1));
|
2023-02-24 19:11:05 -06:00
|
|
|
case "sparkmax_brushed":
|
2024-12-17 18:49:55 +00:00
|
|
|
if (canbus == null)
|
|
|
|
|
{
|
|
|
|
|
canbus = "";
|
|
|
|
|
}
|
2023-02-24 19:11:05 -06:00
|
|
|
switch (canbus)
|
|
|
|
|
{
|
|
|
|
|
case "greyhill_63r256":
|
2024-12-09 23:26:04 +00:00
|
|
|
return new SparkMaxBrushedMotorSwerve(id, isDriveMotor, Type.kQuadrature, 1024, false, DCMotor.getCIM(1));
|
2023-02-24 19:11:05 -06:00
|
|
|
case "srx_mag_encoder":
|
2024-12-09 23:26:04 +00:00
|
|
|
return new SparkMaxBrushedMotorSwerve(id, isDriveMotor, Type.kQuadrature, 4096, false, DCMotor.getCIM(1));
|
2023-02-24 19:11:05 -06:00
|
|
|
case "throughbore":
|
2024-12-09 23:26:04 +00:00
|
|
|
return new SparkMaxBrushedMotorSwerve(id, isDriveMotor, Type.kQuadrature, 8192, false, DCMotor.getCIM(1));
|
2023-02-24 19:11:05 -06:00
|
|
|
case "throughbore_dataport":
|
2024-12-09 23:26:04 +00:00
|
|
|
return new SparkMaxBrushedMotorSwerve(id, isDriveMotor, Type.kNoSensor, 8192, true, DCMotor.getCIM(1));
|
2023-02-24 19:11:05 -06:00
|
|
|
case "greyhill_63r256_dataport":
|
2024-12-09 23:26:04 +00:00
|
|
|
return new SparkMaxBrushedMotorSwerve(id, isDriveMotor, Type.kQuadrature, 1024, true, DCMotor.getCIM(1));
|
2023-02-24 19:11:05 -06:00
|
|
|
case "srx_mag_encoder_dataport":
|
2024-12-09 23:26:04 +00:00
|
|
|
return new SparkMaxBrushedMotorSwerve(id, isDriveMotor, Type.kQuadrature, 4096, true, DCMotor.getCIM(1));
|
2023-02-24 19:11:05 -06:00
|
|
|
default:
|
|
|
|
|
if (isDriveMotor)
|
|
|
|
|
{
|
|
|
|
|
throw new RuntimeException("Spark MAX " + id + " MUST have a encoder attached to the motor controller.");
|
|
|
|
|
}
|
|
|
|
|
// We are creating a motor for an angle motor which will use the absolute encoder attached to the data port.
|
2024-12-09 23:26:04 +00:00
|
|
|
return new SparkMaxBrushedMotorSwerve(id, isDriveMotor, Type.kNoSensor, 0, false, DCMotor.getCIM(1));
|
2023-02-24 19:11:05 -06:00
|
|
|
}
|
2025-01-06 15:44:15 +00:00
|
|
|
case "nova_neo":
|
|
|
|
|
return new ThriftyNovaSwerve(id, isDriveMotor, DCMotor.getNEO(1));
|
|
|
|
|
case "nova_neo550":
|
|
|
|
|
return new ThriftyNovaSwerve(id, isDriveMotor, DCMotor.getNeo550(1));
|
2025-02-22 06:15:56 +00:00
|
|
|
case "nova_vortex":
|
|
|
|
|
return new ThriftyNovaSwerve(id, isDriveMotor, DCMotor.getNeoVortex(1));
|
|
|
|
|
case "nova_minion":
|
|
|
|
|
throw new UnsupportedOperationException("Cannot create minion combination");//return new ThriftyNovaSwerve(id, isDriveMotor, DCMotor.getMinion(1));
|
2023-02-13 17:21:24 -06:00
|
|
|
default:
|
2023-12-12 10:48:54 -06:00
|
|
|
throw new RuntimeException(type + " is not a recognized motor type.");
|
2023-02-13 14:37:05 -06:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|