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


husky_base
Author(s): Mike Purvis , Paul Bovbel
autogenerated on Fri Oct 2 2020 03:40:07