View Single Post
  #1   Spotlight this post!  
Unread 05-02-2013, 16:33
DPG2013 DPG2013 is offline
Registered User
FRC #4163
 
Join Date: Jan 2012
Location: georgia
Posts: 7
DPG2013 is an unknown quantity at this point
WPI cookbpook help

I am kind of new to Java programming and I was looking through the WPI cookbookhere and under the command robot tutorial I saw this:

public class Chassis extends Subsystem {
public static final int LEFT_MOTOR_PORT = 2;
public static final int RIGHT_MOTOR_PORT = 1;
public static final double TURN_AMOUNT = 1.0;
public static final double FORWARD_SPEED = 1.0;
private static Chassis instance = null;
private RobotDrive drive;
public static Chassis getInstance() {
if(instance == null) {
instance = new Chassis();
instance.setDefaultCommand(new DriveWithJoystick());
}
return instance;
}
private Chassis() {
drive = new RobotDrive(LEFT_MOTOR_PORT, RIGHT_MOTOR_PORT);
drive.setSafetyEnabled(false); // to simplify explanation (not good practice)
}
public void straight() {
drive.arcadeDrive(-FORWARD_SPEED, 0.0); // start driving forward
}

public void turnLeft() {
drive.arcadeDrive(0.0, TURN_AMOUNT); // start turning
}
public void driveWithJoystick() {
drive.arcadeDrive(OI.getInstance().getJoystick());
}


I pretty much understand every thing except the instance part. What is a instance and how is it being used here.
Reply With Quote