-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAgentController.nxc
More file actions
50 lines (41 loc) · 1.18 KB
/
AgentController.nxc
File metadata and controls
50 lines (41 loc) · 1.18 KB
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
//Remember to compile with the -EF flags, else enhanced firmware functions won't be defined
#include "movement.nxc"
#include "vectorQueue.nxc"
#include "MonteCarloController.nxc"
#include "ultrasonicSensor.nxc"
#define VECTOR_QUEUE_SIZE 10
void schedule();
void updateMoveVector();
void runVectors();
int cycleCount = 0;
unsigned int touchSensorOutput = 0;
int angleSensorOutput = 0;
vec2 currentMovementVector;
vec2 moveVectorQueue[VECTOR_QUEUE_SIZE];
task main() {
SetSensorLowspeed(IN_1);
SetSensorTouch(IN_2);
SetSensorLowspeed(IN_4);
initQueue(moveVectorQueue, VECTOR_QUEUE_SIZE);
currentMovementVector = getNullVector();
initiateTimeStep();
firstMove(GOAL_X, GOAL_Y, moveVectorQueue, VECTOR_QUEUE_SIZE);
schedule();
}
void schedule(){
do{
for (int i = 0; i < VECTORS_TO_SCHEDUEL; i++) {
runVectors();
}
}while (nextMove(makeSensorReadings(),moveVectorQueue, VECTOR_QUEUE_SIZE));
}
void runVectors() {
updateMoveVector();
rotate(currentMovementVector);
moveAhead(currentMovementVector);
}
void updateMoveVector(){
if(isNullVector(currentMovementVector)){
currentMovementVector = dequeueVector(moveVectorQueue, VECTOR_QUEUE_SIZE);
}
}