ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

Visibility_control header returns "no such file or directory " when i include header into cpp (SOLVED)

asked 2021-03-22 11:24:21 -0600

ferro gravatar image

updated 2021-03-23 13:47:30 -0600

I am currently try to learn ROS2 foxy for my project. I am checking tutorials on ROS2 Foxy documentation and try to write an action server/client(C++) . I did create an action like in tutorial , but when i tried to create action server , i get "no such file or directory" error . I do as said in tutorial, i include visibility_control.h in cpp i get error.

action_tutorials_interfaces/CMakeList.txt

   cmake_minimum_required(VERSION 3.5)
project(action_tutorials_interfaces)

# Default to C99
if(NOT CMAKE_C_STANDARD)
  set(CMAKE_C_STANDARD 99)
endif()

# 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")
  add_compile_options(-Wall -Wextra -Wpedantic)
endif()

# find dependencies
find_package(ament_cmake REQUIRED)
find_package(rosidl_default_generators REQUIRED)

rosidl_generate_interfaces(${PROJECT_NAME}
    "action/Fibonacci.action"
)

# uncomment the following section in order to fill in
# further dependencies manually.
# find_package(<dependency> REQUIRED)

if(BUILD_TESTING)
  find_package(ament_lint_auto REQUIRED)
  # the following line skips the linter which checks for copyrights
  # uncomment the line when a copyright and license is not present in all source files
  #set(ament_cmake_copyright_FOUND TRUE)
  # the following line skips cpplint (only works in a git repo)
  # uncomment the line when this package is not in a git repo
  #set(ament_cmake_cpplint_FOUND TRUE)
  ament_lint_auto_find_test_dependencies()
endif()

ament_package()

action_tutorials_interfaces/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_tutorials_interfaces</name>
  <version>0.0.0</version>
  <description>TODO: Package description</description>

  <maintainer email="ferro@todo.todo">ferro</maintainer>
  <license>TODO: License declaration</license>

  <buildtool_depend>ament_cmake</buildtool_depend>

  <buildtool_depend>rosidl_default_generators</buildtool_depend>
  <depend>action_msgs</depend>
  <member_of_group>rosidl_interface_packages</member_of_group>

  <test_depend>ament_lint_auto</test_depend>
  <test_depend>ament_lint_common</test_depend>

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

action_tutorials_cpp/fibonacci_action_server.cpp

#include <functional>
#include <memory>
#include <thread>

#include "action_tutorials_interfaces/action/fibonacci.hpp"
#include "rclcpp/rclcpp.hpp"
#include "rclcpp_action/rclcpp_action.hpp"
#include "rclcpp_components/register_node_macro.hpp"

#include "action_tutorials_cpp/visibility_control.h"

namespace action_tutorials_cpp
{
class FibonacciActionServer : public rclcpp::Node
{
public:
  using Fibonacci = action_tutorials_interfaces::action::Fibonacci;
  using GoalHandleFibonacci = rclcpp_action::ServerGoalHandle<Fibonacci>;

  ACTION_TUTORIALS_CPP_PUBLIC
  explicit FibonacciActionServer(const rclcpp::NodeOptions & options = rclcpp::NodeOptions())
  : Node("fibonacci_action_server", options)
  {
    using namespace std::placeholders;

    this->action_server_ = rclcpp_action::create_server<Fibonacci>(
      this,
      "fibonacci",
      std::bind(&FibonacciActionServer::handle_goal, this, _1, _2),
      std::bind(&FibonacciActionServer::handle_cancel, this, _1),
      std::bind(&FibonacciActionServer::handle_accepted, this, _1));
  }

private:
  rclcpp_action::Server<Fibonacci>::SharedPtr action_server_;

  rclcpp_action::GoalResponse handle_goal(
    const rclcpp_action::GoalUUID & uuid,
    std::shared_ptr<const Fibonacci::Goal> goal)
  {
    RCLCPP_INFO(this->get_logger(), "Received goal request with order %d", goal->order);
    (void)uuid;
    return rclcpp_action::GoalResponse::ACCEPT_AND_EXECUTE;
  }

  rclcpp_action::CancelResponse handle_cancel(
    const std::shared_ptr<GoalHandleFibonacci> goal_handle)
  {
    RCLCPP_INFO(this->get_logger(), "Received request to cancel goal");
    (void)goal_handle;
    return rclcpp_action::CancelResponse::ACCEPT;
  }

  void handle_accepted(const std::shared_ptr<GoalHandleFibonacci> goal_handle)
  {
    using namespace std::placeholders;
    // this needs to return quickly to avoid blocking the executor, so spin up a new thread
    std::thread{std::bind(&FibonacciActionServer::execute, this, _1), goal_handle}.detach();
  }

  void execute(const std::shared_ptr<GoalHandleFibonacci> goal_handle)
  {
    RCLCPP_INFO(this->get_logger(), "Executing goal");
    rclcpp::Rate loop_rate(1);
    const auto goal = goal_handle->get_goal();
    auto feedback = std::make_shared<Fibonacci::Feedback>();
    auto & sequence = feedback->partial_sequence;
    sequence.push_back(0);
    sequence.push_back(1);
    auto result = std::make_shared<Fibonacci::Result>();

    for (int i = 1; (i < goal->order) && rclcpp::ok(); ++i) {
      // Check if there is a ...
(more)
edit retag flag offensive close merge delete

Comments

where is the visibility_control.h file exactly in your project?

christophebedard gravatar image christophebedard  ( 2021-03-23 11:57:31 -0600 )edit
1

action_tutorials_cpp/include/action_tutorials_cpp/"

ferro gravatar image ferro  ( 2021-03-23 12:36:37 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2021-03-23 13:25:48 -0600

I followed the tutorial and get the same error too.

It looks like if you select the text (for the CMakeLists.txt) and copy/paste into an IDE/text editor, it doesn't keep the $ before <BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> and <INSTALL_INTERFACE:include>.

These lines:

target_include_directories(action_server PRIVATE

<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>

<INSTALL_INTERFACE:include>)

should look like this:

target_include_directories(action_server PRIVATE

$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>

$<INSTALL_INTERFACE:include>)

This is kind of a bug in the documentation website, so I opened an issue: https://github.com/ros2/ros2_document...

edit flag offensive delete link more

Comments

I always write codes myself, but only one time i did copy and that happens :) Thank you so much, i will try as soon as possible.

ferro gravatar image ferro  ( 2021-03-23 13:33:04 -0600 )edit

Yeah i did work thanks again

ferro gravatar image ferro  ( 2021-03-23 13:47:52 -0600 )edit
1

my pleasure! :)

christophebedard gravatar image christophebedard  ( 2021-03-23 15:13:14 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2021-03-22 11:16:38 -0600

Seen: 925 times

Last updated: Mar 23 '21