ECE4960-2022

Course on "Fast Robots", offered Spring 2022 in the ECE dept at Cornell University

This project is maintained by CEI-lab

Cornell University: ECE 4960

Return to main page


Lab 10: Simulator

Objective

In this lab, you will setup and use your simulation environment. You will learn how to control your virtual robot and use the live plotting tool.

Simulation Environment

The simulation environment consists of three components:

1. Simulator

The simulator contains a wheeled robot equipped with laser range finder(s), similar to the physical robot and its ToF sensors. The simulated world is defined in a .yaml configuration file.

Odometry

Odometry is the use of data from onboard sensors to estimate change in position over time. The relative changes recorded by the sensors (typically IMU and/or wheel encoders) are integrated over time to get a pose estimate of the robot. It is used in robotics by mobile robots to estimate their position relative to a starting location. This method is sensitive to errors due to the integration of velocity measurements over time to give position estimates.

The virtual robot provides simulated IMU data that mimics a typical real robot and this data is integrated over time to give you the odometry pose estimate. (In your real robot, we know that accelerometer data is too noisy to estimate forward motion, but you can consider using the gyroscope to estimate turns, and doing forward motion open loop. More on this in future labs!)

Ground Truth

In robotics, ground truth is the most accurate measurement available. New methods, algorithms and sensors are often quantified by comparing them to a ground truth measurement. Ground truth can come either directly from a simulator, or from a much more accurate (and expensive) sensor.

For the virtual robot, ground truth is the exact position of your virtual robot within the simulator.

Virtual Robot

The virtual robot does has a (simulated) constant speed controller and odometry pose estimation built in. It essentially mimics an idealized version of the real robot.

2. Plotter

The 2d plotting tool is a lightweight process that allows for live asynchronous plotting of multiple scatter plots using Python. The Python API to plot points is described in the Jupyter notebook. It allows you to plot the odometry and ground truth poses. It also allows you to plot the map (as line segments) and robot belief in future labs. Play around with the various GUI buttons to familiarize yourself with the tool; you want to be more familiar with the tools before you get into the future labs.

3. Controller

You will be programming the controller in Python to perform various functions on your virtual robot. We provide you with a Python API which, among other things, provides a minimal control interface for the robot in the simulator. It allows you to:

Computer Setup

Upgrade Python

This is a reminder to upgrade python (>= 3.10) and pip (>= 21.0).

NOTE: You may notice different versions when using python and python3 commands; use the one that has the latest version and use pip in that version of python. For example, if python3 has the latest version of python on your computer, use pip as python3 -m pip. Make sure you use the right python command for all the steps detailed in this documentation.

How to check for versions? In a Command Line Interface (CLI), run the below commands to check for Python and pip versions:
python --version
python -m pip --version


  1. Install/Upgrade Python 3.10
  2. Install/Upgrade pip

Install Python Dependencies

If you just upgraded your python version and used an older version in Lab2, then the virtual environment created in Lab 2 will no longer be compatible. Inside your project folder, delete the directory with the name of your virtual environment (ece4960_ble). Verify it is actually deleted! Now, follow instructions in Lab2 to setup your new virtual environment and reinstall the packages from Lab 2.

Install pip packages

  1. Activate your virtual environment.
  2. Install dependencies
      python -m pip install numpy pygame pyqt5 pyqtgraph pyyaml ipywidgets colorama
    

    Replace python with python3 if python3 points to the latest version.

Install Box2D package

Installing from a pip wheel

  1. Activate your virtual environment.
  2. Download the pip wheels and extract it into a known location.

    md5sum: 7af561f39f78c5b29b5bd2699aaebd96

  3. Install Box2D from pip

    Replace <wheel_directory> with the path of the wheel directory. For example in Linux, if the package was extracted to /home/bender/course_work. Then in the below command, replace <wheel_directory> with /home/bender/course_work/box2d_wheels.

      pip install --find-links <wheel_directory> box2d
    
  4. If Box2D is installed successfully, start a python interpreter:
      python
    

    and then run the following code in the python interpreter:

      import Box2D; print(Box2D.__version__)
    
  5. If the above command displays “2.3.10”, you are done! Skip the next section (“Installing from source”).

Installing from source

Follow the instructions in this section IF AND ONLY IF Box2D was NOT successfully installed in the previous section.

1. Activate your virtual environment.
2. Download and install the latest version of swig with your package manager. For example, in a Debian distro:
sudo apt-get install build-essential python-dev swig python-pygame git
3. Clone the git repository
git clone https://github.com/pybox2d/pybox2d
4. Build and install the pybox2d library
python setup.py build
python setup.py install
1. Start an elevated Powershell: Type "Powershell" in your start menu, rightclick on the Windows PowerShell icon, and click on Run as Administrator.
2. With PowerShell, you must ensure Get-ExecutionPolicy is not Restricted.
3. Set the execution policy: Run the following command,
Get-ExecutionPolicy
4. If the command returns "Restricted", then run
Set-ExecutionPolicy AllSigned
5. Install choco: Run the following command
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
6. Close the powershell window.
7. Start a new elevated powershell window.
8. Install swig: Run the following command
choco install swig
9. Install git: Run the following command
choco install git
10. Close the powershell window.
11. Start a new elevated Powershell: Type "Powershell" in your start menu, rightclick on the Windows PowerShell icon, and click on Run as Administrator.
12. Activate your virtual environment. (If you have issues with execution priveleges in Powershell, check out this solution)
13. Clone the repo, and install the python package.
git clone https://github.com/pybox2d/pybox2d
cd pybox2d
python setup.py build
python setup.py install
1. Install brew:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
2. Install swig:
brew install swig
3. Activate your virtual environment.
4. Clone the repo, and install the python package.
git clone https://github.com/pybox2d/pybox2d
cd pybox2d
python setup.py build
python setup.py install

Lab Instructions

  1. Download and extract the simulation base code into your project folder.
  2. Download the lab10 notebook from here and copy lab10.ipynb into the notebooks directory (inside the simulation base code directory).
  3. Follow the instructions in the notebook to understand how to control your virtual robot and use the plotter.

Tasks

  1. Include a brief description of the simulator and its functionalities in your lab report.
  2. Open Loop Control
    • Make your robot follow a set of velocity commands to execute a “square” loop anywhere in the map.
    • Plot and analyze the ground truth and odometry of the robot.
    • What is the duration of a velocity command?
    • Does the robot always execute the exact same shape?
  3. Closed Loop Control
    • Design a simple controller in your Jupyter notebook to perform a closed-loop obstacle avoidance.
    • By how much should the virtual robot turn when it is close to an obstacle?
    • At what linear speed should the virtual robot move to minimize/prevent collisions? Can you make it go faster?
    • How close can the virtual robot get to an obstacle without colliding?
    • Does your obstacle avoidance code always work? If not, what can you do to minimize crashes or (may be) prevent them completely?

Write-up

Please upload a brief lab report (<600 words) describing the various tests performed along with a short video of the virtual robot moving around in the simulator. Please use screen recording tools for recording the screen.