Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
INTRODUCTION TO JAVA PROGRAMMING FOR THE FIRST ROBOTICS COMPETITION JONATHAN DANIEL HEAD PROGRAMMER FERNBANK LINKS DISCLAIMERS • This session WILL NOT teach you all of Java. • This session WILL teach you how to use your knowledge of Java with the FRC Java Libraries. WHAT IS PROGRAMMING? PROGRAMMING IS… • Computer programming is the craft of writing useful, maintainable, and extensible source code which can be interpreted or compiled by a computing system to perform a meaningful task. • FRC Programming Languages • • • • C++ Java Python LabVIEW REVIEW OF JAVA • Java is an object-oriented programming language. • Object-oriented programming (OOP) is a programming language model organized around objects rather than "actions" and data rather than logic. • A Java program can be separated into different classes, which are templates for creating objects with different behaviors. WHAT’S IN A CLASS? • Java classes contain methods and variables. • All Java class files end with the extension .java . • A method is a function that can be executed by a • In order for a class to read another class, you class. Sometimes, you will have a method that returns some form of data to the robot. • One method could be to ask the robot how much battery power it has. • A variable is a container for data. • Variable X = 9 • Variable Y = “These three words” have to use an import statement. • When you use an import statement, all of the public methods in that class will be absorbed into your new class. • For example, you might import class1 into class2, so you can use class1’s methods! IMPORTANT JAVA KEYWORDS • A keyword is a special word/phrase that is used to define some aspect of a class, method or variable. • Public • All other classes can see this method/variable. • Private • This method/variable will only be seen in its current class. • Protected • This method/variable can only be seen by subclasses of the current class. • Extends • This is when the class becomes a subclass of another class. • Public class Dog extends Animal • Import • When you load all of another class’s public methods/variables into your own class. • New • Creates a new object of a certain class. TYPES OF OBJECTS • Objects are digital items that can be referenced by computers. • There are many types of objects, but these are the most common ones. • Integer • Any number that doesn’t contain a decimal point. • Double • Any number that does contain a decimal point. • Boolean • A binary variable that can be interpreted as true or false. • String • Any text that is surrounded by double quotation marks. • Void • This will only be used with methods, and it means that the method returns nothing. • Static • No matter how many objects of this type are created, there will only be one of this method OR variable. LET’S DO A QUICK QUIZ! WHAT TYPE OF OBJECT IS 9.0 ? A. Integer B. String C. Double D. Boolean WHAT TYPE OF OBJECT IS “TRUE”? A. Double B. C. String D. Integer Boolean THE MOST IMPORTANT ASPECT OF JAVA! • Semicolons are one of the most important symbols in Java! • Unless you are creating a method or loop, you have to use a semicolon to end the a line of code. • This lets the program know that it has reached the end of a line and it needs to move to the next one. WHAT DO I USE TO PROGRAM MY ROBOT? INTRODUCE THE ECLIPSE IDE PACKAGE EXPLORER • The package explorer is a file explorer for all of your Eclipse Projects. • Eclipse Project = Java Program • Packages are folders that can be used to contain java classes • When you create a robot project using the iterative template, Eclipse will create a default package and a default class. • Org.usfirst.frc.team0000.robot • Robot.java. • Depending on your robot’s functions, you may want to create different packages for each function. CONSOLE • Will document the deployment of your code to the robot, so you will know if it was successful. THE PROGRAMMABLE ELECTRONICS ROBORIO • Main Robot Controller • RIO to PC Communication • Ethernet • USB Cable • Wireless (if Radio is configured) • 10 Pulse Width Modulation Ports (0-9) • Controls the Motors • 10 Digital Ports (0-9) Digital PWM • Communicates with digital sensors • 4 Analog Ports (0-3) • Communicates with analog sensors Analog JOYSTICKS MOTOR CONTROLLER • PWM - Pulse Width Modulation • To control the speed of the motor, the speed controller switches the full input voltage on and off very quickly. • There are ten PWM ports on the RoboRIO, and each port controls one motor. • Most PWM classes use set(speed) methods to determine the speed of the motor. • The parameter is a double value that ranges from -1.0 to +1.0, with 1.0 being full forward and -1.0 being full reverse. • Inversion of Motors • Typically, you will need to set one of your motors to interpret +1.0 as -1.0 by using setInverted(). • CAN – Controller Area Network • More advanced form of control that allows for feedback. LET’S PROGRAM A ROBOT TO DRIVE AROUND! CONTROLLING PNEUMATICS THE MAIN ELECTRONICS OVERVIEW OF PNEUMATICS Outside Environment Compressor Air Tanks Solenoids Actuators PNEUMATICS OVERVIEW – PNEUMATICS CONTROL MODULE • The Pneumatics Control Module is the mechanism that is responsible for the management of the compressors and solenoids on the robot. • 8 Solenoid Ports • 8 Single Solenoids • 4 Double Solenoids • 1 Compressor Port • Pressure Relief Valve Port WHY USE PNEUMATICS? LET’S PROGRAM A SHIFTING DRIVETRAIN! SENSORS WHY USE A SENSOR? SYSTEM.OUT.PRINTLN(‘MESSAGE’) SYSTEM.OUT.PRINT(‘MESSAGE’) THE SENSOR FAMILY TREE Sensors Analog Gyro Encoder Accelerometer Digital Encoder Limit Switch ANALOG VS. DIGITAL Analog Sensors • These sensors can return any value based on whatever they are measuring. • Encoders act like Analog Sensors, but are technically digital sensors. Digital Sensors • Digital Sensors return one of two values, either a 1 or a 0. • Encoders are the odd member of the family. LET’S HAVE OUR ROBOT TELL US ABOUT OUR GYRO! CAMERAS IN FRC! CAMERAS LET’S PROGRAM OUR ROBOT TO STREAM VIDEO! NETWORKING • If you are using an IP Camera, you will have to assign it an IP Address. • 10.TE.AM.11 • A good static address should be safe from other internet devices. • 10.08.00 for Team 800 • Subnet 255.255.255.0 • 10.44.68.11 • The FMS allows each team to use a bandwidth of 7 megabits/second. • 6 Mbps after driver station packets. • If you plan on streaming your camera to the driver station, you will probably need to use compression. RESOURCES – FRC STACK • WPILib ScreenSteps Tutorials • https://wpilib.screenstepslive.com/s/4485 • API Documentation • http://first.wpi.edu/FRC/roborio/release/docs/java/ • Chief Delphi • https://www.chiefdelphi.com/ • GitHub • GitHub Student Developer Pack: https://education.github.com/pack • Fernbank LINKS GitHub: https://www.github.com/fernbanklinksrobotics • Team GitHub List • http://bit.ly/TeamGithubs RESOURCES – LEARNING JAVA • Codecademy • www.codecademy.com • Start:Code • Classes in the Decatur Area • www.startcode.net • AP Computer Science • Teaches CS with Java QUESTIONS? EMAIL: [email protected]