-
Notifications
You must be signed in to change notification settings - Fork 3
/
decisionHandler.c
142 lines (120 loc) · 3.77 KB
/
decisionHandler.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#ifndef DECISIONHANDLER_C_INCLUDED
#define DECISIONHANDLER_C_INCLUDED
//Drives the robot based on recieved commands
task commandRobot()
{
long xDemand[MPC_MSG_OBJ_COUNT], yDemand[MPC_MSG_OBJ_COUNT], pickup[MPC_MSG_OBJ_COUNT];
sendMPCMsg();
wait1Msec(100);
while (true)
{
if (mpcMsgFlag && !badData && ((nPgmTime - autoStartTime) < 35000))
{
writeDebugStreamLine("MPC : Flag");
BCI_lockSem(mpc_msgSem, "commandRobot")
{
int j;
for (int i = 0; i < MPC_MSG_OBJ_COUNT; i++)
{
j = i * 9;
xDemand[i] = mpc_msg[MPC_MSG_X_COORD + j];
yDemand[i] = mpc_msg[MPC_MSG_Y_COORD + j];
pickup[i] = mpc_msg[MPC_MSG_PICKUP + j];
writeDebugStreamLine("%d,%d,%d", xDemand[i], yDemand[i], pickup[i]);
}
BCI_unlockSem(mpc_msgSem, "commandRobot")
}
//Check for bad data
for (int i = 0; i < MPC_MSG_OBJ_COUNT; i++)
{
if (xDemand[i] < -1 ||
xDemand[i] > 3658 ||
yDemand[i] < -1 ||
yDemand[i] > 1829)
{
badData = true;
SensorValue[LED] = 0;
writeDebugStreamLine("MPC: BAD DATA");
break;
}
else{
badData=false;
}
}
//Break out if we get bad data from pi
if (badData)
{
//break;
}
//Go through each msg and perform the action
for (int i = 0; i < MPC_MSG_OBJ_COUNT; i++)
{
switch (pickup[i])
{
case MPC_MSG_PICKUP_CLEAR:
#ifdef MPC_DEBUG
writeDebugStreamLine("moving to point (%d,%d)", xDemand[i], yDemand[i]);
#endif
moveToPoint(xDemand[i], yDemand[i]);
break;
case MPC_MSG_PICKUP_STAR:
#ifdef MPC_DEBUG
writeDebugStreamLine("getting star at (%d,%d)", xDemand[i], yDemand[i]);
#endif
if( pickUp(xDemand[i], yDemand[i] , false))
i = MPC_MSG_OBJ_COUNT;//totally done
break;
case MPC_MSG_PICKUP_CUBE:
#ifdef MPC_DEBUG
writeDebugStreamLine("getting cube at (%d,%d)", xDemand[i], yDemand[i]);
#endif
pickUp(xDemand[i], yDemand[i], true);
i = MPC_MSG_OBJ_COUNT;//totally done
break;
case MPC_MSG_PICKUP_BACK:
#ifdef MPC_DEBUG
writeDebugStreamLine("moving to point (%d,%d) backwards", xDemand[i], yDemand[i]);
#endif
moveToPoint(xDemand[i], yDemand[i], true);
break;
case MPC_MSG_PICKUP_WALL:
#ifdef MPC_DEBUG
writeDebugStreamLine("knocking stars off fence %d", xDemand[i]);
#endif
switch (xDemand[i])
{
case 1:
scoreFence(FENCE_LEFT);
break;
case 2:
scoreFence(FENCE_MIDDLE);
break;
case 3:
scoreFence(FENCE_RIGHT);
break;
default:
break;
}
break;
default:
break;
}
}
//Score whats in the intake
writeDebugStreamLine("closing claw");
intakeAndLiftTask_intakeState = INTAKE_CLOSED;
intakeAndLiftTask_liftState = LIFT_DOWN;
wait1Msec(650);
driveStraight_Ballsy(-400);
intakeAndLiftTask_liftState = LIFT_HALF;
wait1Msec(250);
writeDebugStreamLine("about to dump");
dumpIntake();
writeDebugStreamLine("dumped");
mpcMsgFlag = false;
}
sendMPCMsg();
wait1Msec(100);
}
}
#endif //DECISIONHANDLER_C_INCLUDED