Has anyone been able to use the 2025 version of YAGSL to control swerve drive?
After figuring out how to put together the Java library and the Config JSONs while attempting to create a simple program to drive our swerve drive we keep getting IOExceptions when running SwerveParser. As far as I can tell it should be trying to pull the files from /swerve.
Does anyone know why it would be unable to find the files?
There is probably a problem with your config or code. There is no official 2025 release yet as required vendordeps are not released yet.
I remade the config files but it still throws the IOException, may I ask what would be wrong with this code?
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
package frc.robot;
import edu.wpi.first.util.sendable.SendableRegistry;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.TimedRobot;
import edu.wpi.first.wpilibj.drive.DifferentialDrive;
import edu.wpi.first.wpilibj.motorcontrol.PWMSparkMax;
import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import edu.wpi.first.wpilibj.Filesystem;
import swervelib.parser.SwerveParser;
import swervelib.SwerveDrive;
import edu.wpi.first.math.geometry.Translation2d;
import edu.wpi.first.math.util.Units;
/**
* This is a demo program showing the use of the DifferentialDrive class, specifically it contains
* the code necessary to operate a robot with tank drive.
*/
public class Robot extends TimedRobot {
private final SwerveDrive m_robotDrive;
//private final DifferentialDrive m_robotDrive;
private final Joystick m_leftStick;
private final Joystick m_rightStick;
//private final PWMSparkMax m_leftMotor = new PWMSparkMax(0);
//private final PWMSparkMax m_rightMotor = new PWMSparkMax(1);
public Robot() {
// We need to invert one side of the drivetrain so that positive voltages
// result in both sides moving forward. Depending on how your robot's
// gearbox is constructed, you might have to invert the left side instead.
//m_rightMotor.setInverted(true);
double maxSpeed = Units.feetToMeters(4);
Path swerveConfigDir = Filesystem.getDeployDirectory().toPath();
swerveConfigDir = Path.of(swerveConfigDir.toString(), "swerve");
String test = "src/main/deploy/swerve";
System.out.println(swerveConfigDir.toString());
System.out.println(Path.of(swerveConfigDir.toString(), "swervedrive.json").toString());
m_robotDrive = new SwerveParser(swerveConfigDir.toFile()).createSwerveDrive(maxSpeed);
//m_robotDrive = new DifferentialDrive(m_leftMotor::set, m_rightMotor::set);
m_leftStick = new Joystick(0);
m_rightStick = new Joystick(1);
System.out.println(swerveConfigDir);
//SendableRegistry.addChild(m_robotDrive, m_leftMotor);
//SendableRegistry.addChild(m_robotDrive, m_rightMotor);
}
@Override
public void teleopPeriodic() {
//m_robotDrive.tankDrive(-m_leftStick.getY(), -m_rightStick.getY());
m_robotDrive.drive(new Translation2d(0.0, 0.2), 0.7, true, false);
}
}
I dont know without seeing your entire project? If you could link to a github repo i can tell you.
As an FYI your test dir will never work as the deployment directory on the rio is not src/main/deploy
When pulling the config files you need to get the deploy directory from the rio. Using something like this.
private File directory = new File(Filesystem.getDeployDirectory(), "swerve"))
You also need to surround the swerve creation in a try catch such as our implementation.
try {
swerveDrive =
new SwerveParser(directory)
.createSwerveDrive(
RobotConstants.MAX_SPEED,
new Pose2d(
new Translation2d(Meter.of(1), Meter.of(4)), Rotation2d.fromDegrees(0)));
} catch (Exception e) {
throw new RuntimeException(e);
}
Here is a modified version of your code. I have not tested it yet but it should work.
package frc.robot;
import edu.wpi.first.util.sendable.SendableRegistry;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.TimedRobot;
import edu.wpi.first.wpilibj.Filesystem;
import swervelib.parser.SwerveParser;
import swervelib.SwerveDrive;
import edu.wpi.first.math.geometry.Translation2d;
import edu.wpi.first.math.geometry.Pose2d;
import edu.wpi.first.math.geometry.Rotation2d;
import edu.wpi.first.math.util.Units;
import java.io.File;
public class Robot extends TimedRobot {
private SwerveDrive m_robotDrive;
private final Joystick m_leftStick;
private final Joystick m_rightStick;
public Robot() {
double maxSpeed = Units.feetToMeters(4);
File directory = new File(Filesystem.getDeployDirectory(), "swerve");
try {
m_robotDrive = new SwerveParser(directory).createSwerveDrive(
maxSpeed,
new Pose2d(
new Translation2d(1, 4),
Rotation2d.fromDegrees(0)
)
);
} catch (Exception e) {
throw new RuntimeException(e);
}
m_leftStick = new Joystick(0);
m_rightStick = new Joystick(1);
}
@Override
public void teleopPeriodic() {
m_robotDrive.drive(new Translation2d(0.0, 0.2), 0.7, true, false);
}
}