javaworkshop part 3. instead of going over previous years’ code. we will rewrite 2014’s code...

34
Jav a Worksho p Part 3

Upload: lily-douglas

Post on 17-Dec-2015

218 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: JavaWorkshop Part 3. Instead of going over previous years’ code. We will rewrite 2014’s code using the SimpleRobot Template But first let’s get thru OOP

Java WorkshopPart 3

Page 2: JavaWorkshop Part 3. Instead of going over previous years’ code. We will rewrite 2014’s code using the SimpleRobot Template But first let’s get thru OOP

Instead of going over previous years’ code. Wewill rewrite 2014’s code using the SimpleRobotTemplate

But first let’s get thru OOP 101•

Page 3: JavaWorkshop Part 3. Instead of going over previous years’ code. We will rewrite 2014’s code using the SimpleRobot Template But first let’s get thru OOP

Object OrientedProgramming

CLASS!•

A class is just a blueprint of the objectwill create

that we•

Page 4: JavaWorkshop Part 3. Instead of going over previous years’ code. We will rewrite 2014’s code using the SimpleRobot Template But first let’s get thru OOP

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

Page 5: JavaWorkshop Part 3. Instead of going over previous years’ code. We will rewrite 2014’s code using the SimpleRobot Template But first let’s get thru OOP

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•

Page 6: JavaWorkshop Part 3. Instead of going over previous years’ code. We will rewrite 2014’s code using the SimpleRobot Template But first let’s get thru OOP

Private functions

Public functions

Page 7: JavaWorkshop Part 3. Instead of going over previous years’ code. We will rewrite 2014’s code using the SimpleRobot Template But first let’s get thru OOP

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

Page 8: JavaWorkshop Part 3. Instead of going over previous years’ code. We will rewrite 2014’s code using the SimpleRobot Template But first let’s get thru OOP

Constants

Constants are often declared with•

public static final•

in some cases just static final•

Page 9: JavaWorkshop Part 3. Instead of going over previous years’ code. We will rewrite 2014’s code using the SimpleRobot Template But first let’s get thru OOP

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

Page 10: JavaWorkshop Part 3. Instead of going over previous years’ code. We will rewrite 2014’s code using the SimpleRobot Template But first let’s get thru OOP

O

How to instantiate an object

School lowellHighSchool = new School(697);•

Type of object MAGIC WORD T

MAKENEW

THINGS!!Name of object Constructor withargument

Page 11: JavaWorkshop Part 3. Instead of going over previous years’ code. We will rewrite 2014’s code using the SimpleRobot Template But first let’s get thru OOP

Make a new project and name it 2014Team4159Recode•

Name the class Main•

Page 12: JavaWorkshop Part 3. Instead of going over previous years’ code. We will rewrite 2014’s code using the SimpleRobot Template But first let’s get thru OOP

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•

Page 13: JavaWorkshop Part 3. Instead of going over previous years’ code. We will rewrite 2014’s code using the SimpleRobot Template But first let’s get thru OOP

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•

Page 14: JavaWorkshop Part 3. Instead of going over previous years’ code. We will rewrite 2014’s code using the SimpleRobot Template But first let’s get thru OOP

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.

Page 15: JavaWorkshop Part 3. Instead of going over previous years’ code. We will rewrite 2014’s code using the SimpleRobot Template But first let’s get thru OOP

Just a bit more gardening to make it look evenmore organized

Page 16: JavaWorkshop Part 3. Instead of going over previous years’ code. We will rewrite 2014’s code using the SimpleRobot Template But first let’s get thru OOP

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

Page 17: JavaWorkshop Part 3. Instead of going over previous years’ code. We will rewrite 2014’s code using the SimpleRobot Template But first let’s get thru OOP

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

Page 18: JavaWorkshop Part 3. Instead of going over previous years’ code. We will rewrite 2014’s code using the SimpleRobot Template But first let’s get thru OOP

Now time for some classes for our individualcomponents of the robot

Drive•

we will write our own custom drive functionsto incorporate the gyro

Pickup•

Page 19: JavaWorkshop Part 3. Instead of going over previous years’ code. We will rewrite 2014’s code using the SimpleRobot Template But first let’s get thru OOP

Drive

Page 20: JavaWorkshop Part 3. Instead of going over previous years’ code. We will rewrite 2014’s code using the SimpleRobot Template But first let’s get thru OOP

Pickup

Page 21: JavaWorkshop Part 3. Instead of going over previous years’ code. We will rewrite 2014’s code using the SimpleRobot Template But first let’s get thru OOP

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)•

Page 22: JavaWorkshop Part 3. Instead of going over previous years’ code. We will rewrite 2014’s code using the SimpleRobot Template But first let’s get thru OOP

Button actions•

DriveStick: 2/3 => low/high gear•

ShooterStick: 4/5 => lower/raise pickup•

ShooterStick: 3/Trigger => spins pickup•

Set refresh rate at 20ms•

Page 23: JavaWorkshop Part 3. Instead of going over previous years’ code. We will rewrite 2014’s code using the SimpleRobot Template But first let’s get thru OOP
Page 24: JavaWorkshop Part 3. Instead of going over previous years’ code. We will rewrite 2014’s code using the SimpleRobot Template But first let’s get thru OOP

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•

Page 25: JavaWorkshop Part 3. Instead of going over previous years’ code. We will rewrite 2014’s code using the SimpleRobot Template But first let’s get thru OOP

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

Page 26: JavaWorkshop Part 3. Instead of going over previous years’ code. We will rewrite 2014’s code using the SimpleRobot Template But first let’s get thru OOP

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•

Page 27: JavaWorkshop Part 3. Instead of going over previous years’ code. We will rewrite 2014’s code using the SimpleRobot Template But first let’s get thru OOP

Add those 4 variables as constants into theAutonomousModeActions class

Now write those 4 methods•

Page 28: JavaWorkshop Part 3. Instead of going over previous years’ code. We will rewrite 2014’s code using the SimpleRobot Template But first let’s get thru OOP
Page 29: JavaWorkshop Part 3. Instead of going over previous years’ code. We will rewrite 2014’s code using the SimpleRobot Template But first let’s get thru OOP

DashboardManager

Now we can setup a radio button list inSmartDashboard for each mode. Assign the int associated with each mode to the radio button.

Page 30: JavaWorkshop Part 3. Instead of going over previous years’ code. We will rewrite 2014’s code using the SimpleRobot Template But first let’s get thru OOP
Page 31: JavaWorkshop Part 3. Instead of going over previous years’ code. We will rewrite 2014’s code using the SimpleRobot Template But first let’s get thru OOP

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

Page 32: JavaWorkshop Part 3. Instead of going over previous years’ code. We will rewrite 2014’s code using the SimpleRobot Template But first let’s get thru OOP

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

Page 33: JavaWorkshop Part 3. Instead of going over previous years’ code. We will rewrite 2014’s code using the SimpleRobot Template But first let’s get thru OOP
Page 34: JavaWorkshop Part 3. Instead of going over previous years’ code. We will rewrite 2014’s code using the SimpleRobot Template But first let’s get thru OOP

We are DONE!!!!•

Now clean and build the program to make surethere’s no bug.