2016 software.html - frc971/website GitHub Wiki

Source Code

The 2016 robot code is available for current team members to access and create.  See the robot code notes below for details on how to do this.

Here is a snapshot of our robot source code taken after the 2016 Championship Event (May 2016).  Expand it with "tar -xvf 2016_post_champs_code.tar.xz".  This has been tested on a Debian 64bit Linux system.  Here is a snapshot of the main 971 2016 source code taken on January 4, 2017.  Here is a snapshot of the 971 2016 vision code taken on January 4, 2017.  This will be our final posting of the 2016 source code.  Here are listings of the final 2016 main code and visiion code snapshots.

Robot Code

We use the git source code control system for the robot code and gerrit for code review.  You can browse the git code repository by going to https://software.frc971.org/gerrit and using your team svn account credentials.  Log in to gerrit and add your name and email address to your account.  Then, have Austin or Brian add you to the '971 Software Developers' group.  Ask one of them to do this at a team meeting or email them.  If you don't see the 971-Robot-Code project on gerrit, then you have not been added to the '971 Software Developers' group.

Building the code requires setting up an appropriate environment, using sources contained in the team's APT repository. Please read through the README file included in the top directory of the code folder for more information about how to go about doing this.

Terminology

Here's a list of some basic terminology related to the code which is helpful for gaining a basic understanding.

  • commit (git) = A snapshot of all of the source code with an author, commit message, data, and some other metadata.
    • Commits are commonly refererred to by their SHA1 hash, which is unique for each. These look like 4a644e44e66ec7af982d145cdc861338d02de462 (complete) or 4a644e4 (abbreviated; any unique prefix works most places that want a commit ID).
  • repository (git) = A folder with git commits and branches, and possibly a "currently checked out" copy of the code.
    • This "currently checked out" version of the code is called a "working tree".
    • One unique part of git is that the repository on each person's computer that they work from is a complete repository with all the history.
  • branch (git) = A "sticky note" referring to a commit.
    • Many of the git tools default to your "currently checked out" branch. This means they do things like update it when you make new commits.
    • gerrit:master is the branch we generally work off of.
    • Each repository has its own set of branches, possibly with overlapping names, so in order to uniquely identify a branch you have to identify the repository it's in too. gerrit/master and gerrit:master are two common ways to do that.
    • Branches under the gerrit:/unreviewed/{username}/ namespace are "scratch" branches by each user that have not necessarily been reviewed or anything. These are useful for sharing work-in-progress code.
  • patch/diff = The differences between two sets of files.
    • This is generally between two commits, often different patch sets of the same change.
  • change (Gerrit) = A single logical modification to the code. This will eventually end up as a single commit in the git history.
    • A change has one or more patch sets (see below).
    • Each change has an ID, which shows up in the commit message for each patch set and looks like I8ee4ac19705aeba179124c44f9b53d53b450ca49.
    • They also have a number, which increases by 1 for each new one (like 336).
    • Accessible with URLs like https://software.frc971.org/gerrit/#/c/336/.
  • patch set (Gerrit) = A git commit (see above) representing a specific version of a change (see above).
    • Each patch set for a single change is a whole new version; they do not build on top of each other.
    • The change ID needs to be in the message of each commit because this is how Gerrit knows that they are part of the same change.
    • Each one has a number which starts at 1.
    • You can access a specific one with a URL like https://software.frc971.org/gerrit/#/c/336/8. The version without the last number goes to the latest one.

Late breaking news on the build system.  I don't know how this works with all of the material below, but I do know that it is important.

2015-11-01: Building code with Bazel + Jessie - From Brian

