- Software Setup
- Table Of Contents
- Introduction
- Installation and Setup
- Operating Systems
- Getting the Code
- Running the setup scripts
- Building and Running the Code
- Debugging
- Profiling
- Flashing And Debugging A STM32F4 MCU
- Flashing the Radio Dongle
- Flashing And Debugging A STM32H7 MCU
- Working with CubeMX to regenerate code
- Setting up Virtual Robocup 2021
These instructions assume that you have the following accounts setup:
These instructions assume you have a basic understanding of Linux and the command-line. There are many great tutorials online, such as LinuxCommand. The most important things you'll need to know are how to move around the filesystem, and how to run programs or scripts.
We currently only support Linux, specifically Ubuntu 18.04 LTS. You are welcome to use a different version or distribution of Linux, but may need to make some tweaks in order for things to work.
You can use Ubuntu 18.04 LTS inside Windows through Windows Subsystem for Linux, by following this guide. Running and developing Thunderbots on Windows is experimental and not officially supported.
- Open a new terminal
- Install git by running
sudo apt-get install git - Go to the software repository
- Click the
Forkbutton in the top-right to fork the repository (click here to learn about Forks)- Click on your user when prompted
- You should be automatically redirected to your new fork
- Clone your fork of the repository (you can put it wherever you want)
- Eg.
git clone https://github.com/<your-username>/Software.git - You can find this link under the green
Clone or Downloadbutton on the main page of the Software repository - We recommend cloning with SSH if you don't like typing your username and password all the time. Instructions can be found here.
- Eg.
- Set up your git remotes (what is a remote and how does it work?)
- You should have a remote named
originthat points to your fork of the repository. Git will have set this up automatically when you cloned your fork in the previous step. - You will need to add a second remote, named
upstream, that points to our main Software repository, which is where you created your fork from. (Note: This is not your fork)- Open a terminal and navigate to the folder you cloned (your fork):
cd path/to/the/repository/Software - Navigate to our main Software repository in your browser and copy the url from the "Clone or Download" button. Copy the HTTPS url if you originally cloned with HTTPS, and use the SSH url if you previously cloned with SSH
- From your terminal, add the new remote by running
git remote add upstream <the url>(without the angle brackets)- Eg.
git remote add upstream https://github.com/UBC-Thunderbots/Software.git
- Eg.
- That's it. If you want to double check your remotes are set up correctly, run
git remote -vfrom your terminal (at the base of the repository folder again). You should see two entries:originwith the url for your fork of the repository, andupstreamwith the url for the main repository
- Open a terminal and navigate to the folder you cloned (your fork):
- You should have a remote named
See our workflow document for how to use git to make branches, submit Pull Requests, and track issues
We have several setup scripts to help you easily install the necessary dependencies in order to build and run our code. You will want to run the following scripts, which can all be found in Software/environment_setup
- Inside a terminal, navigate to the environment_setup folder. Eg.
cd path/to/the/repository/Software/environment_setup - Run
./setup_software.sh- You will be prompted for your admin password
- This script will install everything necessary in order to build and run our main
AIsoftware
- Inside a terminal, navigate to the environment_setup folder. Eg.
cd path/to/the/repository/Software/environment_setup - Run
./setup_firmware.sh- You will be prompted for your admin password
- This script will install everything necessary in order to build and run our robot firmware
- inside a terminal, navigate to the
environment_setupfolder. Eg.cd path/to/the/repository/Software/environment_setup- Run
./setup_udev_rules.sh- You will be prompted for your admin password
- This script will set up the USB permissions required in order to use our radio/wifi dongle
- Run
For those who prefer working on C/C++ with an IDE, we provide two options: CLion for an integrated experience and VSCode for a more lightweight setup. Both support our build system bazel.
CLion is the most full-featured IDE, with code completion, code navigation, and integrated building, testing, and debugging.
CLion is free for students, and you can use your UBC alumni email address to create a student account. If you already have a student account with JetBrains, you can skip this step.
- If you haven't done so already, setup your UBC alumni email account here.
- Using your UBC email account, get a JetBrains education account here.
- JetBrains will send an initial email to confirm the UBC email you inputted. Once you have confirmed, another email will be sent to activate your new education account. You will use this account to set up CLion later on.
- Inside a terminal, navigate to the environment_setup folder. Eg.
cd path/to/the/repository/Software/environment_setup - Run
./install_clion.sh(* DO NOT download CLion yourself unless you know what you're doing. Theinstall_clion.shscript will grab the correct version of CLion and the Bazel plugin to ensure everything is compatible *). - When you run CLion for the first time you will be prompted to enter your JetBrains account or License credentials. Use your student account.
VSCode is the more lightweight IDE, with support for code navigation, code completion, and integrated building and testing. However, debugging isn't integrated into this IDE.
- Inside a terminal, navigate to the environment_setup folder. Eg.
cd path/to/the/repository/Software/environment_setup - Run
./install_vscode.sh(* DO NOT download VSCode yourself unless you know what you're doing. Theinstall_vscode.shscript will grab the most stable version of VSCode) - Open
vscode. You can typevscodein the terminal, or click the icon on your Desktop. &. ClickOpen Folderand navigate to where you cloned software. So if I cloned the repo to/home/my_username/Downloads/Software, I would select/home/my_username/Downloads/Software. - VSCode will prompt you to install recommended extensions, click
Install, this installs necessary plugins to work on the codebase. (Bazel, C++, Python, etc..) - Navigate to File -> Preferences -> Settings -> Workspace -> Extensions -> Bazel and select the
Bazel: Enable Code Lensoption.
- Navigate to the root of this repository (wherever you have it cloned on your computer)
- Navigate to
src. - Build a specific target for running (for example):
bazel build //software/geom:angle_test - Run a specific target by running (for example):
bazel run //software/geom:angle_test - Run a specific test by running (for example):
bazel test //software/geom:angle_test - Build everything by running
bazel build //... - Run all the tests by running
bazel test //...See the bazel command-line docs for more info.
First we need to setup CLion
- Open CLion
- Select
Import Bazel Project - Set
Workspaceto wherever you cloned the repository +/src. So if I cloned the repo to/home/my_username/Downloads/Software, my workspace would be/home/my_username/Downloads/Software/src. - Select
Import project view file, and select the file.bazelproject(which will be under thesrcfolder) - Click
Next - Change the Project Name to whatever you want. Leave everything else as it is ("Use shared project view file" should be selected).
- Click
Finishand you're good to go! Give CLion some time to find everything in your repo.
Now that you're setup, if you can run it on the command line, you can run it in clion. There are two main ways of doing so.
- Open any
BUILDfile and right clight in acc_library()call. This will give you the option toRunorDebugthat specific target. Try it by openingSoftware/src/software/geom/BUILDand right-clicking on thecc_libraryforangle_test! - Add a custom build configuration (more powerful, so make sure you understand this!)
- Select
Add Configurationfrom the drop-down in the top-right of CLion - Click on
+, chooseBazel Command. - For
Target Expression, you can put anything that comes after abuild,run,test, etc. call on the command line. For example://software/geom:angle_test. - For
Bazel Commandyou can put any bazel command, likebuild,run,test, etc. - Click
Ok, then there should be a green arrow in the top right corner by the drop-down menu. Click it and the test will run!
- Select
- Open VSCode
- Navigate to
Software/src/software/geom/BUILD - On top of every
cc_test,cc_libraryandcc_binarythere should be aTest ...,Build ...orRun ...for the respective target. - Click
Test //software/geom:angle_testto run theangle_test
- Open your terminal,
cdintoSoftware/srcand runifconfig. - Pick the network interface you would like to use:
- If you are running things locally, you can pick any interface that is not
lo - If you would like to communicate with robots on the network, make sure to select the interface that is connected to the same network as the robots.
- If you are running things locally, you can pick any interface that is not
- Run our AI:
bazel run //software:full_system -- --interface=[interface_here] --backend=SimulatorBackend- This will launch the Visualizer, which displays what the AI is currently "seeing" and allows us to interact with the AI through the dynamic parameters.
- The field should be empty, as we are currently not receiving SSL Vision packets.
- Run our Simulator:
bazel run //software:standalone_simulator_main -- --interface=[interface_here]- The Simulator runs our firmware and Box2D (a physics engine) to simulate how our robots would behave on the field.
- The Simulator outputs SSL Vision packets, which contain position information of all robots and the ball.
- Our AI can now "see" the robots, and they should be displayed on the Visualizer.
- You can use ctrl-click to move the ball around in the Simulator, and try changing the Play Override on the Visualizer to see the robots move!
- Run Robot Diagnostics:
bazel run //software:robot_diagnostics:robot_diagnostics_main -- --interface=[interface_here] --backend=WifiBackend- The Mechanical and Electrical sub-teams use Robot Diagnostics to test specific parts of the Robot.
- Run our SimulatedPlayTests in the visualizer:
bazel test //software/ai/hl/stp/play:[some_target_here] --test_arg="--enable_visualizer"orbazel run //software/ai/hl/stp/play:[some_target_here] -- --enable_visualizer- This will launch the visualizer and simulate AI Plays, allowing us to visually see the robots acting according to their roles.
- Run our SimulatedTacticTests in the visualizer:
bazel test //software/ai/hl/stp/tactic:[some_target_here] --test_arg="--enable_visualizer"orbazel run //software/ai/hl/stp/tactic:[some_target_here] -- --enable_visualizer- This will launch the visualizer and simulate AI Tactic on a single robot
** NOTE: If you want to run SimulatedTests with the AI initially stopped, then use the --stop_ai_on_start flag **
- Open your terminal,
cdintoSoftware/src - Run
./software/run_simulated_ai_vs_ai.sh interface_name, using the same interface as from above - If AI vs AI is not running properly (eg. the visualizer does not respond after starting a play), closed ports are likely the cause. Run
sudo ufw disableto disable UFW and allow traffic through the visualizer ports.
Debugging from the command line is certainly possible, but debugging in a full IDE is really nice (plz trust us).
Debugging in CLion is as simple as running the above instructions for building CLion, but clicking the little green bug in the top right corner instead of the little green arrow!
bazel run -c dbg --run_under="gdb" //some/target:here will run the target in gdb. Please see here for a tutorial on how to use gdb if you're not familiar with it.
Unfortunately profiling for Bazel targets is not supported in CLion at this time. Hence the only way is via command line. Use the following command:
bazel run -c dbg --run_under="valgrind --tool=callgrind --callgrind-out-file=/ABSOLUTE/PATH/TO/profile.callgrind" //target/to:run
// Example
bazel run -c dbg --run_under="valgrind --tool=callgrind --callgrind-out-file=/tmp/profile.callgrind" //software/geom:angle_test
This will output the file at the absolute path given via the --callgrind-out-file argument. This file can then be viewed using kcachegrind (example: kcachegrind /tmp/profile.callgrind), giving lots of useful information about where time is being spent in the code.
- Make sure you've followed Installing Firmware Dependencies, and have a STM32F4 based main board plugged into your computer. Do not plug both the dongle and the robot at the same time!
- Make sure the robot is elevated, with the wheels not touching any surface to avoid experimental firmware causing accidental damage.
- From the
srcfolder, to flash the radio dongle, runbazel run --cpu=stm32f4 //firmware/tools:legacy_flash_firmware robot - For the robot, make sure the robot is in bootloader mode (BL switch on the piano keys is down), and push the power switch away from the dribbler (i.e towards the back of the robot) and hold it there before running the command.
- There should be a progress bar indicating the flashing progress, hold the switch back until the process finishes.
- When the process is finished, release the power switch, push the BL switch back up, and the robot now has been flashed!
- To see print outs from the robot, run
sudo cat /dev/ttyACM0. IfttyACM0isn't the right device, runls /dev/tty*with the robot disconnected, and again with the robot connected, and replacettyACM0with the new device that has been added. The radio dongle does not have this feature.
-
Make sure you've followed Installing Firmware Dependencies and have a dongle plugged into your computer. Do not plug both the dongle and the robot at the same time!
-
From the
srcfolder, to flash the radio dongle, runbazel run --cpu=stm32f4 //firmware/tools:legacy_flash_firmware radio_dongle. -
If the dongle has a blue pcb, then follow step (a). If the dongle has a green pcb then follow step (b). There should be a progress bar indicating the flashing progress.
(a) Hold down the red button while unplugging and plugging in the dongle. There should be a single orange light on. Then run the script described in step 2.
(b) Hold down the yellow button while running the script described in step 2.
- Make sure you've followed Installing Firmware Dependencies, and have a NUCLEO-H743ZI plugged into your computer.
- From the
srcfolder, runbazel run --cpu=stm32h7 --compilation_mode=dbg //firmware/tools:stm32h7_firmware. We specify--cpu=stm32h7because we want to compile code for the stm32h7 MCU (rather then ax86_64processor like you have in your computer), and--compilation_mode=dbgin order to build in the debug symbols required so you can step through the code and see what's going on. You'll be given a list of elf files to choose from. - If you want just flash the firmware, go to step 5. Assuming you choose 0 from the list in step (2), run
bazel run --cpu=stm32h7 --compilation_mode=dbg //firmware/tools:stm32h7_firmware 0 debug. This will load the.elffile associated with (0) to the nucleo and put you into a gdb prompt. - At this point you should be in a gdb window. Take a look at this tutorial for some basics.
- To flash the firmware without debugging, run
bazel run --cpu=stm32h7 --compilation_mode=dbg //firmware/tools:stm32h7_firmware 0 program
- Make sure you've followed Installing Firmware Dependencies
- To regenerate code from the
.iocfile, runbazel run //firmware/tools:cubemx_regen path/to/directory/with/.ioc. The directory that is passed in as an argument must only contain 1 ioc file, which will be used to generate code into the same directory.
To make sure we are all using the same cube version, run STM32CubeMX when editing the .ioc file.
- Fork the SSL-Simulation-Setup repository.
- Clone it.
- Follow these instructions to set up and run the repository.
After editing the dockerfile, build the image and push it to dockerhub with the following steps
- To build the image, make sure that you are in the same directory as your image, and then run
docker build -t ubcthunderbots/<image name>[:tag] .Make sure that your chosen image name matches a repository in dockerhub. Here's an example with the robocup 2021 setup image:docker build -t ubcthunderbots/tbots-software-env:0.0.1 - Now, push your image to dockerhub. Get the credentials for the thunderbots dockerhub account from a software lead.
- Log into the docker account with
docker login. You will be prompted for a username and password - Now, push this image by its name:
docker push ubcthunderbots/<image name>[:tag]
- Log into the docker account with