ax2550.h
Go to the documentation of this file.
00001 
00035 #ifndef AX2550_AX2550_H
00036 #define AX2550_AX2550_H
00037 
00038 #include <string>
00039 #include <sstream>
00040 #include <serial/serial.h>
00041 // #define SERIAL_LISTENER_DEBUG 1
00042 #include <serial/utils/serial_listener.h>
00043 
00044 // Handy macro for throwing exceptions
00045 #define AX2550_THROW(exceptionClass,message) throw \
00046   exceptionClass(__FILE__,__LINE__,(message))
00047 
00048 namespace ax2550 {
00049 
00056   typedef boost::function<void(const std::string&)> LoggingCallback;
00057 
00064   typedef boost::function<void()> WatchDogCallback;
00065 
00069   class AX2550 {
00070   public:
00071     AX2550 (std::string port = "");
00072     ~AX2550 ();
00073 
00074     void connect (std::string port = "");
00075 
00076     void disconnect ();
00077 
00078     bool isConnected ();
00079 
00080     bool issueCommand (const std::string &command, std::string &fail_why);
00081 
00082     void move (double speed, double direction);
00083 
00084     void queryEncoders (long &encoder1, long &encoder2, bool relative = false);
00085 
00086     WatchDogCallback watch_dog_callback;
00087     LoggingCallback debug;
00088     LoggingCallback info;
00089     LoggingCallback warn;
00090   private:
00091     // Serial stuff
00092     std::string port_;
00093     serial::Serial * serial_port_;
00094     serial::utils::SerialListener serial_listener_;
00095     // Filter stuff
00096     void setupFilters_ ();
00097     serial::utils::BufferedFilterPtr encoders_filt_;
00098     void watchDogCallback_ (const std::string&);
00099     serial::utils::FilterPtr watch_dog_filt_;
00100     serial::utils::BufferedFilterPtr ack_nak_filt_;
00101     // serial::utils::BufferedFilterPtr rc_msg_filt_;
00102     // State stuff
00103     void sync_ ();
00104     bool connected_;
00105     bool synced_;
00106     boost::mutex mc_mutex;
00107   };
00108 
00112   class ConnectionException : public std::exception {
00113     std::string file_;
00114     int line_;
00115     const char* e_what_;
00116   public:
00117     ConnectionException (std::string file, int line, const char * description)
00118     : file_(file), line_(line), e_what_ (description) {}
00119     virtual ~ConnectionException() throw() {}
00120 
00121     virtual const char* what () const throw () {
00122       std::stringstream ss;
00123       ss << "Connection Exception: " << e_what_;
00124       ss << ", file " << file_ << ", line " << line_ << ".";
00125       return ss.str ().c_str ();
00126     }
00127   };
00128 
00132   class SynchronizationException : public std::exception {
00133     std::string file_;
00134     int line_;
00135     const char* e_what_;
00136   public:
00137     SynchronizationException (std::string file, int line,
00138                               const char * description)
00139     : file_(file), line_(line), e_what_ (description) {}
00140     virtual ~SynchronizationException() throw() {}
00141 
00142     virtual const char* what () const throw () {
00143       std::stringstream ss;
00144       ss << "Synchronization Exception: " << e_what_;
00145       ss << ", file " << file_ << ", line " << line_ << ".";
00146       return ss.str ().c_str ();
00147     }
00148   };
00149 
00153   class CommandFailedException : public std::exception {
00154     std::string file_;
00155     int line_;
00156     const char* e_what_;
00157   public:
00158     CommandFailedException (std::string file, int line,
00159                               const char * description)
00160     : file_(file), line_(line), e_what_ (description) {}
00161     virtual ~CommandFailedException() throw() {}
00162 
00163     virtual const char* what () const throw () {
00164       std::stringstream ss;
00165       ss << "Command Failed Exception: " << e_what_;
00166       ss << ", file " << file_ << ", line " << line_ << ".";
00167       return ss.str ().c_str ();
00168     }
00169   };
00170 
00171 } // namespace ax2550
00172 
00173 #endif


ax2550
Author(s): William Woodall , Michael Carroll
autogenerated on Sat Jun 8 2019 18:26:02