Go to Post There are few times I sleep so soundly as I do after an FRC build season and regional. - JamesCH95 [more]
Home
Go Back   Chief Delphi > Technical > Programming > Java
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rate Thread Display Modes
  #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
  #2   Spotlight this post!  
Unread 05-02-2013, 18:35
gixxy's Avatar
gixxy gixxy is offline
Programming and Arduino Mentor
AKA: Gustave Michel III
FRC #3946 (Tiger Robotics)
Team Role: Mentor
 
Join Date: Nov 2011
Rookie Year: 2012
Location: Ruston, LA
Posts: 207
gixxy is on a distinguished road
Re: WPI cookbpook help

A class is the blueprint for an object.

An instance is an object of a class.

Basically what that code is saying is: "Only one instance of Chassis will exist, and it is this one. In order to use it you need to get it from me."

another example: the drive object in that code is an instance of RobotDrive.

Code:
private RobotDrive drive;
__________________
Programmer - A creature known for converting Caffeine into Code.
Studying Computer Science @ Louisiana Tech University
Associate Consultant @ Fenway Group

2012-13: 3946 - Head of Programming, Electrical and Web
2014 - 3468 - Programming Mentor
2015 - Present - Lurker
Reply With Quote
  #3   Spotlight this post!  
Unread 05-02-2013, 19:20
DPG2013 DPG2013 is offline
Registered User
FRC #4163
 
Join Date: Jan 2012
Location: georgia
Posts: 7
DPG2013 is an unknown quantity at this point
Re: WPI cookbpook help

That makes sense thank you.
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 09:51.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi