discoverpixy
pixy.h
Go to the documentation of this file.
1 //
2 // begin license header
3 //
4 // This file is part of Pixy CMUcam5 or "Pixy" for short
5 //
6 // All Pixy source code is provided under the terms of the
7 // GNU General Public License v2 (http://www.gnu.org/licenses/gpl-2.0.html).
8 // Those wishing to use Pixy source code, software and/or
9 // technologies under different licensing terms should contact us at
10 // cmucam@cs.cmu.edu. Such licensing terms are available for
11 // all portions of the Pixy codebase presented here.
12 //
13 // end license header
14 //
15 
16 #ifndef __PIXY_H__
17 #define __PIXY_H__
18 
19 #include <stdint.h>
20 #include "pixydefs.h"
21 
22 // Pixy C API //
23 
24 #ifdef __cplusplus
25 extern "C"
26 {
27 #endif
28 
34 
35 
36  #define PIXY_MAX_SIGNATURE 7
37 
38  // Pixy x-y position values
39  #define PIXY_MIN_X 0
40  #define PIXY_MAX_X 319
41  #define PIXY_MIN_Y 0
42  #define PIXY_MAX_Y 199
43 
44  // RC-servo values
45  #define PIXY_RCS_MIN_POS 0
46  #define PIXY_RCS_MAX_POS 1000
47  #define PIXY_RCS_CENTER_POS ((PIXY_RCS_MAX_POS-PIXY_RCS_MIN_POS)/2)
48 
49  // Block types
50  #define PIXY_BLOCKTYPE_NORMAL 0
51  #define PIXY_BLOCKTYPE_COLOR_CODE 1
52 
53  struct Block
54  {
55  /*void print(char *buf)
56  {
57  int i, j;
58  char sig[6], d;
59  bool flag;
60  if (type==PIXY_BLOCKTYPE_COLOR_CODE)
61  {
62  // convert signature number to an octal string
63  for (i=12, j=0, flag=false; i>=0; i-=3)
64  {
65  d = (signature>>i)&0x07;
66  if (d>0 && !flag)
67  flag = true;
68  if (flag)
69  sig[j++] = d + '0';
70  }
71  sig[j] = '\0';
72  sprintf(buf, "CC block! sig: %s (%d decimal) x: %d y: %d width: %d height: %d angle %d", sig, signature, x, y, width, height, angle);
73  }
74  else // regular block. Note, angle is always zero, so no need to print
75  sprintf(buf, "sig: %d x: %d y: %d width: %d height: %d", signature, x, y, width, height);
76  }*/
77 
78  uint16_t type;
79  uint16_t signature;
80  uint16_t x;
81  uint16_t y;
82  uint16_t width;
83  uint16_t height;
84  int16_t angle;
85  };
86 
95  int pixy_init();
96 
104  int pixy_blocks_are_new();
105 
121  int pixy_get_blocks(uint16_t max_blocks, struct Block * blocks);
122 
123 
124 
125  int pixy_service();
126 
133  int pixy_command(const char *name, ...);
134 
138  void pixy_close();
139 
144  void pixy_error(int error_code);
145 
154  int pixy_led_set_RGB(uint8_t red, uint8_t green, uint8_t blue);
155 
162  int pixy_led_set_max_current(uint32_t current);
163 
170 
178  int pixy_cam_set_auto_white_balance(uint8_t value);
179 
187 
194 
203  int pixy_cam_set_white_balance_value(uint8_t red, uint8_t green, uint8_t blue);
204 
212  int pixy_cam_set_auto_exposure_compensation(uint8_t enable);
213 
221 
229  int pixy_cam_set_exposure_compensation(uint8_t gain, uint16_t comp);
230 
238  int pixy_cam_get_exposure_compensation(uint8_t * gain, uint16_t * comp);
239 
246  int pixy_cam_set_brightness(uint8_t brightness);
247 
254 
261  int pixy_rcs_get_position(uint8_t channel);
262 
270  int pixy_rcs_set_position(uint8_t channel, uint16_t position);
271 
276  int pixy_rcs_set_frequency(uint16_t frequency);
277 
286  int pixy_get_firmware_version(uint16_t * major, uint16_t * minor, uint16_t * build);
287 
290 #ifdef __cplusplus
291 }
292 #endif
293 
294 #endif
int pixy_cam_set_brightness(uint8_t brightness)
Set pixy camera brightness.
int pixy_get_firmware_version(uint16_t *major, uint16_t *minor, uint16_t *build)
Get pixy firmware version.
int pixy_rcs_set_frequency(uint16_t frequency)
Set pixy servo pulse width modulation (PWM) frequency.
int pixy_cam_set_white_balance_value(uint8_t red, uint8_t green, uint8_t blue)
Set pixy camera white balance.
uint16_t y
Definition: pixy.h:81
int pixy_cam_get_auto_exposure_compensation()
Get pixy camera auto exposure compensation setting.
int pixy_rcs_get_position(uint8_t channel)
Get pixy servo axis position.
int pixy_blocks_are_new()
Indicates when new block data from Pixy is received.
int pixy_cam_get_brightness()
Get pixy camera brightness.
int pixy_service()
int pixy_command(const char *name,...)
Send a command to Pixy.
int pixy_cam_set_exposure_compensation(uint8_t gain, uint16_t comp)
Set pixy camera exposure compensation.
uint16_t type
Definition: pixy.h:78
uint16_t height
Definition: pixy.h:83
int pixy_led_set_max_current(uint32_t current)
Set pixy LED maximum current.
int pixy_cam_set_auto_white_balance(uint8_t value)
Enable or disable pixy camera auto white balance.
int pixy_cam_set_auto_exposure_compensation(uint8_t enable)
Enable or disable pixy camera auto exposure compensation.
int pixy_init()
Creates a connection with Pixy and listens for Pixy messages.
uint16_t width
Definition: pixy.h:82
int pixy_rcs_set_position(uint8_t channel, uint16_t position)
Set pixy servo axis position.
void pixy_error(int error_code)
Send description of pixy error to stdout.
uint16_t signature
Definition: pixy.h:79
void pixy_close()
Terminates connection with Pixy.
int pixy_cam_get_exposure_compensation(uint8_t *gain, uint16_t *comp)
Get pixy camera exposure compensation.
int pixy_get_blocks(uint16_t max_blocks, struct Block *blocks)
Copies up to 'max_blocks' number of Blocks to the address pointed to by 'blocks'. ...
int pixy_led_set_RGB(uint8_t red, uint8_t green, uint8_t blue)
Set color of pixy LED.
uint16_t x
Definition: pixy.h:80
uint32_t pixy_cam_get_white_balance_value()
Get pixy camera white balance()
Definition: pixy.h:53
int pixy_cam_get_auto_white_balance()
Get pixy camera auto white balance setting.
int pixy_led_get_max_current()
Get pixy LED maximum current.
int16_t angle
Definition: pixy.h:84