def sendDirections(self, receivedString):
        splittedList = receivedString.split('-')
        startPosition = Position(splittedList[1], splittedList[2])
        endPosition = Position(splittedList[3], splittedList[4])

        robotMap = Map(5)
        robotMap.addObstacle(self.obstacleOnePosition)
        robotMap.addObstacle(self.obstacleTwoPosition)

        if self.cornerAPlaced == "A":
            robotMap.addPuck("A")
        elif self.cornerBPlaced == "B":
            robotMap.addPuck("B")
        elif self.cornerCPlaced == "C":
            robotMap.addPuck("C")
        elif self.cornerDPlaced == "D":
            robotMap.addPuck("D")

        planner = TrajectoryPlanner(robotMap, False)
        returnedDirections, path = planner.getDirections(
            startPosition, endPosition)
        self.currentPath = path
        self.gui.currentPathList = path
        self.numberOfPath = self.numberOfPath + 1
        self.robotQueue.put("UP")

        if returnedDirections == "STARTNOTFREE":
            self.baseStation.sendDataToRobot("DIRECTIONS-STARTNOTFREE")
        elif returnedDirections == "NOTHINGTODO":
            self.baseStation.sendDataToRobot("DIRECTIONS-NOTHING")
        else:
            stringToSend = "DIRECTIONS-" + str(returnedDirections)
            self.baseStation.sendDataToRobot(stringToSend)
Beispiel #2
0
class PositionTest(unittest.TestCase):
    def setUp(self):
        self.aPosition = Position(A_POSITION_X, A_POSITION_Y)

    def test_getPositionXShouldReturnGoodX(self):
        self.assertTrue(self.aPosition.getX() == A_POSITION_X)

    def test_getPositionXShouldReturnGoodY(self):
        self.assertTrue(self.aPosition.getX() == A_POSITION_Y)
Beispiel #3
0
 def processDataInQueue(self):
     while self.robotQueue.qsize():
         try:
             msg = self.robotQueue.get(0)
             print "The robot has received the following in his robotQueue : " + str(
                 msg)
             if msg == "START":
                 self.game.start()
             elif msg == "STOP":
                 self.game.stop()
             elif msg == "RESET":
                 self.game.reset()
             elif msg == "TURNALITTLE":
                 self.game.robot.rotateCounterClockwise(30)
             elif "OBSTACLESPOSITION" in msg:
                 splittedList = msg.split('-')
                 p1 = Position(splittedList[1], splittedList[2])
                 p2 = Position(splittedList[3], splittedList[4])
                 self.game.robot.obstacleOnePosition = p1
                 self.game.robot.obstacleTwoPosition = p2
                 self.game.robot.obstaclesPositionFetched = True
             elif msg[:17] == "REFRESHEDPOSITION":
                 splittedList = msg.split('-', 3)
                 if splittedList[1] == "None" or splittedList[
                         2] == "None" or splittedList[3] == "None":
                     pass
                 else:
                     refreshedPosition = Position(splittedList[1],
                                                  splittedList[2])
                     refreshedAngle = float(splittedList[3])
                     self.game.robot.setPosition(refreshedPosition)
                     self.game.robot.setAngle(refreshedAngle)
                 self.game.robot.numberOfUpdates = self.game.robot.numberOfUpdates + 1
             elif msg[:14] == "REFRESHEDANGLE":
                 splittedList = msg.split('-', 1)
                 if splittedList[1] == "None":
                     pass
                 else:
                     refreshedAngle = float(splittedList[1])
                     self.game.robot.setAngle(refreshedAngle)
                 self.game.robot.numberOfUpdates = self.game.robot.numberOfUpdates + 1
             elif msg[:10] == "DIRECTIONS":
                 splittedDirectionList = msg.split('-')
                 splittedDirectionList.remove("DIRECTIONS")
                 if "" in splittedDirectionList:
                     splittedDirectionList.remove("")
                 self.game.robot.listOfDirections = splittedDirectionList
                 self.game.robot.numberOfUpdates = self.game.robot.numberOfUpdates + 1
             else:
                 if msg != "":
                     self.robotSocket.sendDataToBaseStation(msg)
         except Queue.Empty:
             pass
