1 package simworldobjects;
2
3 import interfaces.*;
4
5
10 public class SimTouchSensor extends SimSensor
11 {
12 private SimRCX robot;
13 private double xOffset, zOffset;
14 private boolean currentValue;
15 private boolean previousValue;
16
17
25 public SimTouchSensor(SimRCX r, double xOffset, double zOffset, char loc)
26 {
27 robot=r;
28 initSimSensor(r,xOffset,zOffset,10.0,10.0,10.0,"sensorTouch",loc);
29 this.xOffset=xOffset;
30 this.zOffset=zOffset;
31 this.currentValue = false;
32 this.previousValue = false;
33 }
34
35
41 public int getValue()
42 {
43 SimWorld world=robot.getWorld();
44
45 if (world.hasObstacle(this.getXCoord(),this.getYCoord(),this.getZCoord()))
46 {
47 return 1;
48 }
49 else
50 {
51 return 0;
52 }
53 }
54
55
61 public boolean getBooleanValue(){
62 BasicSimWorld world= (BasicSimWorld)robot.getWorld();
63
64 return world.hasObstacle(this.getXCoord(),this.getYCoord(),this.getZCoord());
65
66 }
67
68 public double getXOffset()
69 {
70 return xOffset;
71 }
72
73 public double getZOffset()
74 {
75 return zOffset;
76 }
77
78 public boolean getPreviousValue(){
79 return this.previousValue;
80 }
81
82 public boolean getCurrentValue(){
83 BasicSimWorld world= (BasicSimWorld)robot.getWorld();
84 previousValue = currentValue;
85 currentValue = world.hasObstacle(this.getXCoord(),this.getYCoord(),this.getZCoord());
86 return this.currentValue;
87 }
88 }
89