ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A
Ask Your Question

Implement std_msgs in C++ programs (ros2)

asked 2021-01-11 07:58:44 -0600

Danroy gravatar image

updated 2021-01-11 08:39:23 -0600

gvdhoorn gravatar image

Hallo everyone, I am trying to write a simple C++ Subscriber, who listen to a python program, which publishes x-, and y values. Therefore i am using std_msgs/msg/Float64MultiArray and fill the array with received x-, y values. This is already working and when i echo the topic i can see the values being published. Unfortunately moveit2 can currently only be used with C++. That's why i have to write the subscribe in c++ to get the values and based on them, doing the motion planning to move to the received values. I have tried to follow the ros2 Simple-Cpp-Publisher-And-Subscriber instruction, which worked fine. I also tried to include the floatarray into my c++ file as followed:

#include "std_msgs/msg/Float64MultiArray.hpp"

But when i try to build my package i get the following message:

Starting >>> motion_planning
--- stderr: motion_planning                             
/home/ubuntu-20041/ros2_ws/src/motion_planning/src/obj_dect_sub.cpp:7:10: fatal error: std_msgs/msg/Float64MultiArray.hpp: No such file or directory
    7 | #include "std_msgs/msg/Float64MultiArray.hpp"
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
make[2]: *** [CMakeFiles/obj_dect_sub.dir/build.make:63: CMakeFiles/obj_dect_sub.dir/src/obj_dect_sub.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:78: CMakeFiles/obj_dect_sub.dir/all] Error 2
make: *** [Makefile:141: all] Error 2

i also included the std_msgs into my package (CMake, package.xml file). I am not good with c++, so i hope you guys can tell me, what i am missing. If there are any informations missing please let me now.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2021-01-11 22:29:23 -0600

drtritm gravatar image

updated 2021-01-11 22:29:52 -0600

dear my friend, according to directory of ROS2 in opt, maybe you should change it to "std_msgs/msg/float64_multi_array.hpp"

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



Asked: 2021-01-11 07:58:44 -0600

Seen: 616 times

Last updated: Jan 11 '21