-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
76 lines (57 loc) · 2.18 KB
/
Copy pathmain.c
File metadata and controls
76 lines (57 loc) · 2.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
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
#include <stdio.h>
#include "Locomotion.h"
#include "costAlgorithm.h"
// enable this to perform run via simulation.
#define ENABLE_SIMULATION 1
#if ENABLE_SIMULATION
#include "Simulation/simulator.h"
#endif
extern CELL CURRENT_CELL;
extern ABSOLUTE_DIRECTION CURRENT_ABSOLUTE_DIRECTION;
// Path Finding from Home to goal and goal to home. Vice versa
void gotoGoal(CELL goal);
void gotoGoal(CELL goal)
{
while ((CURRENT_CELL.x != goal.x) || (CURRENT_CELL.y != goal.y))
{
#if !ENABLE_SIMULATION
// read the values from 3 sensors for mapping walls.
WallState frontWall = (API_frontWall() == 1) ? WALL_PRESENT : WALL_ABSENT;
WallState rightWall = (API_rightWall() == 1) ? WALL_PRESENT : WALL_ABSENT;
WallState leftWall = (API_leftWall() == 1) ? WALL_PRESENT : WALL_ABSENT;
#elif ENABLE_SIMULATION
// read the values from 3 sensors for mapping walls via simulation.
WallState frontWall = 0;
WallState rightWall = 0;
WallState leftWall = 0;
getSimulatedWall(CURRENT_CELL, CURRENT_ABSOLUTE_DIRECTION, &frontWall, &rightWall, &leftWall);
#endif
updateWalls(frontWall, rightWall, leftWall);
propagateCost(goal);
CELL nextCellToMove = smallestNextNeighbourCell(CURRENT_CELL, CURRENT_ABSOLUTE_DIRECTION);
moveToCurrentLocation(CURRENT_CELL.x, CURRENT_CELL.y, nextCellToMove.x, nextCellToMove.y, &CURRENT_ABSOLUTE_DIRECTION);
// Update current cell after movement.
CURRENT_CELL.x = nextCellToMove.x; CURRENT_CELL.y = nextCellToMove.y;
// break;
}
}
int main() {
printf("Hello, World!\n");
/*
* Initialise the Walls based on out "L" finger rule.
* All boundaries are marked as wall present and rest all as unseen
*/
initWalls();
// assign the goal.
CELL goal = END;
// set current cell to 0,0
CURRENT_CELL.x = 0;
CURRENT_CELL.y = 0;
// Set current pointing Direction
CURRENT_ABSOLUTE_DIRECTION = NORTH;
// do update walls and propagate Cost till current cell != goal
gotoGoal(goal);
// give home as new goal and make the bot come back.
gotoGoal((CELL){0,0});
return 0;
}