Beispiel #1
0
void ExecuteTurn(char data)
{
    PLIB_PORTS_Write(PORTS_ID_0, PORT_CHANNEL_B, data);
    switch(data)
    {
        case 'r':
            TurnRight();
            break;
        case 'l':
            TurnLeft();
            break;
        case 'f':
            MoveDistance(16, 600);
            break;
        case 't':
            TurnAround();
            MoveDistance(16, 600);
            break;
        case 'S':
            moveRobot(0, 0);
            while(true);
    }
}
Beispiel #2
0
void CPMotion::OnTurnAround()
{
    short Velocity = 100;
    TurnAround(Velocity);
}
Beispiel #3
0
	void Mouse::Explore()
	{
		std::unique_ptr<Path_new> * path_chosen;

		// Turn to face a direction where there's actually an opening
		// Start off going forward once, set previous to start
		MoveForward();

		maze->printClean();
		maze->printMaze(true);
		maze->printClean();
		
		while (true)
		{
			// Delay *******************************************************
			std::this_thread::sleep_until(
				std::chrono::system_clock::now() + std::chrono::seconds(1));
			// *************************************************************

			// Get sensor data
			this->sensor->sense(maze.get());

			// Check to see if there's more than one new path in the current physical room
			switch (CheckForOptions())
			{
			// dead end
			case 0:	
				TurnAround();
				// Reverse backtracking variable
				backtracking ? backtracking = false : backtracking = true;
				MoveForward();
				break;

			// only one option
			case 1:	
				// Get the next cell to turn to as there's only one option 
				Turn(currentRoom->get_children(previousRoom)->front());
				MoveForward();
				break;

			// 2 or 3 options in direction
			case 2:	
			case 3:
				if (!backtracking)
				{
					// Guess all the possible paths from the current "cross-roads"
					path_chosen = Evaluate();

					// Get the next room from the new completePathGuess, aka path_chosen
					delete(completePathGuess);
					completePathGuess = path_chosen->get();
					Room * nextr = completePathGuess->Rooms()->at(actualPath->Rooms()->size());

					// Start down the new path
					Turn(nextr);
					MoveForward();
				}
				else
				{
					// backtracking

					// Choose the room with the least visits, avoiding going back down the previous path
					Room * nextr = Filter::LeastVisited(currentRoom->get_children(previousRoom));
					
					if (!actualPath->Contains(nextr->Location().x, nextr->Location().y))
					{
						// change back to regular advancements
						backtracking = false;
					}
					
					// Start down path
					Turn(nextr);
					MoveForward();
				}
				break;
			}

			maze->printClean();
			maze->printMaze(true);
			maze->printClean();
		}

	}