We've got all of the code building with Bazel on Debian Jessie now. We're planning to migrate away from Gyp on Wheezy soon. The README.md in the git repository has directions for setting up a computer (to download the 971 team software, build/compile it, and download it to a robot - Michael). I would like to get everybody migrated off of Gyp soon so we can remove it and stop having to worry about updating two sets of build system files.
Some context for anybody who doesn't know already: we've been using Gyp for couple of years because it was the best build system we could find. However, since then, Google has released their internal build tool (called Bazel) which is nicer in many ways.
We're migrating build systems and operating system versions at the same time because it's easier to only have two supported combinations vs four.
The Bazel infrastructure doesn't currently support all of the configurations the Gyp one does, which I'm working on. I want to finish that before getting rid of the Gyp stuff. Austin has successfully used Bazel to download code to a robot though.
Upgrading a Debian machine is generally pretty easy, and they have good instructions. Some people prefer reinstalling from scratch too.
I recently created a bazel mirror on our Gerrit to keep track of which version we're using. We might do some reviews there, but my release process is mostly picking a version and then cherry-picking/reverting a few commits so it works.
Feel free to contact me with any questions,
Brian Silverman
2015-11-01: Follow on to Austin's 2015-10-28 message - From Phil Schrader
I've updated the Vagrantfile to install the packages (including bazel) that Austin's mentioned.
Find it here: https://software.frc971.org/svn/frc971/2016/trunk/src/vagrant_dev_vm

If anyone has a chance, to try it out, please let me know!

I have not yet tried building robot code, but I should get around to that tonight or tomorrow.
 
