Class AutoParser

java.lang.Object
me.nabdev.pathfinding.autos.AutoParser

public class AutoParser extends Object
Converts json autos to commands which can be scheduled.
  • Constructor Details

    • AutoParser

      public AutoParser()
  • Method Details

    • registerCommand

      public static void registerCommand(String id, Function<org.json.JSONObject,edu.wpi.first.wpilibj2.command.Command> command)
      Register a command which can be used in the autos.
      Parameters:
      id - The id of the command, which will be used in the auto json file
      command - A function that takes in a JSONObject of parameters and returns a Command.
    • registerGroupType

      public static void registerGroupType(String id, AutoGroup group)
      Add a group type to use in autos.
      Parameters:
      id - The id of the group, which will be used in the auto json file
      group - The autogroup instance to use
    • registerMacro

      public static void registerMacro(String id, String name)
      Register a macro to use in autos.
      Parameters:
      id - The id of the macro, which will be used in the auto json file
      name - The name of the macro file, in deploy/autos/macros
    • registerBoolean

      public static void registerBoolean(String id, Function<org.json.JSONObject,AutoBoolean> bool)
      Register a boolean to use in autos.
      Parameters:
      id - The id of the boolean, which will be used in the auto json file
      bool - A function that takes in a JSONObject of parameters and returns an AutoBoolean
    • loadAuto

      public static edu.wpi.first.wpilibj2.command.Command loadAuto(String name) throws FileNotFoundException, org.json.JSONException, IOException
      Load an auto from a json file in the deploy directory
      Parameters:
      name - The name of the json file
      Returns:
      The autonomous command
      Throws:
      FileNotFoundException - if the file could not be found
      org.json.JSONException - if the auto is invalid
      IOException - if the macro could not be used
    • loadAutoFromPath

      public static edu.wpi.first.wpilibj2.command.Command loadAutoFromPath(String path) throws FileNotFoundException, org.json.JSONException, IOException
      Load an auto from a json file at the given path
      Parameters:
      path - The path of the json auto
      Returns:
      The autonomous command
      Throws:
      FileNotFoundException - if the file could not be found
      org.json.JSONException - if the auto is invalid
      IOException - if the macro could not be used
    • parseAuto

      public static edu.wpi.first.wpilibj2.command.Command parseAuto(org.json.JSONArray auto) throws org.json.JSONException, IOException
      Parse an auto from a JSONArray and return a command to run.
      Parameters:
      auto - The auto to parse
      Returns:
      The auto command
      Throws:
      IOException - if the macro could not be used
      org.json.JSONException - if the auto is invalid
    • parseBoolean

      public static BooleanSupplier parseBoolean(org.json.JSONObject bool)
      Parse a BooleanSupplier from a JSONObject that represents an AutoBoolean
      Parameters:
      bool - The JSONObject to parse
      Returns:
      The parsed BooleanSupplier