Package me.nabdev.pathfinding.autos
Class AutoParser
java.lang.Object
me.nabdev.pathfinding.autos.AutoParser
Converts json autos to commands which can be scheduled.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic edu.wpi.first.wpilibj2.command.CommandLoad an auto from a json file in the deploy directorystatic edu.wpi.first.wpilibj2.command.CommandloadAutoFromPath(String path) Load an auto from a json file at the given pathstatic edu.wpi.first.wpilibj2.command.CommandparseAuto(org.json.JSONArray auto) Parse an auto from a JSONArray and return a command to run.static BooleanSupplierparseBoolean(org.json.JSONObject bool) Parse a BooleanSupplier from a JSONObject that represents an AutoBooleanstatic voidregisterBoolean(String id, Function<org.json.JSONObject, AutoBoolean> bool) Register a boolean to use in autos.static voidregisterCommand(String id, Function<org.json.JSONObject, edu.wpi.first.wpilibj2.command.Command> command) Register a command which can be used in the autos.static voidregisterGroupType(String id, AutoGroup group) Add a group type to use in autos.static voidregisterMacro(String id, String name) Register a macro to use in autos.
-
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 filecommand- A function that takes in a JSONObject of parameters and returns a Command.
-
registerGroupType
Add a group type to use in autos.- Parameters:
id- The id of the group, which will be used in the auto json filegroup- The autogroup instance to use
-
registerMacro
Register a macro to use in autos.- Parameters:
id- The id of the macro, which will be used in the auto json filename- The name of the macro file, in deploy/autos/macros
-
registerBoolean
Register a boolean to use in autos.- Parameters:
id- The id of the boolean, which will be used in the auto json filebool- 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 foundorg.json.JSONException- if the auto is invalidIOException- 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 foundorg.json.JSONException- if the auto is invalidIOException- 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 usedorg.json.JSONException- if the auto is invalid
-
parseBoolean
Parse a BooleanSupplier from a JSONObject that represents an AutoBoolean- Parameters:
bool- The JSONObject to parse- Returns:
- The parsed BooleanSupplier
-