Presentation is loading. Please wait.

Presentation is loading. Please wait.

Java Workshop. Quick java review Goal: We want the application to tell us what the nth fibonacci number is. Components needed to achieve the goal: A Scanner.

Similar presentations


Presentation on theme: "Java Workshop. Quick java review Goal: We want the application to tell us what the nth fibonacci number is. Components needed to achieve the goal: A Scanner."— Presentation transcript:

1 Java Workshop

2 Quick java review Goal: We want the application to tell us what the nth fibonacci number is. Components needed to achieve the goal: A Scanner to listen to inputs A function to calculate the fibonacci numbers

3 How to instantiate an object School lowellHighSchool = new School(697); Type of object Name of object MAGIC WORD TO MAKE NEW THINGS!! Constructor with argument

4 Start a new java application in Netbeans Name it fibonacciNumberCalculator

5 Java has a scanner class part of the utility package, so we can just take it for granted. Instantiate a new scanner and write some code to listen to the input and spit it back out.

6 Java has a scanner class part of the utility package, so we can just take it for granted. Instantiate a new scanner and write some code to listen to the input and spit it back out.

7 But we don't want the program to just quit after putting in one number, we want it to keep on listening to our inputs. So let’s put it in a while-true loop

8

9 Well, how do we deal with the less intelligent people that can’t seem to enter whole numbers?? Let’s use a try-catch

10

11 Now what? Stuck in a unwanted feature! (infinite loop) So we need to make our own parsing logic First we need to check if there’s a NEW input Then we take the input and try to parse it as integer

12

13 Components needed to achieve the goal: A Scanner to listen to inputs A function to calculate the fibonacci numbers Now we can move on to the second component of the application

14 What is fibonacci number? It’s actually really easy to make a recursive function in computer language! So why don’t we calculate it with a recursive function!

15 Complete this function

16

17 Now let’s modify the program so we can interface the user input with our calculating function

18 GREAT ARE WE DONE YET?!?!?

19 Not quite. As you can see, recursive functions are one of the slowest functions in computer science. There are tricks to make it significantly faster by using more memory to store those values, but how can we make it faster when we don’t have a massive memory bank and very limited computing power like on a robot??

20 Thanks to this cool guy Jacques Philippe Marie Binet He found this! Well let’s not put his hard work up for display!

21 Now that we have 2 different methods that can calculate the fibonacci sequence, which one SHOULD we use? Why don’t we use both? Write a function that takes in the user input as argument, and automatically chooses which method to use.

22

23 FRC Java Difference: Written by WPI Slimmed down JVM Essentially Java ME (SE 1.2/3 ish) No generics, autoboxing

24 FIRST provided us with 3 basic styles to control the robot Simple Robot Iterative Robot Command Based Robot

25 Command Based Very very detailed control of every subsystem Requires A LOT of testing/fine tuning. Idea for teams with a lot of time at their hands.

26

27 Iterative Robot Much more automation and less programmer control than command base robot. Still allows for modularization in different modes Good for teams that is trying to optimize resource consumption on the cRIO.

28

29 Simple Robot Used by most first year teams without a strong programming team or is trying to switch over to Java Easy to use, best for testing prototypes!!! 4 Modes Autonomous, Teleop, Disabled, Testing

30

31 Our version It’s a 3 way hybrid that we wrote on our own. It’s written from ground up, with modularization in mind. It’s automated like simple and iterative robot, but also allows for command based controls and it’s been multi-threaded to optimize for performance

32

33 Simple Robot Let’s start with simple robot

34 To control anything, you must first register it with the system. For example, lets walkthrough how to setup a drivetrain. Physically we have: MotorSpeed ContollerPWM Signal YouJoystickcRIOSidecar

35 How to instantiate an object School lowellHighSchool = new School(697); Type of object Name of object MAGIC WORD TO MAKE NEW THINGS!! Constructor with argument

36 How to access class methods The Dot Operator!!! lowellHighSchool.getTeachersNames(); access the function written in School class that will return the names of the teachers of lowellHighSchool lowellHighSchool.enrollStudent(“John Smith”); enrolls the student named John Smith into lowellHighSchool

37 We are really just interfacing with the speed controllers via a joystick So we must register those two things with the program To do so, simply import the needed library and create an instant of the desired object

38 Now that we have the physical connections setup, lets tell the computer what to do with those connections We want to use the RobotDrive class and tell that class about these two connections we created

39 Our connection has been setup We told the cRIO where the two speed controllers are (port 1&2) and what we would like to use them for (RobotDrive) We told the robot that we have a joystick plugged into virtual usb hub 1 Now let’s do something with the system in operatorControl

40 Since it’s simple robot, we just need to dump code into the operatorControl function and the cRIO will run whatever it’s inside. We are accessing the arcadeDrive function written for RobotDrive class.

41 If you don’t know what to put inside an argument, like PIDController drivePID = new PIDController(?????????);

42 That takes you to the programming bible (API)

43 Find the name of the class you have questions about

44 This is what we’re interested in

45 Now we know what to put into the question marks: PIDController drivePID = new PIDController(?????????); You have to pick one of the overloaded constructors then instantiate your drivePID system

46 You can also find information about the class functions, that’s why it’s called the bible!

47 If you have time, try writing this Use a gyro to drive straight in autonomous mode for 10 seconds. You need to create an instance of a gyroscope, and use the reading from the gyroscope to correct the heading hint: use arcadeDrive as driving method instead.


Download ppt "Java Workshop. Quick java review Goal: We want the application to tell us what the nth fibonacci number is. Components needed to achieve the goal: A Scanner."

Similar presentations


Ads by Google