Skip to content
Joe Thompson - FTC Coach edited this page Oct 1, 2021 · 15 revisions

Introduction

This wiki provides an introduction to the basic commands and procedures required to make a robot go. The primary reference source for most of the information here is the WPI FRC documentation wiki. The WPI documentation covers most aspects of robot design and build, but we will focus on software here.

The information presented here assumes that you have a basic familiarity with Java and git SCM. If you aren't familiar with these things, don't worry. Some of the information here may not make sense to you, but we'll help you get through it.

Getting Started

Development System Requirements

Creating software for an FRC robot requires the installation of a few software packages on a Windows system:

The WPI documentation has detailed step-by-step instructions for installing these software packages (except for git) starting here. You will also need to install some vendor-specific libraries, but we'll discuss those later.

The WPI libraries include a specially-configured version of Visual Studio Code. If you already have VS Code installed on your machine, it is important that you use the special WPI configuration for working with FRC code and the robot. The installation routine will place an icon for this and a local copy of the WPI documentation on your desktop.

Cloning the Robot-Go repository

> git clone https://github.com/FRC8592/Robot-Go.git

We're going to all work on our own branch so that we don't overwrite each other's code. After cloning the repository, change into the new directory and create a personal branch:

> git checkout -b <my name>

The git checkout command is used to switch among branches. The -b option tells git to create a new branch.

All of our software efforts will make use of git Source Control Management (SCM). Using an SCM like git has many advantages:

  • Our code is shared with the team. Anyone can see our code and anyone can modify our code. It can be downloaded anywhere. A useful collary is that our code is inherently backed up on github. If something happens to our laptop, we don't lose any work.
  • Our software can be modified in private branches. This let's multiple people make changes to the code without interfering with each other. Modified code is merged to the main branch only after it is tested and ready to share.
  • Git lets us tag our code to identify and retrieve an important version. For example, we may want to tag the code we take to a competition so that we know exactly what is on the robot.

Creating a new robot project

We're going to create a new, blank project skeleton.

Making the Robot Go!

We're going to start off by creating a robot program that will drive the robot like a tank. The left and right sides of the robot will be controlled by independent joysticks and the result will emulate the way a tank with treads drives. Once we have our basic tank drive working, we'll add additional features.

In order to do this we only need to know two things: how to read control values from a joystick and how to write control values to a motor. Once we know how to do these two things, it's relatively easy to expand our knowledge to things like reading sensors (e.g. a color or distance sensor) and operating the motor in more sophisticated modes (e.g. constant velocity or constant position mode.

Reading joystick values

There are at least two different libraries we can use to read joystick values. The basic Joystick class (edu.wpi.first.wpilibj.Joystick) is fairly generic and only requires that we know two different methods (getRawButton, getRawAxis) to read any joystick value. However, it does require that we determine the index for any button or axis that we want to use. This isn't hard, but it's a little tedious.

In contrast, the XboxController class (edu.wpi.first.wpilibj.XboxController) requires the use of many different methods, but they are all named after the button or axis that they read and all work in the same way.

We're going to use the XboxController class to control our robot.

Before we start coding anything for the robot, we should plan out how we want to control it. This will require us to think about how we divide labor between the driver and co-driver and also how human hands work (seriously). This is a critical discussion, because the control scheme can have a major impact on robot driveability. We must consider both the physical difficulty of managing the controls (i.e. do we require finger tutting) and the cognitive load on the drivers.

For now, we're going to control the left wheels with the left analog stick, and the right wheels with the right analog stick.

The code

We start by importing the library into the class we're working in: import edu.wpi.first.wpilibj.XboxController;

Next we have to create the controller object. For now, we'll just create one, called driverController public XboxController driverController;

Finally, we read the joystick leftPower = driverController.getY(GenericHID.Hand.kLeft);

double leftPower =

Clone this wiki locally