Share
Embed
Intro to Java Development
Covers the basics of using Java for FRC robot development, and shows the concepts about how Git and GitHub work. There's nothing specifically in it about the cRIO, so it should apply just as well for the 2015 FRC season with the RoboRIO. This does not cover connecting (via SSH) to the RoboRIO, which will be an important capability in 2015.
FRC Team 4931
December 19, 2014
Transcript
45 slides
-
Source code • Text files that developers read and write
to tell the program what to do • The programming language dictates - the structure and format of the “code” - whether the files are compiled or interpreted -
Compiling Java code .java compile build source code 01101 10101
01101 10101 01101 10101 01101 10101 01101 10101 01101 10101 01101 10101 01101 10101 .class bytecode .jar archive -
Compiling Java code .java compile build .jar source code 01101
10101 01101 10101 01101 10101 01101 10101 01101 10101 01101 10101 01101 10101 01101 10101 .class bytecode .jar archive dependencies -
Running Java code .jar run .jar archive dependencies Java Runtime
Environment (JRE) all .jar files -
Deploying Java code to robot .jar deploy .jar archive dependencies
Java Runtime Environment (JRE) all .jar files cRIO or roboRIO requires your computer being connected to the robot’s network -
Our environment We’ve carefully set up our tools and our
source code to make this easier -
Compiling and deploying robot code .java compile source code .class
bytecode .jar archive .jar dependencies build deploy JRE all .jar files cRIO or roboRIO $ ant compile $ ant jar $ ant deploy $ ant deploy run or ‘deploy’ and ‘run’ require your computer being connected to the robot’s network -
Compiling and deploying robot code .java compile source code .class
bytecode .jar archive .jar dependencies build deploy JRE all .jar files cRIO or roboRIO $ ant compile jar deploy run ‘deploy’ and ‘run’ require your computer being connected to the robot’s network -
Compiling and deploying robot code .java compile source code .class
bytecode .jar archive .jar dependencies build deploy JRE all .jar files cRIO or roboRIO $ ant run ‘deploy’ and ‘run’ require your computer being connected to the robot’s network -
Compiling and deploying robot code For a specific robot program
in one of the folders/projects: $ cd <robotFolder> $ ant compile or $ ant deploy or $ ant run ‘deploy’ and ‘run’ require your computer being connected to the robot’s network -
Compiling and deploying robot code ‘deploy’ and ‘run’ require your
computer being connected to the robot’s network -
Within Eclipse 1. Select project 2. Select External Tools button
3. Click “Compile” menu item 4. Check output -
What is Git? • Program that keeps track of all
changes to a set of files • Keeps entire history in a repository - makes local file system look like the files at some point in time - user changes files locally, then commits into history • Every developer - has a local copy of the repository - can pull changes from other copies of the repository - can (sometimes) push changes into other copies of the repository -
Version 1 Version 2 Version 3 Version 4 Version 5
Version 6 History of files over time A0 B0 C0 time B0 A1 C1 A2 B0 C1 A2 B1 C1 A3 B2 C2 A3 B3 C2 D0 D0 D1 each of these is called a commit -
ab387de 8376def 12acef3 87bb322 501ae4 f634ca History of files over
time A0 B0 C0 time B0 A1 C1 A2 B0 C1 A2 B1 C1 A3 B2 C2 A3 B3 C2 D0 D0 D1 and are identified with a content-based secure hash ID -
A3 B3 C2 D1 ab387de 8376def 12acef3 87bb322 501ae4 f634ca
History of files over time Git can make the files and folders look exactly like any one of these commits last first -
B0 A1 C1 ab387de 8376def 12acef3 87bb322 501ae4 f634ca History
of files over time …which means we can go back in time to the way the source code looked at a specific point last first -
B0 A1 C1 ab387de 8376def 12acef3 87bb322 501ae4 f634ca History
of files over time We can even tag commits with meaningful labels. That makes it easy to see the code for a particular version or release or point in time. 2.0 1.0 -
ab387de 8376def 12acef3 87bb322 501ae4 f634ca History of files over
time A branch is simply a line of commits master We often call the primary branch “master” We can name branches anything -
ab387de 8376def 12acef3 87bb322 501ae4 f634ca History of files over
time master We can create branches at any time -
B0 B0 ab387de 8376def 12acef3 87bb322 501ae4 f634ca History of
files over time We might create a branch to fix a bug on an old version so we can release an update 2.0 1.0 A1 C1 acfef3 1.1 A1 C1 B0.1 -
ab387de 8376def 12acef3 87bb322 501ae4 f634ca History of files over
time master A3 B3 C2 D1 -
D1 C3 B4 E0 A3 A3 B3 C2 D1 ab387de
8376def 12acef3 87bb322 501ae4 f634ca History of files over time master feature1 A3 B3 C2 D1 B4 C3 E0 dae74c A4 E1 9893a4 We call these local branches on which we work topic branches git checkout -b feature1 master -
D1 A3 B4 C3 E0 D1 C3 B4 E0 A3
ab387de 8376def 12acef3 87bb322 501ae4 f634ca History of files over time master feature1 dae74c A4 E1 9893a4 But how do we get the commits on our topic branch into the ‘master’ branch? After all, these are only on our local machines. -
Git is distributed ! (which means we can pull from
and push to other repositories) -
Remember when you set up your repository? frc-4931/2014 jsmith/2014 fork
2014 Jane’s computer github.com sdaniels/2014 kthompson/2014 2014 Sid’s computer 2014 Kathy’s computer clone clone clone -
Git knows about the other repositories frc-4931/2014 jsmith/2014 2014 Jane’s
computer github.com “origin” “upstream” -
Git knows about the other repositories frc-4931/2014 jsmith/2014 2014 Jane’s
computer github.com gets ‘master’ branch from “upstream” repository (only what we don’t already have) git pull upstream master We can do things like: -
Git knows about the other repositories frc-4931/2014 jsmith/2014 2014 Jane’s
computer github.com git pull upstream master git push origin master We can do things like: copies ‘master’ branch into “origin” repository -
Sharing topic branches via GitHub frc-4931/2014 jsmith/2014 2014 Jane’s computer
github.com git pull upstream master git push origin master We can do things like: copies ‘feature’ branch into “origin” repository git push origin feature1 feature1 feature1 -
Request your commits get merged into master frc-4931/2014 jsmith/2014 2014
Jane’s computer github.com feature1 pull-request feature1 Use github.com to create a pull request for “feature1” branch Anyone watching frc-4931/2014 gets an email notification -
Commits are merged into ‘upstream’ repository frc-4931/2014 jsmith/2014 2014 Jane’s
computer github.com feature1 feature1 merge pull-request merges commits from ‘feature1’ into ‘master’ branch Someone reviews pull- request. If acceptable, they merge it into the ‘master’ branch. -
The ‘master’ branch now has the new commits frc-4931/2014 jsmith/2014
2014 Jane’s computer github.com feature1 feature1 master But you don’t have them yet! (The commits are on ‘feature1’ branch, not ‘master’) -
Pull the latest ‘master’ from the official repository frc-4931/2014 jsmith/2014
2014 Jane’s computer github.com gets ‘master’ branch from “upstream” repository git pull upstream master master feature1 feature1 master (We already have the new commits, but they’re on ‘feature1’ branch, so this operation simply updates ‘master’ branch to have those commits.) -
Clean up your local topic branches frc-4931/2014 jsmith/2014 2014 Jane’s
computer github.com git branch -r feature1 master feature1 feature1 master git push origin :feature1 -
Others update their ‘master’ the same way frc-4931/2014 jsmith/2014 2014
Jane’s computer github.com sdaniels/2014 kthompson/2014 2014 Sid’s computer 2014 Kathy’s computer master master master master master git pull upstream master git pull upstream master -
Deploy latest code on robot First get the latest from
‘master’ and compile…! $ git checkout master $ git pull upstream master $ cd <RobotProgramFolder> $ ant compile Then connect to robot’s network, deploy and run:! $ ant deploy run -
Make changes to robot code (part 1 of 2) First
make sure there’s an issue for your work.! Then get the latest from ‘master’ …! $ git checkout master $ git pull upstream master $ git checkout -b <topicBranchName> master Make changes and compile! $ cd <RobotProgramFolder> $ ant compile Connect to robot network, and compile/run on robot:! $ ant deploy run -
Make changes to robot code (part 2 of 2) When
everything works, commit and push to your fork:! $ git commit . $ git push origin <topicBranchName> Finally use github.com to create a pull-request!