}
public void run()
{
Sensor sensor;
Logger.info( "El canal de comunicaciones comienza su ejecuci�n." );
int width = ((ImageBasedGPS) Simulation.getCurrent().getGps()).getImageCollector().getImageResolution().width;
int height = ((ImageBasedGPS) Simulation.getCurrent().getGps()).getImageCollector().getImageResolution().height;
if ( width <= 0 ) width = Defines.DEFAULT_IMAGE_RESOLUTION[0];
if ( height <= 0 ) height = Defines.DEFAULT_IMAGE_RESOLUTION[1];
int samples=1;
int direccion = RobotCamColorTrack.NO_MOVE;
int antmove = RobotCamColorTrack.MOVER_ADELANTE;
while ( ! isClosed() )
{
Simulation.getCurrent().getSerialTurn().WAIT();
getCommChannelSemaphore().WAIT();
try{
try {
Thread.sleep(2*SerialCommunicationChannel.MOVE_TIME);
} catch (InterruptedException e) {
e.printStackTrace();
}
long start = System.currentTimeMillis();
///// SE CARGA UNA IMAGEN ////
frontCam.grabFrame();
///// SE OBTIENE INFO DE RIEL Y LUGARES ////
ArrayList<TrackingInformation> tiRails = frontCam.getTrackingInformation(RobotCamColorTrack.TrackType.RAIL_TRACK,samples);
ArrayList<TrackingInformation> tiColors = frontCam.getTrackingInformation(RobotCamColorTrack.TrackType.COLOR_TRACK,samples);
long end = System.currentTimeMillis();
//log.debug("CAM TIME="+((float)(end-start))/1000f);
/// SE DETERMINA EL RIEL Y EL LUGAR ////
TrackingInformation currentRail = frontCam.calculateBestRailColor(tiRails);
VectorValues currentVector = frontCam.calculateBestVector(tiColors);
int railMass = currentRail.getColorMass();
direccion = frontCam.getTurningDirection(currentRail.getMeanX(),railMass,15,antmove);
antmove=direccion;
log.debug("===========================");
log.debug(currentRail.getDescription());
log.debug(currentRail);
log.debug("===========================");
log.debug(currentVector.getDescription().toUpperCase());
log.debug(currentVector.toString());
///// Se graba la recomendacion de nuestros algoritmos acerca de qu� hay que hacer /////
sensor = (ProximitySensor)features.featuresHash.get( MOVE_HINT );
if ( sensor != null )
{
sensor.setValue( new Integer(direccion) );
}
else
{
Logger.error("Oops! No anduvo..");
}
///// Se graba lo que dicen los algoritmos acerca de si llegamos a un lugar /////
sensor = (ProximitySensor)features.featuresHash.get( IN_PLACE );
if ( sensor != null )
{
sensor.setValue( frontCam.isInPlace(currentVector) );
}
else
{
Logger.error("Oops! No anduvo..");
}
///// Se analiza el SENSOR FRONTAL /////
sensor = (ProximitySensor)features.featuresHash.get( FRONT_SENSOR_NAME );
if ( sensor != null )
{
if ( direccion != RobotCamColorTrack.MOVER_ADELANTE )
sensor.setValue( new Boolean(true) );
else
sensor.setValue( new Boolean(false) );
}
else
{
// TODO: ver c�mo manejar la situaci�n en que no se
// encuentra el feature en el hash.
Logger.error("No se pudo acceder al sensor.");
}
////// Se analiza el SENSOR DE COLOR /////
sensor = (ColorSensor)features.featuresHash.get( COLOR_SENSOR_NAME );
sensor.setValue( currentVector );
}catch(Exception e){
e.printStackTrace();
}
getCommChannelSemaphore().SIGNAL();