Goals

The goals for this lab are to:

Deliverables

By the end of this Lab you will need to:

Log into GitHub

This time, when you execute the ros2_jmu_setup.sh script you should go through the process of logging into GitHub. Otherwise you won’t be able to clone or push your repository.

Creating and Building a ROS2 Package

  1. First, cd into ~/dev_ws/src.

    cd ~/dev_ws/src/
  2. Now create the package:

    ros2 pkg create --build-type ament_python --node-name wander_node wander

    This will populate the wander folder with a properly-formatted ROS2 Python package.

  3. If you look inside your wander folder, you should now see the following initial layout:

    wander/                          <-- Folder name matches package name
         package.xml                  <-- ROS2 package information
         setup.cfg                    <-- Python package installation config file
         setup.py                     <-- Python package installation script
         resource/                    <-- Honestly... I'm not sure
             wander
         test/
             test_flake8.py           <-- Tests for Python PEP8 formatting
             test_pep257.py           <-- Tests for docstrings
             test_copyright.py        <-- Test that a copyright is provided
         wander/                      <-- Python package source
             __init__.py              <-- Turns the folder into a Python package
             wander_node.py           <-- Python executable
  4. Build your newly created package by changing into your workspace directory and typing:

    colcon build --symlink-install

    Once this command completes, there should be build, install and log directories alongside the existing src directory. Type the following command into the terminal:

    source install/setup.bash

    This command configures your environment so that the ROS 2 system is aware of your newly created package.

    You should now be able to interact with your package using ROS 2 command line tools:

    $ ros2 run wander wander_node 
     Hi from wander.

Congratulations! You now have a fully-functional, properly built, ROS 2 package.

Creating a GitHub Repository

Congratulations! You have a git repository on GitHub.

Adding Functionality

At this point you should log out and log back in and SOMEONE ELSE from your group should clone the repository and make the changes described below. Full credit for the lab will require commits from multiple group members.

Note that if you clone the package like this:

git clone GIT_URL

The folder will have the same name as the GitHub repository.

If you clone it like this:

git clone GIT_URL wander

Then the folder name will match the package name, which will be less confusing. Once the repository is cloned into ~/dev_ws/src complete the steps below.

Tidying Up

You can check style issues by running flake8 in the folder containing your Python code. For example:

python -m flake8 --max-line-length 100

Fix as many style errors as possible.

Saving Your Work

Once you are satisfied with your package, commit your work, and push it back to GitHub by completing the following steps:

Submitting

There is nothing to submit for this lab. I’ll check your work through GitHub.

If You Have Extra Time

Modify your wander_node.py solution (or mine) so that the wandering is random. Rather than turning until the obstacle is out of range, turn by some randomly determined angle. Push your changes to the GitHub repository.

You may also want to improve the avoidance logic so that the obstacle detection takes into account the width of the robot.


Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License.