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

shinnqy's profile - activity

2017-07-07 04:09:51 -0500 received badge  Favorite Question (source)
2014-07-27 16:04:39 -0500 received badge  Famous Question (source)
2014-05-23 00:42:55 -0500 received badge  Enthusiast
2014-05-22 01:39:24 -0500 commented answer How can I get depth data from Kinect?

Thank you very much. I already solved the problem. The hackish solution you mentioned works, but it's difficult for a beginner like me to understand. So I tried OpenCV as you answered and I will update it under my question for other beginners.

2014-05-21 22:59:25 -0500 commented answer get the raw kinect data

Can you tell how to access the floating point values in cv_ptr->image?

2014-05-09 00:55:09 -0500 received badge  Scholar (source)
2014-05-08 23:21:48 -0500 received badge  Notable Question (source)
2014-05-07 20:35:15 -0500 received badge  Famous Question (source)
2014-05-07 07:30:32 -0500 received badge  Popular Question (source)
2014-05-06 23:08:40 -0500 received badge  Editor (source)
2014-05-06 23:07:38 -0500 asked a question How can I publish the subscribed and processed msgs in a single node?

Hi guys, I'm quite new to ROS and I also just start learning C++ in ROS.

I have followed the tutorial ROS/Tutorials/WritingPublisherSubscriber(c++) and already known how to write a publisher and a subscriber separately.

But I wonder can I put a publisher and subscriber in the same node. I searched and found this answer how to put subscriber and publisher in one cpp file ?. Yes, it does put them together, but they just work separately.

What I want to do is Node A published "hello world" to Node B, and Node B can process the messages and then publish the edited resultes to Node C.

I tried a simple node and this is my code based on the sample codes.

#include "ros/ros.h"
#include "std_msgs/String.h"
#include <sstream>

void chatterCallback(const std_msgs::String::ConstPtr& msg)
{
  if("%s" == "hello world ", msg->data.c_str())
  {
    ROS_INFO("I heard: [%s]", msg->data.c_str());

    ros::NodeHandle n;
    ros::Publisher chatter_pub = n.advertise<std_msgs::String>("chatter2", 1000);
    std_msgs::String msg;
    std::stringstream ss;
    ss << "long time no see";
    msg.data = ss.str();
    chatter_pub.publish(msg);
    ros::spinOnce();
  }
  else
  {
    ROS_INFO("I didn't hear: [%s]", msg->data.c_str());
  }
}

int main(int argc, char **argv)
{
  ros::init(argc, argv, "trans");
  ros::NodeHandle n;
  ros::Subscriber sub = n.subscribe("chatter1", 1000, chatterCallback);
  ros::spin();

  return 0;
}

But only the communication between talker and trans works, there is no message on topic chatter2.

Can anyone help me find where is wrong or give me a sample code to study?

2014-05-06 03:10:16 -0500 received badge  Supporter (source)
2014-05-06 00:07:24 -0500 received badge  Notable Question (source)
2014-05-05 23:41:24 -0500 received badge  Nice Question (source)
2014-05-05 23:09:15 -0500 received badge  Student (source)
2014-05-05 19:23:05 -0500 received badge  Popular Question (source)
2014-05-04 20:52:49 -0500 asked a question How can I get depth data from Kinect?

Hi guys, I'm quite new to ROS. I'm using the Ubuntu 12.04 and openni driver.

What I've been trying to do is to use Kinect to detect whether a door is open or closed. My idea is to write a node to subscribe to camera/depth/image, and and can retrieve a distance at the center point in the image.

But when I use rostopic echo camera/depth/image I just get a lot of numbers like 0, 0, 65, 128, 36, 56, 77, 102, 140, 65. So does anyone know what should I do with these numbers, or are there other ways to get depth data?


Firstly, thank Martin Günther's answer, it really help me a lot. And I already solve the problem by using OpenCV. Here is part of my code, it's very easy. If some beginners cannot understand that hackish solution, maybe you should try this one:

#include <image_transport/image_transport.h>
#include <cv_bridge/cv_bridge.h>
#include <sensor_msgs/image_encodings.h>
#include ..........

namespace enc = sensor_msgs::image_encodings;
void imageCallback(const sensor_msgs::ImageConstPtr& msg)
{
    cv_bridge::CvImagePtr cv_ptr;
    try
    {
      cv_ptr = cv_bridge::toCvCopy(msg, enc::TYPE_16UC1);//now cv_ptr is the matrix, do not forget "TYPE_" before "16UC1"
    }
    catch (cv_bridge::Exception& e)
    {
      ROS_ERROR("cv_bridge exception: %s", e.what());
      return;
    }

    int depth = cv_ptr->image.at<short int>(cv::Point(240,320));//you can change 240,320 to your interested pixel
    ROS_INFO("Depth: %d", depth);
}

int main(int argc, char **argv)
{.........}