ROS2 Basics
Experiment 02 - Create and Build a Workspace Package
1. Create a ROS2 Workspace Package
In the board's system, create a new package directory (in the user directory, e.g., /home/sunrise), name it ros2_ws, and create a subdirectory under it named src. Then transfer the arm_demo resource package to the ros2_ws/src directory on the board's system.
2. Set Up the Build Environment (skip if already set up)
Step 1: Install MoveIt 2
For ROS 2 Humble (recommended)
sudo apt install ros-humble-moveitStep 2: Verify the MoveIt 2 installation
Find the moveit_core package
ros2 pkg prefix moveit_coreShould return a path similar to:
/opt/ros/humble/share/moveit_core
Step 3: Update workspace dependencies
cd ~/ros2_ws
rosdep install --from-paths src --ignore-src -y(If rosdep is not installed, install it first. If installation fails, refer to fishros's rosdepc and replace the rosdep command with rosdepc.)
Step 4: Modify CMakeLists.txt
In arm_demo/CMakeLists.txt, ensure the following key parts are present:
After find_package(ament_cmake REQUIRED), add
find_package(moveit_core REQUIRED)
Add to the include paths
include_directories(include${moveit_core_INCLUDE_DIRS})
Step 5: Check and add package.xml dependencies
In arm_demo/package.xml, add: (skip if already present)
<depend>moveit_core</depend>
<depend>moveit_ros_planning</depend>The workspace environment is now set up!
Step 6: Build the workspace (verify the environment; using the arm_demo package as an example. If absent, replace with another package or skip.)
cd ~/ros2_ws && colcon build --packages-select arm_demo