discoverpixy
Functions
Pixy Control Helper
Collaboration diagram for Pixy Control Helper:

Functions

int16_t pixy_PID_Y (int16_t x, int16_t w)
 
int16_t pixy_PID_X (int16_t x, int16_t w)
 

Detailed Description

A collection of helper functions that contain PID Control code used for object tracking.

Function Documentation

int16_t pixy_PID_X ( int16_t  x,
int16_t  w 
)

Execute one step of PID regulation for the X-servo.

Parameters
xdesired value (e.g. current x-position of the biggest block)
wactual value (e.g desired x-position)
Returns
The offset which needs to be added to the X-Servo position

Definition at line 67 of file pixy_control.c.

68 {
69  float e = 0;
70  static float esum = 0;
71  static float eold = 0;
72  float y = 0;
73 
74  e = (float)(x - w); // calculate the controller offset
75 
76  //----PID-control-------------------------------------------------------------------------
77  esum = esum + e; // add e to the current sum
78 
79  y += REG_PID_KP * e; // add the proportional part to the output
80  y += REG_PID_KI * REG_PID_TA * esum; // add the integral part to the output
81  y += REG_PID_KD * (e - eold) / REG_PID_TA; // add the differential part to the output
82  //----------------------------------------------------------------------------------------
83 
84  eold = e; // save the previous value
85 
86  return (int16_t)y;
87 }
#define REG_PID_KI
Definition: pixy_control.c:38
#define REG_PID_KP
Definition: pixy_control.c:37
#define REG_PID_TA
Definition: pixy_control.c:40
uint16_t y
Definition: pixy.h:81
uint16_t x
Definition: pixy.h:80
#define REG_PID_KD
Definition: pixy_control.c:39

Here is the caller graph for this function:

int16_t pixy_PID_Y ( int16_t  x,
int16_t  w 
)

Execute one step of PID regulation for the Y-servo.

Parameters
xdesired value (e.g. current y-position of the biggest block)
wactual value (e.g desired y-position)
Returns
The offset which needs to be added to the Y-Servo position

Definition at line 44 of file pixy_control.c.

45 {
46  float e = 0;
47  static float esum = 0;
48  static float eold = 0;
49  float y = 0;
50 
51  e = (float)(x - w); // calculate the controller offset
52 
53  //----PID-control-------------------------------------------------------------------------
54  esum = esum + e; // add e to the current sum
55 
56  y += REG_PID_KP * e; // add the proportional part to the output
57  y += REG_PID_KI * REG_PID_TA * esum; // add the integral part to the output
58  y += REG_PID_KD * (e - eold) / REG_PID_TA; // add the differential part to the output
59  //----------------------------------------------------------------------------------------
60 
61  eold = e; // save the previous value
62 
63  return (int16_t)y;
64 }
#define REG_PID_KI
Definition: pixy_control.c:38
#define REG_PID_KP
Definition: pixy_control.c:37
#define REG_PID_TA
Definition: pixy_control.c:40
uint16_t y
Definition: pixy.h:81
uint16_t x
Definition: pixy.h:80
#define REG_PID_KD
Definition: pixy_control.c:39

Here is the caller graph for this function: