robi.sim.objects
Class SimSensor

java.lang.Object
  |
  +--robi.sim.objects.SimSensor
All Implemented Interfaces:
java.lang.Runnable

public class SimSensor
extends java.lang.Object
implements java.lang.Runnable

Author:
Reto Witschi A sensor object on a robot

Field Summary
 double d
          Direction of sensor
 double direction
          Start direction of sensor
 boolean isThRunning
          Indicates whether the sensor thread is running or not
 java.awt.Point p
          Position of sensor
 SimRobot robo
          SimRobot object where this sensor is set on
 java.awt.Point startPos
          Start position of sensor
 java.lang.Thread thUpdate
          Update thread
 int value
          Sensor value of this sensor
 
Constructor Summary
SimSensor(int x, int y, double di, SimRobot r)
           
 
Method Summary
private  double calcSensorValue(int xLight, int yLight, int val)
          Calculates sensor value (for one light)
private  double getAngle(int xLight, int yLight)
          Calculates the angle between light and sensor
private  int getDistance(int xLight, int yLight)
          Calculates distance between light and sensor
private  double getPercentFromAngle(double angle)
          Special function to calculate percentage from an angle
private  double getPercentFromDistance(int dist)
          Special function to calculate percentage from a distance
 int getSensorValue()
          Returns sensor vlaue
private  int getSensorValue(java.util.Vector lights)
          Calculates sensor values (for all lights)
 void run()
          Main method of update thread which updates the sensor value
 void start()
          Starts the sensor thread
 void stop()
          Stops the sensor thread
 void updatePos()
          Updates position of sensor
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

isThRunning

public boolean isThRunning
Indicates whether the sensor thread is running or not


startPos

public java.awt.Point startPos
Start position of sensor


direction

public double direction
Start direction of sensor


robo

public SimRobot robo
SimRobot object where this sensor is set on


value

public int value
Sensor value of this sensor


thUpdate

public java.lang.Thread thUpdate
Update thread


p

public java.awt.Point p
Position of sensor


d

public double d
Direction of sensor

Constructor Detail

SimSensor

public SimSensor(int x,
                 int y,
                 double di,
                 SimRobot r)
Method Detail

start

public void start()
Starts the sensor thread


stop

public void stop()
Stops the sensor thread


run

public void run()
Main method of update thread which updates the sensor value

Specified by:
run in interface java.lang.Runnable

getSensorValue

public int getSensorValue()
Returns sensor vlaue

Returns:
Sensor vlaue

getSensorValue

private int getSensorValue(java.util.Vector lights)
Calculates sensor values (for all lights)

Parameters:
lights - All lights in simulation
Returns:
Sensor value (0 <= x <= 100)

updatePos

public void updatePos()
Updates position of sensor


calcSensorValue

private double calcSensorValue(int xLight,
                               int yLight,
                               int val)
Calculates sensor value (for one light)

Parameters:
xLight - x coordinate of light
yLight - y coordiante of light
val - light value
Returns:
Sensor value for one light

getAngle

private double getAngle(int xLight,
                        int yLight)
Calculates the angle between light and sensor

Parameters:
xLight - x coordinate of light
yLight - y coordinate of light
Returns:
Angle between light and sensor

getDistance

private int getDistance(int xLight,
                        int yLight)
Calculates distance between light and sensor

Parameters:
xLight - x coordinate of light
yLight - y coordinate of light
Returns:
Distance to light

getPercentFromAngle

private double getPercentFromAngle(double angle)
Special function to calculate percentage from an angle

Parameters:
angle - Calculated angle
Returns:
Percentage of light influence

getPercentFromDistance

private double getPercentFromDistance(int dist)
Special function to calculate percentage from a distance

Parameters:
dist - Calculated distance
Returns:
Percentage of light influence