Changed the rotation functions.
This commit is contained in:
@@ -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;
|
||||||
|
|||||||
@@ -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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user