CS 354 Autonomous Robotics
Fall 2021
Goals
The goals for this lab are to:
- Get comfortable with creating, and working with, ROS2 packages.
- Gain experience with submitting code through GitHub Classroom.
- Gain experience creating git repositories and committing changes.
Deliverables
By the end of this Lab you will need to:
- Create a properly-formatted ROS2 Python package.
- Integrate your wander code from the previous lab into that package.
- Modify your code so that it conforms to Python and ROS2 coding standards.
- Create a git repository to store your work (with commits by at least two group members).
Workspace
When you configured your ROS2 environment, you should have executed the script:
In addition to setting up your .bashrc
file, this script created a
folder named ~/dev_ws
that you will use to store your ROS2 files.
Creating and Building a ROS2 Package
First, create a
src
folder in your workspace andcd
into it:mkdir ~/dev_ws/src/ cd ~/dev_ws/src/
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.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
Build your newly created package by changing into your workspace directory and typing:
colcon build
Once this command completes, there should be
build
,install
andlog
directories alongside the existingsrc
directory. Type the following command into the terminal:source install/setup.bash
This command configures your environment so that the ROS2 system is aware of your newly created package.
You should now be able to interact with your package using ROS2 command line tools:
$ ros2 run wander wander_node Hi from wander.
Congratulations! You now have a fully-functional, properly built, ROS2 package.
Creating a GitHub Repository
Copy the URL for the assignment invitation from the course Piazza page. Paste the URL into your browser window and follow the link.
Click on the link to access the GitHub page for your repository.
Follow the instructions to select a team name for this assignment. You should see a page with some text like the following:
Your team’s assignment repository has been created: https://github.com/JMU-CS354-F21/ros2-packaging-your-team-name
Complete the following steps in order to add your package to a new git repository. Don't just copy and paste the instructions below! Make sure you understand the meaning of each step. (
GIT_URL
should be replaced with the URL for your GitHub project. It should look something like:https://github.com/JMU-CS354-F21/ros2-packaging-your-team-name
)cd ~/dev_ws/src/wander git init echo "# Packaging Lab" >> README.md git add * git commit -m "first commit" git branch -M master git remote add origin GIT_URL git push -u origin master
Reload your repository in GitHub to confirm that your package has been pushed correctly.
Congratulations! You have a git repository on GitHub.
Adding Functionality
At this point 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.
Copy the contents of your
wander.py
solution from the previous lab intowander_node.py
. Rebuild your package and test that you can useros2 node run
to execute your new node:ros2 launch turtlebot3_gazebo turtlebot3_world.launch.py
In a separate terminal:
ros2 run wander wander_node
Copy your
forward.py
solution form the last lab into a file namedforward_node.py
. Updatesetup.py
so that it recognizesforward_node
as an entry point, rebuild, and test the result:ros2 run wander forward_node
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 ROS2 coding style guidelines. You can
run these tests by using colcon test
in the root of your workspace:
cd ~/dev_ws/
colcon test
The output is stored in text files in the log
directory. Open the file
~/dev_ws/log/latest_test/wander/stdout_stderr.log
to see which style
checks your code is failing.
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:
Change into your package folder and type:
git add *
to add all of your newly created files to the repository.
Commit your changes by typing:
git commit -m 'Added wander code. Fixed style issues.'
Every time you commit your code you MUST provide a reasonably informative commit message.
Push your changes
git push
Your changes are not safe until you complete this step! Once you have completed the previous step, test that everything is OK by accessing your repository through the GitHub web interface. You should be able to see the files you've pushed.
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 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.