Fixed some things with search ball.
This commit is contained in:
@@ -40,6 +40,7 @@ public class SearchBallBehavior extends BaseBehavior {
|
|||||||
private FeatureDetectorsHandler detectorHandler;
|
private FeatureDetectorsHandler detectorHandler;
|
||||||
private RobotStateSingleton state;
|
private RobotStateSingleton state;
|
||||||
private boolean turnLeft;
|
private boolean turnLeft;
|
||||||
|
private boolean supress;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new {@link SearchBallBehavior}.
|
* Creates a new {@link SearchBallBehavior}.
|
||||||
@@ -58,6 +59,7 @@ public class SearchBallBehavior extends BaseBehavior {
|
|||||||
this.detectorHandler = FeatureDetectorsHandler.getInstance();
|
this.detectorHandler = FeatureDetectorsHandler.getInstance();
|
||||||
this.state = RobotStateSingleton.getInstance();
|
this.state = RobotStateSingleton.getInstance();
|
||||||
this.turnLeft = true;
|
this.turnLeft = true;
|
||||||
|
this.supress = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -69,6 +71,7 @@ public class SearchBallBehavior extends BaseBehavior {
|
|||||||
/* If the current state is SEARCH_BALL then set the detectors and take control. */
|
/* If the current state is SEARCH_BALL then set the detectors and take control. */
|
||||||
if(state.getState() == States.SEARCH_BALL) {
|
if(state.getState() == States.SEARCH_BALL) {
|
||||||
setDetectors();
|
setDetectors();
|
||||||
|
this.supress = false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -82,6 +85,8 @@ public class SearchBallBehavior extends BaseBehavior {
|
|||||||
while(queue.hasNextLightSensorEvent())
|
while(queue.hasNextLightSensorEvent())
|
||||||
queue.getNextLightSensorEvent();
|
queue.getNextLightSensorEvent();
|
||||||
|
|
||||||
|
this.supress = false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -91,64 +96,66 @@ public class SearchBallBehavior extends BaseBehavior {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void action() {
|
public void action() {
|
||||||
if(queue.hasNextRangeSensorEvent()) {
|
while(!supress) {
|
||||||
/* If the pedestal has been found then stop the robot and set the state to BALL_FOUND. */
|
if(queue.hasNextRangeSensorEvent()) {
|
||||||
if(pilot.isMoving())
|
/* If the pedestal has been found then stop the robot and set the state to BALL_FOUND. */
|
||||||
pilot.stop();
|
if(pilot.isMoving())
|
||||||
ballFound = true;
|
pilot.stop();
|
||||||
state.setState(States.BALL_FOUND);
|
ballFound = true;
|
||||||
|
state.setState(States.BALL_FOUND);
|
||||||
|
|
||||||
/* Discard unneeded range features. */
|
/* Discard unneeded range features. */
|
||||||
while(queue.hasNextRangeSensorEvent())
|
while(queue.hasNextRangeSensorEvent())
|
||||||
queue.getNextRangeSensorEvent();
|
queue.getNextRangeSensorEvent();
|
||||||
|
|
||||||
} else {
|
|
||||||
if(turnLeft) {
|
|
||||||
/* Search to the left of the robot. */
|
|
||||||
Rotations.rotateM90(compass, pilot);
|
|
||||||
pilot.travel(100);
|
|
||||||
|
|
||||||
if(queue.hasNextTouchSensorEvent()) {
|
|
||||||
/* If an obstacle is found while searching then start searching
|
|
||||||
* to the opposite side. */
|
|
||||||
pilot.travel(-100);
|
|
||||||
|
|
||||||
turnLeft = false;
|
|
||||||
|
|
||||||
/* Discard unneeded touch events. */
|
|
||||||
while(queue.hasNextTouchSensorEvent())
|
|
||||||
queue.getNextTouchSensorEvent();
|
|
||||||
|
|
||||||
detectorHandler.enableTouchDetector();
|
|
||||||
}
|
|
||||||
|
|
||||||
Rotations.rotate90(compass, pilot);
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
/* Search to the right of the robot. */
|
if(turnLeft) {
|
||||||
Rotations.rotate90(compass, pilot);
|
/* Search to the left of the robot. */
|
||||||
pilot.travel(100);
|
Rotations.rotateM90(compass, pilot);
|
||||||
|
pilot.travel(100);
|
||||||
|
|
||||||
if(queue.hasNextTouchSensorEvent()) {
|
if(queue.hasNextTouchSensorEvent()) {
|
||||||
/* If an obstacle is found while searching then give up and go back
|
/* If an obstacle is found while searching then start searching
|
||||||
* to the start line. */
|
* to the opposite side. */
|
||||||
pilot.travel(-100);
|
pilot.travel(-100);
|
||||||
|
|
||||||
state.setState(States.WANDER);
|
turnLeft = false;
|
||||||
ballFound = true;
|
|
||||||
|
|
||||||
/* Discard unneeded touch events. */
|
/* Discard unneeded touch events. */
|
||||||
while(queue.hasNextTouchSensorEvent())
|
while(queue.hasNextTouchSensorEvent())
|
||||||
queue.getNextTouchSensorEvent();
|
queue.getNextTouchSensorEvent();
|
||||||
|
|
||||||
detectorHandler.enableTouchDetector();
|
detectorHandler.enableTouchDetector();
|
||||||
|
}
|
||||||
|
|
||||||
|
Rotations.rotate90(compass, pilot);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
/* Search to the right of the robot. */
|
||||||
|
Rotations.rotate90(compass, pilot);
|
||||||
|
pilot.travel(100);
|
||||||
|
|
||||||
|
if(queue.hasNextTouchSensorEvent()) {
|
||||||
|
/* If an obstacle is found while searching then give up and go back
|
||||||
|
* to the start line. */
|
||||||
|
pilot.travel(-100);
|
||||||
|
|
||||||
|
state.setState(States.WANDER);
|
||||||
|
ballFound = true;
|
||||||
|
|
||||||
|
/* Discard unneeded touch events. */
|
||||||
|
while(queue.hasNextTouchSensorEvent())
|
||||||
|
queue.getNextTouchSensorEvent();
|
||||||
|
|
||||||
|
detectorHandler.enableTouchDetector();
|
||||||
|
}
|
||||||
|
|
||||||
|
Rotations.rotateM90(compass, pilot);
|
||||||
|
|
||||||
|
/* If the ball was found or the robot gave up then turn around towards the start line. */
|
||||||
|
if(ballFound)
|
||||||
|
Rotations.rotate180(compass, pilot);
|
||||||
}
|
}
|
||||||
|
|
||||||
Rotations.rotateM90(compass, pilot);
|
|
||||||
|
|
||||||
/* If the ball was found or the robot gave up then turn around towards the start line. */
|
|
||||||
if(ballFound)
|
|
||||||
Rotations.rotate180(compass, pilot);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -157,6 +164,7 @@ public class SearchBallBehavior extends BaseBehavior {
|
|||||||
public void suppress() {
|
public void suppress() {
|
||||||
if(pilot.isMoving())
|
if(pilot.isMoving())
|
||||||
pilot.stop();
|
pilot.stop();
|
||||||
|
this.supress = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user