how to subscriber from /diagnastic

asked 2017-07-01 21:35:40 -0600

RaoBrother gravatar image

updated 2017-07-01 21:53:51 -0600

ahendrix gravatar image

Hi All, Please help me for how to subscriber from /diagnastic according levels(OK , WARN , ERROR). below my example code ...

Example :

DiagnosticSubscriber::DiagnosticSubscriber()
{

    cout<<"Constructor calling"<<endl;

}

void DiagnosticSubscriber::msgCallback(const diagnostic_msgs::DiagnosticStatus::ConstPtr& DiagnosticStatusmsg)
{
    cout<<"msgCallback calling"<<endl;
    ROS_INFO("CPP Subscriber  ");

}

void DiagnosticSubscriber::display()
{
    cout<<"display calling"<<endl;
    sub = nh.subscribe("/diagnostics",1,&DiagnosticSubscriber::msgCallback,this);

}


int main(int argc , char **argv)
{
    ros::init(argc,argv,"DiagnosticSubscriber");
    DiagnosticSubscriber obj;
    obj.display();
    ros::spin();
    return 0;
}
edit retag flag offensive close merge delete

Comments

It looks like you're written the basic subscriber.

ahendrix gravatar image ahendrix  ( 2017-07-01 21:54:44 -0600 )edit

yes , its basic subscriber .. is there any other idea please give me answer ....

Thanks very much u r responses.

RaoBrother gravatar image RaoBrother  ( 2017-07-02 02:18:06 -0600 )edit

I don't understand what your question is. You asked how to write a subscriber but you have written the subscriber.

ahendrix gravatar image ahendrix  ( 2017-07-02 15:53:38 -0600 )edit

yes sir i have written code for subscriber . Using /diagnastic topic i am publishing three levels like Ok , warn , error . my gole is the write code for subscriber on topic /diagnostic so if i code get any warn or error / ok .. but is not working .

RaoBrother gravatar image RaoBrother  ( 2017-07-02 22:40:15 -0600 )edit

is this code is worng way or if you have have better solution .. please shared with me ..

Thanks

RaoBrother gravatar image RaoBrother  ( 2017-07-02 22:41:02 -0600 )edit