Search in sources :

Example 6 with MoveAction

use of spacesettlers.actions.MoveAction in project spacesettlers by amymcgovern.

the class TestMoveAction method testpdControlOrientToGoal.

/**
 * Test orienting in both directions
 *
 * (40, 40)
 * 			(50,50)
 * (40, 60)
 *
 * @throws SpaceSettlersActionException
 */
@Test
public void testpdControlOrientToGoal() throws SpaceSettlersActionException {
    // first to -3pi/4
    Position currentLoc = new Position(50, 50);
    Position goalLoc = new Position(40, 40);
    moveAction = new MoveAction();
    double accel = moveAction.pdControlOrientToGoal(space, goalLoc, currentLoc, 0);
    Movement movement = new Movement();
    while (Math.abs(accel) > MoveAction.TARGET_REACHED_ACCEL) {
        movement.setAngularAccleration(accel);
        currentLoc = space.applyMovement(currentLoc, movement, timestep);
        accel = moveAction.pdControlOrientToGoal(space, goalLoc, currentLoc, 0);
    }
    assertEquals(currentLoc.getOrientation(), -(3 * Math.PI) / 4, 0.01);
    // then to 3pi/4
    currentLoc = new Position(50, 50);
    currentLoc.setOrientation(0);
    goalLoc = new Position(40, 60);
    accel = moveAction.pdControlOrientToGoal(space, goalLoc, currentLoc, 0);
    movement = new Movement();
    while (Math.abs(accel) > MoveAction.TARGET_REACHED_ACCEL) {
        movement.setAngularAccleration(accel);
        currentLoc = space.applyMovement(currentLoc, movement, timestep);
        accel = moveAction.pdControlOrientToGoal(space, goalLoc, currentLoc, 0);
    }
    assertEquals(currentLoc.getOrientation(), (3 * Math.PI) / 4, 0.01);
}
Also used : MoveAction(spacesettlers.actions.MoveAction) Movement(spacesettlers.utilities.Movement) Position(spacesettlers.utilities.Position) Test(org.junit.Test)

Aggregations

MoveAction (spacesettlers.actions.MoveAction)6 Position (spacesettlers.utilities.Position)6 Test (org.junit.Test)4 Movement (spacesettlers.utilities.Movement)4 Vector2D (spacesettlers.utilities.Vector2D)4 HashMap (java.util.HashMap)2 UUID (java.util.UUID)2 AbstractAction (spacesettlers.actions.AbstractAction)2 DoNothingAction (spacesettlers.actions.DoNothingAction)2 AbstractObject (spacesettlers.objects.AbstractObject)2 Ship (spacesettlers.objects.Ship)2 RawAction (spacesettlers.actions.RawAction)1 CircleGraphics (spacesettlers.graphics.CircleGraphics)1 LineGraphics (spacesettlers.graphics.LineGraphics)1 SpacewarGraphics (spacesettlers.graphics.SpacewarGraphics)1 StarGraphics (spacesettlers.graphics.StarGraphics)1