Homologation Cachan

Fork of TPixy-Interface by Stephen Wilkins

Files at this revision

API Documentation at this revision

Comitter:
lenriquez389
Date:
Sat Jun 09 03:56:25 2018 +0000
Parent:
3:66df7d295245
Commit message:
PIXY

Changed in this revision

Pixy.h Show annotated file Show diff for this revision Revisions of this file
TPixy.h Show annotated file Show diff for this revision Revisions of this file
diff -r 66df7d295245 -r ee635fc62b6e Pixy.h
--- a/Pixy.h	Mon Mar 14 18:53:43 2016 +0000
+++ b/Pixy.h	Sat Jun 09 03:56:25 2018 +0000
@@ -7,19 +7,6 @@
 #define X_CENTER        ((PIXY_MAX_X-PIXY_MIN_X)/2)
 #define Y_CENTER        ((PIXY_MAX_Y-PIXY_MIN_Y)/2)
 
-/** The SPI Pixy interface for the Pixy camera
-  * @code
-  * #include "Pixy.h"
-  * Serial serial(USBTX, USBRX);
-  * SPI spi(p5, p6, p7);
-  * PixySPI pixy(&spi, &serial);
-  *
-  * int main() {
-  *     runPanTiltDemo();
-  * }
-  * @endcode
-  */
-  
 class PixySPI : public TPixy<PixyInterfaceSPI>
 {
 public:
@@ -33,17 +20,6 @@
         TPixy<PixyInterfaceSPI>((new PixyInterfaceSPI(spi)), serialOut, arg) {}
 };
 
-
-/* Not Implemented */
-/*
-class PixyI2C : TPixy<PixyInterfaceI2C> {
-    public:
-        PixyI2C(I2C* i2c, Serial* serialOut = NULL, uint16_t arg = PIXY_DEFAULT_ARGVAL) : i2cInterface(i2c), TPixy<PixyInterfaceI2C>(i2cInterface, serialOut, arg);
-    private:
-        TPixyInterface<I2C>* i2cInterface;
-    };
-    */
-    
 class ServoLoop
 {
 public:
@@ -64,45 +40,4 @@
     int32_t m_pgain;
     int32_t m_dgain;
 };
-
-/** Basic Pan/Tilt Demo code
-  * Runs the Pan/Tilt demo code
-  * @param pixy the pointer to the pixy object to run the demo on
-  * @param serial the optional serial pointer to display output to
-  */
-template <class TPixyInterface> void runPanTiltDemo(TPixy<TPixyInterface>* pixy, Serial* serial = NULL)
-{
-    ServoLoop panLoop(-150, -300);
-    ServoLoop tiltLoop(200, 250);
-    if (serial != NULL) {
-        serial->printf("Starting...\n");
-    }   
-    static int i = 0;
-    int j;
-    uint16_t blocks;
-    int32_t panError, tiltError;
-    pixy->init();
-    while(true) {
-        blocks = pixy->getBlocks();
-        if (blocks) {
-            panError = X_CENTER - pixy->blocks[0].x;
-            tiltError = pixy->blocks[0].y - Y_CENTER;
-
-            panLoop.update(panError);
-            tiltLoop.update(tiltError);
-
-            pixy->setServos(panLoop.m_pos, tiltLoop.m_pos);
-            i++;
-
-            if (i % 50 == 0 && serial != NULL) {
-                serial->printf("Detected %d:\n", blocks);
-                //toPC.printf(buf);
-                for (j = 0; j < blocks; j++) {
-                    serial->printf("  block %d: ", j);
-                    pixy->printBlock(pixy->blocks[j]);
-                }
-            }
-        }
-    }
-}
 #endif
\ No newline at end of file
diff -r 66df7d295245 -r ee635fc62b6e TPixy.h
--- a/TPixy.h	Mon Mar 14 18:53:43 2016 +0000
+++ b/TPixy.h	Sat Jun 09 03:56:25 2018 +0000
@@ -1,25 +1,5 @@
-//
-// begin license header
-//
-// This file is part of Pixy CMUcam5 or "Pixy" for short
-//
-// All Pixy source code is provided under the terms of the
-// GNU General Public License v2 (http://www.gnu.org/licenses/gpl-2.0.html).
-// Those wishing to use Pixy source code, software and/or
-// technologies under different licensing terms should contact us at
-// cmucam@cs.cmu.edu. Such licensing terms are available for
-// all portions of the Pixy codebase presented here.
-//
-// end license header
-//
-// This file is for defining the Block struct and the Pixy template class.
-// (TPixy).  TPixy takes a communication link as a template parameter so that
-// all communication modes (SPI, I2C and UART) can share the same code.
-//
-
 #ifndef _TPIXY_H
 #define _TPIXY_H
-
 #include "mbed.h"
 #include "TPixyInterface.h"
 
@@ -37,9 +17,9 @@
 #define PIXY_MAX_X                  319L
 #define PIXY_MIN_Y                  0L
 #define PIXY_MAX_Y                  199L
-
+#define PIXY_CENTER_X               ((PIXY_MAX_X-PIXY_MIN_X)/2)
 // RC-servo values
-#define PIXY_RCS_MIN_POS            0L
+#define PIXY_RCS_MIN_POS            650L
 #define PIXY_RCS_MAX_POS            1000L
 #define PIXY_RCS_CENTER_POS         ((PIXY_RCS_MAX_POS-PIXY_RCS_MIN_POS)/2)
 
