00001 00045 #ifndef POLOLUQIK2_H_ 00046 #define POLOLUQIK2_H_ 00047 00048 #include "../NewSoftSerial/NewSoftSerial.h" 00049 #include "../CRC7/CRC7.h" 00050 #include "WProgram.h" 00051 #include <inttypes.h> 00052 #include <avr/interrupt.h> 00053 00054 #define INITIALPACKET 0xAA 00055 #define MOTOR0FORWARDPACKET 0x88 00056 #define MOTOR1FORWARDPACKET 0x8C 00057 #define MOTOR0REVERSEPACKET 0x8A 00058 #define MOTOR1REVERSEPACKET 0x8E 00059 #define MOTOR0COASTPACKET 0x86 00060 #define MOTOR1COASTPACKET 0x87 00061 #define FWVERSIONPACKET 0x81 00062 #define ERRORPACKET 0x82 00063 00064 #define DATAOVERRUNERRORBIT 3 00065 #define FRAMEERRORBIT 4 00066 #define CRCERRORBIT 5 00067 #define FORMATERRORBIT 6 00068 #define TIMEOUTERRORBIT 7 00069 00075 class PololuQik2 { 00076 public: 00077 00090 PololuQik2(NewSoftSerial *serial, uint8_t reset, uint8_t errPin, bool EnableCRC, CRC7 *crc); 00091 00098 void begin(); 00099 00105 void motor0Forward(uint8_t speed); 00106 00112 void motor1Forward(uint8_t speed); 00113 00119 void motor0Reverse(uint8_t speed); 00120 00126 void motor1Reverse(uint8_t speed); 00127 00135 void stopBothMotors(); 00136 00142 void stopMotor0(); 00143 00149 void stopMotor1(); 00150 00154 void motor0Coast(); 00155 00159 void motor1Coast(); 00160 00166 unsigned int getFirmwareVersion(); 00167 00173 bool hasDataOverrunError(); 00174 00180 bool hasFrameError(); 00181 00187 bool hasCRCError(); 00188 00194 bool hasFormatError(); 00195 00201 bool hasTimeoutError(); 00202 00203 private: 00204 00211 void sendMessage(unsigned char message[], unsigned int length); 00212 00220 bool errorBitSet(uint8_t bitToCheck); 00221 00228 uint8_t getError(); 00229 00238 void error(); 00239 00245 void sendByte(uint8_t byte); 00246 00253 uint8_t readByte(); 00254 00259 NewSoftSerial *_serial; 00260 00264 uint8_t _resetPin; 00265 00269 uint8_t _errByte; 00270 00277 uint8_t _fwVersion; 00278 00286 uint8_t _errPin; 00287 00291 bool _enCRC; 00292 00297 CRC7 *_crc; 00298 00299 00300 }; 00301 00302 #endif /* POLOLUQIK2_H_ */