simple_packet_controller.hpp
Go to the documentation of this file.
1 #ifndef USB_CAM_CONTROLLERS_SIMPLE_PACKET_CONTROLLER
2 #define USB_CAM_CONTROLLERS_SIMPLE_PACKET_CONTROLLER
3 
4 #include <string>
5 #include <vector>
6 
8 #include <ros/console.h>
9 #include <ros/duration.h>
10 #include <ros/node_handle.h>
11 #include <ros/time.h>
13 
14 namespace usb_cam_controllers {
15 
16 // a base class for simple packet controllers which
17 // - only use the primary interface of packets
18 // - expect updated with every new packet
20  : public controller_interface::Controller< usb_cam_hardware_interface::PacketInterface > {
21 public:
23 
25 
27  ros::NodeHandle &controller_nh) {
28  // grab the primary interface of packets
29  if (!hw) {
30  ROS_ERROR("Null packet interface");
31  return false;
32  }
33  const std::vector< std::string > names(hw->getNames());
34  if (names.empty()) {
35  ROS_ERROR("No packet handle");
36  return false;
37  }
38  if (names.size() > 1) {
39  ROS_WARN_STREAM(names.size() << " packet handles. camera info synchronized to stamps from "
40  "the first handle will be published.");
41  }
42  packet_iface_ = hw->getHandle(names.front());
43 
45 
46  // init the child controller
47  return initImpl(hw, root_nh, controller_nh);
48  }
49 
50  virtual void starting(const ros::Time &time) { startingImpl(time); }
51 
52  virtual void update(const ros::Time &time, const ros::Duration &period) {
53  // abort if the packet has already been processed
54  if (!packet_iface_.getStart()) {
55  ROS_DEBUG("No packet. Will skip publishing camera info.");
56  return;
57  }
59  ROS_DEBUG("Packet is not updated. Will skip publishing camera info.");
60  return;
61  }
62 
63  // process the packet by the child controller
64  updateImpl(time, period);
65 
67  }
68 
69  virtual void stopping(const ros::Time &time) { stoppingImpl(time); }
70 
71 protected:
72  // init child-controller-specific things. no need to grab the primary packet interface
74  ros::NodeHandle &controller_nh) = 0;
75 
76  virtual void startingImpl(const ros::Time &time) = 0;
77 
78  // update the child controller. called when every new packet comes.
79  virtual void updateImpl(const ros::Time &time, const ros::Duration &period) = 0;
80 
81  virtual void stoppingImpl(const ros::Time &time) = 0;
82 
83 protected:
84  // the primary packet interface accessible by the child controler
86 
87 private:
89 };
90 
91 } // namespace usb_cam_controllers
92 
93 #endif
virtual bool initImpl(usb_cam_hardware_interface::PacketInterface *hw, ros::NodeHandle &root_nh, ros::NodeHandle &controller_nh)=0
virtual void stoppingImpl(const ros::Time &time)=0
virtual bool init(usb_cam_hardware_interface::PacketInterface *hw, ros::NodeHandle &root_nh, ros::NodeHandle &controller_nh)
virtual void starting(const ros::Time &time)
virtual void startingImpl(const ros::Time &time)=0
virtual void update(const ros::Time &time, const ros::Duration &period)
virtual void updateImpl(const ros::Time &time, const ros::Duration &period)=0
#define ROS_WARN_STREAM(args)
usb_cam_hardware_interface::PacketHandle packet_iface_
virtual void stopping(const ros::Time &time)
#define ROS_ERROR(...)
#define ROS_DEBUG(...)


usb_cam_controllers
Author(s):
autogenerated on Tue Jul 14 2020 03:12:08