Skip to content

The Json Config

Varun A edited this page Nov 26, 2022 · 2 revisions

Before you start

This app stores its configuration in json config files. This page will guide you through setting everything up so that you can use the app.

Unfortunately, if your config fails to load for some reason, it will be reset to its default values. If you are using Notepad++ to the edit the config select No when it asks you to reload the file if you notice an error in the GUI about being unable to load the config.

The app saves all its data when it is closed. It will overwrite all changes you have made while the app was open. CLOSE THE APP BEFORE YOU EDIT THE CONFIGS.

Setting up the config

Lauch the app and find your config

  1. You will first need to launch the app and then close it. Since everything is saved when the app is closed this is when all the files will be created.
  2. Refer to the following table to find the location of the config file based on your OS
OS Config Folder Location
Windows %appdata%/AutoBuilder
Mac ~/Library/Preferences/AutoBuilder
Linux XDG_CONFIG_HOME/AutoBuilder
Linux (if XDG_CONFIG_HOME is not present) ~/.config/AutoBuilder

The config values you actually need to change

  1. Set up your team number
  2. Set up your robot length and width
  3. Disable Network Tables if you aren't currently working with your robot
  4. Set up your pathing config

Example config

Below is the config file that we use for our swerve robot.

{
  "scriptMethods" : [ "print", "sleep" ],
  "selectedAuto" : "<Location of our auto file in the deploy folder of our code>",
  "selectedShooterConfig" : "<Location of our shooter config in the deploy folder of our code>",
  "teamNumber" : 3476,
  "robotLength" : 0.9398,
  "robotWidth" : 0.9398,
  "pointScaleFactor" : 159.96748,
  "originX" : -601.0,
  "originY" : -1080.0,
  "pathingConfig" : {
    "maxVelocityMetersPerSecond" : 3.0,
    "maxAccelerationMetersPerSecondSq" : 4.0,
    "trajectoryConstraints" : [ {
      "type" : "CentripetalAccelerationConstraint",
      "maxCentripetalAccelerationMetersPerSecondSq" : 2.032
    }, {
      "type" : "SwerveDriveKinematicsConstraint",
      "kinematics" : {
        "wheelsMeters" : [ {
          "x" : 0.30797,
          "y" : 0.307975
        }, {
          "x" : -0.307975,
          "y" : 0.307975
        }, {
          "x" : 0.307975,
          "y" : -0.307975
        }, {
          "x" : -0.307975,
          "y" : -0.307975
        } ]
      },
      "maxSpeedMetersPerSecond" : 3.1
    } ]
  },
  "networkTablesEnabled" : false,
  "robotCodeDataFile" : "robotCodeData.json",
  "useReflection" : true,
  "isHolonomic" : true,
  "shooterConfigEnabled" : false,
  "readMe" : "the scriptMethods contains the list of valid methods that will be allowed in the script block. print and sleep are currently hardcoded to allow for error checking on the arguments. You to edit them you will need to clone & compile the code. You can find them at src/me/varun/autobuilder/scripting/parser. selectedAuto & selectedShooterConfig point to the files that the code will read to get and save data. The team number is used for connect to your robot though network tables. The robot length and width are in meters and is used to draw the blue box when clicking on a point. The point scale factor is calculated by getting the (length and pixels of the field in the image)/(length of the field in meters). It is used to render everything in the correct position. The units for the origin is in pixels. It represents how much the image should be translated so that (0,0) in the application space is (0,0) on the image. You can disable network tables by setting networkTablesEnabled to false. This is useful if you are using the app while not connected to the robot and are getting lag spikes/errors in the console"
}

The rest of the values in the config should work with their default values!

scriptMethods Set up your script methods

This is ignored unless useReflection is set to false.

See: I don't want to use reflection

Default: "scriptMethods" : [ "print", "sleep" ]

teamNumber Set your team number

This number is used to connect to your robot. Not setting this will prevent you from uploading autos and seeing the live preview.

Default : "teamNumber" : 3476

Set your robot dimensions

This is used to determine the bounding box preview that is seen when dragging points around the field. Units are in meters. Its recommended that this dimension include your bumpers.

Defualt: "robotLength" : 0.9191625, "robotWidth" : 0.9229725

networkTablesEnabled Enable/Disable Networktables

If you are getting lag spikes while using the app and are not connected to the robot you can disable networktables to fix the lag spikes.

Warning: You will not be able to connect to the robot if you disable this.

Default: "networkTablesEnabled" : true

useReflection Decide if you want to use reflection

Keep this value set to true if you want to use the reflection powered scripting features. Keep this enabled unless you have a reason to disable it.

Default: "useReflection" : true

pathingConfig Pathing config

