예제 #1
0
void Game_Character::MoveLeft() {
	if (turn_enabled) TurnLeft();

	if (IsPassable(x, y, RPG::EventPage::Direction_left)) {
		TurnLeft();
		x -= 1;
		//IncreaseSteps();
		move_failed = false;
	} else {
		CheckEventTriggerTouch(x - 1, y);
		move_failed = true;
	}
}
예제 #2
0
void testMovement()
{
	int time = 0;
	int speed = 0;
	int test = 0;
	while(true)
	{
		test = random(5);
		speed = random(100);
		time = random(20);

		switch(test){
			case 1:
				MoveForward(time,speed); break;
			case 2:
				MoveBackwards(time,speed); break;
			case 3:
				TurnLeft(time,speed); break;
			case 4:
				TurnRight(time,speed); break;
			case 5:
				Stop(time); break;
			default:
				break;
		}
	}
}
예제 #3
0
void Snake::HandleInput(sf::Event & E)
{
	//Implementacja interfejsu IControl. Zmienia stan wê¿a w zale¿noœci od rodzaju zda¿enia
	//przekazanego w argumencie, albo tworzy nowy pocisk zmierzaj¹cy do miejsca klikniêcia myszk¹.
	switch (E.type)
	{
	case sf::Event::KeyPressed:
		if (E.key.code == sf::Keyboard::W)
			TurnUp();
		else
		if (E.key.code == sf::Keyboard::S)
			TurnDown();
		else
		if (E.key.code == sf::Keyboard::D)
			TurnRight();
		else
		if (E.key.code == sf::Keyboard::A)
			TurnLeft();
		break;

	case sf::Event::MouseButtonPressed:
		if (E.mouseButton.button == sf::Mouse::Left)
			Shoot(E.mouseButton.x, E.mouseButton.y);
		break;
	default:
		break;
	}
}
예제 #4
0
//**************************************************
//  NAME: TurnLeft
//  DESCRIPTION: Robot turns over the left wheel    
//  PARAMETERS:  - speed->Right motor speed
//              - angle->Rotation angle
//**************************************************
void Motor::TurnLeft(byte speed, int angle)
{
  unsigned long time,timeout;
  byte count;
  byte encoder;

	ReduceInertia();
	
  count = EncodeAngle(speed, angle);
  encoder = digitalRead(ENC_R);
  time=millis();
  TurnLeft(speed);
  while (count > 0)
  {
    while (encoder == digitalRead(ENC_R))
    {
      timeout=millis();
      if (timeout - time > MAX_TIMEOUT)
      {        
        return;
      }
    }
    encoder=digitalRead(ENC_R);
    count--;
    time=millis();
  }
  ReduceInertia();
}
예제 #5
0
void Game_Character::MoveUpLeft() {
	if (!IsDirectionFixed()) {
		if (GetDirection() % 2) {
			TurnLeft();
		} else {
			TurnUp();
		}
	}

	if (jumping) {
		jump_plus_x--;
		jump_plus_y--;
		return;
	}

	if ((IsPassable(GetX(), GetY(), RPG::EventPage::Direction_left)
		&& IsPassable(GetX() - 1, GetY(), RPG::EventPage::Direction_up))
		|| (IsPassable(GetX(), GetY(), RPG::EventPage::Direction_up)
		&& IsPassable(GetX(), GetY() - 1, RPG::EventPage::Direction_left))) {
			SetX(GetX() - 1);
			SetY(GetY() - 1);
			BeginMove();
			stop_count = 0;
			move_failed = false;
	}
}
예제 #6
0
파일: mech.c 프로젝트: kendallb/scitech-mgl
static void handleScanCode(
    int key)
{
    switch (key) {
        /* start of view position functions */
        case KB_right:
            TurnRight();
            break;
        case KB_left:
            TurnLeft();
            break;
        case KB_down:
            TurnForwards();
            break;
        case KB_up:
            TurnBackwards();
            break;
            /* end of view postions functions */
            /* start of miseclleneous functions */
        case KB_pageUp:
            FireCannon();
            break;
        case KB_home:
            Toggle();
            break;
            /* end of miscelleneous functions */
        }
}
예제 #7
0
/********************************************************************************
 Yaw. You can add in a deadzone here.
 ********************************************************************************/
