how to publish sensor_msgs/Joy in C++ ?

asked 2016-03-30 01:43:04 -0500

Jeesang gravatar image

updated 2016-03-30 02:05:26 -0500

I already did check that using command in terminal using 'rostopic echo /teleop/joy'. But, I 'd like to check in my source code based on C++.

Here is my current test source code,


ros::Publisher  pub_joy;  
pub_joy = nh.advertise<sensor_msgs::Joy>("/teleop/joy", 1000);



   void push_joyBtnStart() {

    sensor_msgs::Joy joy;

    joy.buttons.clear();

    joy.buttons.push_back(0);   
    joy.buttons.push_back(0);
    joy.buttons.push_back(0);
    joy.buttons.push_back(0);
    joy.buttons.push_back(0);
    joy.buttons.push_back(0);   
    joy.buttons.push_back(0);
    joy.buttons.push_back(0);
    joy.buttons.push_back(1);   // means 'start' button
    joy.buttons.push_back(0);
    joy.buttons.push_back(0);
    joy.buttons.push_back(0);
    joy.buttons.push_back(0);   // 11

    pub_joy.publish(joy);

    ROS_INFO("pushed start button");
}

This running node while doing echo rostopic('teleop/joy') in terminal. But, result is no response.

Any idea about this issue ? or Did you find my problem of this situation ?

Thanks.

edit retag flag offensive close merge delete

Comments

what do you mean by no response? rostopic echo teleop/joy does not show anything or your robot is not moving? and are you making sure your function is being called?

Mehdi. gravatar image Mehdi.  ( 2016-03-30 02:58:54 -0500 )edit

Sorry, it means that rostopic echo does not show anything. also I make sure my function is being called in main loop.

Jeesang gravatar image Jeesang  ( 2016-03-30 03:23:40 -0500 )edit

As @Mehdi said please confirm that this function is being called. Second do you spin your node?

BennyRe gravatar image BennyRe  ( 2016-03-30 04:56:05 -0500 )edit