Timer Callback not getting called
Here Is My timer callback code
#include <ros ros.h="">
#include <stdio.h>
class Timer {
public:
ros::NodeHandle nh_;
Timer(ros::NodeHandle* nh) ;
void init_timers();
void stateTimerCallback(const ros::TimerEvent& event);
};
Timer::Timer(ros::NodeHandle* nh) : nh_(*nh) {
Timer::init_timers();
}
void Timer::init_timers()
{
const bool oneshot = false;
bool autostart = true;
ros::Timer timer_ = nh_.createTimer(ros::Duration(1.0),&Timer::stateTimerCallback,this,oneshot,autostart);
timer_.start() ;
ROS_INFO("Init_Timer \n");
printf("Init_Timer\n");
ROS_DEBUG("Init_Timer\n");
}
void Timer::stateTimerCallback(const ros::TimerEvent& event)
{
ROS_INFO("I am here\n");
printf("I am here\n");
ROS_DEBUG("I am here\n");
}
int main(int argc, char **argv)
{
ros::init(argc,argv,"timer_node");
ros::NodeHandle nh;
Timer timer(&nh);
ros::spin();
return 0;
}
The output i get after running the node
$ rosrun timertest timertest_node
[ INFO] [1685511182.674019058]: /timer_node: Init_Timer
Init_Timer
I wait for 1 minute but still there was no output from callback. What might be the reason ?
Really sorry if my question comes out as silly. I am not completely sure about working of roscpp.