timer_test.cpp
Go to the documentation of this file.
1 #include <ros/ros.h>
2 #include <swri_roscpp/timer.h>
4 
6 
7 namespace du = diagnostic_updater;
8 
9 // Alias type for easier access to DiagnosticStatus enumerations.
10 typedef diagnostic_msgs::DiagnosticStatus DS;
11 
12 class TimerTest
13 {
18 
20 
22 
23  public:
25  {
26  // Setup a one-shot timer to initialize the node after a brief
27  // delay so that /rosout is always fully initialized.
28  ROS_INFO("Starting initialization timer...");
31  this,
32  true);
33  }
34 
35  void initialize(const ros::WallTimerEvent &ignored)
36  {
39  this);
40 
41  ros::NodeHandle pnh("~");
42  swri::param(pnh, "fibonacci_index", fibonacci_index_, 30);
43 
46  "swri::Timer test", this,
48 
51  this);
52  }
53 
54  void handleUpdateTimer(const ros::TimerEvent &ignored)
55  {
56  // Do some work to give us a measurable time.
57  size_t number = super_slow_fibonacci(fibonacci_index_);
58  ROS_INFO("The %d-th number of the fibonacci sequence is %lu",
59  fibonacci_index_, number);
60  }
61 
63  {
64  if (x <= 0) {
65  return 0;
66  } else if (x == 1) {
67  return 1;
68  } else {
69  return super_slow_fibonacci(x-1) + super_slow_fibonacci(x-2);
70  }
71  }
72 
74  {
76  }
77 
79  {
80  status.summary(DS::OK, "No errors reported.");
81 
82  // This example uses swri::Timer's appendDiagnostics method to
83  // include diagnostics using a common format and common summary
84  // semantics. If we didn't care about specific bits of
85  // information, we use more specific flags.
86  update_timer_.appendDiagnostics(status, "Update",
88  }
89 
90 }; // class TimerTest
91 
92 int main(int argc, char **argv)
93 {
94  ros::init(argc, argv, "timer_test");
95 
96  TimerTest node;
97  ros::spin();
98 
99  return 0;
100 }
TimerTest::timerDiagnostics
void timerDiagnostics(du::DiagnosticStatusWrapper &status)
Definition: timer_test.cpp:78
ros::init
ROSCPP_DECL void init(const M_string &remappings, const std::string &name, uint32_t options=0)
ros.h
TimerTest::initialize
void initialize(const ros::WallTimerEvent &ignored)
Definition: timer_test.cpp:35
ros::WallTimer
diagnostic_updater::Updater
main
int main(int argc, char **argv)
Definition: timer_test.cpp:92
TimerTest::diag_timer_
swri::Timer diag_timer_
Definition: timer_test.cpp:17
TimerTest::handleUpdateTimer
void handleUpdateTimer(const ros::TimerEvent &ignored)
Definition: timer_test.cpp:54
diagnostic_updater.h
TimerTest::super_slow_fibonacci
int super_slow_fibonacci(int x)
Definition: timer_test.cpp:62
swri::Timer::appendDiagnostics
void appendDiagnostics(diagnostic_updater::DiagnosticStatusWrapper &status, const std::string &name, const int flags)
Definition: timer.h:228
TimerTest
Definition: timer_test.cpp:12
diagnostic_updater::DiagnosticStatusWrapper::summary
void summary(const diagnostic_msgs::DiagnosticStatus &src)
DS
diagnostic_msgs::DiagnosticStatus DS
Definition: timer_test.cpp:10
TimerTest::init_timer_
ros::WallTimer init_timer_
Definition: timer_test.cpp:15
swri::Timer::DIAG_ALL
@ DIAG_ALL
Definition: timer.h:87
diagnostic_updater
timer.h
TimerTest::nh_
ros::NodeHandle nh_
Definition: timer_test.cpp:14
TimerTest::handleDiagnosticsTimer
void handleDiagnosticsTimer(const ros::TimerEvent &ignored)
Definition: timer_test.cpp:73
TimerTest::TimerTest
TimerTest()
Definition: timer_test.cpp:24
ros::TimerEvent
diagnostic_updater::Updater::setHardwareID
void setHardwareID(const std::string &hwid)
parameters.h
TimerTest::fibonacci_index_
int fibonacci_index_
Definition: timer_test.cpp:21
diagnostic_updater::Updater::update
void update()
ros::WallTimerEvent
TimerTest::diagnostic_updater_
du::Updater diagnostic_updater_
Definition: timer_test.cpp:19
swri::param
void param(swri::NodeHandle &nh, const std::string name, std::string &value, const std::string def, const std::string description)
Definition: node_handle.h:1159
diagnostic_updater::DiagnosticStatusWrapper
ros::spin
ROSCPP_DECL void spin()
ros::WallDuration
ROS_INFO
#define ROS_INFO(...)
diagnostic_updater::DiagnosticTaskVector::add
void add(const std::string &name, TaskFunction f)
ros::Duration
ros::NodeHandle::createWallTimer
WallTimer createWallTimer(WallDuration period, const WallTimerCallback &callback, bool oneshot=false, bool autostart=true) const
TimerTest::update_timer_
swri::Timer update_timer_
Definition: timer_test.cpp:16
ros::NodeHandle
swri::Timer
Definition: timer.h:38


swri_roscpp
Author(s): P. J. Reed
autogenerated on Fri Aug 2 2024 08:39:15