How to solve error Invoking make when creating a subscriber node?

asked 2016-06-30 11:15:42 -0500

Nissrine gravatar image

updated 2022-01-22 16:16:32 -0500

Evgeny gravatar image

I am trying to create a subscriber called Bearings that will take the pose (x, y and z) from ar_track_alvar package and output a bearing 'a' and and angle 'b' using mathematical formulas. I tried to follow the beginner tutorial for creating a subscriber. This is my subscriber code

I included at the beginning of the code ros.h, AlvarMarker.h, pose.h, tf.h and trasform_datatypes.h.

void printPose(const ar_track_alvar_msgs::AlvarMarker::ConstPtr& msg)
{
    float a
    float b
    tf::Pose X;
    tf::Pose Y;
    tf::Pose Z;
    X.setOrigin(tf::pointMsgToTF(msg->pose.pose.position.x));
    Y.setOrigin(tf::pointMsgToTF(msg->pose.pose.position.y));
    Z.setOrigin(tf::pointMsgToTF(msg->pose.pose.position.z));

    a = sqrt(X^2 +Y^2);
    b = atan((Z/a);
    ROS_INFO("distance: ", a, "Angle", b);
}

int main(int argc, char **argv)
{
    ros::init(argc, argv, "Bearings");
    ros::NodeHandle n;
    ros::Subscriber sub = n.subscribe("ar_pose_marker",1000,printPose);
    ros:: spin();
    return 0;
}

I added these these lines to my cmakelist:

add_executable(Bearings src/Bearings.cpp)
target_link_libraries(Bearings ${catkin_LIBRARIES})
add_dependencies(Bearings ar_track_alvar_msgs_AlvarMarker)

find_package(catkin REQUIRED COMPONENTS
  roscpp
  rospy
  std_msgs
  ar_track_alvar
  tf
)

Thank you for your help,

Nissrine

EDIT

This is what is in my Cmakelist:

cmake_minimum_required(VERSION 2.8.3)
project(beginner_tutorials)

find_package(catkin REQUIRED COMPONENTS
  roscpp
  rospy
  std_msgs
ar_track_alvar
tf
)
catkin_package(
 INCLUDE_DIRS include
  LIBRARIES beginner_tutorials
  CATKIN_DEPENDS roscpp rospy std_msgs
  DEPENDS system_lib
)
include_directories(
  ${catkin_INCLUDE_DIRS}
)
add_executable(Bearings src/Bearings.cpp)
target_link_libraries(Bearings ${catkin_LIBRARIES})
add_dependencies(Bearings ar_track_alvar_msgs_AlvarMarker)

And this is what the error in the terminal looks like:

> /home/nissrine/catkin_ws/src/beginner_tutorials/src/Bearings.cpp:2:45:
> fatal error:
> ar_track_alvar_msgs/AlvarMarker.h: No
> such file or directory compilation
> terminated. make[2]: ***
> [beginner_tutorials/CMakeFiles/Bearings.dir/src/Bearings.cpp.o]
> Error 1 make[1]: ***
> [beginner_tutorials/CMakeFiles/Bearings.dir/all]
> Error 2 make: *** [all] Error 2
> Invoking "make" failed
> nissrine@nissrine-VirtualBox:~/catkin_ws$

I hope this helps,

Thanks again for your help

edit retag flag offensive close merge delete

Comments

I edited your question to improve the formatting

Icehawk101 gravatar image Icehawk101  ( 2016-06-30 11:53:53 -0500 )edit

Could you please post the output of running catkin_make? Without seeing the errors, it's difficult to know what might be wrong. You might also want to post the entire CMakeLists.txt (minus boilerplate comments).

jarvisschultz gravatar image jarvisschultz  ( 2016-06-30 12:35:51 -0500 )edit

I moved your answer to be an edit of your original question. In the future, please only post answers that are actually answers. Use edits and comments for additional information/questions.

jarvisschultz gravatar image jarvisschultz  ( 2016-06-30 14:11:28 -0500 )edit
1

The error is that catkin can't find an included header file. Your code must also have a #include <ar_track_alvar_msgs/AlvarMarker.h> line in it. Have you installed ar_track_alvar_msgs somehow? Did you install it from source or apt-get? Can you find that header file on your system?

jarvisschultz gravatar image jarvisschultz  ( 2016-06-30 14:46:39 -0500 )edit

Is there a way to do it without ar_track_alvar_msgs? I have the hydro distribution and that package comes indigo and after.

Nissrine gravatar image Nissrine  ( 2016-07-06 09:17:11 -0500 )edit

No... you'll need that required package. You could install that package from source as well.

jarvisschultz gravatar image jarvisschultz  ( 2016-07-14 12:31:31 -0500 )edit