Learning Programming

Learning to write robot code

In order to write efficient and scalable robot programs, it is important to have an understanding of both basic programming concepts and the structure of commonly-used robot libraries. Between syntax, paradigms, and thinking algorithmically, programming can take time to master. Learning to code, however, is a very rewarding process, and there are countless online resources on the topic. Listed in this document are some especially helpful guides which explain programming in a clear, comprehensible manner.

This guide focuses on Java, as it is natively-supported by WPILib and arguably simpler than C++. However, most of the ideas described here are applicable to any object-oriented language.

Basic concepts

In many ways, writing effective code is just as complex as mechanical engineering. It is not enough to write code that "just works;" good programming is extensible and allows for the easy addition of new features. This is akin to how easily new subsystems can be added to a well-designed robot CAD. To facilitate efficient programming, many "paradigms" or programming styles have been created. Languages like Java are built around object-oriented paradigm, which is a way of organizing data and actions that may be taken on the data.

To program well in Java, one must understand how to manage/use data - this is thinking algorithmically, and comes with practice - as well as the object-oriented principles employed to organize code. The official Java documentation contains an excellent set of resources for learning basic programming principles, and is the recommended resource for learning programming.

One may also find it helpful to understand how computers physically process and execute human-written code. This video and this article on how code is processed provide a good starting point.

Common robot libraries

There are multiple software packages which 4311 utilizes in its robot programs. Those on the programming subteam should be familiar with all of the following commonly-used frameworks:

  • The WPILib framework is the primary tool used for writing FRC programs. It contains functions for numerous robot-related tasks, such as turning on motors or reading from sensors. Specific sections to note are actuators, sensors, CAN devices, and command-based programming.

  • The Phoenix framework from CTRE is another useful library employed by the Swampscott Currents. It allows for the control of CAN-based motors like the Falcon 500, and comes with a useful software tool for debugging individual CAN devices (Phoenix Tuner).

  • The Swampscott Currents use a small, custom API called SerpentFramework for robot programming. It contains some special classes to make coding easier.

  • 4311 also uses GamePlan, a custom Shuffleboard widget for composing autonomous routines. While it is not necessary to understand how GamePlan works in order to program the robot, one should be familiar with using GamePlan's output for the robot's autonomous.