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.

Slides:



Advertisements
Similar presentations
Programming with Alice Computing Institute for K-12 Teachers Summer 2011 Workshop.
Advertisements

Objects. 2 Object Oriented Programming (OOP) OOP is a different way to view programming Models the real world A different view than Structured programming.
Robot Code MVRT 2010 – 2011 Season. Robot code controls the robot Robot Main.vi –Calls all the smaller SubVis Rules of programming the robot –Be careful.
Introduction to Programming using Matlab Session 2 P DuffourJan 2008.
Python Objects and Classes
Introduction to Recursion and Recursive Algorithms
Computer Programming Mr. José A. Ortiz Morris. Computer Language  Languages that the computer understands.  They are low level languages. (BINARY 1.
Lecture 4 Basic Scripting. Administrative  Files on the website will be posted in pdf for compatibility  Website is now mirrored at:
Add and Use a Sensor & Autonomous For FIRST Robotics
1. 2 LabVIEW for FRC Doug Norman National Instruments January 6, 2012.
1/1/ / faculty of Electrical Engineering eindhoven university of technology Introduction Part 3: Input/output and co-processors dr.ir. A.C. Verschueren.
Programming  Write a program to control the robot  Work closely with mechanical and electrical teams  Important to know what hardware will be.
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.
Lab6 – Debug Assembly Language Lab
©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. COMPSCI 125 Introduction to Computer Science I.
Programming an FRC Robot Choosing a Language 1. INDEX The Programing Languages and their Environments The Three Major Enviroments Java with the NetBeans.
How to turn on the robot How to start Bluetooth How to connect to robot How to initialize the robot How to not break the robot Sec Getting Started.
What is RobotC?!?! Team 2425 Hydra. Overview What is RobotC What is RobotC used for What you need to program a robot How a robot program works Framework.
Driver Station MVRT 2009 – 2010 Season. Add information Breadboard Classmate PC USB Hub Joysticks Stop Button.
Chapter 3.1:Operating Systems Concepts 1. A Computer Model An operating system has to deal with the fact that a computer is made up of a CPU, random access.
Week 4-5 Java Programming. Loops What is a loop? Loop is code that repeats itself a certain number of times There are two types of loops: For loop Used.
LabView Basics The Fighting Pi Controls Group. About LabView LabView is a highly adaptable programming GUI (Graphic User Interface) LabView compiles the.
Classes / Objects An introduction to object-oriented programming.
Methods Chapter 6. 2 Program Modules in Java What we call "functions" in C++ are called "methods" in Java Purpose Reuse code Modularize the program This.
FRC Java for Robotics Introduction Team 1279 ColdFusion January 8, 2011.
Why you should be using Version Control. Matt Krass Electrical/Software Engineer November 22, 2014.
Weston Schreiber & Joshua Gabrielse Robotics Summer Training Programming #1: EasyC Basics.
Welcome to CIS 083 ! Events CIS 068.
The New FTC Platform (Connecting your legacy hardware)
FRC Robot Framework Labview Made Easy (er) For FIRST Robotics 1.
Nonvisual Arrays and Recursion by Chris Brown under Prof. Susan Rodger Duke University June 2012.
Lecture 2: Classes and Objects, using Scanner and String.
ADTs and C++ Classes Classes and Members Constructors The header file and the implementation file Classes and Parameters Operator Overloading.
Parts of a Computer - Introduction
We will talking about story of JAVA language. By Kristsada Songpartom.
Fall 2002CS 150: Intro. to Computing1 Streams and File I/O (That is, Input/Output) OR How you read data from files and write data to files.
M1G Introduction to Programming 2 5. Completing the program.
Session 11 Intro to FRC API.
Lecture 4 Mechanisms & Kernel for NOSs. Mechanisms for Network Operating Systems  Network operating systems provide three basic mechanisms that support.
Unit 1: Computing Fundamentals. Computer Tour-There are 7 major components inside a computer  Write down each major component as it is discussed.  Watch.
CSE 143 Lecture 13 Recursive Backtracking slides created by Ethan Apter
1- How to connect the robot to the pc Sec Getting Started 3- How to move the robot Sec Scribbler movements 4- How to make a turn 11- How to.
12-Jun-16 Event loops. 2 Programming in prehistoric times Earliest programs were all “batch” processing There was no interaction with the user Input Output.
Review – Primitive Data What is primitive data? What are 3 examples of primitive data types? How is a piece of primitive data different from an object?
Introduction of Wget. Wget Wget is a package for retrieving files using HTTP and FTP, the most widely-used Internet protocols. Wget is non-interactive,
Today Threading, Cont. Multi-core processing. Java Never Ends! Winter 2016CMPE212 - Prof. McLeod1.
Creating Flexible, Script-Controlled Autonomous Software.
4. Java language basics: Function
Lesson #6 Modular Programming and Functions.
Key Ideas from day 1 slides
Event loops 16-Jun-18.
Lesson #6 Modular Programming and Functions.
Methods Chapter 6.
Application Development Theory
Lesson #6 Modular Programming and Functions.
Lesson 4: Overall Review and Assessment
Event loops.
Lesson 1: Fundamentals of Programming
Training 11/11/16 Robot Code (WPILib).
Coding Concepts (Basics)
Event loops 17-Jan-19.
Event loops 17-Jan-19.
Lesson #6 Modular Programming and Functions.
(Computer fundamental Lab)
Event loops 8-Apr-19.
Introducing JavaScript
Event loops.
Event loops.
Event loops 19-Aug-19.
Presentation transcript:

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 to listen to inputs A function to calculate the fibonacci numbers

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

Start a new java application in Netbeans Name it fibonacciNumberCalculator

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.

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.

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

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

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

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

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!

Complete this function

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

GREAT ARE WE DONE YET?!?!?

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??

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

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.

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

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

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.

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.

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

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

Simple Robot Let’s start with simple robot

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

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

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

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

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

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

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.

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

That takes you to the programming bible (API)

Find the name of the class you have questions about

This is what we’re interested in

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

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

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.