Introduction: 2019 FRC Writing a Simple Drive Train (Java)

About: I am currently a student in highschool just about to finish my junior year and I am on a first robotics team where I do programming in java, python, c# and many other things. I also have experience with Autode…

THIS INSTRUCTABLE IS OUT OF DATE!

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.