Goals

The goals for this lab are to:

Deliverables

By the end of this Lab you will need to:

Workspace

Don’t forget to source the script:

ros2_jmu_setup.sh.

In addition to setting up your .bashrc file, this script creates a folder named ~/dev_ws that you will use to store your ROS 2 files.

Creating and Building a ROS2 Package

  1. First, create a src folder in your workspace and cd into it:

  2. Now create the package:

    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:

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

    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:

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:

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

If you clone it like this:

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

As you may have noticed above, the skeleton file hierarchy created by ros2 pkg create includes a number of scripts for checking that your source files follow Python and ROS 2 coding style guidelines. You can run these tests by using colcon test in the root of your workspace:

You can view the test results with the command:

Fix all of the style errors found by test_flake8.

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.


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