void Camera3::Yaw(const double dt)
{
	if ( Application::camera_yaw > 0.0 )
		TurnRight( Application::camera_yaw * dt );
	else if ( Application::camera_yaw < 0.0 )
		TurnLeft( Application::camera_yaw * dt );
}
예제 #8
0
task autonomous()
{
	switch(AutoSelect)
	{
		//AUTO SKILLS
	case 1:
		RedSkills();
		break;
		// AUTO ROUTINES
	case 2:
		//BALL AUTO
		Balls(3500);
		break;
	case 3:
		Park();
		break;
	case 4:
		WalloB();
		break;
	case 5:
		WalloR();
		break;
	case 6:
		FrontMiddleL();
		break;
	case 7:
		FrontMiddleR();
		break;
	case 8:
		SideMiddleB();
		break;
	case 9:
		SideMiddleR();
		break;

		///// TEST CODE /////
	case 17:
		//PID TURN TEST
		TurnLeft(900);
		wait1Msec(500);
		TurnRight(900);
		break;
	case 18:
		//PID DRIVE TEST
		Drive(36);
		break;
	case 19:
		// LEFT TEST
		LeftTest();
		break;
	case 20:
		// RIGHT TEST
		RightTest();
		break;
	default:
		//NOTHING
	}
}
예제 #9
0
void TurnLeftDegrees(float degrees)
{
  SensorValue[Gyroscope] = 0;
  while(abs(SensorValue[Gyroscope]) < abs(degrees) * 10 * 0.935)
  {
    if (abs(degrees) * 10 - abs(SensorValue[Gyroscope]) < 300)
      TurnLeft(30);
    else if (abs(degrees) * 10 - abs(SensorValue[Gyroscope]) < 500)
      TurnLeft(40);
    else if (abs(degrees) * 10 - abs(SensorValue[Gyroscope]) < 700)
      TurnLeft(50);
    else
      TurnLeft(60);

    if (stopEventFunction("none"))
      break;
  }
  StopMoving();
}
예제 #10
0
void loop()
{
 if(infraredReceiverDecode.buttonState() == 1)
    {
        switch(infraredReceiverDecode.read())
        {
          case IR_BUTTON_PLUS: 
               Forward();
               break;
          case IR_BUTTON_MINUS:
               Backward();
               break;
          case IR_BUTTON_NEXT:
               TurnRight();
               break;
          case IR_BUTTON_PREVIOUS:
               TurnLeft();
               break;
          case IR_BUTTON_9:
               ChangeSpeed(factor*9+minSpeed);
               break;
          case IR_BUTTON_8:
               ChangeSpeed(factor*8+minSpeed);
               break;
          case IR_BUTTON_7:
               ChangeSpeed(factor*7+minSpeed);
               break;
          case IR_BUTTON_6:
               ChangeSpeed(factor*6+minSpeed);
               break;
          case IR_BUTTON_5:
               ChangeSpeed(factor*5+minSpeed);
               break;
          case IR_BUTTON_4:
               ChangeSpeed(factor*4+minSpeed);
               break;
         case IR_BUTTON_3:
               ChangeSpeed(factor*3+minSpeed);
               break;
         case IR_BUTTON_2:
               ChangeSpeed(factor*2+minSpeed);
               break;
         case IR_BUTTON_1:
               ChangeSpeed(factor*1+minSpeed);
               break;
           default:
       //    Stop();
           break;
        }
    }
    else
    {
      Stop();
    }
}
예제 #11
0
void DriveToPegRight (bool use_guided)
{ GoForward (5);
  TurnRight (40);
  GoForward (34);
  TurnLeft (24);
  GoForward (45);
  if (use_guided)
    GuidedDriveForward (60);
  else
    GoForward (60);
}
예제 #12
0
void Game_Character::TurnTowardPlayer() {
	int sx = DistanceXfromPlayer();
	int sy = DistanceYfromPlayer();

	if ( std::abs(sx) > std::abs(sy) ) {
		(sx > 0) ? TurnLeft() : TurnRight();
	}
	else if ( std::abs(sx) < std::abs(sy) ) {
		(sy > 0) ? TurnUp() : TurnDown();
	}
}
예제 #13
0
void TurnLeftUsingTimer()
{
	TIM_Cmd(TIM2, ENABLE);
	TurnLeft();
	while (timerCount < 30)
	{

	}
	StopVehicle();
	TIM_Cmd(TIM2, DISABLE);
	timerCount = 0;
}
예제 #14
0
void CPMotion::Meander(short Velocity, short Duration, short Iterations)
{
    //OK
    double OriginalHeading = m_Robot->GetHeading();
    MoveForward(Velocity, Duration);
    TurnLeft(Velocity);

    for (int i = 1; i < Iterations; i++)
    {
        MoveForward(Velocity, Duration);
        TurnRight(Velocity);
        MoveForward(Velocity, Duration);
        TurnRight(Velocity);
        MoveForward(Velocity, Duration);
        TurnLeft(Velocity);
        MoveForward(Velocity, Duration);
        TurnLeft(Velocity);
    }

    m_Robot->SetHeadingDestination(OriginalHeading, Velocity, 2);
}
예제 #15
0
파일: main.c 프로젝트: DerekTitus/Lab6
/*
 * main.c
 */