2015-10-28: Building on a vagrant machine notes - From Austin
You need to install openjdk8 (I used Peloton's packages) and bazel from somewhere.
Then, you need to add the following to /etc/apt/sources.list.d/llvm-3.6.list
$ cat /etc/apt/sources.list.d/llvm-3.6.list 
# llvm-3.6
deb  http://llvm.org/apt/jessie/ llvm-toolchain-jessie-3.6 main
deb-src  http://llvm.org/apt/jessie/ llvm-toolchain-jessie-3.6 main
Then, install
sudo apt-get install git clang-3.6 ruby clang-format-3.5
  (Brian added a comment on the packages: You also need python (and maybe python3) (I know python is necessary for downloading) unless something else drags that in already)
 
You should then be ready to check out the repo and build.

Ben Fredrickson short cheat sheet of commands is:

<text> means you should type something specific here

Get the code on a new computer:

Before making any changes in the code, make new branch to work on:

  • git checkout -b <username>/<project title>

The project title can be anything you want.  It is local to your copy of the git project. 

Add your new and changed files:

  • git add <list of file names>

Commit changes locally:

  • git commit -m "<project title>: <description>"

Push your changes to the server for backup and sharing:

  • git push origin HEAD:unreviewed/<username>/<project title>

To get these changes from the server to work on:

  • git fetch origin unreviewed/ <username>/<project title>
  • git co FETCH_HEAD
  • git checkout -b new_branch_name # where new_branch_name is whatever local name you want to give this branch.

Making a code review:

Make sure your master is up to date and you are on your branch. 

  • git co master
  • git pull origin master
  • git co -

Rebase all your changes onto master:

  • git rebase -i master

Here you should squash all your commits into a single commit for review. In the menu that pops up change all the commit line to "squash" except the first line which should be left as "pick".

Now push your commit  for review:

  • git push origin HEAD:refs/for/master

If this works you are done.

If the following command is in the error:
gitdir=$(git rev-parse --git-dir); scp -p -P 29418 <username>@software.frc971.org:hooks/commit-msg ${gitdir}/hooks/
you can use it if the network you are on will allow port 29418 access to the school.  If it does not work, then run this one instead:
gitdir=$(git rev-parse --git-dir) && curl --insecure -u <username> -o ${gitdir}/hooks/commit-msg https://software.frc971.org/gerrit/tools/hooks/commit-msg && chmod +x ${gitdir}/hooks/commit-msg
The first one works for anybody who has a gerrit account and the scp part of the command connects to the gerrit ssh server on port 29418.  Port 29418 is not available on some corporate networks and the NASA guest network so use the second option with https for those networks.  Jack opened port 29418 for the team to use to on February 7, 2015.
Then run:
 

  • git commit --amend

And try the push again:

  • git push origin HEAD:refs/for/master

Adding changes to existing code review:  (TODO this part is incomplete. git rebase master again?)

  • git checkout <your branch that is in review>
  • Make your changes.
  • git add <files>
  • git commit --amend
  • git push origin HEAD:refs/for/master 

Brian gave me the following command as I was trying to change code on the robot and needed to do a git update.

   `git add` any changes you want to keep, then `git stash --keep-index` 

Checking out the latest code

Ask Brian or Austin what code you should be using.  They will give you a link like 
 https://software.frc971.org/gerrit/#/c/336 
Browse to that link and click on the "Download" tab in the upper right hand corner of the page.  Then copy the downlaod checkout command by clicking on the copy to clipboard icon on the right.  Paste that into your linux terminal.  This will "fetch" the version you want and checkout the code. 

The outstanding changes can be viewed on Gerrit here.  

Building the code

Building the code requires setting up an appropriate environment, using sources contained in the team's APT repository. Please read through the README file included in the top directory of the code folder for more information about how to go about doing this.

Running the code on the robot

To deploy the code to the robot, run

  • bazel run -c opt --cpu=roborio //y2016:download_stripped -- roboRIO-971-frc.local

If the code does not start up when the robot is turned on, then you need to run the frcEnableTBLStartupApp.sh script in /usr/local/frc/bin.  It will enable starting code when the robot is turned on.

After doing this for the Third Robot, the robot code did not start up automatically.  We traced through the script and found a configuration file in something like /etc/natinst/share/lvtc.config.  The last line in the configuration file had "False" for some configuration parameter that suggested it was supposed to run at boot time.  We changed this to "True", rebooted, and the code started at boot time.  Michael, Campbell, and Adam.  Oct 30, 2016.

After that, you need to copy the aos/config/robotCommand script to /home/lvuser.

June 20, 2018: Brian, Andrew, Anya, James, and Michael had to run 

To restart the robot code run: "/usr/local/frc/bin/frcKillRobot.sh -tr" to get the robot code to start at boot.  Don't know why this worked.

  • touch /home/admin/robot_code/core 

Running the code

Create a fresh log file on the robot with

  • touch ~/robot_code/binary_log_writer

 

Use this to reboot the robot:

  • shutdown -r now

Commands for looking at the robot logs
   cd /media/sda1    # Use "mount" to figure out where the external USB drive for logs is mounted.
   ~/robot_code/log_displayer -f -l DEBUG -n fridge | fgrep .Position

You often want something from .Status instead of .Position as in that command. It depends if you want encoder value, potetiometer value, zeroed value, or something else.

The following is useful to check the elevator height zeroing. The elevator timing belt teeth are 0.009 m apart (9 mm). Errors in the elevator height that are multiples of this are due to the timing belt skipping:

   ~/robot_code/log_displayer -f -l DEBUG -n fridge | fgrep .Status 

# Use the following to see a list of flags for the log_displayer routine.
~/robot_code/log_displayer --help

~/robot_code/log_displayer -f    # Shows the log file live as it's being written.
# The "-f" says to follow the log file as it is being generated.  This is useful for seeing what is going on on the robot as you are view the log file output.  If the 2014 shooter is e-stopped, the output will say so repeatedly in the "-f" output.
# If you want to see the current state of the buttons every time it gets read, then run
log_displayer -f -l DEBUG -n wpilib_interface.DSReader | joystick_state

We used to use PNY Turbo 64GB USB 3.0 Flash Drive - P-FD64GTBOP-GE for the log files.  They cost $20 each.  They kept failing so we changed to SanDisk Ultra Fit CZ43 64GB USB 3.0 Low-Profile Flash Drive Up To 130MB/s Read- SDCZ43-064G-G46 for $17 from Amazon for the 2016 competition season and they have worked flawlessly and are smaller than the PNY drives.

Working with and Changing robot code

To change the height of the fridge after the robot deposits a stack on the platform or make some other such change.  Looking in files like frc971/joystick_reader.cc and/or frc971/actors/score_actor.cc.  The first one passes parameters (i.e. the ending height of the elevator) to the score_actor.cc code which uses them to move the robot elevator and arm around.

 

Configuring a Debian Computer to Connect to the roboRIO

To be able to connect to the 2015 robot, the router must be running mdns (bonjour) also called zero-conf according to Phil.

The Bonjour Support page says to install it with 
     sudo apt-get install avahi-daemon libavahi-compat-libdnssd1 mdns-scan

# Use mdns-scan to search the network for devices.
     mdns-scan

# Use ssh to connect to the admin user on the robot.  The password is blank.
     ssh [email protected]

# To configure the computer so that the wireless network is the default network, add the line "never-default=true" to the IPV4 section of the file
   /etc/NetworkManager/system-connections/Wired\ connection\ 1

Restart the network with
    /etc/init.d/network-manager restart

This will put the 10.0.0.10 entry at the bottom of the resolv.conf file:
     cat /etc/resolv.conf

# Generated by NetworkManager
nameserver 172.20.253.2
nameserver 172.20.253.6
nameserver 10.0.0.10

I found this approach described in the Setting Default Ubuntu eth port post.

In a pinch, the default route can be set by hand.  Check the default route with
    ip route default

    default via 172.20.252.1 dev wlan0  proto static 
    10.0.0.0/24 dev eth0  proto kernel  scope link  src 10.0.0.22 
    172.20.0.0/16 dev wlan0  proto kernel  scope link  src 172.20.101.20 
 

Change the default route by deleting it and then remaking it.

     ip route del default
     ip route add default via 172.20.252.1

Use the following command to set up the eth0 network:
sudo /sbin/ifconfig ethp 10.89.71.20.20 netmask 255.0.0.0

To let Brian login to a laptop that is behind a firewall, run
ssh -R 2222:localhost:22 [email protected] -f -N
This will start a connection that will stay active as long as the network stays up.  Brian can then login to software.frc971.org and connect to his "brian" account on the laptop behind the firewall with:
ssh -p 2222 brian@localhost

 

Configuring the Driver Station and Linksys Router

It appears that there needs to be a DHCP server running for the networking to work.  Parker and Michael were able to do this on 3/23/15 by using the National Instruments Bridge Configuration Utility and setting the SSID to 9971 and the password to Axxxxx15.  We set the router to have the same settings using AES only and Wireless N only.  The driver station was set to use DHCP too.

General Notes

The notes from here to the bottom of the page are from the 2014 season.  They will be updated for the 2015 season after I install the FRC software.
The first few times that I installed FRC software on team computes, I installed the NI software and the NI and WPI lib update as described in the second set of directions below.  On Sept 13, 2014, I read in the page that 
  • The Installing the 2014 FRC NI Update (for ALL TEAMS) page explains that all that is needed is the NI Update.  We don't have to install anything else to program the robot in C++, run the driver station, flash the cRIO, or run the FRC Bridge configuration tool.  I installed the NI "FRC 2014 Update Suite, Download Only" only from http://ni.com/frc. Installed it on a Windows 7 machine and it worked fine.  Use 00303x87M bkwds. 
  • This year the NI updates have been reconfigured into a single standalone installer. This means that the FRC Driver Station, cRIO Imaging Tool and other utilities such as the Camera Configuration Tool will all be bundled into a single installer which will not require any components from the DVD. The LabVIEW update is also included in this installer and will install if a LabVIEW installation is detected. To use the DS and Imaging tool all teams must install the 2014 NI Update.

  • The Programming your radio for home use guide shows how to use the 2013 FRC Bridge Configuration Tool software to configure your robot's wireless bridge for use outside of FRC events. b  It appears that they are using the 2013 tool for the 2014 season.  Somewhere it said the tool should be in the Start menu, but I did not find it there.  I did find it at C:\Program Files\National Instruments\LabVIEW 2013\project\FRC Bridge Tool\FRC Bridge Configuration Utility.exe.  When I ran it the first time, it took me to the Java download page and so I installed Java.  I made a link to this tool on the desktop.

Here are my notes from installing the FRC software before I figured out that I don't need to install the National Instruments or WPI Lib software (see my notes above).

The 2015 FRC Software Component Overview page directed me to the Installing the FRC 2015 Update Suite page to find the download and install instructions for the roboRIO imaging software and driver station software.  The Installing the FRC 2015 Update Suite page said that all we needed to install is the driver station software and utilities including the imaging tool.  It said that the FRC 2015 Update Suite includes the runtime parts needed to run the driver station software and utilities.  I installed the contents of the FRCUpdate2015.0.0.zip file on FRC 2014-4 on 2/11/15.
The FRC 2015 Update Suite directed me to the NI FRC page for more information.
Michael  
2014 Notes:
The 2014 FIRST software consists of National Instruments Software and WPI/WindRiver software.  The National Instruments software has the driverstation program and cRIO imaging software in it.  The WPI/WindRiver software has the image FRC_2014_v52.zip image in it which is used to flash the cRIO from the NI software.  We roll our own C++ code so we don't use anything else from the WindRiver software.
For the 2014 season, we did the following to set up the laptop we use to image the cRIO and the drivers station laptops.
  • Uninstall the 2013 NI and WindRiver software.  The NI uninstaller is obvious but the WindRiver one is not.  The WindRiver uninstaller has the name "Maintenance Tool" and the WindRiver icon.  Some people recognize the icon.  If you can't find it, go to Start/WindRiver and use the uninstaller located there.
  • Install the "Vision" only half of the NI software from the DVD they sent us in the kit of parts.  I installed this software with the computer connected to the internet so that the software key would be validated.  Use the software key that is printed on the back of the envelope the software was shipped in.  I ran the update tool that came up automatically.  I installed the NI "FRC 2014 Update Suite, Download Only" only from http://ni.com/frc. Installed it on Win XP Pro machine and it worked fine.  If you only install the FRC 2014 Update Suite without installing the "Vision" software from the DVD, the cRIO imaging tool will see the cRIO and appear to be working but not get past the "Rebooting the cRIO" screen.  Again, use the software key that is printed on the back of the envelope that the software was shipped in for the update.
  • This WPI lib page has a link to the software update for WPILib Workbench  http://first.wpi.edu/FRC/c/update/Release/ .  The WindRiver software installs the FRC_2014_v52.zip image in /WindRiver/WPILib/cRIO_Images.  I copied it to my desktop.  On Aug 23, 2014, I downloaded WorkbenchUpdate20140325rev3887.exe with March 25, 2014 date.
  • I set the IP address to the download computer to 10.99.97.201 and the netmask to 255.0.0.0 and turned the firewall off so that the cRIO imaging software would find the cRIO.  The imaging tool was able to find the cRIO at 10.99.97.2 with the computer at 10.9.97.201 but could not communicate enough to get set up for the download.  It did show the IP address on the cRIO so I was able to reset the computer's network to the same subnet.

The 2013 FRC Bridge Configuration Tool software to configure your robot's wireless bridge for use outside of FRC events. This WPI page talks about it and tells how to download it.  It appears that they are using the 2013 tool for the 2014 season.  It said the tool should be in the Start menu, but I did not find it there.  I did find it at C:\Program Files\National Instruments\LabVIEW 2013\project\FRC Bridge Tool\FRC Bridge Configuration Utility.exe.  When I ran it the first time, it took me to the Java download page and so I installed Java.  I made a link to this tool on the desktop.

 

Michael Schuh
Feb 15, 2014
Aug 23, 2014 - installed on FRC 2014-4 Nickel and updated the install notes.  Added Bridge Configuration Tool notes.
⚠️ **GitHub.com Fallback** ⚠️