Skip to content

1. Cheat Sheets

Emma edited this page Oct 22, 2023 · 12 revisions

Quick Links

Environment Setup

To setup your computer to be able to write and run code for the drone, follow the following steps exactly. If you get stuck, reach out to the team on Discord! The virtual machine option is slower and does not work with external devices, but is the "safer" option. If you can, we recommend doing a dual-boot, but a virtual machine can do 90% of what a dual boot can.

1. Install Ubuntu 20.04 (NOTE: this will require a 64-bit computer. If you do not have one, reach out to the lead to explore options)

NOTE: If you run into problems, Google has plenty of resources for figuring them out...

For Windows Virtual Machine Setup (slower, does not work with some external devices, safer option)

  1. Download the Ubuntu 20.04 image file from here
  2. Install VirtualBox for your computer
  3. Once installed and open, click "New" and set up your virtual machine
  4. When your virtual machine is setup, run your virtual machine and start the Ubuntu installation!
  5. Make sure you select Minimal Installation when prompted! Otherwise there can be problems with graphics drivers, libraries, etc. Try to keep additional software it wants you to install to a bare minimum.

For Mac Virtual Machine Setup (M1/M2 chip)

  1. Download the Ubuntu 20.04 image file from here and choose 64-bit ARM desktop image.
  2. Install UTM for your computer
  3. Once installed and open, click "New" and set up your virtual machine
  4. When your virtual machine is setup, run your virtual machine and start the Ubuntu installation!
  5. Make sure you select Minimal Installation when prompted! Otherwise there can be problems with graphics drivers, libraries, etc. Try to keep additional software it wants you to install to a bare minimum.

For Dual-boot Setup (riskier than a virtual machine, does not work for Apple computers, faster)

  1. Download the Ubuntu 20.04 image file from here
  2. Flash the image file to an external USB drive (this will erase all data on the drive!). You can follow a tutorial (Windows/MacOS)
  3. Disable bitlocker if you have it enabled.
  4. Disable secure boot from the BIOS.
  5. Partition your hard drive to make a drive for Ubuntu (you shouldn't need more than 50 GB, and you can always increase this size later)
  6. Once the USB drive has been flashed, restart your computer and enter the BIOS. (how to do this depends on computer brand, but it is easy to find out how on Google)
  7. Once in the BIOS, select the option to boot from the USB device.
  8. When prompted, select the drive that you just partitioned to install Ubuntu to.
  9. Make sure you select Minimal Installation when prompted! Otherwise there can be problems with graphics drivers, libraries, etc. Try to keep additional software it wants you to install to a bare minimum.

2. Set up Git, Clone the drone repositories (there currently aren't any), and install the dependencies

NOTE: If you get the error 'Username is not in the sudoers file': You need to add the user (you) directly to the sudoers file. 1. To do this, switch to the root user using su root 2. It will then ask you for the password to your account 3. Now, we are in the root user. Edit the sudoers file using nano, which is a text file that allows us to edit files from the command line: nano /etc/sudoers 4. Scroll down until you find the User privilege specification. Its purpose is to grant the system user mentioned certain privileges. 5. Make sure yours looks like this (but put your username where it says username): User privilege specification_ _root ALL=(ALL:ALL) ALL_ _username ALL=(ALL:ALL) ALL 6. Now to exit out of the root user, press the keyboard keys CTRL+X to exit, Y to save, and ENTER to submit.

  1. First, install git: sudo apt-get update and sudo apt-get install git
  2. Verify the installation was successful by running git --version
  3. Register your GitHub username and e-mail: run git config --global user.name "YOUR_USERNAME" and git config --global user.email "[email protected]"
  4. Set up the credentials manager to remember your GitHub username/password: run git config --global credential.helper store
  5. Run git clone https:/mcgill-robotics/drone_2024.git to clone the repository to your local file system.

There will be some more things to install in order to be able to run the simulation on gazebo; however, you will not be doing that yet :).

Git

Initializing a Repository

  • git init: Create a new Git repository in the current directory.

Cloning a Repository

  • git clone <repository_url>: Clone a remote repository to your local machine.

Checking Repository Status

  • git status: Show the status of your working directory.
  • git log: Displays a chronological list of commits, including their messages and unique identifiers.

Adding Changes

  • git add <file>: Stage a changed file for commit.
  • git add -A: Stage all changes.

Committing Changes

  • git commit -m "Commit message": Create a new commit with staged changes.

Branching

  • git branch: List all branches.
  • git branch -r: List all remote branches
  • git branch <branch_name>: Create a new branch.
  • git checkout <branch_name>: Switch to a different branch.
  • git checkout -b <branch_name>: Create and switch to a new branch.

Merging

  • git merge <branch_name>: Merge changes from one branch into the current branch.

Undoing Changes

  • git reset <file>: Unstage changes.
  • git reset --soft <commit>: Reset to a previous commit, keeping changes staged.
  • git reset --hard <commit>: Reset to a previous commit, discarding all changes.
  • git revert <commit>: Create a new commit that undoes a previous commit.

Fetching and Pruning

  • git fetch --prune: Fetch changes from a remote and remove deleted branches from your local.

Pushing a New Branch

  • git push origin <branch_name>: Push a new branch to a remote repository.

Pulling and pushing commits

  • git pull: Fetch and merge commits from the remote, only applies to the branch you are currently on.
  • git push: Push commits made locally to the remote, so they can be seen by others on the same branch.

Git Ignore

  • The .gitignore file is used to specify files and directories to be ignored in commits.

ROS 2

We will be using the Debian packages to install ROS 2 Galactic on Ubuntu

  1. Ensure that the Ubuntu Universe repository is enabled

    sudo apt install software-properties-common
    sudo add-apt-repository universe
    
  2. Now add the ROS 2 GPG key with apt

    sudo apt update
    sudo apt install curl
    sudo curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key -o /usr/share/keyrings/ros-archive-keyring.gpg
    
  3. Then add the repository to your sources list

    echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/ros-archive-keyring.gpg] http://packages.ros.org/ros2/ubuntu $(. /etc/os-release && echo $UBUNTU_CODENAME) main" | sudo tee /etc/apt/sources.list.d/ros2.list > /dev/null
    

Install ROS 2 packages

  1. Update your apt repository caches after setting up the repositories by using sudo apt update

  2. ROS 2 packages are built on frequently updated Ubuntu systems. It is always recommended that you ensure your system is up to date before installing new packages using sudo apt upgrade

  3. Desktop Install (Recommended): ROS, RViz, demos, tutorials using sudo apt install ros-galactic-desktop and sudo apt install ros-dev-tools

  4. Set up your environment by sourcing the following file: Replace ".bash" with your shell if you're not using bash source /opt/ros/galactic/setup.bash and echo "source /opt/ros/galactic/setup.bash" >> ~/.bashrc

Now try some examples!

If you installed ros-galactic-desktop above then you can try some examples. In one terminal, source the setup file and then run a C++ talker:

source /opt/ros/galactic/setup.bash
ros2 run demo_nodes_cpp talker

In another terminal source the setup file and then run a Python listener:

source /opt/ros/galactic/setup.bash
ros2 run demo_nodes_py listener

You should see the talker saying that it's Publishing messages and the listener saying I heard those messages. This verifies both the C++ and Python APIs are working properly. YAYYYY!!!!

Installing Gazebo

  1. Install curl -sSL http://get.gazebosim.org | sh
  2. Run gazebo

And it should work!