Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: robotic_fish_ver_4_9_pixy UMO
pixy.h@5:f54759b26096, 2014-06-05 (annotated)
- Committer:
- sandwich
- Date:
- Thu Jun 05 00:12:48 2014 +0000
- Revision:
- 5:f54759b26096
- Parent:
- 4:440e747935db
- Child:
- 6:4bf8d39fc5ce
-switched to rtos to facilitate better threading; -integrated pixycam and there are now 2 operating modes; -pixycam tracking feedback isn't tuned yet. Currently using proportional controller
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sandwich | 0:1b99a0bee9e0 | 1 | #pragma once |
sandwich | 0:1b99a0bee9e0 | 2 | #include "mbed.h" |
sandwich | 0:1b99a0bee9e0 | 3 | |
sandwich | 2:fc86438b206f | 4 | #define INVALID_BLOCK 20 |
sandwich | 4:440e747935db | 5 | #define CENTER_X 320 |
sandwich | 4:440e747935db | 6 | #define CENTER_Y 200 |
sandwich | 5:f54759b26096 | 7 | #define NUM_BLOCKS 10 |
sandwich | 0:1b99a0bee9e0 | 8 | //a class to aid in SPI communication with the pixy camera |
sandwich | 0:1b99a0bee9e0 | 9 | |
sandwich | 0:1b99a0bee9e0 | 10 | //this details the object block format of returned data as described in |
sandwich | 0:1b99a0bee9e0 | 11 | //http://www.cmucam.org/projects/cmucam5/wiki/Pixy_Serial_Protocol |
sandwich | 0:1b99a0bee9e0 | 12 | |
sandwich | 0:1b99a0bee9e0 | 13 | //blatantly stole this from their code |
sandwich | 0:1b99a0bee9e0 | 14 | struct Block |
sandwich | 0:1b99a0bee9e0 | 15 | { |
sandwich | 0:1b99a0bee9e0 | 16 | uint16_t signature; |
sandwich | 0:1b99a0bee9e0 | 17 | uint16_t x; |
sandwich | 0:1b99a0bee9e0 | 18 | uint16_t y; |
sandwich | 0:1b99a0bee9e0 | 19 | uint16_t width; |
sandwich | 0:1b99a0bee9e0 | 20 | uint16_t height; |
sandwich | 0:1b99a0bee9e0 | 21 | }; |
sandwich | 0:1b99a0bee9e0 | 22 | |
sandwich | 0:1b99a0bee9e0 | 23 | class pixySPI |
sandwich | 0:1b99a0bee9e0 | 24 | { |
sandwich | 0:1b99a0bee9e0 | 25 | private: |
sandwich | 5:f54759b26096 | 26 | SPI spi; |
sandwich | 0:1b99a0bee9e0 | 27 | //SPI spi(p5, p6, p7); // mosi, miso, sclk |
sandwich | 0:1b99a0bee9e0 | 28 | short sync; //the block signature. 16 bits |
sandwich | 0:1b99a0bee9e0 | 29 | short readTwoBytesLSB(); |
sandwich | 0:1b99a0bee9e0 | 30 | void readNBytes(char* buf, int num); |
sandwich | 5:f54759b26096 | 31 | Block blocks[NUM_BLOCKS]; //where the blocks are stored |
sandwich | 2:fc86438b206f | 32 | int numBlocks; //amt |
sandwich | 5:f54759b26096 | 33 | int bestX; |
sandwich | 5:f54759b26096 | 34 | int bestY; |
sandwich | 0:1b99a0bee9e0 | 35 | public: |
sandwich | 5:f54759b26096 | 36 | pixySPI(PinName mosi,PinName miso,PinName sclk, int nBlocks); |
sandwich | 0:1b99a0bee9e0 | 37 | ~pixySPI(); |
sandwich | 2:fc86438b206f | 38 | void capture(); //fills in the blocks pointer |
sandwich | 0:1b99a0bee9e0 | 39 | char getRawData(); |
sandwich | 2:fc86438b206f | 40 | Block* getBlocks(); |
sandwich | 2:fc86438b206f | 41 | int getNumBlocks(); |
sandwich | 5:f54759b26096 | 42 | int getBestX(); |
sandwich | 5:f54759b26096 | 43 | int getBestY(); |
sandwich | 0:1b99a0bee9e0 | 44 | }; |