From 2bba4ea46ccad5c7c6d29e24867bf8fda43a5935 Mon Sep 17 00:00:00 2001 From: PJ Reiniger Date: Fri, 26 Jan 2024 00:46:58 -0500 Subject: [PATCH 1/2] Add driver station warning if named command is not known --- .../main/java/com/pathplanner/lib/auto/NamedCommands.java | 6 ++++++ .../main/native/cpp/pathplanner/lib/auto/NamedCommands.cpp | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/pathplannerlib/src/main/java/com/pathplanner/lib/auto/NamedCommands.java b/pathplannerlib/src/main/java/com/pathplanner/lib/auto/NamedCommands.java index c66bb2b9..e02e341f 100644 --- a/pathplannerlib/src/main/java/com/pathplanner/lib/auto/NamedCommands.java +++ b/pathplannerlib/src/main/java/com/pathplanner/lib/auto/NamedCommands.java @@ -1,6 +1,7 @@ package com.pathplanner.lib.auto; import edu.wpi.first.math.Pair; +import edu.wpi.first.wpilibj.DriverStation; import edu.wpi.first.wpilibj2.command.*; import java.util.HashMap; import java.util.List; @@ -61,6 +62,11 @@ public static Command getCommand(String name) { if (hasCommand(name)) { return CommandUtil.wrappedEventCommand(namedCommands.get(name)); } else { + DriverStation.reportWarning( + "PathPlanner attempted to create a command '" + + name + + "' that has not been registered with NamedCommands.registerCommand", + false); return Commands.none(); } } diff --git a/pathplannerlib/src/main/native/cpp/pathplanner/lib/auto/NamedCommands.cpp b/pathplannerlib/src/main/native/cpp/pathplanner/lib/auto/NamedCommands.cpp index f329875e..3d0f0075 100644 --- a/pathplannerlib/src/main/native/cpp/pathplanner/lib/auto/NamedCommands.cpp +++ b/pathplannerlib/src/main/native/cpp/pathplanner/lib/auto/NamedCommands.cpp @@ -1,5 +1,6 @@ #include "pathplanner/lib/auto/NamedCommands.h" #include "pathplanner/lib/auto/CommandUtil.h" +#include "frc/Errors.h" using namespace pathplanner; @@ -10,5 +11,8 @@ frc2::CommandPtr NamedCommands::getCommand(std::string name) { return CommandUtil::wrappedEventCommand( NamedCommands::namedCommands.at(name)); } + FRC_ReportError(frc::warn::Warning, + "PathPlanner attempted to create a command '{}' that has not been registered with NamedCommands::registerCommand", + name); return frc2::cmd::None(); } From 23920e27bc0e5257abb4097ba48b1295724cb3be Mon Sep 17 00:00:00 2001 From: PJ Reiniger Date: Fri, 26 Jan 2024 16:07:54 -0500 Subject: [PATCH 2/2] Add to python --- pathplannerlib-python/pathplannerlib/auto.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pathplannerlib-python/pathplannerlib/auto.py b/pathplannerlib-python/pathplannerlib/auto.py index 717fcc12..770636d9 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, reportError +from wpilib import getDeployDirectory, reportError, reportWarning import json from commands2.command import Command from commands2.subsystem import Subsystem @@ -51,6 +51,7 @@ def getCommand(name: str) -> Command: if NamedCommands.hasCommand(name): return CommandUtil.wrappedEventCommand(NamedCommands._namedCommands[name]) else: + reportWarning(f"PathPlanner attempted to create a command '{name}' that has not been registered with NamedCommands.registerCommand", False) return cmd.none()