-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathEVs_SumoEyes.cpp
98 lines (79 loc) · 2.3 KB
/
EVs_SumoEyes.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
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
/*
* EVShield interface library
* Copyright (C) 2011 mindsensors.com
*
* This file is part of EVShield interface library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "EVs_SumoEyes.h"
bool EVs_SumoEyes::init(EVShield * shield, SH_BankPort bp)
{
EVShieldAGS::init(shield, bp);
return true;
}
bool EVs_SumoEyes::setType(int8_t type)
{
if ( mp_shield == NULL) return false;
switch (m_bp) {
case SH_BAS1:
return mp_shield->bank_a.sensorSetType(SH_S1, type);
case SH_BAS2:
return mp_shield->bank_a.sensorSetType(SH_S2, type);
case SH_BBS1:
return mp_shield->bank_b.sensorSetType(SH_S1, type);
case SH_BBS2:
return mp_shield->bank_b.sensorSetType(SH_S2, type);
}
}
bool EVs_SumoEyes::setShortRange()
{
return setType( SH_Type_LIGHT_AMBIENT );
}
bool EVs_SumoEyes::setLongRange()
{
return setType( SH_Type_LIGHT_REFLECTED );
}
bool EVs_SumoEyes::isNear(int reference, int delta, int comet)
{
if ( (comet > (reference - delta))
&& (comet < (reference + delta)) ) {
return true;
}
return false;
}
SE_Zone EVs_SumoEyes::detectObstacleZone()
{
int se_value;
se_value = readRaw();
if ( isNear(830, 10, se_value) ) return SE_Front;
if ( isNear(580, 10, se_value) ) return SE_Left;
if ( isNear(487, 10, se_value) ) return SE_Right;
return (SE_None);
}
char *EVs_SumoEyes::OBZoneToString(SE_Zone ob)
{
switch (ob) {
case SE_None:
return (char *) "NONE";
break;
case SE_Front:
return (char *) "FRONT";
break;
case SE_Left:
return (char *) "LEFT";
break;
case SE_Right:
return (char *) "RIGHT";
break;
}
}