Exemplo n.º 1
0
    def steer(self, prediction):

        # FORWARD
        if np.all(prediction == [0., 0., 1.]):
            car.forward(100)
            car.pause(300)
            dir_log.append('Forward')
            print 'Forward'

        # FORWARD-LEFT
        elif np.all(prediction == [1., 0., 0.]):
            car.left(300)
            car.forward_left(200)
            car.left(700)
            car.pause(200)
            dir_log.append('Left')
            print 'Left'

        # FORWARD-RIGHT
        elif np.all(prediction == [0., 1., 0.]):
            car.right(300)
            car.forward_right(200)
            car.right(700)
            car.pause(200)
            dir_log.append('Right')
            print 'Right'
Exemplo n.º 2
0
    def ctrl_z(self):

        print '\n< < < CTRL-Z MODE ACTIVATED! > > >'

        last_dir = dir_log[-1]

        # Forward -> Reverse
        if last_dir == 'Forward':
            car.reverse(200)
            car.pause(500)
            print '< REVERSE >'

        # Left -> Reverse-Left
        elif last_dir == 'Left':
            car.left(300)
            car.reverse_left(250)
            car.left(700)
            car.pause(500)
            print '< REVERSE-LEFT >'

        # Right -> Reverse-Right
        elif last_dir == 'Right':
            car.right(300)
            car.reverse_right(250)
            car.right(700)
            car.pause(500)
            print '< REVERSE-RIGHT >'

        return
Exemplo n.º 3
0
    def make_decision(self):

        # Calculate the percent_difference to decide whether to act on 'difference'

        print 'make_decision1'

        calc_difference = np.sum(self.difference)
        max_difference = np.sum(255 * self.difference.shape)
        percent_difference = float(calc_difference) / max_difference

        print 'make_decision2'

        # If percent_difference is below ctrlz_thresh (i.e. the two images are < 5% different), then commence ctrl-z protocol.
        if percent_difference <= self.ctrlz_thresh:

            # Activate ctrl-z mode
            print '< < < CTRL-Z MODE ACTIVATED! > > >'

            # Get the last 10 directions executed from the log (or however many you specified for self.ctrlz_iter)
            recent_dirs = dir_log[-self.ctrlz_iter:]
            recent_dirs_reversed = recent_dirs.reverse()

            for each in recent_dirs_reversed:

                # Forward -> Reverse
                if each == 'Forward':
                    car.reverse(100)
                    car.pause(300)
                    print '< REVERSE >'

                # Left -> Right
                elif each == 'Left':
                    car.right(300)
                    car.reverse_right(200)
                    car.right(700)
                    car.pause(200)
                    print '< REVERSE-RIGHT >'

                # FORWARD-RIGHT
                elif each == 'Right':
                    car.left(300)
                    car.reverse_left(200)
                    car.left(700)
                    car.pause(200)
                    print '< REVERSE-LEFT >'
Exemplo n.º 4
0
    def steer(self, prediction):

        # FORWARD
        if np.all(prediction == [0., 0., 1.]):
            car.forward(100)
            car.pause(500)
            print("Forward")

        # FORWARD-LEFT
        elif np.all(prediction == [1., 0., 0.]):
            car.left(300)
            car.forward_left(200)
            car.left(700)
            car.pause(500)
            print("Left")

        # FORWARD-RIGHT
        elif np.all(prediction == [0., 1., 0.]):
            car.right(300)
            car.forward_right(200)
            car.right(700)
            car.pause(500)
            print("Right")
Exemplo n.º 5
0
import car
''' Move forward for 1000ms (1s) and pause. '''
car.forward(1000)
car.pause(1000)

car.forward(1000)
car.pause(1000)
''' Move backward for 1000ms (1s) and pause. '''
car.reverse(1000)
car.pause(1000)

car.reverse(1000)
car.pause(500)
 def stop(self):
     print ('* * * STOPPING! * * *')
     car.pause(5000)
Exemplo n.º 7
0
 def stop(self):
     print ' * * * STOPPING! * * * '
     car.pause(8000)
Exemplo n.º 8
0
 def stop(self):
     print '*** STOPPING! ***'
     car.pause(8000)
     car.forward(100)