- Table Of Contents
- Introduction
- Installation and Setup
- Operating Systems
- Getting the Code
- Running the setup scripts
- Building and Running the Code
- Debugging
- Flashing and Debugging A STM32 MCU
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.
- Open a new terminal
- Install git by running
sudo apt-get install git
- Go to the software repository
- Click the
Fork
button 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 Download
button 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
origin
that 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 -v
from your terminal (at the base of the repository folder again). You should see two entries:origin
with the url for your fork of the repository, andupstream
with 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
AI
software
- 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_setup
folder. 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
- Inside a terminal, navigate to the environment_setup folder. Eg.
cd path/to/the/repository/Software/environment_setup
- Run
./setup_grsim.sh
- You will be prompted for your admin password
- This script will install
grSim
, which is the main simulator we use for development
CLion is our main IDE for editing our C/C++ code. It is designed to work with our build system, bazel
, and has all the great features of an IDE such as code completion, syntax highlighting etc. We strongly recommend installing CLion and using it for development.
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.sh
script 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.
- 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
Workspace
to 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 thesrc
folder) - 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
Finish
and 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
BUILD
file and right clight in acc_library()
call. This will give you the option toRun
orDebug
that specific target. Try it by openingSoftware/src/software/geom/BUILD
and right-clicking on thecc_library
forangle_test
! - Add a custom build configuration (more powerful, so make sure you understand this!)
- Select
Add Configuration
from 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 Command
you 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
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! Debugging from the command line is certainly possible, but debugging in a full IDE is really nice (plz trust us). If you insist on using the command line for everything, or if you have CLion issues, see here.
- Make sure you've followed Installing Firmware Dependencies, and have a NUCLEO-H743ZI plugged into your computer.
- From the
src
folder, runbazel run --cpu=stm32h7 --compilation_mode=dbg //firmware_new/tools:debug_firmware_on_arm_board
. We specify--cpu=stm32h7
because we want to compile code for the stm32h7 MCU (rather then ax86_64
processor like you have in your computer), and--compilation_mode=dbg
in 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. - Assuming you choose 0 from the list in step (2), run
bazel run --cpu=stm32h7 --compilation_mode=dbg //firmware_new/tools:debug_firmware_on_arm_board 0
. This will load the.elf
file associated with (0) to the 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.
- Make sure you've followed Installing Firmware Dependencies
- To regenerate code from the
.ioc
file, runbazel run //firmware_new/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.