140 likes | 295 Views
FRC Java for Robotics Introduction. Team 1279 ColdFusion January 8, 2011. NetBeans IDE. Full featured development environment Edit Build Debug Deploy Bundled with the latest Java SE JDK FRC plug-ins for WPILibJ. Advantages. Widely Used AP Test means school support Many Resources
E N D
FRC Java for RoboticsIntroduction Team 1279 ColdFusion January 8, 2011
NetBeans IDE • Full featured development environment • Edit • Build • Debug • Deploy • Bundled with the latest Java SE JDK • FRC plug-ins for WPILibJ
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
Disadvantages • New to FIRST • Still Bugs & Rough Edges • Teams have, at most ,1 season of experience • Fewer Robotics resources • Not much existing code • CAN not up to C++ • Not 100% standard Java • Based in Java ME • No formatted output (yet)
Sample CodeWalk-through • Example from SimpleRobotTemplate • Check IterativeRobot too • Good Sample code • Described in the Getting Started Guide • Still a typo or two • Suggest everyone new try it
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;
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;
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); }
Sample Code IVMethods Called by FMS • Don’t Change These! • Called by the Field Management System public void autonomous() { public void OperatorControl() {
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)
Sample Code VIoperatorControl() while (isOperatorControl() && isEnabled()) { // drive w/joysticks drivetrain.tankDrive(leftStick,rightStick); Timer.delay(0.05); }
Debugging • println Output • Console • Debugger • Files • NetBeans Debugger • Main Project only • Set at least 1 breakpoint • Download debug code • Debugger now attaches automatically
Resources • The reference guide for this presentation on the NJ/NY FIRST website • www.coldfusion1279.com • WPI website • FIRST website