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 <unistd.h>
21 #include "pixydefs.h"
22 
23 // Pixy C API //
24 
25 #ifdef __cplusplus
26 extern "C"
27 {
28 #endif
29 
30  #define PIXY_MAX_SIGNATURE 7
31 
32  // Pixy x-y position values
33  #define PIXY_MIN_X 0
34  #define PIXY_MAX_X 319
35  #define PIXY_MIN_Y 0
36  #define PIXY_MAX_Y 199
37 
38  // RC-servo values
39  #define PIXY_RCS_MIN_POS 0
40  #define PIXY_RCS_MAX_POS 1000
41  #define PIXY_RCS_CENTER_POS ((PIXY_RCS_MAX_POS-PIXY_RCS_MIN_POS)/2)
42 
43  // Block types
44  #define PIXY_BLOCKTYPE_NORMAL 0
45  #define PIXY_BLOCKTYPE_COLOR_CODE 1
46 
47  struct Block
48  {
49  /*void print(char *buf)
50  {
51  int i, j;
52  char sig[6], d;
53  bool flag;
54  if (type==PIXY_BLOCKTYPE_COLOR_CODE)
55  {
56  // convert signature number to an octal string
57  for (i=12, j=0, flag=false; i>=0; i-=3)
58  {
59  d = (signature>>i)&0x07;
60  if (d>0 && !flag)
61  flag = true;
62  if (flag)
63  sig[j++] = d + '0';
64  }
65  sig[j] = '\0';
66  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);
67  }
68  else // regular block. Note, angle is always zero, so no need to print
69  sprintf(buf, "sig: %d x: %d y: %d width: %d height: %d", signature, x, y, width, height);
70  }*/
71 
72  uint16_t type;
73  uint16_t signature;
74  uint16_t x;
75  uint16_t y;
76  uint16_t width;
77  uint16_t height;
78  int16_t angle;
79  };
80 
89  int pixy_init();
90 
98  int pixy_blocks_are_new();
99 
115  int pixy_get_blocks(uint16_t max_blocks, struct Block * blocks);
116 
117 
118 
119  int pixy_service();
120 
127  int pixy_command(const char *name, ...);
128 
132  void pixy_close();
133 
138  void pixy_error(int error_code);
139 
148  int pixy_led_set_RGB(uint8_t red, uint8_t green, uint8_t blue);
149 
156  int pixy_led_set_max_current(uint32_t current);
157 
164 
172  int pixy_cam_set_auto_white_balance(uint8_t value);
173 
181 
188 
197  int pixy_cam_set_white_balance_value(uint8_t red, uint8_t green, uint8_t blue);
198 
206  int pixy_cam_set_auto_exposure_compensation(uint8_t enable);
207 
215 
223  int pixy_cam_set_exposure_compensation(uint8_t gain, uint16_t compensation);
224 
232  int pixy_cam_get_exposure_compensation(uint8_t * gain, uint16_t * compensation);
233 
240  int pixy_cam_set_brightness(uint8_t brightness);
241 
248 
255  int pixy_rcs_get_position(uint8_t channel);
256 
264  int pixy_rcs_set_position(uint8_t channel, uint16_t position);
265 
270  int pixy_rcs_set_frequency(uint16_t frequency);
271 
280  int pixy_get_firmware_version(uint16_t * major, uint16_t * minor, uint16_t * build);
281 
282 #ifdef __cplusplus
283 }
284 #endif
285 
286 #endif
int pixy_rcs_set_position(uint8_t channel, uint16_t position)
Set pixy servo axis position.
int pixy_cam_set_brightness(uint8_t brightness)
Set pixy camera brightness.
void pixy_close()
Terminates connection with Pixy.
uint16_t y
Definition: pixy.h:75
int pixy_get_firmware_version(uint16_t *major, uint16_t *minor, uint16_t *build)
Get pixy firmware version.
int pixy_cam_set_auto_white_balance(uint8_t value)
Enable or disable pixy camera auto white balance.
uint32_t pixy_cam_get_white_balance_value()
Get pixy camera white balance()
uint16_t type
Definition: pixy.h:72
uint16_t height
Definition: pixy.h:77
int pixy_rcs_get_position(uint8_t channel)
Get pixy servo axis position.
int pixy_cam_get_auto_exposure_compensation()
Get pixy camera auto exposure compensation setting.
int pixy_cam_set_exposure_compensation(uint8_t gain, uint16_t compensation)
Set pixy camera exposure compensation.
int pixy_cam_set_white_balance_value(uint8_t red, uint8_t green, uint8_t blue)
Set pixy camera white balance.
int pixy_cam_set_auto_exposure_compensation(uint8_t enable)
Enable or disable pixy camera auto exposure compensation.
uint16_t width
Definition: pixy.h:76
int pixy_service()
int pixy_led_set_RGB(uint8_t red, uint8_t green, uint8_t blue)
Set color of pixy LED.
int pixy_led_get_max_current()
Get pixy LED maximum current.
int pixy_cam_get_auto_white_balance()
Get pixy camera auto white balance setting.
int pixy_led_set_max_current(uint32_t current)
Set pixy LED maximum current.
int pixy_cam_get_exposure_compensation(uint8_t *gain, uint16_t *compensation)
Get pixy camera exposure compensation.
uint16_t signature
Definition: pixy.h:73
int pixy_command(const char *name,...)
Send a command to Pixy.
uint16_t x
Definition: pixy.h:74
int pixy_cam_get_brightness()
Get pixy camera brightness.
int pixy_blocks_are_new()
Indicates when new block data from Pixy is received.
Definition: pixy.h:47
int pixy_init()
Creates a connection with Pixy and listens for Pixy messages.
void pixy_error(int error_code)
Send description of pixy error to stdout.
int pixy_rcs_set_frequency(uint16_t frequency)
Set pixy servo pulse width modulation (PWM) frequency.
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'. ...
int16_t angle
Definition: pixy.h:78