@@ -48,14 +28,6 @@
     CC_BLOCK
 };
 
-/** A structure for containing Block data
-  * signature the signature of the block
-  * x the x position of the block on the screen
-  * y the y position of the block on the screen
-  * width the width of the block on the screen
-  * height the height of the block on the screen
-  * angle the angle of the block
-  */
 struct Block {
     uint16_t signature;
     uint16_t x;
@@ -65,61 +37,21 @@
     uint16_t angle;
 };
 
-/** The superclass handler for the Pixy camera from a given connection handler (SPI, I2C, etc)
-  * Used for instantiating a Pixy object that interfaces via an abtritrary connection handler
-  */
 template <class TPixyInterface> class TPixy
 {
 public:
     Serial* serial;
     Block *blocks;
-    
-    /** Creates a TPixy object with a given connection handler
-      * @param type the pointer to the interface connection handler
-      * @param serialOut the optional serial output pointer to print out Pixy camera data
-      * @param arg an optional integer argument used for custom implementations of the Pixy library
-      */
     TPixy(TPixyInterface* type, Serial* serialOut = NULL, uint16_t arg = PIXY_DEFAULT_ARGVAL);
     ~TPixy();
-
-    /** Prints the given Block out to the given serial port
-      * @param &block the Block to print
-      */
-    void printBlock(Block &block);
-    /** Returns the number of Blocks found in the current view and updates all Blocks' info
-      * @param maxBlocks the maximum number of Blocks to search for
-      * @return the number of Blocks found
-      */
     uint16_t getBlocks(uint16_t maxBlocks = 1000);
-    /** Sets the PWM value of the Pixy servos
-      * @param s0 the value of the left servo
-      * @param s1 the value of the right servo
-      * @return the interface return value for sending the servo command
-      */
     int8_t setServos(uint16_t s0, uint16_t s1);
-    /** Sets the brightness of the Pixy RGB LED
-      * @param brightness the brightness of the LED
-      * @return the interface return value for sending the brightness command
-      */
-    int8_t setBrightness(uint8_t brightness);
-    /** Sets the color of the Pixy RGB LED
-      * @param r the red color value
-      * @param g the green color value
-      * @param b the blue color value
-      */
-    int8_t setLED(uint8_t r, uint8_t g, uint8_t b);
-    /** Initializes the Pixy
-      */
     void init();
 
 private:
     TPixyInterface* link;
     BlockType blockType;
-    /** Returns if the Pixy is ready to receive/send a message
-      */
     bool getStart();
-    /** Resizes the block array to add an additional block
-      */
     void resize();
     bool skipStart;
     uint16_t blockCount;
@@ -141,30 +73,6 @@
     link->setArg(arg);
 }
 
-template <class TPixyInterface> void TPixy<TPixyInterface>::printBlock(Block &block)
-{
-    int i, j;
-    char sig[6], d;
-    bool flag;
-    if (block.signature > PIXY_MAX_SIGNATURE) { // color code! (CC)
-        // convert signature number to an octal string
-        for (i = 12, j = 0, flag = false; i >= 0; i -= 3) {
-            d = (block.signature >> i) & 0x07;
-            if (d > 0 && !flag) {
-                flag = true;
-            }
-            if (flag) {
-                sig[j++] = d + '0';
-            }
-        }
-        sig[j] = '\0';
-        if (serial != NULL) {
-            serial->printf("CC block! sig: %s (%d decimal) x: %d y: %d width: %d height: %d angle %d\n", sig, block.signature, block.x, block.y, block.width, block.height, block.angle);
-        }
-    } else {}// regular block.  Note, angle is always zero, so no need to print
-    serial->printf("sig: %d x: %d y: %d width: %d height: %d\n", block.signature, block.x, block.y, block.width, block.height);
-}
-
 template <class TPixyInterface> TPixy<TPixyInterface>::~TPixy()
 {
     free(blocks);
@@ -216,7 +124,7 @@
     }
     for(blockCount = 0; blockCount < maxBlocks && blockCount < PIXY_MAXIMUM_ARRAYSIZE;) {
         checksum = link->getWord();
-        if (checksum == PIXY_START_WORD) { // we've reached the beginning of the next frame
+        if (checksum == PIXY_START_WORD) { 
             skipStart = true;
             blockType = NORMAL_BLOCK;
             if (serial != NULL) {
@@ -274,24 +182,4 @@
     return link->send(outBuf, 6);
 }
 
-template <class TPixyInterface> int8_t TPixy<TPixyInterface>::setBrightness(uint8_t brightness)
-{
-    uint8_t outBuf[3];
-    outBuf[0] = 0x00;
-    outBuf[1] = 0xfe;
-    outBuf[2] = brightness;
-    return link->send(outBuf, 3);
-}
-
-template <class TPixyInterface> int8_t TPixy<TPixyInterface>::setLED(uint8_t r, uint8_t g, uint8_t b)
-{
-    uint8_t outBuf[5];
-    outBuf[0] = 0x00;
-    outBuf[1] = 0xfd;
-    outBuf[2] = r;
-    outBuf[3] = g;
-    outBuf[4] = b;
-    return link->send(outBuf, 5);
-}
-
 #endif
\ No newline at end of file