Exemplo n.º 1
0
def turn(direction):
    if direction == 'Left':
        dr.left()
        print('Turning left')
    if direction == 'Right':
        dr.right()
        print('Turning right')
Exemplo n.º 2
0
def turn_motion(direction):
    if direction=="Left":
        dr.left()
    elif direction=="Right":
        dr.right()
    else:
        pass
Exemplo n.º 3
0
def checkColor(image):
    count=0
    hsv = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)
    mask = cv2.inRange(hsv, (36, 25, 25), (70, 255,255))
    res = cv2.bitwise_and(image,image, mask=mask)
    ret,thrshed = cv2.threshold(cv2.cvtColor(res,cv2.COLOR_BGR2GRAY),3,255,cv2.THRESH_BINARY)
    _,contours,hier = cv2.findContours(thrshed,cv2.RETR_LIST,cv2.CHAIN_APPROX_SIMPLE)
    for cnt in contours:
        area = cv2.contourArea(cnt)
        if area >10000:
            print('object found')
            gray=cv2.cvtColor(image,cv2.COLOR_BGR2GRAY)
            corners()
            cv2.putText(image, 'Green Object Detected', (10,80), cv2.FONT_HERSHEY_SIMPLEX, 1.0,(255, 255, 255),lineType=cv2.LINE_AA)
            cv2.rectangle(image,(5,40),(400,100),(0,255,255),2)
            count+=1
    print('count', count)
    if count==10:
        gray=cv2.cvtColor(image,cv2.COLOR_BGR2GRAY)
        a=corners(gray)
        j=0
        while j<20:
            dr.goCustom(90,90)
            j+=1
            n=0
            while n<1:
                dr.stop(2)
                if a =='Left':
                    dr.left()
                else:
                    dr.right()
                n=n+1
Exemplo n.º 4
0
def turn(direction):
    if direction == 'Left':
        stop(3)
        dr.goStraight()
        time.sleep(2)
        dr.stop(1)
        dr.left()
        #print('Turning left')
    if direction == 'Right':
        stop(3)
        dr.goStraight()
        time.sleep(2)
        dr.stop(1)
        dr.right()
Exemplo n.º 5
0
    def tick(self):
        pacmanLoc = self.coordinates
        pacman = self.game.getPacman()
        if (pacman):
            pacmanLoc = pacman.coordinates

        if (self.panicked() is True):
            self.direction = avoid(self.coordinates, pacmanLoc)
            self.panicLevel -= 1

        front = self.direction
        directions = [front, left(front), right(front)]
        choices = []
        for option in directions:
            if self.clear(self.nextMove(option)):
                choices.append(option)
        if len(choices) > 0:
            self.direction = choices[randint(0, len(choices)-1)]
        elif self.panicked() is False:
            self.direction = opposite(front)

        nextLocation = self.nextMove(self.direction)
        if ((self.panicLevel % 2) == 0) and self.clear(nextLocation):
            self.coordinates = (nextLocation)

        if (self.game.isPacman(self.coordinates)):
            if (self.panicked() is True):
                self.game.killGhost(self)
            else:
                self.game.killPacman()
        if (self.game.isGate(self.coordinates)):
            self.passedGate = True
        self.icon = Ghost.iconByState[self.panicLevel > 0]
Exemplo n.º 6
0
 def handleKey(self, event):
     if event.key == pygame.K_LEFT:
         self.decision = direction.left()
     elif event.key == pygame.K_RIGHT:
         self.decision = direction.right()
     elif event.key == pygame.K_DOWN:
         self.decision = direction.down()
     elif event.key == pygame.K_UP:
         self.decision = direction.up()
Exemplo n.º 7
0
import RoboPiLib as RPL
import setup
import direction

print('Type "stop" to stop the motors and then type "exit" to close the program')

while True:
  usrin = input(' ')
  
  if usrin == 'w':
    direction.front()
  elif usrin == 's':
    direction.back()
  elif usrin == 'a':
    direction.left()
  elif usrin == 'd':
    direction.right()
  elif usrin == 'stop':
    direction.stop
  else:
    print('please input a w,a,s,d,stop,exit')
Exemplo n.º 8
0
import RoboPiLib as RPL
import setup
import direction
apin = PIN  #right side

while True:
    analog = RPL.analogRead(apin)
    if analog >= 300 and analog <= 400:
        direction.front(10)
    elif analog > 400:
        direction.left(7)
    elif analog < 300:
        direction.right(7)