basic_profiler_example_node.cpp
Go to the documentation of this file.
1 #include <ros/ros.h>
3 #include <std_msgs/Int32.h>
4 
6 {
9 
12 
14 
17 
18  public:
20  {
21  pnh_ = ros::NodeHandle("~");
22 
23  // Setup a one-shot timer to initialize the node after a brief
24  // delay so that /rosout is always fully initialized.
25  ROS_INFO("Starting initialization timer...");
26  init_timer_ = nh_.createWallTimer(ros::WallDuration(1.0),
28  this,
29  true);
30  }
31 
32  void initialize(const ros::WallTimerEvent &ignored)
33  {
34  (void)ignored;
35 
36  pnh_.param("fibonacci_index1", fibonacci_index1_, 30);
37  pnh_.param("fibonacci_index2", fibonacci_index2_, 40);
38 
39  update_timer_ = nh_.createTimer(ros::Duration(1/10.0),
41  this);
42 
43  int_callback_ = nh_.subscribe("trigger_fibonacci", 10,
45  this);
46  }
47 
49  {
50  if (x <= 0) {
51  return 0;
52  } else if (x == 1) {
53  return 1;
54  } else {
56  }
57  }
58 
59  void superSlowFibonacci(int x)
60  {
61  SWRI_PROFILE("super-slow-fibonacci");
62  ROS_INFO("Fibonacci %d = %d", x, superSlowFibonacciInt(x));
63  }
64 
65  void handleUpdateTimer(const ros::TimerEvent &ignored)
66  {
67  (void)ignored;
68  SWRI_PROFILE("handle-update-timer");
69 
70  {
71  SWRI_PROFILE("fibonacci-1");
72  superSlowFibonacci(fibonacci_index1_);
73  }
74 
75  {
76  SWRI_PROFILE("fibonacci-2");
77  superSlowFibonacci(fibonacci_index2_);
78  }
79  }
80 
81  void handleTriggerFibonacci(const std_msgs::Int32ConstPtr &msg)
82  {
83  SWRI_PROFILE("handle-trigger-fibonacci");
84  superSlowFibonacci(msg->data);
85  }
86 };
87 
88 int main(int argc, char **argv)
89 {
90  ros::init(argc, argv, "basic_profiler_example");
91 
93  ros::spin();
94 
95  return 0;
96 }
97 
int main(int argc, char **argv)
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
void handleUpdateTimer(const ros::TimerEvent &ignored)
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
void initialize(const ros::WallTimerEvent &ignored)
#define ROS_INFO(...)
bool param(const std::string &param_name, T &param_val, const T &default_val) const
Timer createTimer(Rate r, Handler h, Obj o, bool oneshot=false, bool autostart=true) const
WallTimer createWallTimer(WallDuration period, void(T::*callback)(const WallTimerEvent &), T *obj, bool oneshot=false, bool autostart=true) const
ROSCPP_DECL void spin()
void handleTriggerFibonacci(const std_msgs::Int32ConstPtr &msg)
#define SWRI_PROFILE(name)
Definition: profiler.h:202


swri_profiler
Author(s):
autogenerated on Fri Nov 27 2020 03:44:17