Skip to main content

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

  1. First, navigate to your ROS 2 workspace:

    cd ~/ros2_ws/src
  2. 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

  1. Inside the lift_svc_interface package, create a directory named action:

    mkdir -p ~/ros2_ws/src/lift_svc_interface/action
  2. Create a file named LOPAction.action inside the action directory:

    touch ~/ros2_ws/src/lift_svc_interface/action/LOPAction.action
  3. 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
  1. Create a file named COPAction.action inside the action directory:

    touch ~/ros2_ws/src/lift_svc_interface/action/COPAction.action
  2. 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

  1. Open the CMakeLists.txt file of your lift_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

  1. Open the package.xml file of your lift_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

  1. 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.