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          private char loc;
25      
26      /**
27      * Initialises this SimSensor
28      */
29      public void initSimSensor(SimObject object, double xOffset, double zOffset, double height, double width, double length, String type, char loc)
30      {
31          this.object=object;
32          this.xOffset=xOffset;
33          this.zOffset=zOffset;
34          this.height=height;
35          this.width=width;
36          this.length=length;
37          this.type=type;
38                  this.loc = loc;
39      }
40      
41      /**
42      * Returns this sensor's current value
43      *
44      * @return the current value of this sensor as an int
45      */
46      public abstract int getValue();
47      
48      public void setDesiredVelocity(double v){}
49      public void setActualVelocity(double v){}
50      public void setXCoord(double x){}
51      public void setYCoord(double y){}
52      public void setZCoord(double z){}
53      
54      public double getDesiredVelocity()
55      {
56          return 0.0;
57      }
58      
59      public double getActualVelocity()
60      {
61          return 0.0;
62      }
63      
64      /**
65      * Returns this sensor's X coordinate - derived from its owning SimObject
66      */
67      public double getXCoord()
68      {
69          return  object.getXCoord()+
70                  (xOffset*Math.cos(Math.toRadians(object.getActualBearingXZ())))+
71                  (zOffset*-Math.sin(Math.toRadians(object.getActualBearingXZ())));
72      }
73      
74      /**
75      * Returns this sensor's X coordinate
76      */
77      public double getYCoord()
78      {
79          return 0.0;
80      }
81      
82      /**
83      * Returns this sensor's Z coordinate - derived from its owning SimObject
84      */
85      public double getZCoord()
86      {
87          return  object.getZCoord()+
88                  (zOffset*Math.cos(Math.toRadians(object.getActualBearingXZ())))+
89                  (xOffset*Math.sin(Math.toRadians(object.getActualBearingXZ())));
90      }
91      
92      public void setDesiredBearingVelocityXZ(double v){}
93      public void setDesiredBearingVelocityXY(double v){}
94      public void setActualBearingVelocityXZ(double b){}
95      public void setActualBearingVelocityXY(double b){}
96      public void setActualBearingXZ(double b){}
97      public void setActualBearingXY(double b){}
98  
99      public double getDesiredBearingVelocityXZ()
100     {
101         return 0.0;
102     }
103     
104     public double getDesiredBearingVelocityXY()
105     {
106         return 0.0;
107     }   
108     
109     public double getActualBearingVelocityXZ()
110     {
111         return 0.0;
112     }
113     
114     public double getActualBearingVelocityXY()
115     {
116         return 0.0;
117     }
118     
119     /**
120     * Returns this sensor's XZ bearing (the same as the owning SimObject's bearing)
121     */
122     public double getActualBearingXZ()
123     {
124         return object.getActualBearingXZ();
125     }
126     
127     public double getActualBearingXY()
128     {
129         return 0.0;
130     }
131     
132     public double getHeight()
133     {
134         return this.height;
135     }
136     
137     public double getWidth()
138     {
139         return this.width;
140     }
141     
142     public double getLength()
143     {
144         return this.length;
145     }
146 
147     public String getType()
148     {
149         return this.type;
150     }
151         public char getPosition(){
152             return this.loc;
153         }
154         public SimObject getOwner(){
155             return this.object;
156         }
157 }
158