Ask Your Question
0

How to create custom action interface definition in ros2?

asked 2019-05-17 05:26:58 -0500

SkandaNR gravatar image

I want to create the following plan_aid.action file:

string planning_problem
---
string trajectory
---
string planning_status

What is the exact procedure to do it in ROS2 (Crystal) I followed the following approach:

  • created a package named action_interface (action_interface, setup.py, package.xml)
  • action_interface folder with __ init __.py(empty) and action(plan_aid.action) folders
  • package.xml of action_client is added with <exec_depend>action_interface </exec_depend>

I am still getting the following error for the following code in action client node:

from aid.action_interface.action import plan_aid

Traceback (most recent call last):
File "/home/developer/ros2_ws/ros2/src/sm/state_machine/state_machine_node.py", line 8, in <module>
from aid.action_interface.action import plan_aid
ImportError: cannot import name 'plan_aid'
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2019-05-17 08:03:07 -0500

alsora gravatar image

updated 2019-05-17 08:03:43 -0500

Package structure

action_interface
 |_ action
 |     |_PlanAid.action
 |_ CMakeLists.txt
 |_ package.xml

Let's look at the files.

PlanAid.action

string planning_problem
---
string trajectory
---
string planning_status

package.xml

<?xml version="1.0"?>
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3">
  <name>action_interface</name>
  <version>0.0.1</version>
  <description>Examples of message and service interfaces</description>
  <maintainer email="alberto.soragna@gmail.com">Alberto Soragna</maintainer>
  <license>MIT</license>

  <buildtool_depend>ament_cmake</buildtool_depend>
  <buildtool_depend>rosidl_default_generators</buildtool_depend>

  <build_depend>std_msgs</build_depend>
  <build_depend>action_msgs</build_depend>

  <exec_depend>rosidl_default_runtime</exec_depend>
  <exec_depend>std_msgs</exec_depend>
  <exec_depend>action_msgs</exec_depend>

  <member_of_group>rosidl_interface_packages</member_of_group>

  <export>
    <build_type>ament_cmake</build_type>
  </export>
</package>

CMakeLists.txt

cmake_minimum_required(VERSION 3.5)

project(action_interface)

# Default to C++14
if(NOT CMAKE_CXX_STANDARD)
  set(CMAKE_CXX_STANDARD 14)
endif()
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
  # we dont use add_compile_options with pedantic in message packages
  # because the Python C extensions dont comply with it
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wpedantic")
endif()

find_package(ament_cmake REQUIRED)
find_package(rosidl_default_generators REQUIRED)
find_package(std_msgs REQUIRED)
find_package(action_msgs REQUIRED)

rosidl_generate_interfaces(${PROJECT_NAME}
  action/PlanAid.action
  DEPENDENCIES std_msgs action_msgs
)

ament_export_dependencies(rosidl_default_runtime)
ament_package()
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

2 followers

Stats

Asked: 2019-05-17 05:26:58 -0500

Seen: 36 times

Last updated: May 17