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

Using Float64MultiArray with C++

asked 2021-02-18 04:06:06 -0600

Danroy gravatar image

Hallo everyone, im trying to write a C++ subscriber, which receive Float64MultiArray data. I use to work with python and successfully wrote a publisher in python which sends Float64MultiArray data. Now i am trying to write a C++ program and followed this simple C++ Publisher to get it running. But when i try to build my package i get the following error:

Starting >>> schulung_cpp --- stderr: schulung_cpp /home/ubuntu-20041/ros2_ws/src/schulung_cpp/src/moveit.cpp:8:10: fatal error: std_msgs/msg/Float64MultiArray.h: No such file or directory 8 | #include "std_msgs/msg/Float64MultiArray.h" | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ compilation terminated. make[2]: * [CMakeFiles/moveit.dir/build.make:63: CMakeFiles/moveit.dir/src/moveit.cpp.o] Error 1 make[1]: [CMakeFiles/Makefile2:78: CMakeFiles/moveit.dir/all] Error 2 make: ** [Makefile:141: all] Error 2 --- Failed <<< schulung_cpp [0.53s, exited with code 2]

it seems that i fail to implement the Float64MultiArray correct. I already tried different implentation to get it running but was not successfull yet. The subscriber needs to be written C++ for my case. I'll provide my cpp file as well as my CMakeLists.txt and package.xml file. Any help would be appreciated.

C++ File:

#include <chrono>
#include <functional>
#include <memory>
#include <string>
#include <memory>

#include "rclcpp/rclcpp.hpp"
#include "std_msgs/msg/Float64MultiArray.h"


using std::placeholders::_1;

class MinimalSubscriber : public rclcpp::Node
{
  public:
    MinimalSubscriber()
    : Node("minimal_subscriber")
    {
      subscription_ = this->create_subscription<std_msgs::msg::Float64MultiArray>(
      "topic", 10, std::bind(&MinimalSubscriber::topic_callback, this, _1));
    }

  private:
    void topic_callback(const std_msgs::msg::Float64MultiArray::ConstPtr& msg) const
    {
        RCLCPP_INFO(this->get_logger(), "I heard: '%s'", msg->data.c_str());
    }
    rclcpp::Subscription<std_msgs::msg::Float64MultiArray>::ConstPtr& subscription_;
};

int main(int argc, char * argv[])
{
  rclcpp::init(argc, argv);
  rclcpp::spin(std::make_shared<MinimalSubscriber>());
  rclcpp::shutdown();
  return 0;
}

CMakeLists.txt:

cmake_minimum_required(VERSION 3.5)
project(schulung_cpp)

# 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_package(ament_cmake REQUIRED)
find_package(rclcpp REQUIRED)
find_package(std_msgs REQUIRED)

add_executable(moveit src/moveit.cpp)
ament_target_dependencies(moveit rclcpp std_msgs)

install(TARGETS
  moveit
  DESTINATION lib/${PROJECT_NAME})

ament_package()

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>schulung_cpp</name>
  <version>0.0.0</version>
  <description>Schulung</description>
  <maintainer email="ubuntu-20041@todo.todo">ubuntu-20041</maintainer>
  <license>Declaration</license>

  <buildtool_depend>ament_cmake</buildtool_depend>
  <depend>rclcpp</depend>
  <depend>std_msgs</depend>

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

  <export>
    <build_type>ament_cmake</build_type>
  </export>
</package>
edit retag flag offensive close merge delete

Comments

1

I've removed my answer, as it was not correct. std_msgs is still available in Foxy. It will be removed in "a future ROS 2 release".

gvdhoorn gravatar image gvdhoorn  ( 2021-02-18 05:47:15 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2021-02-18 09:03:18 -0600

miura gravatar image

updated 2021-02-19 07:53:13 -0600

Perhaps changing

#include "std_msgs/msg/Float64MultiArray.h"

to

#include "std_msgs/msg/float64_multi_array.hpp"

will solve the problem.

edit flag offensive delete link more

Comments

1

I think it should be "std_msgs/msg/float64_multi_array.hpp"

drtritm gravatar image drtritm  ( 2021-02-18 22:49:30 -0600 )edit

@drtritm Thanks for the comment. I think it is as you pointed out. I will correct it.

miura gravatar image miura  ( 2021-02-19 07:52:18 -0600 )edit

Hi, I tried your suggestion and I am still getting the error

fatal error: std_msgs/msg/float64_multi_array.hpp: No such file or directory
   30 | #include "std_msgs/msg/float64_multi_array.hpp"
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

~~

akumar3.1428 gravatar image akumar3.1428  ( 2023-02-15 09:07:53 -0600 )edit

@akumar3.1428 This may be because the include destination changes depending on the distribution. For example, in ROS2 Humble, it seems to be std_msgs/msg/std_msgs/float64_multi_array.hpp.

miura gravatar image miura  ( 2023-02-17 22:07:00 -0600 )edit

Question Tools

2 followers

Stats

Asked: 2021-02-18 04:06:06 -0600

Seen: 2,914 times

Last updated: Feb 19 '21