This code just added an algorithm to calculate angle form the pixy center

Dependents:   pixyHelloWorld2_copy_servoTest pixy_pan_tilt Servo_camera_pan Camera_Gimbal_Tracking

Fork of pixy by Arcadie Cracan

Committer:
LucasUIUC
Date:
Wed Jul 01 19:43:36 2015 +0000
Revision:
2:a58a6a71ae7b
Parent:
1:f8b6497870d3
Code with servo position in pixy.h

Who changed what in which revision?

UserRevisionLine numberNew contents of line
acracan 0:ed8dc4531ac1 1 #ifndef TUIASI_PIXY_H
acracan 0:ed8dc4531ac1 2 #define TUIASI_PIXY_H
acracan 0:ed8dc4531ac1 3
acracan 0:ed8dc4531ac1 4 #include "mbed.h"
acracan 0:ed8dc4531ac1 5 #include "PixyLinkSPI.h"
acracan 0:ed8dc4531ac1 6 #include "PixyLinkI2C.h"
acracan 0:ed8dc4531ac1 7 #include "PixyLinkUART.h"
acracan 0:ed8dc4531ac1 8
acracan 0:ed8dc4531ac1 9 struct Block {
acracan 0:ed8dc4531ac1 10 void print(Serial &pc) {
LucasUIUC 2:a58a6a71ae7b 11
LucasUIUC 1:f8b6497870d3 12 float angle;
LucasUIUC 1:f8b6497870d3 13 angle = (float)(160 - x)*9/32;
LucasUIUC 2:a58a6a71ae7b 14 float ServoPosition;
LucasUIUC 2:a58a6a71ae7b 15 ServoPosition = (float)(angle + 45)*1/90;
LucasUIUC 2:a58a6a71ae7b 16
LucasUIUC 2:a58a6a71ae7b 17 pc.printf("sig: %d x: %d y: %d width: %d height: %d angle: %f ServoP: %f\n", signature, x, y, width, height, angle, ServoPosition);
acracan 0:ed8dc4531ac1 18 };
acracan 0:ed8dc4531ac1 19 uint16_t signature;
acracan 0:ed8dc4531ac1 20 uint16_t x;
acracan 0:ed8dc4531ac1 21 uint16_t y;
acracan 0:ed8dc4531ac1 22 uint16_t width;
acracan 0:ed8dc4531ac1 23 uint16_t height;
acracan 0:ed8dc4531ac1 24 };
acracan 0:ed8dc4531ac1 25
LucasUIUC 2:a58a6a71ae7b 26
acracan 0:ed8dc4531ac1 27 class Pixy
acracan 0:ed8dc4531ac1 28 {
acracan 0:ed8dc4531ac1 29 public:
acracan 0:ed8dc4531ac1 30 enum LinkType {SPI, I2C, UART};
acracan 0:ed8dc4531ac1 31 Pixy(LinkType linkType, PinName mosi_sda_tx, PinName miso_scl_rx, PinName sclk = NC);
acracan 0:ed8dc4531ac1 32 ~Pixy();
acracan 0:ed8dc4531ac1 33 uint16_t getBlocks(uint16_t maxBlocks=1000);
acracan 0:ed8dc4531ac1 34 int8_t setServos(uint16_t s0, uint16_t s1);
acracan 0:ed8dc4531ac1 35 void setAddress(uint8_t addr);
acracan 0:ed8dc4531ac1 36 void setSerialOutput(Serial *pc);
acracan 0:ed8dc4531ac1 37
acracan 0:ed8dc4531ac1 38 Block *blocks;
acracan 0:ed8dc4531ac1 39
acracan 0:ed8dc4531ac1 40 private:
acracan 0:ed8dc4531ac1 41 static const uint8_t PIXY_INITIAL_ARRAYSIZE = 30;
acracan 0:ed8dc4531ac1 42 static const uint8_t PIXY_MAXIMUM_ARRAYSIZE = 130;
acracan 0:ed8dc4531ac1 43 static const uint16_t PIXY_START_WORD = 0xaa55;
acracan 0:ed8dc4531ac1 44 static const uint16_t PIXY_START_WORDX = 0x55aa;
acracan 0:ed8dc4531ac1 45 static const uint8_t PIXY_DEFAULT_ADDR = 0x54; // I2C
acracan 0:ed8dc4531ac1 46
acracan 0:ed8dc4531ac1 47 bool getStart();
acracan 0:ed8dc4531ac1 48 void resize();
acracan 0:ed8dc4531ac1 49
acracan 0:ed8dc4531ac1 50 bool skipStart;
acracan 0:ed8dc4531ac1 51 uint16_t blockCount;
acracan 0:ed8dc4531ac1 52 uint16_t blockArraySize;
acracan 0:ed8dc4531ac1 53
acracan 0:ed8dc4531ac1 54 PixyLink *m_link;
acracan 0:ed8dc4531ac1 55 Serial *pc;
acracan 0:ed8dc4531ac1 56 };
acracan 0:ed8dc4531ac1 57 #endif //TUIASI_PIXY_H