int main(void) {

	WDTCTL = WDTPW|WDTHOLD;                 // stop the watchdog timer

	initMotors();
	
	while(1)
	{
		TurnLeft();
		ShortDelay();
		StopBot();
		Delay();
		TurnRight();
		ShortDelay();
		StopBot();
		Delay();
		MoveForward();
		Delay();
		StopBot();
		Delay();
		MoveBack();
		Delay();
		StopBot();
		Delay();
		TurnRight();
		Delay();
		StopBot();
		Delay();
		TurnLeft();
		Delay();
		StopBot();
		Delay();
		Delay();
		Delay();

	}

}
예제 #16
0
task main()
{
  initialize ();  // In the original template this was "initializeRobot();"

  waitForStart (); // Wait for the beginning of autonomous phase.

  clasp_goal(true);

  distanceToDrive = 72.0; //6 feet
  drive_both_wheels (-motorSpeed, -motorSpeed, distanceToDrive * kInch); //drives out of parking zone to kickstand

  int i = 0;
  for(i = 0; i <= 1; i++){
  	distanceToDrive = 6.0; //6 in
  	drive_both_wheels (motorSpeed, motorSpeed, distanceToDrive * kInch);

  	distanceToDrive = 10.0 //10 in
  	drive_both_wheels (-motorSpeed, -motorSpeed, distanceToDrive * kInch);
  }

  distanceToDrive = 12.0; //12 in
  drive_both_wheels(motorSpeed, motorSpeed, distanceToDrive * kInch); //backs up to angle for final try

  degreesToTurn = 90.0; //90 degrees
  TurnLeft(degreesToTurn * kDegrees); //turns 90 degrees

  distanceToDrive = 10.0; //10 in
  drive_both_wheels(motorSpeed, motorSpeed, distanceToDrive * kInch); //drives 4 in

  degreesToTurn = 90.0; //90 degrees
  TurnRight(degreesToTurn * kDegrees); //turns 90 degrees

  distanceToDrive = 30.0; //2.5 feet
  drive_both_wheels(-motorSpeed, -motorSpeed, distanceToDrive * kInch); //comes in for final try to knock down the kickstand

  for(i = 0; i <= 1; i++){
  	distanceToDrive = 6.0; //6 in
  	drive_both_wheels (motorSpeed, motorSpeed, distanceToDrive * kInch);

  	distanceToDrive = 10.0; //10 in
  	drive_both_wheels (-motorSpeed, -motorSpeed, distanceToDrive * kInch);
  }
  //the program basically flails around to knock down the kickstand




  transition(); //waits for autonomous phase to end

} // main
예제 #17
0
void TurnToIR()
{
		while(!facingIR())
		{
			if(IROnLeft())
			{
					TurnRight(0.05,autospeed);
			}
			else
			{
					TurnLeft(0.05,autospeed);
			}
		}
}
예제 #18
0
void DriveToPegRight ()
{ GoForward (5);
	TurnRight (50);
	GoForward (34);
	TurnLeft (24);
	if (USE_GUIDED_FWD)
	{ GoForward (45);
		GuidedDriveForward (60);
	}
	else
		GoForward (105);
	DropHand ();
	GoBackwards (10.0);
}
예제 #19
0
private func Activity() {
  var pBait;
  // Ein Köder in der Nähe?
  if (pBait=FindObject(0,-1000,-1250,2000,1500, OCF_InLiquid(), "Bait" ) )
    // Schwarze Fische sind nicht wählerisch
    SetCommand(this(),"Follow",pBait);

  // Schwimmverhalten
  if (!GBackLiquid (0, -8)) return (SetComDir (COMD_Down ()));
  if (Random(2)) return(1);
  if (SEqual(GetAction(),"Walk")) WalkDir();
  if (Not( SEqual(GetAction(),"Swim") )) return(1);
  if (Random(2)) return(TurnRight(),SetComDir(COMD_Right()));
  return(TurnLeft(),SetComDir(COMD_Left()));
}
예제 #20
0
void Game_Character::Turn180Degree() {
	switch (direction) {
	case RPG::EventPage::Direction_down:
		TurnUp();
		break;
	case RPG::EventPage::Direction_left:
		TurnRight();
		break;
	case RPG::EventPage::Direction_right:
		TurnLeft();
		break;
	case RPG::EventPage::Direction_up:
		TurnDown();
		break;
	}
}
예제 #21
0
void CPMotion::RandMotion()
{
    int limit = m_cyepersona->GetRandomNumber(3);

    for (int i = 1; i <= limit; i++)
    {
        TurnLeft(200);
    }

    limit = m_cyepersona->GetRandomNumber(3);

    for (int i = 1; i <= limit; i++)
    {
        TurnRight(200);
    }
}
예제 #22
0
void Game_Character::FaceRandomDirection() {
	switch (rand() % 4) {
	case 0:
		TurnDown();
		break;
	case 1:
		TurnLeft();
		break;
	case 2:
		TurnRight();
		break;
	case 3:
		TurnUp();
		break;
	}
}
예제 #23
0
void main(void)
{
	// Stop watchdog timer to prevent time out reset
	WDTCTL=WDTPW+WDTHOLD;
	//Init_Clk();
	//P1DIR |= BIT0 + BIT6;
	//P1OUT |= (BIT0 + BIT6);
	CarInit();
	while(1)
	{
		TurnLeft(1, 1);
		delayms(1000);
		TurnRight(1, 1);
		delayms(1000);
	}
	//LPM0;
}
예제 #24
0
void UserShip3::Update(float RelativeTime)
{
	m_RelativeTime = RelativeTime;

	if ((IsKeyDown('I')) && (IsKeyDown('K')))
		Brake();
	else if (IsKeyDown('I'))
		MoveForward();
	else if (IsKeyDown('K'))
		MoveBackward();

	if ((IsKeyDown('J')) && !(IsKeyDown('L')))
		TurnLeft();
	if ((IsKeyDown('L')) && !(IsKeyDown('J')))
		TurnRight();

	SpaceShip::Update(RelativeTime);
}
예제 #25
0
void UserShip4::Update(float RelativeTime)
{
	m_RelativeTime = RelativeTime;

	if ((IsKeyDown(VK_NUMPAD8)) && (IsKeyDown(VK_NUMPAD5)))
		Brake();
	else if (IsKeyDown(VK_NUMPAD8))
		MoveForward();
	else if (IsKeyDown(VK_NUMPAD5))
		MoveBackward();

	if ((IsKeyDown(VK_NUMPAD4)) && !(IsKeyDown(VK_NUMPAD6)))
		TurnLeft();
	if ((IsKeyDown(VK_NUMPAD6)) && !(IsKeyDown(VK_NUMPAD4)))
		TurnRight();

	SpaceShip::Update(RelativeTime);
}
예제 #26
0
void Game_Character::MoveLeft() {
	if (!IsDirectionFixed()) TurnLeft();

	if (jumping) {
		jump_plus_x--;
		return;
	}

	if (IsPassable(GetX(), GetY(), RPG::EventPage::Direction_left)) {
		SetX(GetX() - 1);
		BeginMove();
		stop_count = 0;
		move_failed = false;
	} else {
		CheckEventTriggerTouch(GetX() - 1, GetY());
		move_failed = true;
	}
}
예제 #27
0
void UserShip1::Update(float RelativeTime)
{
	m_RelativeTime = RelativeTime;

	if ((IsKeyDown(VK_UP)) && (IsKeyDown(VK_DOWN)))
		Brake();
	else if (IsKeyDown(VK_UP))
		MoveForward();
	else if (IsKeyDown(VK_DOWN))
		MoveBackward();

	if ((IsKeyDown(VK_LEFT)) && !(IsKeyDown(VK_RIGHT)))
		TurnLeft();
	if ((IsKeyDown(VK_RIGHT)) && !(IsKeyDown(VK_LEFT)))
		TurnRight();

	SpaceShip::Update(RelativeTime);
}
예제 #28
0
/*******************************************DECIDE MOVEMENT STATE*******************************************/
void MovementLogic() {
    stateTimer = stateTimer + 1;				// Keep track of how long state has been constant. Roughly: Time = stateTimer * 60ms
    /**********Trigger Change in state***************/
    if (distance_cm <= SENSDISTANCE && forward == 1) {							// Turn to avoid obstacle
        if (turnDirection) {
            changeState = 2;													// Right
        } else {
            changeState = 3;													// Left
        }
        turnDirection = !turnDirection;											// Alternate left and right
    }
    if (stateTimer > WAITTIME && (turnRight == 1 || turnLeft == 1)) {			// Robot is stuck
        changeState = 4;														// Backward
    }
    if (distance_cm > SENSDISTANCE && !backward) {
        changeState = 1;														// Forward
    }
    if (backward == 1 && stateTimer > WAITTIME) {
        changeState = 1;														// Forward
    }
    /*********Change state triggered*************/
    if (changeState > 0) {											// Ensures movement state of robot is only updated once when required.
        switch(changeState) {
        case 1:
            Forward();
            break;
        case 2:
            TurnRight();
            break;
        case 3:
            TurnLeft();
            break;
        case 4:
            Backward();
            break;
        default:
            Stop();
        }
        changeState = 0;
        stateTimer = 0;
    }
}
예제 #29
0
void FollowLine() //Needs better logic just this for tests
{
		if(isOnLine())
		{
			MoveForward(0.05,autospeed);
		}
		else
		{
			while(!isOnLine())
			{
					TurnToIR();
					if(facingIR() && !isOnLine())
					{
						TurnLeft(0.05,autospeed);
					}
					MoveForward(0.05,autospeed);
					LineDown();
			}
		}
}
예제 #30
0
파일: phone.cpp 프로젝트: love1cat/PhoneSim
	void Phone::IntersectAction(double distance_to_intersection, double total_distance) {
		
		// Compute turning direction using given probability.
		int turn_decision = dist(RandomGenerator::get_gen());
		if (turn_decision == 2) {
			// Move straight.
			log << "Turn decision: go straight.\n";
			MoveForward(total_distance);
		}else {
			log << "Turn decision: turn left or right. move to intersection first.\n";
			MoveForward(distance_to_intersection);
			if (turn_decision == 0) {
				log << "Turn left.\n";
				TurnLeft();
			} else {
				log << "Turn right.\n";
				TurnRight();
			}
			MoveForward(total_distance - distance_to_intersection);
		}
	}