48 #define MAIN_THREAD_PERIOD_MS 50000 //50ms (20Hz) 49 #define NSEC_PER_SEC 1000000000L 51 int main(
int argc,
char** argv)
53 ros::init(argc, argv,
"noid_ros_controller");
60 if (!hw.
init(nh, robot_nh)) {
61 ROS_ERROR(
"Faild to initialize hardware");
74 ROS_INFO(
"ControllerManager start with %f Hz", 1.0/period);
78 long main_thread_period_ns = period*1000*1000*1000;
79 double max_interval = 0.0;
80 double ave_interval = 0.0;
82 clock_gettime( CLOCK_MONOTONIC, &m_t );
89 tm.tv_nsec = m_t.tv_nsec;
90 tm.tv_sec = m_t.tv_sec;
91 tm.tv_nsec += main_thread_period_ns;
96 clock_nanosleep( CLOCK_MONOTONIC, TIMER_ABSTIME, &tm, NULL );
99 ROS_INFO(
"max: %f [ms], ave: %f [ms]", max_interval/1000, ave_interval/1000);
104 clock_gettime( CLOCK_MONOTONIC, &n_t );
105 const double measured_interval = ((n_t.tv_sec - m_t.tv_sec)*
NSEC_PER_SEC + (n_t.tv_nsec - m_t.tv_nsec))/1000.0;
106 if (measured_interval > max_interval) max_interval = measured_interval;
107 if(ave_interval == 0.0) {
108 ave_interval = measured_interval;
110 ave_interval = (measured_interval + (100 - 1)*ave_interval)/100.0;
112 m_t.tv_sec = n_t.tv_sec;
113 m_t.tv_nsec = n_t.tv_nsec;
119 hw.
read (now, period);
121 hw.
write (now, period);
int main(int argc, char **argv)
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
virtual void write(const ros::Time &time, const ros::Duration &period)
virtual bool init(ros::NodeHandle &root_nh, ros::NodeHandle &robot_hw_nh)
void update(const ros::Time &time, const ros::Duration &period, bool reset_controllers=false)
virtual void read(const ros::Time &time, const ros::Duration &period)