diff --git a/pathplannerlib-python/pathplannerlib/auto.py b/pathplannerlib-python/pathplannerlib/auto.py index ac161e4e..717fcc12 100644 --- a/pathplannerlib-python/pathplannerlib/auto.py +++ b/pathplannerlib-python/pathplannerlib/auto.py @@ -9,7 +9,7 @@ PathfindThenFollowPathLTV from .geometry_util import flipFieldPose import os -from wpilib import getDeployDirectory +from wpilib import getDeployDirectory, reportError import json from commands2.command import Command from commands2.subsystem import Subsystem @@ -172,7 +172,7 @@ def configureHolonomic(pose_supplier: Callable[[], Pose2d], reset_pose: Callable :param drive_subsystem: the subsystem for the robot's drive """ if AutoBuilder._configured: - raise RuntimeError('AutoBuilder has already been configured. Please only configure AutoBuilder once') + reportError('AutoBuilder has already been configured. This is likely in error.', True) AutoBuilder._pathFollowingCommandBuilder = lambda path: FollowPathHolonomic( path, @@ -233,7 +233,7 @@ def configureRamsete(pose_supplier: Callable[[], Pose2d], reset_pose: Callable[[ :param drive_subsystem: the subsystem for the robot's drive """ if AutoBuilder._configured: - raise RuntimeError('AutoBuilder has already been configured. Please only configure AutoBuilder once') + reportError('AutoBuilder has already been configured. This is likely in error.', True) AutoBuilder._pathFollowingCommandBuilder = lambda path: FollowPathRamsete( path, @@ -296,7 +296,7 @@ def configureLTV(pose_supplier: Callable[[], Pose2d], reset_pose: Callable[[Pose :param drive_subsystem: the subsystem for the robot's drive """ if AutoBuilder._configured: - raise RuntimeError('AutoBuilder has already been configured. Please only configure AutoBuilder once') + reportError('AutoBuilder has already been configured. This is likely in error.', True) AutoBuilder._pathFollowingCommandBuilder = lambda path: FollowPathLTV( path, @@ -351,7 +351,7 @@ def configureCustom(path_following_command_builder: Callable[[PathPlannerPath], :param reset_pose: a consumer for resetting the robot's pose """ if AutoBuilder._configured: - raise RuntimeError('AutoBuilder has already been configured. Please only configure AutoBuilder once') + reportError('AutoBuilder has already been configured. This is likely in error.', True) AutoBuilder._pathFollowingCommandBuilder = path_following_command_builder AutoBuilder._getPose = pose_supplier diff --git a/pathplannerlib/src/main/java/com/pathplanner/lib/auto/AutoBuilder.java b/pathplannerlib/src/main/java/com/pathplanner/lib/auto/AutoBuilder.java index 629ea209..08bf0564 100644 --- a/pathplannerlib/src/main/java/com/pathplanner/lib/auto/AutoBuilder.java +++ b/pathplannerlib/src/main/java/com/pathplanner/lib/auto/AutoBuilder.java @@ -12,6 +12,7 @@ import edu.wpi.first.math.kinematics.ChassisSpeeds; import edu.wpi.first.math.numbers.N2; import edu.wpi.first.math.numbers.N3; +import edu.wpi.first.wpilibj.DriverStation; import edu.wpi.first.wpilibj.Filesystem; import edu.wpi.first.wpilibj.smartdashboard.SendableChooser; import edu.wpi.first.wpilibj2.command.Command; @@ -60,7 +61,6 @@ public class AutoBuilder { * @param shouldFlipPath Supplier that determines if paths should be flipped to the other side of * the field. This will maintain a global blue alliance origin. * @param driveSubsystem the subsystem for the robot's drive - * @throws AutoBuilderException if AutoBuilder has already been configured */ public static void configureHolonomic( Supplier poseSupplier, @@ -71,8 +71,8 @@ public static void configureHolonomic( BooleanSupplier shouldFlipPath, Subsystem driveSubsystem) { if (configured) { - throw new AutoBuilderException( - "Auto builder has already been configured. Please only configure auto builder once"); + DriverStation.reportError( + "Auto builder has already been configured. This is likely in error.", true); } AutoBuilder.pathFollowingCommandBuilder = @@ -128,7 +128,6 @@ public static void configureHolonomic( * @param shouldFlipPath Supplier that determines if paths should be flipped to the other side of * the field. This will maintain a global blue alliance origin. * @param driveSubsystem the subsystem for the robot's drive - * @throws AutoBuilderException if AutoBuilder has already been configured */ public static void configureRamsete( Supplier poseSupplier, @@ -139,8 +138,8 @@ public static void configureRamsete( BooleanSupplier shouldFlipPath, Subsystem driveSubsystem) { if (configured) { - throw new AutoBuilderException( - "Auto builder has already been configured. Please only configure auto builder once"); + DriverStation.reportError( + "Auto builder has already been configured. This is likely in error.", true); } AutoBuilder.pathFollowingCommandBuilder = @@ -198,7 +197,6 @@ public static void configureRamsete( * @param shouldFlipPath Supplier that determines if paths should be flipped to the other side of * the field. This will maintain a global blue alliance origin. * @param driveSubsystem the subsystem for the robot's drive - * @throws AutoBuilderException if AutoBuilder has already been configured */ public static void configureRamsete( Supplier poseSupplier, @@ -211,8 +209,8 @@ public static void configureRamsete( BooleanSupplier shouldFlipPath, Subsystem driveSubsystem) { if (configured) { - throw new AutoBuilderException( - "Auto builder has already been configured. Please only configure auto builder once"); + DriverStation.reportError( + "Auto builder has already been configured. This is likely in error.", true); } AutoBuilder.pathFollowingCommandBuilder = @@ -274,7 +272,6 @@ public static void configureRamsete( * @param shouldFlipPath Supplier that determines if paths should be flipped to the other side of * the field. This will maintain a global blue alliance origin. * @param driveSubsystem the subsystem for the robot's drive - * @throws AutoBuilderException if AutoBuilder has already been configured */ public static void configureLTV( Supplier poseSupplier, @@ -286,8 +283,8 @@ public static void configureLTV( BooleanSupplier shouldFlipPath, Subsystem driveSubsystem) { if (configured) { - throw new AutoBuilderException( - "Auto builder has already been configured. Please only configure auto builder once"); + DriverStation.reportError( + "Auto builder has already been configured. This is likely in error.", true); } AutoBuilder.pathFollowingCommandBuilder = @@ -348,7 +345,6 @@ public static void configureLTV( * @param shouldFlipPath Supplier that determines if paths should be flipped to the other side of * the field. This will maintain a global blue alliance origin. * @param driveSubsystem the subsystem for the robot's drive - * @throws AutoBuilderException if AutoBuilder has already been configured */ public static void configureLTV( Supplier poseSupplier, @@ -362,8 +358,8 @@ public static void configureLTV( BooleanSupplier shouldFlipPath, Subsystem driveSubsystem) { if (configured) { - throw new AutoBuilderException( - "Auto builder has already been configured. Please only configure auto builder once"); + DriverStation.reportError( + "Auto builder has already been configured. This is likely in error.", true); } AutoBuilder.pathFollowingCommandBuilder = @@ -423,15 +419,14 @@ public static void configureLTV( * @param pathFollowingCommandBuilder a function that builds a command to follow a given path * @param poseSupplier a supplier for the robot's current pose * @param resetPose a consumer for resetting the robot's pose - * @throws AutoBuilderException if AutoBuilder has already been configured */ public static void configureCustom( Function pathFollowingCommandBuilder, Supplier poseSupplier, Consumer resetPose) { if (configured) { - throw new AutoBuilderException( - "Auto builder has already been configured. Please only configure auto builder once"); + DriverStation.reportError( + "Auto builder has already been configured. This is likely in error.", true); } AutoBuilder.pathFollowingCommandBuilder = pathFollowingCommandBuilder; diff --git a/pathplannerlib/src/main/native/cpp/pathplanner/lib/auto/AutoBuilder.cpp b/pathplannerlib/src/main/native/cpp/pathplanner/lib/auto/AutoBuilder.cpp index 25b38ecc..66653813 100644 --- a/pathplannerlib/src/main/native/cpp/pathplanner/lib/auto/AutoBuilder.cpp +++ b/pathplannerlib/src/main/native/cpp/pathplanner/lib/auto/AutoBuilder.cpp @@ -38,8 +38,8 @@ void AutoBuilder::configureHolonomic(std::function poseSupplier, HolonomicPathFollowerConfig config, std::function shouldFlipPath, frc2::Subsystem *driveSubsystem) { if (m_configured) { - throw std::runtime_error( - "Auto builder has already been configured. Please only configure auto builder once"); + FRC_ReportError(frc::err::Error, + "Auto builder has already been configured. This is likely in error."); } AutoBuilder::m_pathFollowingCommandBuilder = [poseSupplier, @@ -85,8 +85,8 @@ void AutoBuilder::configureRamsete(std::function poseSupplier, ReplanningConfig replanningConfig, std::function shouldFlipPath, frc2::Subsystem *driveSubsystem) { if (m_configured) { - throw std::runtime_error( - "Auto builder has already been configured. Please only configure auto builder once"); + FRC_ReportError(frc::err::Error, + "Auto builder has already been configured. This is likely in error."); } AutoBuilder::m_pathFollowingCommandBuilder = [poseSupplier, speedsSupplier, @@ -128,8 +128,8 @@ void AutoBuilder::configureRamsete(std::function poseSupplier, ReplanningConfig replanningConfig, std::function shouldFlipPath, frc2::Subsystem *driveSubsystem) { if (m_configured) { - throw std::runtime_error( - "Auto builder has already been configured. Please only configure auto builder once"); + FRC_ReportError(frc::err::Error, + "Auto builder has already been configured. This is likely in error."); } AutoBuilder::m_pathFollowingCommandBuilder = @@ -172,8 +172,8 @@ void AutoBuilder::configureLTV(std::function poseSupplier, units::second_t dt, ReplanningConfig replanningConfig, std::function shouldFlipPath, frc2::Subsystem *driveSubsystem) { if (m_configured) { - throw std::runtime_error( - "Auto builder has already been configured. Please only configure auto builder once"); + FRC_ReportError(frc::err::Error, + "Auto builder has already been configured. This is likely in error."); } AutoBuilder::m_pathFollowingCommandBuilder = @@ -217,8 +217,8 @@ void AutoBuilder::configureLTV(std::function poseSupplier, ReplanningConfig replanningConfig, std::function shouldFlipPath, frc2::Subsystem *driveSubsystem) { if (m_configured) { - throw std::runtime_error( - "Auto builder has already been configured. Please only configure auto builder once"); + FRC_ReportError(frc::err::Error, + "Auto builder has already been configured. This is likely in error."); } AutoBuilder::m_pathFollowingCommandBuilder = [poseSupplier, speedsSupplier, @@ -256,8 +256,8 @@ void AutoBuilder::configureCustom( std::function poseSupplier, std::function resetPose) { if (m_configured) { - throw std::runtime_error( - "Auto builder has already been configured. Please only configure auto builder once"); + FRC_ReportError(frc::err::Error, + "Auto builder has already been configured. This is likely in error."); } AutoBuilder::m_pathFollowingCommandBuilder = pathFollowingCommandBuilder;