0
$\begingroup$

Rosanswers logo

Hi

  • I'm a beginner on ROS.
  • I want to use a topic "/usb_cam/image_raw". (this topic is usb_cam package)
  • So I made a package, and a Subscriber.
  • However, there is still error in the catkin_make process.
  • How can I write CMakeList ?

main source

#include "ros/ros.h"
#include "sensor_msgs/Image.h"

void msgCallback(const sensor_msgs::Image::ConstPtr& msg)
{
        ROS_INFO("height = %d, width = %d",msg->height, msg->width);
}
int main(int argc, char** argv)
{
        ros::init(argc,argv,"cam_data");
        ros::NodeHandle nh;

        ros::Subscriber cam_sub = nh.subscribe("/usb_cam/image_raw",100,msgCallback);
        ros::spin();

        return 0;
}

CMakeList

cmake_minimum_required(VERSION 2.8.3)
project(test_cam)

## Find catkin macros and libraries
## if COMPONENTS list like find_package(catkin REQUIRED COMPONENTS xyz)
## is used, also find other catkin packages
find_package(catkin REQUIRED COMPONENTS
  roscpp
  sensor_msgs
)


 generate_messages(
   DEPENDENCIES
   sensor_msgs
 )

catkin_package(
#  INCLUDE_DIRS include
  LIBRARIES test_cam
  CATKIN_DEPENDS roscpp sensor_msgs
  DEPENDS system_lib
)

include_directories(
  ${catkin_INCLUDE_DIRS}
)

add_executable(receive_cam src/receive_cam.cpp)
#target_link_libraries(test_cam ${catkin_LIBRARIES})
#add_dependencies(receive_cam test_cam_cpp)

Originally posted by anonymous28394 on ROS Answers with karma: 13 on 2016-10-31

Post score: 1

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

You have several problems:

  1. If you are going to use the generate_msgs() macro to ensure message dependencies are built, you'll need a find_package call for message_generation, you'll also need to list message_runtime as a CATKIN_DEPENDS in your catkin_package macro. You'll also need to add message_generation as a build dependency and message_runtime as a run dependency in your package.xml. Documentation here.
  2. You have what appear to be incorrectly specified dependencies in your catkin_package macro. Is system_lib actually a CMake project containing libraries that you depend on? Are you providing the test_cam library for use with other catkin packages? Documentation here
  3. You need to link your executable against libraries that your package depends on with target_link_libraries.

Here's a version that should work:

cmake_minimum_required(VERSION 2.8.3)
project(test_cam)

find_package(catkin REQUIRED COMPONENTS
  roscpp
  sensor_msgs
  message_generation
)

generate_messages(
  DEPENDENCIES sensor_msgs
 )

catkin_package(
  INCLUDE_DIRS include
  CATKIN_DEPENDS roscpp message_runtime sensor_msgs
)

include_directories(
  ${catkin_INCLUDE_DIRS}
)

add_executable(receive_cam src/receive_cam.cpp)
target_link_libraries(receive_cam ${catkin_LIBRARIES})

Originally posted by jarvisschultz with karma: 9031 on 2016-10-31

This answer was ACCEPTED on the original site

Post score: 1


Original comments

Comment by gvdhoorn on 2016-10-31:
Note: @breeze6478 is writing a subscriber. generate_message(..) is typically not needed/used in that case, as he depends on sensor_msgs. I think the only problem (but this is a guess) was that generate_messages(..) is there. It's not needed. And of course the test_cam etc.

Comment by jarvisschultz on 2016-10-31:
That is for sure correct, unless the package is defining custom messages, no call to generate_messages() should be needed. Without more info on the package, it was tough to tell whether I should delete the call or fix the call.

Comment by jarvisschultz on 2016-10-31:
If he is only writing a subscriber, I should have probably just deleted the call.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.