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


roch_base
Author(s): Mike Purvis , Paul Bovbel , Carl
autogenerated on Sat Jun 8 2019 20:32:33