Package Creation
Well, it's time to do the same code as we did for the DDS layer, but now for ROS 2 instead.
The first thing we need to do to create ROS-2 code is to build a package. A package works as a container for your code to be run and shared among other ROS-2 users / machines / projects.
To create a package, first we need to have a workspace set up.
Workspace
First you need to choose a path for your workspace. For this example, let's make one called ws. The name doesn't matter.
mkdir -p ws/src cd ws/
Notice that we also created a subdir called src. This dir is to be holding our package code. It is considered good practice having a subdir called src to hold the packages in a workspace.
Next, let's activate ROS-2 shell env
source /opt/ros/galactic/setup.bash
Package building
- package.xml - meta information about our package
- CMakeList.txt - describes how to compile our package's code
ros2 pkg create --build-type ament_cmake --node-name hello_node hello_worldThis creates the basic structure of a package named hello_world for a node called hello_node for us.
cd .. colcon buildStarting >>> hello_world
colcon build --packages-select (package name) . install/local_setup.bash
ros2 run hello_world hello_nodecolcon build --packages-select --allow-overriding hello_world
ros2 run hello_world hello_node

Nenhum comentário:
Postar um comentário