More Java Robot Examples

Learn more about robot programming by studying more simple example programs. Run them, study what they do, and incrementally expand their functionality. The WPILib software you installed includes example programs that you can compile and run on a RoboRIO. Review how to use VSCode and then try creating a new robot project.

  • WPILib provides 3 frameworks for building robot programs. Build your first program using the TimedRobot (previously had been IterativeRobot) framework as described here.
  • Connect your laptop to the RoboRIO USB port or WiFi
  • Connect your joystick or xbox controller to another USB port on your laptop
  • Launch the NI Driver Station Software. For details see here
  • Confirm that the software detects your joystick/controller and responds to button presses and stick movement
  • Use Microsoft Internet Explorer (not Chrome or Firefox) to connect to the RoboRIO's web interface (usually at and confirm that you have connectivity with the RobORIO
  • Create a test project and follow these instructions to build, load, and run it on your RoboRIO/Robot
  • Create another WPILib project based on the TimedRobot framework
    • Study an example program. This is a simple program for one of our test robots: Peanut 2 (Hazelnut)
      • 2-wheel-drive (2WD) robot with two CIM motors driving plaction wheels
      • Motors are controlled by Talon SRX smart motor controllers; these are networked to the roboRIO (robot control computer) using CAN bus and are at addresses 3 (left motor) and 4 (right motor)
      • An ultrasonic sensor for forward collision avoidance connected to roboRIO digital I/O pins (DIO) 0 and 1
      • A USB camera so you can drive even when you can't see the robot
      • The driver controls the robot using the two analog sticks on an X-box game controller
    • Copy the program below over the default created by the framework
    • Use the WPILib->Manage Vendor Libraries->Install New Libraries Offline->select the CTRE Framework
  • More sample code for Hazelnut (peanut robot) is here
  • You can learn more about FRC robot programming here
  • You can learn more about game controllers here
  • Note: the sample program assumes two !TalonSRX motor controllers at IDs 3 and 4. You can set them using the CTRE Phoneix Tuner
  • Note: the !RoboRIO web web interface is available via browser at
Last modified 3 years ago Last modified on Oct 31, 2019, 1:29:10 PM

Attachments (2)

Download all attachments as: .zip