The goals for this lab are to:
By the end of this Lab you will need to:
Don’t forget to source the script:
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.
First, create a src
folder in your workspace and cd
into it:
Now create the package:
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:
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.
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. Your team name should have the format
wander_name1_name2
where name1
and name2
are the last names
of the team members. You should see a page with some text like the
following:
Your team’s assignment repository has been created:
https://github.com/JMU-CS354-F22/wander-wander_name1_name2
Use the gh
command-line tool to log into GitHub:
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-F22/wander-wander_name1_name2
)
Reload your repository in GitHub to confirm that your package has been pushed correctly.
Congratulations! You have a git repository on GitHub.
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.
Copy the contents of your wander.py
solution from the previous
lab into wander_node.py
. Rebuild your package and test that you
can use ros2 node run
to execute your new node:
In a separate terminal:
Copy your forward.py
solution form the last lab into a file
named forward_node.py
. Update setup.py
so that it recognizes
forward_node
as an entry point, rebuild, and test the result:
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
.
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:
to add all of your newly created files to the repository.
Commit your changes by typing:
Every time you commit your code you MUST provide a reasonably informative commit message.
Push your changes
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.
There is nothing to submit for this lab. I’ll check your work through GitHub.
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.