1am
Serializer.h@1:9a7e6c978adb, 2010-12-13 (annotated)
- Committer:
- sowmy87
- Date:
- Mon Dec 13 04:26:04 2010 +0000
- Revision:
- 1:9a7e6c978adb
- Parent:
- 0:d2dcb47dc8e9
- Child:
- 2:9e0d3f159ec3
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 | 0:d2dcb47dc8e9 | 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 | 0:d2dcb47dc8e9 | 32 | */ |
sowmy87 | 0:d2dcb47dc8e9 | 33 | Serializer(); |
sowmy87 | 0:d2dcb47dc8e9 | 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 | 0:d2dcb47dc8e9 | 46 | |
sowmy87 | 0:d2dcb47dc8e9 | 47 | /** |
sowmy87 | 0:d2dcb47dc8e9 | 48 | * Clears right motor encoder count |
sowmy87 | 0:d2dcb47dc8e9 | 49 | * |
sowmy87 | 0:d2dcb47dc8e9 | 50 | */ |
sowmy87 | 0:d2dcb47dc8e9 | 51 | void ClearCountRight(); |
sowmy87 | 0:d2dcb47dc8e9 | 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 | 0:d2dcb47dc8e9 | 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 | 0:d2dcb47dc8e9 | 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 | 0:d2dcb47dc8e9 | 70 | |
sowmy87 | 0:d2dcb47dc8e9 | 71 | /** |
sowmy87 | 0:d2dcb47dc8e9 | 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 | 0:d2dcb47dc8e9 | 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 | 0:d2dcb47dc8e9 | 94 | |
sowmy87 | 0:d2dcb47dc8e9 | 95 | /** |
sowmy87 | 0:d2dcb47dc8e9 | 96 | * Sets left motor distance and speed |
sowmy87 | 0:d2dcb47dc8e9 | 97 | * @param inches Distance in inches |
sowmy87 | 0:d2dcb47dc8e9 | 98 | * @param inPsec Motor Speed |
sowmy87 | 0:d2dcb47dc8e9 | 99 | */ |
sowmy87 | 0:d2dcb47dc8e9 | 100 | void DiGoLeft(int inches,int inPsec); |
sowmy87 | 0:d2dcb47dc8e9 | 101 | |
sowmy87 | 0:d2dcb47dc8e9 | 102 | /** |
sowmy87 | 0:d2dcb47dc8e9 | 103 | * Sets right motor distance and speed |
sowmy87 | 0:d2dcb47dc8e9 | 104 | * @param inches Distance in inches |
sowmy87 | 0:d2dcb47dc8e9 | 105 | * @param inPsec Motor Speed |
sowmy87 | 0:d2dcb47dc8e9 | 106 | */ |
sowmy87 | 0:d2dcb47dc8e9 | 107 | void DiGoRight(int inches,int inPsec); |
sowmy87 | 0:d2dcb47dc8e9 | 108 | |
sowmy87 | 0:d2dcb47dc8e9 | 109 | /** |
sowmy87 | 0:d2dcb47dc8e9 | 110 | * Sets both motors distance and speed |
sowmy87 | 0:d2dcb47dc8e9 | 111 | * @param inches Distance in inches |
sowmy87 | 0:d2dcb47dc8e9 | 112 | * @param inPsec Motor Speed |
sowmy87 | 0:d2dcb47dc8e9 | 113 | */ |
sowmy87 | 0:d2dcb47dc8e9 | 114 | void DiGo(int inches,int inPsec); |
sowmy87 | 0:d2dcb47dc8e9 | 115 | |
sowmy87 | 0:d2dcb47dc8e9 | 116 | void SetLeftPWM(int pwm); |
sowmy87 | 0:d2dcb47dc8e9 | 117 | void SetRightPWM(int pwm); |
sowmy87 | 0:d2dcb47dc8e9 | 118 | |
sowmy87 | 0:d2dcb47dc8e9 | 119 | int IsBusy(); |
sowmy87 | 0:d2dcb47dc8e9 | 120 | |
sowmy87 | 0:d2dcb47dc8e9 | 121 | /** |
sowmy87 | 0:d2dcb47dc8e9 | 122 | * Stops both motors |
sowmy87 | 0:d2dcb47dc8e9 | 123 | */ |
sowmy87 | 0:d2dcb47dc8e9 | 124 | void Stop(); |
sowmy87 | 0:d2dcb47dc8e9 | 125 | |
sowmy87 | 0:d2dcb47dc8e9 | 126 | void TurnLeft(int deg); |
sowmy87 | 0:d2dcb47dc8e9 | 127 | void TurnRight(int deg); |
sowmy87 | 0:d2dcb47dc8e9 | 128 | void PivetLeft(int deg); |
sowmy87 | 0:d2dcb47dc8e9 | 129 | void PivetRight(int deg); |
sowmy87 | 0:d2dcb47dc8e9 | 130 | |
sowmy87 | 0:d2dcb47dc8e9 | 131 | int GetCountLeft(); |
sowmy87 | 0:d2dcb47dc8e9 | 132 | int GetCountRight(); |
sowmy87 | 0:d2dcb47dc8e9 | 133 | int GetCount(); |
sowmy87 | 0:d2dcb47dc8e9 | 134 | int GetDistanceLeft(); |
sowmy87 | 0:d2dcb47dc8e9 | 135 | int GetDistanceRight(); |
sowmy87 | 0:d2dcb47dc8e9 | 136 | int GetDistance(); |
sowmy87 | 0:d2dcb47dc8e9 | 137 | |
sowmy87 | 0:d2dcb47dc8e9 | 138 | |
sowmy87 | 0:d2dcb47dc8e9 | 139 | |
sowmy87 | 0:d2dcb47dc8e9 | 140 | |
sowmy87 | 0:d2dcb47dc8e9 | 141 | |
sowmy87 | 0:d2dcb47dc8e9 | 142 | //protected: |
sowmy87 | 0:d2dcb47dc8e9 | 143 | int GetReply(); |
sowmy87 | 0:d2dcb47dc8e9 | 144 | void InterruptHandler(); |
sowmy87 | 0:d2dcb47dc8e9 | 145 | int Initialize(); |
sowmy87 | 0:d2dcb47dc8e9 | 146 | //private: |
sowmy87 | 0:d2dcb47dc8e9 | 147 | Serial *serial; |
sowmy87 | 0:d2dcb47dc8e9 | 148 | volatile int leftSpeed, rightSpeed; |
sowmy87 | 0:d2dcb47dc8e9 | 149 | volatile int _lPWM, _rPWM; |
sowmy87 | 1:9a7e6c978adb | 150 | volatile char _isBusy; |
sowmy87 | 1:9a7e6c978adb | 151 | volatile char _irqIsBusy; |
sowmy87 | 0:d2dcb47dc8e9 | 152 | }; |
sowmy87 | 0:d2dcb47dc8e9 | 153 | #endif |