core_wrapper.h
Go to the documentation of this file.
1 
33 #ifndef roch_BASE_core_WRAPPER_H
34 #define roch_BASE_core_WRAPPER_H
35 
36 #include "roch_base/core/sawyer.h"
37 #include "boost/type_traits/is_base_of.hpp"
38 
39 namespace
40 {
41  const uint16_t UNSUBSCRIBE = 0xFFFF;
42 }
43 
44 namespace core
45 {
46 
47  void connect(std::string port);
48 
49  void reconnect();
50 
51  void configureLimits(double max_speed, double max_accel);
52 
53  void controlSpeed(double speed_left, double speed_right, double accel_left, double accel_right);
54 
55  void controloverallSpeed(double speed_left, double speed_right, double accel_left, double accel_right);
56 
57  template<typename T>
58  struct Channel
59  {
60 
64  (boost::is_base_of<sawyer::Message, T>::value),
65  "T must be a descendant of sawyer::Message"
66  );
67 
68  static Ptr getLatest(double timeout)
69  {
70  T *latest = 0;
71 
72  // Iterate over all messages in queue and find the latest
73  while (T *next = T::popNext())
74  {
75  if (latest)
76  {
77  delete latest;
78  latest = 0;
79  }
80  latest = next;
81  }
82 
83  // If no messages found in queue, then poll for timeout until one is received
84  if (!latest)
85  {
86  latest = T::waitNext(timeout);
87  }
88 
89  // If no messages received within timeout, make a request
90  if (!latest)
91  {
92  return requestData(timeout);
93  }
94 
95  return Ptr(latest);
96  }
97 
98  static Ptr requestData(double timeout)
99  {
100  T *update = 0;
101  while (!update)
102  {
103 
104  update = T::getUpdate(timeout);
105  if (!update)
106  {
107  reconnect();
108  }
109  }
110  return Ptr(update);
111  }
112 
113  static void subscribe(double frequency)
114  {
115  T::subscribe(frequency);
116  }
117 
118  static void unsubscribe()
119  {
120  T::subscribe(UNSUBSCRIBE);
121  }
122 
123  };
124 
125 } // namespace roch_base
126 #endif // roch_BASE_core_WRAPPER_H
static void subscribe(double frequency)
Definition: core_wrapper.h:113
BOOST_STATIC_ASSERT_MSG((boost::is_base_of< sawyer::Message, T >::value),"T must be a descendant of sawyer::Message")
boost::shared_ptr< T > Ptr
Definition: core_wrapper.h:61
static Ptr getLatest(double timeout)
Definition: core_wrapper.h:68
void reconnect()
boost::shared_ptr< const T > ConstPtr
Definition: core_wrapper.h:62
void connect(std::string port)
void controloverallSpeed(double speed_left, double speed_right, double accel_left, double accel_right)
void controlSpeed(double speed_left, double speed_right, double accel_left, double accel_right)
void update(controller_manager::ControllerManager &cm, const ros::TimerEvent &e)
void configureLimits(double max_speed, double max_accel)
static void unsubscribe()
Definition: core_wrapper.h:118
static Ptr requestData(double timeout)
Definition: core_wrapper.h:98


roch_base
Author(s): Mike Purvis , Paul Bovbel , Chen
autogenerated on Mon Jun 10 2019 14:41:13