Repository navigation
Extra ‐ Your own ROS Pkg
This guide outlines the steps required to set up your module repository and initialise a new ROS 2 package within it.
-
GitHub Repository Setup
-
Ensure you have a GitHub account at
https://github.com/. -
Generate a new repository from the University of Lincoln template:
- Navigate to the module's code template:
https://github.com/UoL-SoCS/cmp9767-ws. - Click the 'Use this template' button.
- Choose your account as the owner and provide a descriptive Repository name (e.g.,
cmp9767-your-name-module).
- Navigate to the module's code template:
-
Ensure you have a GitHub account at
-
Local Setup and Cloning
-
Open your terminal and navigate to your chosen development directory (e.g.,
cd ~). -
Clone your newly created repository to your local machine:
# IMPORTANT: Replace 'YourUsername/your-new-repo-name.git' with your actual repository URL git clone [https://github.com/YourUsername/your-new-repo-name.git](https://github.com/YourUsername/your-new-repo-name.git) ### ```
-
-
Create the ROS 2 Package
The cloned repository contains the top-level
srcfolder, which serves as the source space for your Colcon workspace. You will create your new package inside this folder.-
Navigate into the source directory of your local repository:
cd your-new-repo-name/src -
Use the
ros2 pkg createcommand to generate the package skeleton. You must specify the build type (ament_cmakefor C++ orament_pythonfor Python) and any dependencies.-
For a Python Package:
# Replace 'my_ros2_package' with your chosen package name ros2 pkg create --build-type ament_python my_ros2_package --dependencies rclpy std_msgs
-
For a Python Package:
-
-
Build and Source (Colcon)
These steps compile your new code and make it available in your ROS 2 environment using the Colcon build tool.
-
Return to the root directory of your Colcon workspace:
cd .. -
Build the entire workspace using Colcon:
colcon build
-
Source the setup file to register the new packages in your current terminal session:
source install/setup.bash -
Tip: You should ensure your main ROS 2 distribution's setup file is sourced first (e.g.,
source /opt/ros/humble/setup.bash), followed by the workspace-specificinstall/setup.bashcommand, for everything to work properly!
-
-
Any Python script you are going to write yourself needs to be put within the
my_ros2_package/my_ros2_packagefolder of your ROS package (you should find here a__init__.pyfile that makes this folder a Python module), and you need to specify in thesetup.pythe name of the script you want to install and make visible.# Inside setup.py # ... entry_points={ 'console_scripts': [ # 'executable_name = package_name.module_file_name:main_function' 'talker = my_ros2_package.my_node:main', ], }, # ...
You can also have a look at this file for inspiration.
-
Remember to push online any changes you introduce to the local copy of your code, especially if working on a shared lab machine. You can find more information on how to use Git, here.