1   package simworldobjects;
2   
3   import interfaces.*;
4   
5   /**
6   * Abstract class for SimSensors.
7   * A SimSensor is a different sort of object to a BasicSimObject. It has single
8   * 'owning' SimObject (normally a SimRCX) and all of its parameters are derived 
9   * from this object. Many of its methods therefore do nothing - they are simply
10  * included here to fulfill the requirements of a SimObject.
11  *
12  * @see interfaces.SimObject
13  *
14  * @author Graham Ritchie
15  */
16  public abstract class SimSensor implements SimObject
17  {
18      // the SimObject which 'owns' this sensor
19      private SimObject object;
20      
21      private double xOffset, zOffset;
22      private double height, width, length;
23      private String type;
24      
25      /**
26      * Initialises this SimSensor
27      */
28      public void initSimSensor(SimObject object, double xOffset, double zOffset, double height, double width, double length, String type)
29      {
30          this.object=object;
31          this.xOffset=xOffset;
32          this.zOffset=zOffset;
33          this.height=height;
34          this.width=width;
35          this.length=length;
36          this.type=type;
37      }
38      
39      /**
40      * Returns this sensor's current value
41      *
42      * @return the current value of this sensor as an int
43      */
44      public abstract int getValue();
45      
46      public void setDesiredVelocity(double v){}
47      public void setActualVelocity(double v){}
48      public void setXCoord(double x){}
49      public void setYCoord(double y){}
50      public void setZCoord(double z){}
51      
52      public double getDesiredVelocity()
53      {
54          return 0.0;
55      }
56      
57      public double getActualVelocity()
58      {
59          return 0.0;
60      }
61      
62      /**
63      * Returns this sensor's X coordinate - derived from its owning SimObject
64      */
65      public double getXCoord()
66      {
67          return  object.getXCoord()+
68                  (xOffset*Math.cos(Math.toRadians(object.getActualBearingXZ())))+
69                  (zOffset*-Math.sin(Math.toRadians(object.getActualBearingXZ())));
70      }
71      
72      /**
73      * Returns this sensor's X coordinate
74      */
75      public double getYCoord()
76      {
77          return 0.0;
78      }
79      
80      /**
81      * Returns this sensor's Z coordinate - derived from its owning SimObject
82      */
83      public double getZCoord()
84      {
85          return  object.getZCoord()+
86                  (zOffset*Math.cos(Math.toRadians(object.getActualBearingXZ())))+
87                  (xOffset*Math.sin(Math.toRadians(object.getActualBearingXZ())));
88      }
89      
90      public void setDesiredBearingVelocityXZ(double v){}
91      public void setDesiredBearingVelocityXY(double v){}
92      public void setActualBearingVelocityXZ(double b){}
93      public void setActualBearingVelocityXY(double b){}
94      public void setActualBearingXZ(double b){}
95      public void setActualBearingXY(double b){}
96  
97      public double getDesiredBearingVelocityXZ()
98      {
99          return 0.0;
100     }
101     
102     public double getDesiredBearingVelocityXY()
103     {
104         return 0.0;
105     }   
106     
107     public double getActualBearingVelocityXZ()
108     {
109         return 0.0;
110     }
111     
112     public double getActualBearingVelocityXY()
113     {
114         return 0.0;
115     }
116     
117     /**
118     * Returns this sensor's XZ bearing (the same as the owning SimObject's bearing)
119     */
120     public double getActualBearingXZ()
121     {
122         return object.getActualBearingXZ();
123     }
124     
125     public double getActualBearingXY()
126     {
127         return 0.0;
128     }
129     
130     public double getHeight()
131     {
132         return this.height;
133     }
134     
135     public double getWidth()
136     {
137         return this.width;
138     }
139     
140     public double getLength()
141     {
142         return this.length;
143     }
144 
145     public String getType()
146     {
147         return this.type;
148     }
149 }
150