Changed the rotation functions.

This commit is contained in:
Miguel Angel Astor Romero
2016-06-23 13:00:59 -04:00
parent 29854f5565
commit 5289603a82
2 changed files with 26 additions and 35 deletions

View File

@@ -117,7 +117,7 @@ public class SearchBallBehavior extends BaseBehavior {
if(queue.hasNextTouchSensorEvent()) { if(queue.hasNextTouchSensorEvent()) {
/* If an obstacle is found while searching then start searching /* If an obstacle is found while searching then start searching
* to the opposite side. */ * to the opposite side. */
pilot.travel(-100); pilot.travel(-200);
turnLeft = false; turnLeft = false;
@@ -138,7 +138,7 @@ public class SearchBallBehavior extends BaseBehavior {
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 give up and go back
* to the start line. */ * to the start line. */
pilot.travel(-100); pilot.travel(-200);
state.setState(States.WANDER); state.setState(States.WANDER);
ballFound = true; ballFound = true;

View File

@@ -28,21 +28,18 @@ public abstract class Rotations {
* @param pilot The {@link ArcRotateMoveController} implementation that controls the robot. * @param pilot The {@link ArcRotateMoveController} implementation that controls the robot.
*/ */
public static void rotate90(CompassHTSensor compass, ArcRotateMoveController pilot) { public static void rotate90(CompassHTSensor compass, ArcRotateMoveController pilot) {
float cMeasure; float cMeasure = 0.0f, diff;
/* First reset the compass. */ pilot.stop();
compass.resetCartesianZero(); compass.resetCartesianZero();
/* Start rotating slowly. */
pilot.setRotateSpeed(25); pilot.setRotateSpeed(25);
pilot.rotate(Integer.MIN_VALUE - 1, true); diff = 90.0f - cMeasure;
do {
/* Keep rotating until the robot has turned 90 degrees. */ pilot.rotate(diff);
cMeasure = 360.0f;
try { Thread.sleep(200); } catch (InterruptedException e) { }
while(cMeasure > 270.0f) {
cMeasure = compass.getDegreesCartesian(); cMeasure = compass.getDegreesCartesian();
} diff = 90.0f - cMeasure;
} while(Math.abs(diff) > 1.0f);
pilot.stop(); pilot.stop();
} }
@@ -53,21 +50,18 @@ public abstract class Rotations {
* @param pilot The {@link ArcRotateMoveController} implementation that controls the robot. * @param pilot The {@link ArcRotateMoveController} implementation that controls the robot.
*/ */
public static void rotateM90(CompassHTSensor compass, ArcRotateMoveController pilot) { public static void rotateM90(CompassHTSensor compass, ArcRotateMoveController pilot) {
float cMeasure; float cMeasure = 0.0f, diff;
/* First reset the compass. */ pilot.stop();
compass.resetCartesianZero(); compass.resetCartesianZero();
/* Start rotating slowly. */
pilot.setRotateSpeed(25); pilot.setRotateSpeed(25);
pilot.rotate(-3000, true); diff = -90;
do {
/* Keep rotating until the robot has turned 90 degrees. */ pilot.rotate(diff);
cMeasure = 0.0f;
try { Thread.sleep(200); } catch (InterruptedException e) { }
while(cMeasure < 90.0f) {
cMeasure = compass.getDegreesCartesian(); cMeasure = compass.getDegreesCartesian();
} diff = -90 + cMeasure;
} while(Math.abs(diff) > 1.0f);
pilot.stop(); pilot.stop();
} }
@@ -78,21 +72,18 @@ public abstract class Rotations {
* @param pilot The {@link ArcRotateMoveController} implementation that controls the robot. * @param pilot The {@link ArcRotateMoveController} implementation that controls the robot.
*/ */
public static void rotate180(CompassHTSensor compass, ArcRotateMoveController pilot) { public static void rotate180(CompassHTSensor compass, ArcRotateMoveController pilot) {
float cMeasure; float cMeasure = 0.0f, diff = 0.0f;
/* First reset the compass. */ pilot.stop();
compass.resetCartesianZero(); compass.resetCartesianZero();
/* Start rotating slowly. */
pilot.setRotateSpeed(25); pilot.setRotateSpeed(25);
pilot.rotate(Integer.MIN_VALUE - 1, true); diff = 180.0f - cMeasure;
do {
/* Keep rotating until the robot has turned 90 degrees. */ pilot.rotate(diff);
cMeasure = 360.0f;
try { Thread.sleep(200); } catch (InterruptedException e) { }
while(cMeasure > 180.0f) {
cMeasure = compass.getDegreesCartesian(); cMeasure = compass.getDegreesCartesian();
} diff = 180.0f - cMeasure;
} while(Math.abs(diff) > 1.0f);
pilot.stop(); pilot.stop();
} }
} }