1am
Serializer.h@3:94b650d0861d, 2010-12-16 (annotated)
- Committer:
- sowmy87
- Date:
- Thu Dec 16 09:25:25 2010 +0000
- Revision:
- 3:94b650d0861d
- Parent:
- 2:9e0d3f159ec3
1
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sowmy87 | 0:d2dcb47dc8e9 | 1 | #ifndef SERIALIZER_H |
sowmy87 | 0:d2dcb47dc8e9 | 2 | #define SERIALIZER_H |
sowmy87 | 0:d2dcb47dc8e9 | 3 | |
sowmy87 | 0:d2dcb47dc8e9 | 4 | |
sowmy87 | 0:d2dcb47dc8e9 | 5 | #define BAUD 19200 |
sowmy87 | 0:d2dcb47dc8e9 | 6 | #define MAX_SPEED 127 |
sowmy87 | 0:d2dcb47dc8e9 | 7 | |
sowmy87 | 0:d2dcb47dc8e9 | 8 | #define WAIT .001 |
sowmy87 | 0:d2dcb47dc8e9 | 9 | #define PI 3.1415926 |
sowmy87 | 1:9a7e6c978adb | 10 | #define PIVET_ADJUSTMENT 7.4 |
sowmy87 | 1:9a7e6c978adb | 11 | #define PIVET_SPEED 20 |
sowmy87 | 0:d2dcb47dc8e9 | 12 | |
sowmy87 | 0:d2dcb47dc8e9 | 13 | #define PULSES_PER_REVOLUTION 624 |
sowmy87 | 0:d2dcb47dc8e9 | 14 | #define WHEEL_DIAMETER 2.25 //inches |
sowmy87 | 0:d2dcb47dc8e9 | 15 | #define WHEEL_CIRCUMFERENCE PI*WHEEL_DIAMETER |
sowmy87 | 0:d2dcb47dc8e9 | 16 | #define PULSE_DISTANCE WHEEL_CIRCUMFERENCE / 624 |
sowmy87 | 0:d2dcb47dc8e9 | 17 | #define PULSES_PER_INCH int(PULSES_PER_REVOLUTION / WHEEL_CIRCUMFERENCE) |
sowmy87 | 0:d2dcb47dc8e9 | 18 | |
sowmy87 | 0:d2dcb47dc8e9 | 19 | |
sowmy87 | 0:d2dcb47dc8e9 | 20 | #include "mbed.h" |
sowmy87 | 0:d2dcb47dc8e9 | 21 | |
sowmy87 | 0:d2dcb47dc8e9 | 22 | /** |
sowmy87 | 3:94b650d0861d | 23 | * Serializer Class to communicate with Robotics |
sowmy87 | 0:d2dcb47dc8e9 | 24 | * Connection Serializer(tm) board |
sowmy87 | 0:d2dcb47dc8e9 | 25 | */ |
sowmy87 | 0:d2dcb47dc8e9 | 26 | class Serializer { |
sowmy87 | 0:d2dcb47dc8e9 | 27 | |
sowmy87 | 0:d2dcb47dc8e9 | 28 | public: |
sowmy87 | 0:d2dcb47dc8e9 | 29 | /** |
sowmy87 | 0:d2dcb47dc8e9 | 30 | * Constructor. |
sowmy87 | 0:d2dcb47dc8e9 | 31 | * |
sowmy87 | 3:94b650d0861d | 32 | */ |
sowmy87 | 0:d2dcb47dc8e9 | 33 | Serializer(); |
sowmy87 | 3:94b650d0861d | 34 | |
sowmy87 | 0:d2dcb47dc8e9 | 35 | /** |
sowmy87 | 0:d2dcb47dc8e9 | 36 | * Destructor. |
sowmy87 | 0:d2dcb47dc8e9 | 37 | * |
sowmy87 | 0:d2dcb47dc8e9 | 38 | */ |
sowmy87 | 0:d2dcb47dc8e9 | 39 | ~Serializer(); |
sowmy87 | 0:d2dcb47dc8e9 | 40 | |
sowmy87 | 0:d2dcb47dc8e9 | 41 | /** |
sowmy87 | 0:d2dcb47dc8e9 | 42 | * Clears left motor encoder count |
sowmy87 | 0:d2dcb47dc8e9 | 43 | * |
sowmy87 | 0:d2dcb47dc8e9 | 44 | */ |
sowmy87 | 0:d2dcb47dc8e9 | 45 | void ClearCountLeft(); |
sowmy87 | 3:94b650d0861d | 46 | |
sowmy87 | 0:d2dcb47dc8e9 | 47 | /** |
sowmy87 | 0:d2dcb47dc8e9 | 48 | * Clears right motor encoder count |
sowmy87 | 0:d2dcb47dc8e9 | 49 | * |
sowmy87 | 3:94b650d0861d | 50 | */ |
sowmy87 | 0:d2dcb47dc8e9 | 51 | void ClearCountRight(); |
sowmy87 | 3:94b650d0861d | 52 | |
sowmy87 | 0:d2dcb47dc8e9 | 53 | /** |
sowmy87 | 0:d2dcb47dc8e9 | 54 | * Clears motors encoder counts |
sowmy87 | 0:d2dcb47dc8e9 | 55 | * |
sowmy87 | 0:d2dcb47dc8e9 | 56 | */ |
sowmy87 | 0:d2dcb47dc8e9 | 57 | void ClearCount(); |
sowmy87 | 3:94b650d0861d | 58 | |
sowmy87 | 0:d2dcb47dc8e9 | 59 | /** |
sowmy87 | 0:d2dcb47dc8e9 | 60 | * Sets left motor speed |
sowmy87 | 0:d2dcb47dc8e9 | 61 | * @param inPsec Motor Speed in inches per second |
sowmy87 | 0:d2dcb47dc8e9 | 62 | */ |
sowmy87 | 0:d2dcb47dc8e9 | 63 | void SetSpeedLeft(int inPsec); |
sowmy87 | 3:94b650d0861d | 64 | |
sowmy87 | 0:d2dcb47dc8e9 | 65 | /** |
sowmy87 | 0:d2dcb47dc8e9 | 66 | * Sets right motor speed |
sowmy87 | 0:d2dcb47dc8e9 | 67 | * @param inPsec Motor Speed in inches per second |
sowmy87 | 0:d2dcb47dc8e9 | 68 | */ |
sowmy87 | 0:d2dcb47dc8e9 | 69 | void SetSpeedRight(int inPsec); |
sowmy87 | 3:94b650d0861d | 70 | |
sowmy87 | 0:d2dcb47dc8e9 | 71 | /** |
sowmy87 | 3:94b650d0861d | 72 | * Sets speed for both motors |
sowmy87 | 0:d2dcb47dc8e9 | 73 | * @param inPsec Motor Speed in inches per second |
sowmy87 | 0:d2dcb47dc8e9 | 74 | */ |
sowmy87 | 0:d2dcb47dc8e9 | 75 | void SetSpeed(int inPsec); |
sowmy87 | 0:d2dcb47dc8e9 | 76 | |
sowmy87 | 0:d2dcb47dc8e9 | 77 | /** |
sowmy87 | 0:d2dcb47dc8e9 | 78 | * Sets VPID |
sowmy87 | 0:d2dcb47dc8e9 | 79 | * @param p |
sowmy87 | 0:d2dcb47dc8e9 | 80 | * @param i |
sowmy87 | 0:d2dcb47dc8e9 | 81 | * @param d |
sowmy87 | 0:d2dcb47dc8e9 | 82 | * @param l |
sowmy87 | 0:d2dcb47dc8e9 | 83 | */ |
sowmy87 | 0:d2dcb47dc8e9 | 84 | void SetVPID(int,int,int,int); |
sowmy87 | 3:94b650d0861d | 85 | |
sowmy87 | 0:d2dcb47dc8e9 | 86 | /** |
sowmy87 | 0:d2dcb47dc8e9 | 87 | * Sets DPID |
sowmy87 | 0:d2dcb47dc8e9 | 88 | * @param p |
sowmy87 | 0:d2dcb47dc8e9 | 89 | * @param i |
sowmy87 | 0:d2dcb47dc8e9 | 90 | * @param d |
sowmy87 | 0:d2dcb47dc8e9 | 91 | * @param a |
sowmy87 | 0:d2dcb47dc8e9 | 92 | */ |
sowmy87 | 0:d2dcb47dc8e9 | 93 | void SetDPID(int,int,int,int); |
sowmy87 | 3:94b650d0861d | 94 | |
sowmy87 | 0:d2dcb47dc8e9 | 95 | /** |
sowmy87 | 0:d2dcb47dc8e9 | 96 | * Sets left motor distance and speed |
sowmy87 | 3:94b650d0861d | 97 | * @param inches Distance in ticks |
sowmy87 | 0:d2dcb47dc8e9 | 98 | * @param inPsec Motor Speed |
sowmy87 | 0:d2dcb47dc8e9 | 99 | */ |
sowmy87 | 0:d2dcb47dc8e9 | 100 | void DiGoLeft(int inches,int inPsec); |
sowmy87 | 3:94b650d0861d | 101 | |
sowmy87 | 0:d2dcb47dc8e9 | 102 | /** |
sowmy87 | 0:d2dcb47dc8e9 | 103 | * Sets right motor distance and speed |
sowmy87 | 3:94b650d0861d | 104 | * @param inches Distance in ticks |
sowmy87 | 0:d2dcb47dc8e9 | 105 | * @param inPsec Motor Speed |
sowmy87 | 0:d2dcb47dc8e9 | 106 | */ |
sowmy87 | 0:d2dcb47dc8e9 | 107 | void DiGoRight(int inches,int inPsec); |
sowmy87 | 3:94b650d0861d | 108 | |
sowmy87 | 0:d2dcb47dc8e9 | 109 | /** |
sowmy87 | 0:d2dcb47dc8e9 | 110 | * Sets both motors distance and speed |
sowmy87 | 3:94b650d0861d | 111 | * @param inches Distance in ticks |
sowmy87 | 0:d2dcb47dc8e9 | 112 | * @param inPsec Motor Speed |
sowmy87 | 0:d2dcb47dc8e9 | 113 | */ |
sowmy87 | 0:d2dcb47dc8e9 | 114 | void DiGo(int inches,int inPsec); |
sowmy87 | 3:94b650d0861d | 115 | |
sowmy87 | 0:d2dcb47dc8e9 | 116 | void SetLeftPWM(int pwm); |
sowmy87 | 0:d2dcb47dc8e9 | 117 | void SetRightPWM(int pwm); |
sowmy87 | 3:94b650d0861d | 118 | void SetPWM(int pwm); |
sowmy87 | 3:94b650d0861d | 119 | void SetPWM(int lPwm, int rPwm); |
sowmy87 | 0:d2dcb47dc8e9 | 120 | int IsBusy(); |
sowmy87 | 3:94b650d0861d | 121 | |
sowmy87 | 0:d2dcb47dc8e9 | 122 | /** |
sowmy87 | 0:d2dcb47dc8e9 | 123 | * Stops both motors |
sowmy87 | 0:d2dcb47dc8e9 | 124 | */ |
sowmy87 | 0:d2dcb47dc8e9 | 125 | void Stop(); |
sowmy87 | 3:94b650d0861d | 126 | |
sowmy87 | 0:d2dcb47dc8e9 | 127 | void TurnLeft(int deg); |
sowmy87 | 0:d2dcb47dc8e9 | 128 | void TurnRight(int deg); |
sowmy87 | 0:d2dcb47dc8e9 | 129 | void PivetLeft(int deg); |
sowmy87 | 0:d2dcb47dc8e9 | 130 | void PivetRight(int deg); |
sowmy87 | 3:94b650d0861d | 131 | |
sowmy87 | 0:d2dcb47dc8e9 | 132 | int GetCountLeft(); |
sowmy87 | 0:d2dcb47dc8e9 | 133 | int GetCountRight(); |
sowmy87 | 0:d2dcb47dc8e9 | 134 | int GetCount(); |
sowmy87 | 2:9e0d3f159ec3 | 135 | float GetDistanceLeft(); |
sowmy87 | 2:9e0d3f159ec3 | 136 | float GetDistanceRight(); |
sowmy87 | 2:9e0d3f159ec3 | 137 | float GetDistance(); |
sowmy87 | 3:94b650d0861d | 138 | |
sowmy87 | 3:94b650d0861d | 139 | |
sowmy87 | 0:d2dcb47dc8e9 | 140 | |
sowmy87 | 0:d2dcb47dc8e9 | 141 | |
sowmy87 | 0:d2dcb47dc8e9 | 142 | |
sowmy87 | 0:d2dcb47dc8e9 | 143 | //protected: |
sowmy87 | 0:d2dcb47dc8e9 | 144 | int GetReply(); |
sowmy87 | 0:d2dcb47dc8e9 | 145 | void InterruptHandler(); |
sowmy87 | 0:d2dcb47dc8e9 | 146 | int Initialize(); |
sowmy87 | 0:d2dcb47dc8e9 | 147 | //private: |
sowmy87 | 0:d2dcb47dc8e9 | 148 | Serial *serial; |
sowmy87 | 0:d2dcb47dc8e9 | 149 | volatile int leftSpeed, rightSpeed; |
sowmy87 | 0:d2dcb47dc8e9 | 150 | volatile int _lPWM, _rPWM; |
sowmy87 | 1:9a7e6c978adb | 151 | volatile char _isBusy; |
sowmy87 | 1:9a7e6c978adb | 152 | volatile char _irqIsBusy; |
sowmy87 | 0:d2dcb47dc8e9 | 153 | }; |
sowmy87 | 0:d2dcb47dc8e9 | 154 | #endif |