-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtracking.c
executable file
·68 lines (55 loc) · 1.85 KB
/
tracking.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include <stdio.h>
#include "mort_defines.h"
#include "tracking.h"
#include "camera.h"
extern int x,y,z;
void Track_Ball(void)
{
int pan_error = 0; //set all these to 0 normally until we calculate
int tilt_error = 0;
static signed char previous_direction = LEFT; //left because if you think about how the field is, it makes more sense. we start in corner
static unsigned int old_camera_t_packets = 0;
x = 0;
y = 0;
z = 0;
if(camera_t_packets != old_camera_t_packets) //if all is good with the camera
{
old_camera_t_packets = camera_t_packets; //update so we know next time if the camera is working
if(T_Packet_Data.confidence >= CONFIDENCE_THRESHOLD_DEFAULT)
{
pan_error = (int)T_Packet_Data.mx - PAN_TARGET_PIXEL_DEFAULT; //calculate errors
tilt_error = (int)T_Packet_Data.my - TILT_TARGET_PIXEL_DEFAULT;
if(pan_error > PAN_ALLOWABLE_ERROR_DEFAULT) // need two if's because of previous direction
{
previous_direction = RIGHT; //we know it's going right
z = pan_error * Z_GAIN; //set z
}
else if (pan_error < -1 * PAN_ALLOWABLE_ERROR_DEFAULT)
{
previous_direction = LEFT; //we know it's going left
z = pan_error * Z_GAIN; // set x
}
else //on target
{
z = 0; //x is 0 if it's ligned up
}
if(tilt_error > TILT_ALLOWABLE_ERROR_DEFAULT || tilt_error < -1 * TILT_ALLOWABLE_ERROR_DEFAULT) //only need one if, no previous direction
{
y = tilt_error * Y_GAIN; //set y
}
else //on target
{
y = 0; // y is zero if it's ligned up
}
}
else //cant see ball - searching
{
y = 0;
z = SEARCH_SPEED * previous_direction;
}
}
x = Limit(x, -127, 127); // check to see that nothing is overflowing
y = Limit(y, -127, 127);
z = Limit(z, -127, 127);
Mec_Drive(x, y, z); // send everything to our motor function
}