Create Action Interface
This guide provides detailed instructions for creating the lift_svc_interface
ROS 2 package and defining the LOPAction
and COPAction
action interfaces used by LOP and COP action servers.
Step 1: Create the Package
First, navigate to your ROS 2 workspace:
cd ~/ros2_ws/src
Create a new package named
lift_svc_interface
:ros2 pkg create --build-type ament_cmake lift_svc_interface --dependencies action_msgs std_msgs
Step 2: Define the Action Interfaces
Inside the
lift_svc_interface
package, create a directory namedaction
:mkdir -p ~/ros2_ws/src/lift_svc_interface/action
Create a file named
LOPAction.action
inside theaction
directory:touch ~/ros2_ws/src/lift_svc_interface/action/LOPAction.action
Open
LOPAction.action
with your preferred text editor and copy-paste the action interface code:
# LOPAction.action
# Request
uint32 hold_door_duration
string api_key
uint16 current_floor
string lift_id
uint16 target_floor
---
# Result
bool success
string message
---
# Feedback
string message
Create a file named
COPAction.action
inside theaction
directory:touch ~/ros2_ws/src/lift_svc_interface/action/COPAction.action
Open
COPAction.action
with your preferred text editor and copy-paste the action interface code:
# COPAction.action
# Request
uint16 target_floor
string otp
string cop_address
string cop_char_uuid
---
# Result
bool success
string message
---
# Feedback
string message
Step 3: Modify the CMakeLists.txt
File
- Open the
CMakeLists.txt
file of yourlift_svc_interface
package and ensure it includes the following:
cmake_minimum_required(VERSION 3.5)
project(lift_svc_interface)
find_package(ament_cmake REQUIRED)
find_package(rosidl_default_generators REQUIRED)
find_package(action_msgs REQUIRED)
find_package(std_msgs REQUIRED)
rosidl_generate_interfaces(${PROJECT_NAME}
"action/LOPAction.action"
"action/COPAction.action"
DEPENDENCIES std_msgs action_msgs
)
ament_package()
Step 4: Modify the package.xml
File
- Open the
package.xml
file of yourlift_svc_interface
package and ensure it includes the necessary dependencies:
<?xml version="1.0"?>
<package format="2">
<name>lift_svc_interface</name>
<version>0.0.0</version>
<description>The lift_svc_interface package</description>
<maintainer email="your_email@example.com">Your Name</maintainer>
<license>Apache-2.0</license>
<buildtool_depend>ament_cmake</buildtool_depend>
<build_depend>rosidl_default_generators</build_depend>
<build_depend>action_msgs</build_depend>
<build_depend>std_msgs</build_depend>
<exec_depend>rosidl_default_runtime</exec_depend>
<exec_depend>action_msgs</exec_depend>
<exec_depend>std_msgs</exec_depend>
<export>
<build_type>ament_cmake</build_type>
</export>
</package>
Step 5: Build the Package
- Navigate back to your ROS 2 workspace root and build the package using
colcon
:
cd ~/ros2_ws
colcon build --packages-select lift_svc_interface
source install/setup.bash
Summary
With these steps, you have created the lift_svc_interface
package and defined lopaction
and copaction
using colcon
. This setup is now ready for use with ROS 2 action servers. Lets begin building the LOP and COP action servers next.