This section is what powers the path preview. You must set this up correctly for your robot to work. Failure to do so will cause all sorts of weird behavior. These values need to be the real values that your robot uses. The path is calculated in the GUI using the following values. Changing these same values in the robot code will have no effect on the path that the robot drives!!

maxVelocityMetersPerSecond

The max velocity of the robot

maxAccelerationMetersPerSecondSq

The max acceleration of the robot

Other constraints

The trajectoryConstraints section is a list of all the constraints that will be applied to the robot path. These are the same constraints that you would add by calling TrajectoryConfig#addConstraint

All the default WPI constraints are added by default for your reference. You should simply delete the ones that you will not use.

Below you will also find all the constraints you can add to this list. Simply copy the json and change the values to your needs

Centripetal Acceleration Constraint

    {
      "type" : "CentripetalAccelerationConstraint",
      "maxCentripetalAccelerationMetersPerSecondSq" : 2.032
    }

Differential Drive Voltage Constraint

    {
      "type" : "DifferentialDriveVoltageConstraint",
      "feedforward" : {
        "ks" : 5.0,
        "kv" : 1.0,
        "ka" : 0.0
      },
      "kinematics" : {
        "trackWidthMeters" : 0.93
      },
      "maxVoltage" : 10.0
    }

Differential Drive Kinematics Constraint

    {
      "type" : "DifferentialDriveKinematicsConstraint",
      "kinematics" : {
        "trackWidthMeters" : 0.93
      },
      "maxSpeedMetersPerSecond" : 2.0
    }

Elliptical Region Constraint

    {
      "type" : "EllipticalRegionConstraint",
      "center" : {
        "x" : 20.0,
        "y" : 25.0
      },
      "radii" : {
        "x" : 2.7755575615628914E-17,
        "y" : 0.35355339059327373
      },
      "constraint" : add the json of another constraint you want to only happen in this area
    }

Max Velocity Constraint

    {
      "type" : "MaxVelocityConstraint",
      "maxVelocity" : 2.0
    }

Mecanum Drive Kinematics Constraint

    {
      "type" : "MecanumDriveKinematicsConstraint",
      "kinematics" : {
        "frontLeftWheelMeters" : {
          "x" : -0.5,
          "y" : 0.5
        },
        "frontRightWheelMeters" : {
          "x" : 0.5,
          "y" : 0.5
        },
        "rearLeftWheelMeters" : {
          "x" : -0.5,
          "y" : 0.5
        },
        "rearRightWheelMeters" : {
          "x" : -0.5,
          "y" : -0.5
        }
      },
      "maxSpeedMetersPerSecond" : 2.0
    }

Rectangular Region Constraint

    {
      "type" : "RectangularRegionConstraint",
      "bottomLeftPoint" : {
        "x" : 0.0,
        "y" : 0.0
      },
      "topRightPoint" : {
        "x" : 20.0,
        "y" : 20.0
      },
      "constraint" : add the json of another constraint you want to only happen in this area
    }

Swerve Drive Kinematics Constraint

     {
      "type" : "SwerveDriveKinematicsConstraint",
      "kinematics" : {
        "wheelsMeters" : [ {
          "x" : -0.5,
          "y" : 0.5
        }, {
          "x" : 0.5,
          "y" : 0.5
        }, {
          "x" : -0.5,
          "y" : 0.5
        }, {
          "x" : -0.5,
          "y" : -0.5
        } ]
      },
      "maxSpeedMetersPerSecond" : 2.0
    }

Custom Constraints

You will need to add your constraint class manually into the code. After you do that, you need to ensure that constraint will be serialized properly.

To do this:

  1. Add your class as a JsonSubType in com.dacubeking.autobuilder.gui.wpi.math.trajectory.constraint.TrajectoryConstraint
  2. Ensure that you class can get serialized and deserialized properly. You will need to add the proper annotations to your code so that data is read and saved properly. It is probably easier to look at one of the other subtypes in the above class and see how we added the annotations to the WPI classes.

Other config options

You probably don't need to change them, but here is what they do anyways.

selectedAuto Selected Auto

This determines the file which the GUI should read/save to.

Default: "selectedAuto" : "auto.json"

pointScaleFactor Point Scale Factor

This number is used to multiply the positions that are stored in meters to get their pixel position to be able to render them.

Default "pointScaleFactor" : 159.96748

Origin X & Y

This is how many pixels the background image is translated. The defualt it moving the image to the left 601 pixel and down 1080 pixels. This is done so that (0,0) in the application space is equivalent to the (0,0) on the image.

Default: "originX" : -601.0, "originY" : -1080.0

I'll make these values available at the beginning of each season

robotCodeDataFile Robot Code Data

Determines where the robot should look for the robot code data file.

Default: "robotCodeDataFile" : "robotCodeData.json"