javaworkshop part 3. instead of going over previous years’ code. we will rewrite 2014’s code...
TRANSCRIPT
Java WorkshopPart 3
Instead of going over previous years’ code. Wewill rewrite 2014’s code using the SimpleRobotTemplate
•
But first let’s get thru OOP 101•
Object OrientedProgramming
CLASS!•
A class is just a blueprint of the objectwill create
that we•
It can importanothermethods from
className of the class
Also tells you whatrelated to
it is
It can havemember variables
It MUST haveconstructor,
a
sometimes more than one
It can havemember functions
Extends: is-a relationship.•
A joystick is a GenericHID•
A joystick can do everything a GenericHID can.•
Implements: has relationship•
A joystick has all the functionsinterface
of IInputOutput•
Private functions
Public functions
Public vs. Private
Public keyword means it can be accessed withdot operator outside of the class
Private keyword means it can only be accessed WITHINthe class. Cannot be accessed with dot operator
Constants
Constants are often declared with•
public static final•
in some cases just static final•
Instantiation
To create an instant of an object usingblueprint.
the class•
You must ask the program to create an objectwith the keyword “new”
•
Once it’s instantiated, you will refer to yourobject by its name, not the name of the blueprint
•
O
How to instantiate an object
School lowellHighSchool = new School(697);•
Type of object MAGIC WORD T
MAKENEW
THINGS!!Name of object Constructor withargument
Make a new project and name it 2014Team4159Recode•
Name the class Main•
Outline of what physical components we have•
Drive Train•
6 Talons, 2 sides•
Pneumatics•
Shifting solenoid•
Pickup soleniods•
Pickup•
1 Talon•
Sensors•
Gyro•
2 Encoders•
Joysticks•
2 driving•
1 secondary•
Outline of desired functions•
Autonomous•
Roborealm interface to allow the “cheat”•
Multiple modes for auto in smartdashboard•
drive straight dump ball•
Teleop•
Tank drive, shifting•
Pickup, both the motor and raise/lower•
Since this program is relatively big, it’s best tokeep everything organized and as modularized as possible.
•
So we will create an IO class to store all of ourconnections to the physical world.
•
Just a bit more gardening to make it look evenmore organized
•
Now fill the stuff in with the pinout sheet. I’ll leavethat to you guys
•
However, you must use public static final as typesince you don’t want these things to change under any circumstances
•
Now we need to call the IO class at thebeginning of the main code so we can instantiate the physical components.
•
DO NOT INSTANTIATE THE IO CLASS
•
Now time for some classes for our individualcomponents of the robot
•
Drive•
we will write our own custom drive functionsto incorporate the gyro
•
Pickup•
Drive
Pickup
Teleop
Since teleop is simpler, lets writewhat we want to do in teleop first
the code for•
Drive(shifting)•
Pickup control(motor spin + raise/lower)•
Button actions•
DriveStick: 2/3 => low/high gear•
ShooterStick: 4/5 => lower/raise pickup•
ShooterStick: 3/Trigger => spins pickup•
Set refresh rate at 20ms•
Autonomous
We have to use SmartDashboard to select the
specific type of autonomous mode we’re doing
•
Make another class, name it DashboardManager•
Assume Roborealm gives a number of howmany “signals” it sees. When it sees more than0, it will return the boolean “shootReady” to true
•
Variable named BLOB_COUNT•
AutonomousModeActions
To prevent Main.java from getting messy andunreadable, we will create another class namedAutonomousModeActions
•
This class will store all the actions of the robotfor each cases during autonomous
•
DashboardManager
We have 4 predefined actions we can take•
Low goal blind auto = 1•
Low goal detection auto = 2•
Drive only auto = 3•
No Drive auto = 4•
Add those 4 variables as constants into theAutonomousModeActions class
•
Now write those 4 methods•
DashboardManager
Now we can setup a radio button list inSmartDashboard for each mode. Assign the int associated with each mode to the radio button.
•
Autonomous
Now going back to Main.java, we need to tellrobot what do to during Autonomous mode
the•
First need to stop all the motors just to makesure we’re not moving
•
use “getAutonomousMode” function you justwrote to get which mode of autonomous the driver selected
•
Since the mode selected will be returned as anint, use a switch to determine which mode you’re in and call the appropriate function in AutonomousModeActions class
•
We are DONE!!!!•
Now clean and build the program to make surethere’s no bug.
•