00001 00007 #ifndef _PTU46_DRIVER_H_ 00008 #define _PTU46_DRIVER_H_ 00009 00010 #include <termios.h> 00011 00012 // serial defines 00013 #define PTU46_DEFAULT_BAUD 9600 00014 #define PTU46_BUFFER_LEN 255 00015 #define PTU46_DEFAULT_PORT "/dev/ttyUSB1" 00016 #define PTU46_DEFAULT_HZ 10 00017 00018 // command defines 00019 #define PTU46_PAN 'p' 00020 #define PTU46_TILT 't' 00021 #define PTU46_MIN 'n' 00022 #define PTU46_MAX 'x' 00023 #define PTU46_MIN_SPEED 'l' 00024 #define PTU46_MAX_SPEED 'u' 00025 #define PTU46_VELOCITY 'v' 00026 #define PTU46_POSITION 'i' 00027 00028 namespace PTU46 { 00029 00058 class PTU46 { 00059 public: 00063 PTU46(const char* port, int rate); 00064 ~PTU46(); 00065 00067 bool isOpen () { 00068 return fd > 0; 00069 }; 00070 00075 float GetPosition (char type); 00076 00081 float GetSpeed (char type); 00082 00087 float GetResolution (char type) { 00088 return (type == PTU46_TILT ? tr : pr); 00089 } 00090 00095 float GetMin (char type) { 00096 return GetResolution(type)*(type == PTU46_TILT ? TMin : PMin); 00097 } 00102 float GetMax (char type) { 00103 return GetResolution(type)*(type == PTU46_TILT ? TMax : PMax); 00104 } 00105 00110 float GetMinSpeed (char type) { 00111 return GetResolution(type)*(type == PTU46_TILT ? TSMin : PSMin); 00112 } 00117 float GetMaxSpeed (char type) { 00118 return GetResolution(type)*(type == PTU46_TILT ? TSMax : PSMax); 00119 } 00120 00121 00122 00131 bool SetPosition (char type, float pos, bool Block = false); 00132 00139 bool SetSpeed (char type, float speed); 00140 00146 bool SetMode (char type); 00147 00152 char GetMode (); 00153 00154 private: 00159 float GetRes (char type); 00160 00167 int GetLimit (char type, char LimType); 00168 00169 00170 00171 // Position Limits 00172 int TMin; 00173 int TMax; 00174 int PMin; 00175 int PMax; 00176 00177 // Speed Limits 00178 int TSMin; 00179 int TSMax; 00180 int PSMin; 00181 int PSMax; 00182 00183 protected: 00184 float tr; 00185 float pr; 00186 00187 int fd; 00188 struct termios oldtio; 00189 00190 char buffer[PTU46_BUFFER_LEN+1]; 00191 00198 int Write(const char * data, int length = 0); 00199 00202 void Disconnect(); 00203 }; 00204 00205 } 00206 00207 #endif