-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathex_7_1_2.cpp
More file actions
75 lines (55 loc) · 1.44 KB
/
Copy pathex_7_1_2.cpp
File metadata and controls
75 lines (55 loc) · 1.44 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
#include <ros/ros.h>
#include <unistd.h>
#include "texas_robotics_academy/texbot_wrapper.h"
void printThreshold(TexBot &bot, int sensorArray[8]) {
int threshold = 145;
char asteriskLine[17];
for(int i = 0; i < 8; i++) {
if(sensorArray[i] > threshold) {
asteriskLine[i * 2] = '*';
asteriskLine[i * 2 + 1] = '*';
} else {
asteriskLine[i * 2] = '-';
asteriskLine[i * 2 + 1] = '-';
}
}
asteriskLine[16] = 0;
bot.lcd1(asteriskLine);
}
int findDarkestPixel(int sensorArray[8]) {
int darkestPixel = 0;
int darkestValue = 0;
for(int i = 0; i < 8; i++) {
if(sensorArray[i] > darkestValue) {
darkestPixel = i;
darkestValue = sensorArray[i];
}
}
return darkestPixel;
}
int main(int argc, char **argv) {
ros::init(argc, argv, "robot");
TexBot bot;
int sensorArray[8];
while(ros::ok()) {
for(int i = 0; i < 8; i++) {
sensorArray[i] = bot.readLineSensor(i);
}
int darkestPixel = findDarkestPixel(sensorArray);
bot.lcd2((darkestPixel-3.5)/3.5);
char asteriskLine[17];
for(int i = 0; i < 8; i++) {
if(i == darkestPixel) {
asteriskLine[i * 2] = '*';
asteriskLine[i * 2 + 1] = '*';
} else {
asteriskLine[i * 2] = '-';
asteriskLine[i * 2]
asteriskLine[16] = 0;
bot.lcd1(asteriskLine);
//printThreshold(bot, sensorArray);
ros::spinOnce();
usleep(200000);
}
return 0;
}