horizon_legacy_wrapper.h
Go to the documentation of this file.
00001 
00032 #ifndef HUSKY_BASE_HORIZON_LEGACY_WRAPPER_H
00033 #define HUSKY_BASE_HORIZON_LEGACY_WRAPPER_H
00034 
00035 #include "husky_base/horizon_legacy/clearpath.h"
00036 #include "boost/type_traits/is_base_of.hpp"
00037 
00038 namespace
00039 {
00040   const uint16_t UNSUBSCRIBE = 0xFFFF;
00041 }
00042 
00043 namespace horizon_legacy
00044 {
00045 
00046   void connect(std::string port);
00047 
00048   void reconnect();
00049 
00050   void configureLimits(double max_speed, double max_accel);
00051 
00052   void controlSpeed(double speed_left, double speed_right, double accel_left, double accel_right);
00053 
00054   template<typename T>
00055   struct Channel
00056   {
00057 
00058     typedef boost::shared_ptr<T> Ptr;
00059     typedef boost::shared_ptr<const T> ConstPtr;
00060     BOOST_STATIC_ASSERT_MSG(
00061       (boost::is_base_of<clearpath::Message, T>::value),
00062       "T must be a descendant of clearpath::Message"
00063     );
00064 
00065     static Ptr getLatest(double timeout)
00066     {
00067       T *latest = 0;
00068 
00069       // Iterate over all messages in queue and find the latest
00070       while (T *next = T::popNext())
00071       {
00072         if (latest)
00073         {
00074           delete latest;
00075           latest = 0;
00076         }
00077         latest = next;
00078       }
00079 
00080       // If no messages found in queue, then poll for timeout until one is received
00081       if (!latest)
00082       {
00083         latest = T::waitNext(timeout);
00084       }
00085 
00086       // If no messages received within timeout, make a request
00087       if (!latest)
00088       {
00089         return requestData(timeout);
00090       }
00091 
00092       return Ptr(latest);
00093     }
00094 
00095     static Ptr requestData(double timeout)
00096     {
00097       T *update = 0;
00098       while (!update)
00099       {
00100         update = T::getUpdate(timeout);
00101         if (!update)
00102         {
00103           reconnect();
00104         }
00105       }
00106       return Ptr(update);
00107     }
00108 
00109     static void subscribe(double frequency)
00110     {
00111       T::subscribe(frequency);
00112     }
00113 
00114     static void unsubscribe()
00115     {
00116       T::subscribe(UNSUBSCRIBE);
00117     }
00118 
00119   };
00120 
00121 } // namespace husky_base
00122 #endif  // HUSKY_BASE_HORIZON_LEGACY_WRAPPER_H


husky_base
Author(s): Mike Purvis , Paul Bovbel
autogenerated on Sat Jun 8 2019 18:26:01