forked from Choate-Robotics/BayesianGame
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSensor.pde
63 lines (55 loc) · 1.39 KB
/
Sensor.pde
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
class Sensor{
float objectErrorRate = 0.2;
float emptyErrorRate = 0.1;
float avgPositionError=5.0;
int myWidth, myHeight;
Map myMapM;
Sensor(int myW, int myH, Map map){
myWidth=myW;
myHeight=myH;
myMapM=map;
}
void sense(){
int newX, newY;
float returnValue=0.0;
// choose a random point in the field
newX=(int)random(myWidth);
newY=(int)random(myHeight);
// determine the color of the that pixel
loadPixels();
float value=red(pixels[newY*width+newX])/255.0;
// jiggle to create error in the readings
// use the errorRates that are posted as class variables
if (value>.5){
// we have something
if (random(1)<objectErrorRate){
//Give false reading
returnValue=0.0;
}
else
{
//Give true reading
returnValue=1.0;
}
}
else
{
if (random(1)<emptyErrorRate){
//Give false reading
returnValue=1.0;
}
else
{
//give true reading
returnValue=0.0;
}
}
// jiggle the chosen x and y values by the avgPositionError
newX+=(int)(randomGaussian()*avgPositionError);
newY+=(int)(randomGaussian()*avgPositionError);
// report the jiggled information the mapMaker
newX=constrain(newX,0,myWidth-myMapM.gridsize/2);
newY=constrain(newY,0,myHeight-myMapM.gridsize/2);
myMapM.update(newX, newY, returnValue);
}
}