ROS2 Basic Development
Experiment 02 - Creating and Building Workspace Package
1. Create ROS2 Workspace Package
Create a new package directory in the development board system (can be in the user directory, e.g., /home/sunrise), name it ros2_ws, and create a subdirectory named src. Then send the arm_demo resource package to the ros2_ws/src directory in the development board system.
2. Build Compilation Environment (skip if already built)
Step 1: Install MoveIt 2
# For ROS 2 Humble (recommended)
sudo apt install ros-humble-moveitStep 2: Verify MoveIt 2 Installation
# Find 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 rosdep commands with rosdepc)
Step 4: Modify CMakeLists.txt
In arm_demo/CMakeLists.txt, ensure the following key parts are present:
Add after find_package(ament_cmake REQUIRED)
find_package(moveit_core REQUIRED)
Add to include directories
include_directories(include${moveit_core_INCLUDE_DIRS})
Step 5: Check and Add package.xml Dependencies
Add to arm_demo/package.xml (skip if already present):
<depend>moveit_core</depend>
<depend>moveit_ros_planning</depend>At this point, the working environment is set up!
Step 6: Build Workspace (Check working environment, using arm_demo package as example, skip if not available)
cd ~/ros2_ws && colcon build --packages-select arm_demo