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

Subscribing to depth information from zed camera

asked 2016-07-08 14:21:02 -0500

skr_robo gravatar image

updated 2016-07-08 14:21:48 -0500

I am trying to write a subscriber to obtain the depth information from a zed camera. I have written the following .cpp code:

//#include <iostream>
#include "ros/ros.h"
//#include "std_msgs/String.h"
#include "sensor_msgs/Image.h"

//using namespace std;

void depthCallback(const sensor_msgs::Image& msg)
{
    ROS_INFO("Depth Info: [%d]", msg->data )
}
int main(int argc, char **argv)
{
    //cout << "Hello world!" << endl;
    ros::init(argc, argv, "zed_depth_subscriber")
    ros::NodeHandle n;
    ros::Subscriber sub = n.subscribe("/camera/depth/image_rect_color",1000, depthCallback);
    ros::spin ();
    return 0;
}

I realize that the line: ROS_INFO("Depth Info: [%d]", msg->data ) may throw an error (I am expecting a matrix, but not really sure how I can handle it in a ROS subscriber). But my current problem is related to CMakeLists.txt and package.xml files.

This subscriber is supposed to obtain depth information from the topic /camera/depth/image_rect_color from the zed wrapper. I am planning to add this .cpp file to

~/catkin_ws/src/zed-ros-wrapper/src/

and edit the CMakeLists.txt in the location:

~/catkin_ws/src/zed-ros-wrapper/

I am looking at the example given in ROS Tutorials which gave me the following:

add_executable(listener src/listener.cpp)
target_link_libraries(listener ${catkin_LIBRARIES})
add_dependencies(listener beginner_tutorials_generate_messages_cpp)

I know that 'listener' should be replaced with 'zed_depth_subscriber'. But how do I identify the dependencies? How will the line add_dependencies(.... change?

Also do I need to edit package.xml residing in the same folder as that of CMakeLists.txt?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2016-07-18 11:18:20 -0500

skr_robo gravatar image

updated 2016-07-18 11:38:44 -0500

I figured out how to do it. I created a separate package for the subscriber. I have the following depthCallback function now:

void depthCallback(const sensor_msgs::Image::ConstPtr& msg)
{
    ROS_INFO("Depth Info: [%d]", msg->data[500]);
}

The main dependency required is sensor_msgs (along with roscpp). The add_dependecies(... line in the CmakeLists.txt would look like:

add_dependencies(zed_depth_subscriber_node sensor_msgs_generate_messages_cpp)

The package.xml should have the sensor_msgs as run and build dependency.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2016-07-08 14:21:02 -0500

Seen: 722 times

Last updated: Jul 18 '16