Beispiel #4
0
    def __init__(self, queue):
        self.robotQueue = queue

        self.position = Position(0, 0)
        self.angle = 0
        
        self.numberOfUpdates = 0

        self.map = Map(5)
        self.trajectoryPlanner = TrajectoryPlanner(self.map, False)
        self.obstaclesPositionFetched = False
        self.obstacleOnePosition = Position(0, 0)
        self.obstacleTwoPosition = Position(0, 0)
        self.listOfDirections = ""
        
        self.initHardwareDevices()
    def runKinectThread(self):
        mapUtil = Map(5)
        self.ObstaclesPutOnMap = False

        while True:
            self.hasTurned = False
            if self.kinect.isBusy(
            ) == False and self.kinect.awaitingToWork == False:
                self.kinect.setToBusy()
                pX, pY = self.kinect.getPosition()
                if pX == None or pY == None:
                    pass
                else:
                    robotI, robotJ = mapUtil.translatePositionXYToPositionIJ(
                        Position(pX, pY))
                    string = "R-" + str(robotI) + "-" + str(robotJ)
                    self.robotQueue.put(string)
                self.kinect.setToNotBusy()
            if self.obstaclesFound == True and self.ObstaclesPutOnMap == False:
                obstacleI_1, obstacleJ_1 = mapUtil.translatePositionXYToPositionIJ(
                    self.obstacleOnePosition)
                obstacleI_2, obstacleJ_2 = mapUtil.translatePositionXYToPositionIJ(
                    self.obstacleTwoPosition)
                string = "O-" + str(obstacleI_1) + "-" + str(
                    obstacleJ_1) + "-" + str(obstacleI_2) + "-" + str(
                        obstacleJ_2)
                self.robotQueue.put(string)
                self.ObstaclesPutOnMap = True
                time.sleep(1)
            time.sleep(5)
    def __init__(self, master):
        self.robotQueue = Queue.Queue()
        self.kinect = Kinect()

        # Set up the GUI part
        self.gui = Gui(master, self.robotQueue)
        self.master = master
        self.obstaclesFound = False
        self.currentPath = []
        self.numberOfPath = 0

        # Start the connection
        self.baseStation = BaseStationSocket()
        self.baseStation.startConnection(EnterIPWindow().serverAddress)

        # Set up the thread for the connection with the robot
        self.connectionThread = threading.Thread(
            target=self.runConnectionThread)
        self.connectionThread.daemon = True
        self.connectionThread.start()

        # Set up the thread for the kinect to calculate the robot position in real time
        self.kinectThread = threading.Thread(target=self.runKinectThread)
        self.kinectThread.daemon = True
        self.kinectThread.start()

        self.gameInProcess = False
        self.guiRunning = True
        self.obstacleOnePosition = Position(0, 0)
        self.obstacleTwoPosition = Position(0, 0)

        self.cornerAPlaced = False
        self.cornerBPlaced = False
        self.cornerCPlaced = False
        self.cornerDPlaced = False

        self.gui.ourBaseStationInterface.mainWindow.gameBoard.addPiece(
            "robot", self.gui.ourBaseStationInterface.mainWindow.robotIcon,
            -11, -11)

        # Start the periodic call in the GUI to check if the robotQueue contains
        # anything
        self.periodicCallToCheckGui()
    def sendObtaclesPositions(self):
        self.kinect.setToBusy()
        listPositions = self.kinect.getTower()

        numberOfTrys = 0
        while listPositions == None and numberOfTrys < 10:
            numberOfTrys = numberOfTrys + 1
            listPositions = self.kinect.getTower()
        if listPositions == None:
            time.sleep(20)
        else:
            message = "OBSTACLESPOSITION-" + str(listPositions[0]) + "-" + str(
                listPositions[1]) + "-" + str(listPositions[2]) + "-" + str(
                    listPositions[3])
            p1 = Position(listPositions[0], listPositions[1])
            p2 = Position(listPositions[2], listPositions[3])
            self.obstacleOnePosition = p1
            self.obstacleTwoPosition = p2
            self.baseStation.sendDataToRobot(message)
            self.obstaclesFound = True
        self.kinect.setToNotBusy()
