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

Implement std_msgs in C++ programs (ros2)

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

Danroy gravatar image

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

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
0

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

drtritm gravatar image

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

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

Question Tools

2 followers

Stats

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

Seen: 1,457 times

Last updated: Jan 11 '21