simulator
Class BarSendVRML

java.lang.Object
  |
  +--simulator.GenericSendVRML
        |
        +--simulator.BarSendVRML

class BarSendVRML
extends simulator.GenericSendVRML

Impements the method that calculate position of robot and send the vrml scene


Field Summary
(package private)  BoxState[] box
          Contains a list of non collided box state position
(package private)  BoxState[] boxColl
          Contains a list of collided with bar box state position
(package private)  double delta
          Use to stimate new solution angle
(package private)  int K
          number of collided box
(package private)  int M
          Number of non collided boxs
(package private)  int N
          Number of robots
(package private)  RobotState[] robot
          Contains a list of robots state position
(package private)  SensorState[] sensor
          Contains a list of sensors state position
 
Fields inherited from class simulator.GenericSendVRML
connectedUsers, server, state
 
Constructor Summary
(package private) BarSendVRML()
           
 
Method Summary
 void adjustBoxesPosition(BarState old, BarState bar)
          Adjust position of all boxes to reflect new bar position
 void adjustRobotSensor(BarState bar)
          Adjust the position of sensor to be valid with the new position of the bar.
 boolean boxRotation(BarState oldBar, BarState newBar, BoxState oldBox, BoxState newBox)
          Calculates the rotation of the box that is done by the bar changing position.
 boolean collidedBox(BoxState box, BarState bar)
          Determine if the passed box has collided with the bar.
 int[] collisionDetect(BarState bar)
          Detect if the bar has collided to boxes object.
 boolean crossProduct(Position p1, Position p2, Position p3, Position p4)
          Search for intersection of line (p1,p2) and (p3,p4) using the cross product algorithm
 void findBoxVertexes(BoxState box, Position a1, Position a2, Position a3, Position a4)
          Calculates the 4 vertexes of the box using fisical dimension and orientation
 boolean getCollidedPoints(double m, double q, BarState bar, BoxState box, Position p1, Position p2)
          Calculates the two points solution of box corner that collided to the bar
 double getRelative(Position point, BarState bar)
          Get the relative position of one point respect the mass center of the bar NB the point are the external of the bar
 BarState interpolation(BarState oldBar, BarState newBar, double k)
          Interpolate the position of bar using linear algorithm
 BarState moveBackBar(BarState oldBar, BarState newBar, int[] index)
          Move the bar back until to the point that there's the minimum boxes that collided
 BarState non_linear_Newton_Raphson(BarState BS, double eps, double[] old1, double[] old2, double[] oldTeta)
          Calculate the numeric solution of the non-linear equations (Fx=0, Fy=0, M=0, sensor...) using Newton-Raphson algorithm
 Position perpendicularPoint(Position box, BarState bar, double m, double q)
          Calculates the point that is perpendicular to the bar from the box center of mass
 boolean quickRejection(Position p1, Position p2, Position p3, Position p4)
          Determine if there's intersection between (p1,p2) and (p3,p4) rectangles (bounding box of original line)
 void runTask()
          Calculate the position of all object in the simulation ambient
 void sendVRML()
          Send the new vrml scene to all the connected clients
 Position shiftRadius(Position first, double xAngle)
          Calculates the position of a point in the bar that is traslated from simmetric axle becouse it is at the external of bar.
 double sign(double arg)
          Calculate an approssimate sign of a parameter using a function that is continuos and has the first and second differential continuos (so it can be used by Newton-Rapson algorithm
 double sign1(double arg)
          Calculate first differential of approssimate sign function in the passed parameter
 int signDouble(double n)
          Calculate the sign of the argument
 BarState stimatePosition(BarState actual)
          Stimate the position of the bar to make the solution found by Newton-Raphson to be calcolated fast.
 
Methods inherited from class simulator.GenericSendVRML
broadcast, init
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

robot

RobotState[] robot
Contains a list of robots state position

sensor

SensorState[] sensor
Contains a list of sensors state position

box

BoxState[] box
Contains a list of non collided box state position

boxColl

BoxState[] boxColl
Contains a list of collided with bar box state position

N

int N
Number of robots

M

int M
Number of non collided boxs

K

int K
number of collided box

delta

double delta
Use to stimate new solution angle
Constructor Detail

BarSendVRML

BarSendVRML()
Method Detail

sign

public double sign(double arg)
Calculate an approssimate sign of a parameter using a function that is continuos and has the first and second differential continuos (so it can be used by Newton-Rapson algorithm
Parameters:
arg - the argument of function

sign1

public double sign1(double arg)
Calculate first differential of approssimate sign function in the passed parameter
Parameters:
arg - the argument

perpendicularPoint

public Position perpendicularPoint(Position box,
                                   BarState bar,
                                   double m,
                                   double q)
Calculates the point that is perpendicular to the bar from the box center of mass
Parameters:
box - the mass center of the box
bar - the state of bar
m - the coefficient of the rect y=mx+q that represent the bar
q - the coefficient of the rect y=mx+q that represent the bar

getRelative

public double getRelative(Position point,
                          BarState bar)
Get the relative position of one point respect the mass center of the bar NB the point are the external of the bar
Parameters:
point - the position of the point
bar - the mass center of bar
alfa - the angle of bar respect x axle

signDouble

public int signDouble(double n)
Calculate the sign of the argument
Parameters:
n - the double argument

getCollidedPoints

public boolean getCollidedPoints(double m,
                                 double q,
                                 BarState bar,
                                 BoxState box,
                                 Position p1,
                                 Position p2)
Calculates the two points solution of box corner that collided to the bar
Parameters:
m - coefficient of rect y=mx+q
q - coefficient of rect y=mx+q
bar - the state of the bar
box - the state of the box
p1 - the first solution
p2 - the second solution

boxRotation

public boolean boxRotation(BarState oldBar,
                           BarState newBar,
                           BoxState oldBox,
                           BoxState newBox)
Calculates the rotation of the box that is done by the bar changing position. It is done by rotate the box until the distance between one point of the bar and the box mass center is the same of precedent configuration. The toward of rotation is calculated considering that the point will be at the same part of the perpendicular between box mass center and the bar.
Parameters:
oldBar - the old state of the bar
newBar - the new state of the bar
oldBox - the old box position
newBox - the state of the box that will be changed

non_linear_Newton_Raphson

public BarState non_linear_Newton_Raphson(BarState BS,
                                          double eps,
                                          double[] old1,
                                          double[] old2,
                                          double[] oldTeta)
Calculate the numeric solution of the non-linear equations (Fx=0, Fy=0, M=0, sensor...) using Newton-Raphson algorithm
Parameters:
BR - the initial stimate solution
eps - the max error we want
old1 -  
old2 -  
oldTeta -  

stimatePosition

public BarState stimatePosition(BarState actual)
Stimate the position of the bar to make the solution found by Newton-Raphson to be calcolated fast.
Parameters:
actual - actual bar state position

quickRejection

public boolean quickRejection(Position p1,
                              Position p2,
                              Position p3,
                              Position p4)
Determine if there's intersection between (p1,p2) and (p3,p4) rectangles (bounding box of original line)
Parameters:
p1 - first point of rectangle 1
p2 - second point (opposite) of rectangle 1
p3 - first point of rectangle 2
p4 - second point (opposite) of rectangle 2

crossProduct

public boolean crossProduct(Position p1,
                            Position p2,
                            Position p3,
                            Position p4)
Search for intersection of line (p1,p2) and (p3,p4) using the cross product algorithm
Parameters:
p1 - first point of first line
p2 - second point of fisrt line
p3 - first point of second line
p4 - second point of second line
Returns:
true if there's intersection

shiftRadius

public Position shiftRadius(Position first,
                            double xAngle)
Calculates the position of a point in the bar that is traslated from simmetric axle becouse it is at the external of bar.
Parameters:
first - the point to shift
xAngle - the angle of bar respect x axle
Returns:
the corect shifting point

collisionDetect

public int[] collisionDetect(BarState bar)
Detect if the bar has collided to boxes object. All the collision are detected and the return value contains the index of collided boxes. The algoritms is based on quick rejection and bounding boxs.
Parameters:
bar - actual bar state position
Returns:
the indexes of box that was collided or -1 for nothing

collidedBox

public boolean collidedBox(BoxState box,
                           BarState bar)
Determine if the passed box has collided with the bar. The used algorithm is like in collisionDetect methode
Parameters:
box - the state of the box who search for collision
bar - the state of the bar
Returns:
true if there's a collision
See Also:
collisionDetect(simulator.BarState)

findBoxVertexes

public void findBoxVertexes(BoxState box,
                            Position a1,
                            Position a2,
                            Position a3,
                            Position a4)
Calculates the 4 vertexes of the box using fisical dimension and orientation
Parameters:
box - the state of the box
a1 - first vertex
a2 - second vertex
a3 - third vertex
a4 - fourth vertex

interpolation

public BarState interpolation(BarState oldBar,
                              BarState newBar,
                              double k)
Interpolate the position of bar using linear algorithm
Parameters:
oldBar - first position of bar (k=0)
newBar - second position of bar (k=1)
k - the interpolator coefficient (0..1)
Returns:
the interpolated position

adjustRobotSensor

public void adjustRobotSensor(BarState bar)
Adjust the position of sensor to be valid with the new position of the bar. This is made by calculate the point where sensor1 and sensor2 become joined.
Parameters:
bar - the state of bar

moveBackBar

public BarState moveBackBar(BarState oldBar,
                            BarState newBar,
                            int[] index)
Move the bar back until to the point that there's the minimum boxes that collided
Parameters:
oldBar - old position of bar
newBar - new position of bar
index - the index of collided box
Returns:
the rigth position of bar

adjustBoxesPosition

public void adjustBoxesPosition(BarState old,
                                BarState bar)
Adjust position of all boxes to reflect new bar position
Parameters:
old - the old state of bar
bar - the actual state of bar

runTask

public void runTask()
Calculate the position of all object in the simulation ambient
Overrides:
runTask in class simulator.GenericSendVRML

sendVRML

public void sendVRML()
Send the new vrml scene to all the connected clients
Overrides:
sendVRML in class simulator.GenericSendVRML