Beispiel #8
0
 def addPuck(self, corner):          
     positionXCorner = 0
     positionYCorner = 0
     if corner == "A":
         positionXCorner, positionYCorner = 87, 87
     elif corner == "B":
         positionXCorner, positionYCorner = 87, 24
     elif corner == "C":
         positionXCorner, positionYCorner = 24, 24
     elif corner == "D":
         positionXCorner, positionYCorner = 24, 87
         
     puckCornerPosition = Position(positionXCorner, positionYCorner)
     
     puckCorner_I, puckCorner_J = self.translatePositionXYToPositionIJ(puckCornerPosition)
     
     self.expandPuck(puckCorner_I, puckCorner_J)
Beispiel #9
0
 def test_ifWallExpandPositionNotNearWallShouldBeFree(self):
     self.aMap.expandWalls()
     self.assertTrue(self.aMap.isPositionXYFree(Position(20, 20)))
Beispiel #10
0
 def test_ifWallExpandPositionNearWallShouldNotBeFree(self):
     self.aMap.expandWalls()
     self.assertFalse(self.aMap.isPositionXYFree(Position(0, 0)))
Beispiel #11
0
 def test_ifPuckAtAPositionCellShouldNotBeFree(self):
     self.aMap.addPuck(Position(15, 15))
     self.assertFalse(self.aMap.isPositionXYFree(Position(15, 15)))
Beispiel #12
0
 def test_ifObstacleAtAPositionCellShouldNotBeFree(self):
     self.aMap.addObstacle(Position(3, 3))
     self.assertFalse(self.aMap.isPositionXYFree(Position(3, 3)))
#!/usr/bin/env python
# -*- coding: utf-8 -*- 

from main.states.GameState import GameState
from main.states.NearResistanceState import NearResistanceState
from main.model.Position import Position
POSITION_TO_GO_FOR_RESISTANCE_TRAY_ = Position(30,30)

class NoResistanceValueState(GameState):

    def doAction(self):
        print self.nameMyself()  
        self.goNextToResistanceTray()
    
    def goNextToResistanceTray(self):      
        self.game.robot.refreshPositionAndAngle()
        self.game.robot.rotateToAngle(0)
        self.game.robot.rotateToAngle(0)
        xDifference = self.game.robot.position.getX() - 23
        yDifference = self.game.robot.position.getY() - 8
        self.game.robot.moveBackward(xDifference)
        self.game.robot.moveRight(yDifference)
        self.game.currentState = NearResistanceState(self.game)        
        
    def nameMyself(self):
        return "NoResistanceValueState"
    

Beispiel #14
0
 def setUp(self):
     self.aPosition = Position(A_POSITION_X, A_POSITION_Y)
Beispiel #15
0
#For connection
PORT_NUMBER = 9998

#Positions and angles used in states
ANGLE_FOR_CARDINAL = {
    'S': 0,
    'SE': 45,
    'E': 90,
    'NE': 135,
    'N': 180,
    'NO': 225,
    'O': 270,
    'SO': 315
}
STARTING_ANGLE_FACING_PUCKS = 85
POSITION_TO_GO_MID_PUCKS = Position(173, 55.75)
POSITION_FACING_LETTER_BOARD = Position(173, 64)
POSITION_TO_GO_MID_SQUARE = Position(55, 55)
POSITION_TO_GO_FOR_RESISTANCE_TRAY = Position(30, 30)

#For GUI

COLOR_OF_PUCKS = [
    "BLACK", "BROWN", "RED", "ORANGE", "YELLOW", "GREEN", "BLUE", "PURPLE",
    "GREY", "WHITE"
]

ORIENTATION_POSITION_FOR_GUI = {
    1: "742-270",
    2: "814-260",
    3: "875-260",