Majordhome/pixy
Servoloop.h@1:7915442d0bd8, 2015-04-14 (annotated)
- Committer:
- johnylafleur
- Date:
- Tue Apr 14 11:00:17 2015 +0000
- Revision:
- 1:7915442d0bd8
- Parent:
- 0:b12a5af91608
Pixy+MD25 Motor Track
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
johnylafleur | 0:b12a5af91608 | 1 | //========================================================================== |
johnylafleur | 0:b12a5af91608 | 2 | // |
johnylafleur | 0:b12a5af91608 | 3 | // Pixy Pet Robot |
johnylafleur | 0:b12a5af91608 | 4 | // |
johnylafleur | 0:b12a5af91608 | 5 | // Adafruit invests time and resources providing this open source code, |
johnylafleur | 0:b12a5af91608 | 6 | // please support Adafruit and open-source hardware by purchasing |
johnylafleur | 0:b12a5af91608 | 7 | // products from Adafruit! |
johnylafleur | 0:b12a5af91608 | 8 | // |
johnylafleur | 0:b12a5af91608 | 9 | // Written by: Bill Earl for Adafruit Industries |
johnylafleur | 0:b12a5af91608 | 10 | // |
johnylafleur | 0:b12a5af91608 | 11 | //========================================================================== |
johnylafleur | 0:b12a5af91608 | 12 | // begin license header |
johnylafleur | 0:b12a5af91608 | 13 | // |
johnylafleur | 0:b12a5af91608 | 14 | // All Pixy Pet source code is provided under the terms of the |
johnylafleur | 0:b12a5af91608 | 15 | // GNU General Public License v2 (http://www.gnu.org/licenses/gpl-2.0.html). |
johnylafleur | 0:b12a5af91608 | 16 | // |
johnylafleur | 0:b12a5af91608 | 17 | // end license header |
johnylafleur | 0:b12a5af91608 | 18 | // |
johnylafleur | 0:b12a5af91608 | 19 | //========================================================================== |
johnylafleur | 0:b12a5af91608 | 20 | // |
johnylafleur | 0:b12a5af91608 | 21 | // Portions of this code are derived from the Pixy CMUcam5 pantilt example code. |
johnylafleur | 0:b12a5af91608 | 22 | // |
johnylafleur | 0:b12a5af91608 | 23 | //========================================================================== |
johnylafleur | 0:b12a5af91608 | 24 | #ifndef SERVOLOOP_H |
johnylafleur | 0:b12a5af91608 | 25 | #define SERVOLOOP_H |
johnylafleur | 0:b12a5af91608 | 26 | #include <SPI.h> |
johnylafleur | 0:b12a5af91608 | 27 | #include <Pixy.h> |
johnylafleur | 0:b12a5af91608 | 28 | #include <MD25.h> |
johnylafleur | 0:b12a5af91608 | 29 | |
johnylafleur | 0:b12a5af91608 | 30 | |
johnylafleur | 0:b12a5af91608 | 31 | #define X_CENTER 160L |
johnylafleur | 0:b12a5af91608 | 32 | #define Y_CENTER 100L |
johnylafleur | 0:b12a5af91608 | 33 | #define RCS_MIN_POS 0L |
johnylafleur | 0:b12a5af91608 | 34 | #define RCS_MAX_POS 1000L |
johnylafleur | 0:b12a5af91608 | 35 | #define RCS_CENTER_POS ((RCS_MAX_POS-RCS_MIN_POS)/2) |
johnylafleur | 0:b12a5af91608 | 36 | //--------------------------------------- |
johnylafleur | 0:b12a5af91608 | 37 | // Servo Loop Class |
johnylafleur | 0:b12a5af91608 | 38 | // A Proportional/Derivative feedback |
johnylafleur | 0:b12a5af91608 | 39 | // loop for pan/tilt servo tracking of |
johnylafleur | 0:b12a5af91608 | 40 | // blocks. |
johnylafleur | 0:b12a5af91608 | 41 | // (Based on Pixy CMUcam5 example code) |
johnylafleur | 0:b12a5af91608 | 42 | //--------------------------------------- |
johnylafleur | 0:b12a5af91608 | 43 | class Servoloop |
johnylafleur | 0:b12a5af91608 | 44 | { |
johnylafleur | 0:b12a5af91608 | 45 | public: |
johnylafleur | 0:b12a5af91608 | 46 | Servoloop(int32_t proportionalGain, int32_t derivativeGain); |
johnylafleur | 0:b12a5af91608 | 47 | void update(int32_t error); |
johnylafleur | 0:b12a5af91608 | 48 | int32_t m_pos; |
johnylafleur | 0:b12a5af91608 | 49 | int32_t m_prevError; |
johnylafleur | 0:b12a5af91608 | 50 | int32_t m_proportionalGain; |
johnylafleur | 0:b12a5af91608 | 51 | int32_t m_derivativeGain; |
johnylafleur | 0:b12a5af91608 | 52 | |
johnylafleur | 0:b12a5af91608 | 53 | }; |
johnylafleur | 0:b12a5af91608 | 54 | #endif |
johnylafleur | 0:b12a5af91608 | 55 | // End Servo Loop Class |
johnylafleur | 0:b12a5af91608 | 56 | //--------------------------------------- |