Transcript
Page 1: FRC Java for Robotics Introduction

FRC Java for RoboticsIntroduction

Team 1279 ColdFusionNovember 6, 2010

Page 2: FRC Java for Robotics Introduction

NetBeans IDE

• Full featured development environment– Edit– Build– Debug– Deploy

• Bundled with the latest Java SE JDK

• FRC plug-ins for WPILibJ

Page 3: FRC Java for Robotics Introduction

Advantages

• Widely Used– AP Test means school support

• Many Resources – Books– Websites– Mentors

• Economical – Free and can run on older hardware under Linux

• Early in its life

Page 4: FRC Java for Robotics Introduction

Disadvantages

• New to FIRST– Still Bugs & Rough Edges– Teams have at most a few months on it

• Fewer Robotics resources– Not much existing code– CAN not up to C++

• Not 100% standard Java– Based in Java ME– No formatted output (yet)

Page 5: FRC Java for Robotics Introduction

Sample CodeWalk-through

• Example from SimpleRobotTemplate– Check IterativeRobot too– Good Sample code

• Described in the Getting Started Guide– Still a typo or two

• Example 7– Suggest everyone new try it

Page 6: FRC Java for Robotics Introduction

Sample Code IThe File Environment

• Package groups related classes together

package edu.wpi.first.wpilibj.templates;

• Import pulls in other classes

import edu.wpi.first.wpilibj.RobotDrive;

import edu.wpi.first.wpilibj.SimpleRobot;

import edu.wpi.first.wpilibj.Timer;

import edu.wpi.first.wpilibj.Joystick;

Page 7: FRC Java for Robotics Introduction

Sample Code IIYour Robot Class

• Derived from the sample• Don’t change the name!

public class Team1279Robot extends SimpleRobot

{

private RobotDrive drivetrain;

private Joystick leftStick;

private Joystick rightStick;

Page 8: FRC Java for Robotics Introduction

Sample Code IIIThe Constructor

• Called Once when Class object is Instantiated• Create and Initialize Instance Objects and Variables

public Team1279Robot() {

// create RobotDrive

drivetrain = new RobotDrive(1, 2);

// and joysticks

leftStick = new Joystick(1);

rightStick = new Joystick(2);

}

Page 9: FRC Java for Robotics Introduction

Sample Code IV

Methods Called by FMS • Don’t Change These!• Called by the Field Management System

public void autonomous() {

public void OperatorControl() {

Page 10: FRC Java for Robotics Introduction

Sample Code Vautonomous()

for (int i = 0; i < 4; i++) { //note turning rate and size of square is different //for every robot, adj delay, speed,turn for yours drivetrain.drive(0.5, 0.0); //50% fwd 0% turn Timer.delay(2.0); // wait 2 seconds drivetrain.drive(0.25, 0.75); //25% fwd 75% turn Timer.delay(1.0); // wait 1 second } drivetrain.drive(0.0, 0.0); //0% fwd 0% turn (stop)

Page 11: FRC Java for Robotics Introduction

Sample Code VIoperatorControl()

while (isOperatorControl() && isEnabled()){

// drive w/joysticksdrivetrain.tankDrive(leftStick,rightStick);Timer.delay(0.005);

}

Page 12: FRC Java for Robotics Introduction

Javadocs

Page 13: FRC Java for Robotics Introduction

Debugging

• println Output– Console– Debugger– Files

• NetBeans Debugger– Main Project only– Set at least 1 breakpoint– Download debug code– Attach debugger

Page 14: FRC Java for Robotics Introduction

Resources

• The reference guide for this presentation on the NJ/NY FIRST website

• www.coldfusion1279.com

• WPI website

• FIRST website


Top Related