-
Notifications
You must be signed in to change notification settings - Fork 1
/
simulator.cpp
54 lines (46 loc) · 1.17 KB
/
simulator.cpp
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
#include <stdio.h>
#include <time.h>
#include <stdbool.h>
#include <unistd.h>
#include "data.cpp"
int NUMBER_OF_BUILDINGS = 0;
time_t startTime;
bool flag = false;
float botSpeed;
void setupSensors() {
// printf("Sensors setup.\n");
startTime = time(NULL);
flag = true;
}
void setBotSpeed(float speed) {
if (!flag) {
printf("Error: Sensors not set up. Call setupSensors() first.\n");
return;
}
// printf("Bot speed set to %d.\n", speed);
botSpeed = speed;
}
const double *predefinedEchoTimes = y;
const double *predefinedEchoLatitude = x;
int calculateIndex(){
if (!flag) {
printf("Error: Sensors not set up. Call setupSensors() first.\n");
return 0;
}
time_t currentTime = time(NULL);
double elapsedTime = difftime(currentTime, startTime);
int index = (int)(elapsedTime * botSpeed / distance_step);
if(index>=num_points)
{
index=num_points-1;
}
return index;
}
double readUltrasoundEchoTime() {
double echoTime = predefinedEchoTimes[calculateIndex()];
sleep(echoTime);
return echoTime;
}
double readLatitude() {
return predefinedEchoLatitude[calculateIndex()];
}