Ask Your Question
0

Why is my callback function not called

asked 2015-03-18 14:11:39 -0600

215 gravatar image

updated 2015-03-18 14:32:19 -0600

I trying to understand why my subscriber isn't outputting anything.. It seems like, it doesn't get called, but it doesn't make sense why it doesn't...

Anyone who could explain??

 #include "image_converter.h"

ImageConverter::ImageConverter()
    : it_(nh_),pos(2),  vel(2)
  {
    // Subscrive to input video feed and publish output video feed
    image_sub_ = it_.subscribe("/bumblebeePTU/left/image_rect_color", 1,
      &ImageConverter::imageCb, this);
    image_pub_ = it_.advertise("/image_converter/output_video", 1);
    //position_prev_pan = 0;

    //cv::namedWindow(OPENCV_WINDOW);
  }

 ImageConverter::~ImageConverter()
  {
    //cv::destroyWindow(OPENCV_WINDOW);
  }

void ImageConverter::chatterCallback(const sensor_msgs::JointState::ConstPtr& msg)
   {   
         position_prev_p = sin(msg->position[0]*0.000727220522);
         position_prev_t = sin(msg->position[0]*0.000727220522);
         ROS_INFO_STREAM("LALALALALALALALALALALALALALALALAL");

   }

  void ImageConverter::imageCb(const sensor_msgs::ImageConstPtr& msg)
  {
         ros::Publisher facedetect_pub = nh_.advertise<sensor_msgs::JointState>("/ptu/cmd", 1);
         ros::Subscriber sub = nh_.subscribe("/joint_states",1,&ImageConverter::chatterCallback,this);  
         cv_bridge::CvImagePtr cv_ptr;
    try
    {
      cv_ptr = cv_bridge::toCvCopy(msg, sensor_msgs::image_encodings::BGR8);
    }
    catch (cv_bridge::Exception& e)
    {
      ROS_ERROR("cv_bridge exception: %s", e.what());
      return;
    }
        sensor_msgs::JointState ms;
        pair<double,double> displacement = detectAndDisplay(cv_ptr->image);
        double positions[9] = {0.6,0,-0.6,0.6,0,-0.6,0.6,0,-0.6};
    // Detect and outputs next position to PTU
    for(int i = 0; i<9; ++i){
                pos[0] = positions[i];//ceil(sin(displacement.first*0.000727220522)*1000)/1000 + position_prev_p;
                pos[1] = 0;//ceil(sin(displacement.second*0.000727220522)*1000)/1000 + position_prev_t;
                ms.position = pos;
                vel[0] = 0.3;//abs(pos[0]);//2*atan(displacement.first+position_prev[0]/2*physical_width)*0.01 ;
                vel[1] = 0.3;//abs(pos[1]);
                ms.velocity = vel;
                ROS_INFO_STREAM("p: "<<pos[0]);
                ROS_INFO_STREAM("p_prev: " << position_prev_pan);

    // Output modified video stream
    image_pub_.publish(cv_ptr->toImageMsg());
        }
  }
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2015-03-18 14:37:24 -0600

215 gravatar image

The subscriber goes out of scope in my class.. I've added the subscriber as a member variable which fixed the problem.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2015-03-18 14:11:39 -0600

Seen: 1,100 times

Last updated: Mar 18 '15