2019 FRC Writing a Simple Drive Train (Java)




Please keep an eye out for my next instructable on the current 2019 programming. Although it is out of date there are still things that you can learn about it like how to actually make the classes and write the code is the same.

This instructable will assume that you know basic Java and know your way around the robot. In the 2019 season, WPI is switching its support from Eclipse to the Visual Studio Code IDE since we have found this out I'm making this instructable one to help people on my team and to help other teams find their way while using the Visual Studio IDE. With the release of the 2019 season being Deep Space themed me and my team are ready and can't wait for the release of the game in January. Having that been said let us get into the CODE!

DISCLAIMER: This VSCode plugin is Alpha, and its guaranteed to change before the season based on feedback? In addition, upgrading from Alpha to release might require manual changes to the build setup.

This code is available on my Github here.

Step 1: Visual Studio Code Install

The first step is to install VSCode you can download it at this link.

Once the file is downloaded it is time to run the installer (PS you might want to add a desktop icon).

After the running VSCode you will get a window that looks like picture 1.

When that screen appears you will need to go to the extensions on the left part of the window and search for "Java Extension Pack" (Picture 2) then click install (by the way when you click install more than just that will install).

After installing (which could take a few minutes) you will need to click the reload button (picture 3).

Next, you will have to download the latest .vsix release from the wpilibsuite VSCode GitHub repository from this link.

Next, we need to go back to the extension tab in VSCode and go to the three dots and go to install from VSIX (picture 4) then select the VSIX file from where you downloaded it after it installs you will then again have to reload VSCode.

After installing the WPILIB VSIX file you should see a small WPI logo in the top right of your window(Picture 5) (if not try restarting VSCode again or restart your computer).

Step 2: Creating a New WPILIB Project

First, we need to go to the WPILIB logo that was mentioned in the last step and click on it and go down and select the "Create a new project" (you might have to search for it). (Picture 1)

After selecting you will have to select a "Project template", "Project Language"(this one will be java), "A Project Base", "Project Folder", "Project Name". (Picture 2, Picture 3)

Then after clicking "Generate Project", you are going to want to select "Yes (Current Window)". (Picture 4)

Step 3: Writing the Code

First, we need to expand the code view (Picture 1) to the find the subsystems and commands where we will delete the example command and example subsystem. (Picture 2)

After deleting the command and subsystem we will need to fix the errors that arise in the robot class we will do this by either deleting or commenting the lines out. (Picture 3)

Next, we are going to need to create a command and a subsystem by right clicking on the command file then clicking create new class/command you will then need to select command then enter a name I named mine DriveCommand then do the same for the subsystem file but instead of selecting command you select subsystem I named mine DriveSub. (Picture 4)

After creating the two new files we will need to go to the RobotMap and add four variables they will be int and they will contain the four motor controller ids. (Picture 5)

Next we will go back to the DriveSub and create 4 TalonSRX objects that are named corresponding with the 4 motors and we need to create a constructor. (Picture 6)

Then in the constructor we need to construct the TalonSRXs with the ids that are in the RobotMap. (Picture 7)

Next, we are going to create a method that will handle all of our talon configuration like max output and max current output. (Picture 8)

Now that we are ready to make the drive method we need to copy a Drive class that I have made that will help us. Copy the files from here. (Put this file in a new folder called utilities inside of the robot folder) (Picture 9)

After we have copied that file we now need to make a Drive object and construct it in the constructor. (Picture 10)

When we have our Drive object created we need a way for the command to call it so we create a driveArcade method with two variables move and rotate that will be sent from

Step 4: Drive Command

Now we need to talk about requires. When the requires method is called it goes to the subsystem and the subsystem stops all the other commands that are requiring the same subsystem. Basically, it says that only this object can be using the subsystem at the moment. So we need to require the driveTrain object in the robot class (When you refer to the DriveSub class you should always be going through the robot class object). (Picture 1)

Secondly, we need to go to the oi class and add a public joystick object that refers to the port that it is plugged into on the driver station. (Picture 2)

Finally, we need to go to the DriveCommand and in the execute method we need to go to the robot class and go to the driveTrain object and call its driveArcade method passing it the left y axis and the right x axis value from the robot oi object. Then in the interrupt method we need to call the end method then in the end method we need to call the robot.driveTrain.driveArcade(0,0) to make sure that when the command is interrupted or the command is ended either on a crash or on a requires stop that it stops driving. (Picture 3)

Step 5: Deploy

To finally deploy to the robot go to the wpi logo and click it and search for deploy and follow the instructions.



    • Arduino Contest 2019

      Arduino Contest 2019
    • Tape Contest

      Tape Contest
    • Trash to Treasure

      Trash to Treasure

    3 Discussions


    Question 12 days ago

    Hello I am trying to write a program to control 1 cim motor with a talon sr controller instead of a talon srx. I am very new to programming and I am using your guide to code my system. I have followed your code to the tee but i am encountering an error on step 8 of writing the code.
    the error showing up is saying that the method ConfigPeakOutputForward(int, int) is undefined for the type Talon. i will include my code down below and am just wondering if you have any tips on how to fix this. Thanks!

    package frc.robot.subsystems;

    import java.io.ObjectInputFilter.Config;

    import edu.wpi.first.wpilibj.Talon;
    import edu.wpi.first.wpilibj.command.Subsystem;
    import frc.robot.RobotMap;

    * Add your docs here.
    public class DriveSub extends Subsystem {
    // Put methods for controlling this subsystem
    // here. Call these from Commands.

    Talon Mo1;

    public DriveSub()
    Mo1 = new Talon(RobotMap.Motor);

    //Config all talons.

    public void ConfigTalons(Talon talon){



    public void initDefaultCommand() {
    // Set the default command for a subsystem here.
    // setDefaultCommand(new MySpecialCommand());

    Question 2 months ago on Step 5

    Hey there! I'm one of the lead programmers on team 7406. We're a rookie team, and we're still trying to get up on our feet. I'm still in the dark about a lot of the coding for FRC, but I'm happy to find your Instructable. I'm wondering in what ways your Instructable is out of date, and if we could still potentially use it as a way of building our code from the ground up and testing the movement on our bot. Many thanks!

    1 answer

    Answer 2 months ago

    The only thing that is out of date about this instructable is how you install the vscode plugin as well as how you create the project. The other information about how to write and organize the code is the same.