Using Float64MultiArray with C++
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>
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".