400 likes | 425 Views
Learn basics of Java programming for First Robotics Competition, understand object-oriented programming, keywords, classes, objects, and Eclipse IDE. Get insights on RoboRIO controls, PWM, and motor controllers.
E N D
Introduction to Java programmingfor 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.
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. • A method is a function that can be executed by a 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” • All Java class files end with the extension .java . • In order for a class to read another class, you 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.
What type of object is 9.0 ? • Integer • String • Double • Boolean
What type of object is “true”? • Double • String • Boolean • Integer
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. ;
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.
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) • Communicates with digital sensors • 4 Analog Ports (0-3) • Communicates with analog sensors Digital PWM Analog
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.
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
System.out.println(‘Message’)System.out.print(‘Message’)System.out.println(‘Message’)System.out.print(‘Message’)
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: jonathandaniel@fernbanklinks.com