Timer callback not always working

asked 2014-04-11 11:28:58 -0600

Vince Cross gravatar image

updated 2016-10-24 08:36:49 -0600

ngrennan gravatar image

I am attempting to use a timer callback in my c++ code. The issue is the when I run it using rosrun or roslaunch the callback does not always start. Sometimes when I run the program the callback function is called and other times when I start the program it is not called. As far as I can tell everything is correct I just don't understand why sometimes the callback timer works and other times it does not.

Here are some portions of my code any assistance would be greatly appreciated.

class CytonServer
{
public:
    CytonServer();
private:
    ...
    void gripper_Callback(const std_msgs::Float64::ConstPtr& msg);
    void execute_Callback(const std_msgs::String::ConstPtr& msg);
    void publish_Callback();
    void joyCallback(const sensor_msgs::Joy::ConstPtr& joy);
    ...
    ros::Timer timer_;
    boost::mutex publish_mutex_;
    ros::NodeHandle nh_, ph_;

CytonServer:CytonServer(){

    timer_ = nh_.createTimer(ros::Duration(0.100), boost::bind(&CytonServer::publish_Callback, this));
  ///Subscriber List
  gripper_ = nh_.subscribe("gripper_value", 10, &CytonServer::gripper_Callback, this);
  execute_ = nh_.subscribe("execute", 10, &CytonServer::execute_Callback, this);
  joy_ = nh_.subscribe("joy", 10, &CytonServer::joyCallback, this);
  ...
}

...
void CytonServer::publish_Callback()
{ 
 ROS_INFO("PUBLISH");
  boost::mutex::scoped_lock lock(publish_mutex_);
  //DO STUFF
}
edit retag flag offensive close merge delete