Beispiel #1
0
def move_robot():
    global x_deviation, y_max, tolerance
    
    if(abs(x_deviation)<tolerance):
        if(y_max>0.9):
            ut.red_light("ON")
            ut.stop()
            print("reached person...........")
    
        else:
            ut.red_light("OFF")
            ut.forward()
            print("moving robot ...FORWARD....!!!!!!!!!!!!!!")
    
    
    else:
        ut.red_light("OFF")
        if(x_deviation>=tolerance):
            delay1=get_delay(x_deviation)
                
            ut.left()
            time.sleep(delay1)
            ut.stop()
            print("moving robot ...Left....<<<<<<<<<<")
    
                
        if(x_deviation<=-1*tolerance):
            delay1=get_delay(x_deviation)
                
            ut.right()
            time.sleep(delay1)
            ut.stop()
            print("moving robot ...Right....>>>>>>>>")
Beispiel #2
0
def initPresets():
    """
    Loads initial presets
    """
    for i in range(64):
        util.setMask[i] = 1 << i
        bit = util.setMask[i]
        util.clearMask[i] = ~bit
        kingAttack = bit | util.right(bit) | util.left(bit)
        kingAttack |= util.up(kingAttack) | util.down(kingAttack)
        kingAttacks[i] = kingAttack & util.clearMask[i]

        l1 = util.left(bit)
        l2 = util.left(bit, 2)
        r1 = util.right(bit)
        r2 = util.right(bit, 2)

        h1 = l2 | r2
        h2 = l1 | r1

        knightAttacks[i] = util.up(h1) | util.down(h1) | util.up(
            h2, 2) | util.down(h2, 2)

        # pawn attacks
        wRightAttack = util.upRight(bit)
        wLeftAttack = util.upLeft(bit)
        bRightAttack = util.downRight(bit)
        bLeftAttack = util.downLeft(bit)
        pawnAttacks[0][i] = (wRightAttack | wLeftAttack)
        pawnAttacks[1][i] = (bRightAttack | bLeftAttack)

    generateOccupancyVariations(True)
    generateMoveDatabase(True)
    generateOccupancyVariations(False)
    generateMoveDatabase(False)
def initPresets():
    """
    Loads initial presets
    """
    for i in range(64):
        util.setMask[i] = 1 << i
        bit = util.setMask[i]
        util.clearMask[i] = ~bit
        kingAttack = bit | util.right(bit) | util.left(bit)
        kingAttack |= util.up(kingAttack) | util.down(kingAttack)
        kingAttacks[i] = kingAttack & util.clearMask[i]

        l1 = util.left(bit)
        l2 = util.left(bit, 2)
        r1 = util.right(bit)
        r2 = util.right(bit, 2)

        h1 = l2 | r2
        h2 = l1 | r1

        knightAttacks[i] = util.up(h1) | util.down(h1) | util.up(h2, 2) | util.down(h2, 2)

        # pawn attacks
        wRightAttack = util.upRight(bit)
        wLeftAttack = util.upLeft(bit)
        bRightAttack = util.downRight(bit)
        bLeftAttack = util.downLeft(bit)
        pawnAttacks[0][i] = (wRightAttack | wLeftAttack)
        pawnAttacks[1][i] = (bRightAttack | bLeftAttack)

    generateOccupancyVariations(True)
    generateMoveDatabase(True)
    generateOccupancyVariations(False)
    generateMoveDatabase(False)
Beispiel #4
0
    def decrypt(self, cipher_line):
        if not util.is_encrypted(cipher_line):
            raise KarnError('"%s" is not encrypted!' % cipher_line)
            
        # convert from base 32 to bytes literal
        cipherbytes = bytearray.fromhex(unicode(util.inttohex(int(cipher_line.strip(), 32))))

        output = bytearray()
        # start at byte 1 because byte 0 is the guard byte
        for i in xrange(1, len(cipherbytes), BLOCK_SIZE):
            cipher = cipherbytes[i:i+BLOCK_SIZE]
            
            # + is the concatenation operator in python
            # ^ is the xor operator
            leftmd = bytearray(hashlib.sha1(str(util.right(cipher)) + str(self.rightkey)).digest())
            leftcipher = util.left(cipher)
            plaintext = bytearray(leftmd[i] ^ leftcipher[i] for i in xrange(len(leftmd)))
            rightmd = bytearray(hashlib.sha1(str(plaintext) + str(self.leftkey)).digest())
            rightcipher = util.right(cipher)
            plaintext.extend(bytearray(rightmd[i] ^ rightcipher[i] for i in xrange(len(rightmd))))

            # break if we decrypted a null byte
            output.extend(plaintext.partition('\x00')[0])
            if '\x00' in plaintext:
                break

        # we are expecting an ascii string, so print debug info 
        # if any decrypted character is out of ascii range
        if any(i > 127 for i in output):
            print 'couldn\'t decrypt ciphertext: %s' % cipher_line
            print 'with key: %d' % self.key
            print 'output: %s' % output
            raise DecryptionError(cipher_line, self.key, output)

        return str(output)
def move_robot():
    global x_deviation, y_deviation, tolerance, arr_track_data
    
    print("moving robot .............!!!!!!!!!!!!!!")
    print(x_deviation, y_deviation, tolerance, arr_track_data)
    
    if(abs(x_deviation)<tolerance and abs(y_deviation)<tolerance):
        cmd="Stop"
        delay1=0
        ut.stop()
        ut.red_light("ON")
    
    else:
        ut.red_light("OFF")
        if (abs(x_deviation)>abs(y_deviation)):
            if(x_deviation>=tolerance):
                cmd="Move Left"
                delay1=get_delay(x_deviation,'l')
                
                ut.left()
                time.sleep(delay1)
                ut.stop()
                
            if(x_deviation<=-1*tolerance):
                cmd="Move Right"
                delay1=get_delay(x_deviation,'r')
                
                ut.right()
                time.sleep(delay1)
                ut.stop()
        else:
            
            if(y_deviation>=tolerance):
                cmd="Move Forward"
                delay1=get_delay(y_deviation,'f')
                
                ut.forward()
                time.sleep(delay1)
                ut.stop()
                
            if(y_deviation<=-1*tolerance):
                cmd="Move Backward"
                delay1=get_delay(y_deviation,'b')
                
                ut.back()
                time.sleep(delay1)
                ut.stop()
    
    
    arr_track_data[4]=cmd
    arr_track_data[5]=delay1
Beispiel #6
0
    def show_results(self):
        util.right(self.log_path, "relative error:")
        if abs(self.relative_error) < TOLERANCE:
            util.result(self.log_path, "OK")
        else:
            util.result(self.log_path, "%0e" % self.relative_error)

        util.right(self.log_path, "mass change:")
        if self.initcond == "delta" or self.initcond == "smooth":
            if abs(self.mass_change) < TOLERANCE:
                util.result(self.log_path, "OK")
            else:
                util.result(self.log_path, "%0e" % self.mass_change)
        else:
            util.result(self.log_path, "--")
Beispiel #7
0
    def encrypt(self, msg):
        msglen = len(msg)
        msgbytes = bytearray(msglen + 1 + BLOCK_SIZE - ((msglen + 1) % BLOCK_SIZE))
        msgbytes[:msglen] = msg

        # add null byte and random byte padding as necessary
        msgbytes[msglen] = NULL_BYTE
        for i in xrange(msglen + 1, len(msgbytes)):
            msgbytes[i] = random.randint(0, 255)

        output = bytearray(1)
        output[0] = GUARD_BYTE

        for i in xrange(0, len(msgbytes), BLOCK_SIZE):
            block = msgbytes[i:i+BLOCK_SIZE]

            leftblock = util.left(block)
            rightblock = util.right(block)

            leftmd = bytearray(hashlib.sha1(str(leftblock) + str(self.leftkey)).digest())
            rightcipher = bytearray(leftmd[i] ^ rightblock[i] for i in xrange(len(leftmd)))
            rightmd = bytearray(hashlib.sha1(str(rightcipher) + str(self.rightkey)).digest())
            leftcipher = bytearray(rightmd[i] ^ leftblock[i] for i in xrange(len(rightmd)))

            output.extend(leftcipher)
            output.extend(rightcipher) 

        return util.base32(int(util.bytestohex(output), 16)) + '\n'
Beispiel #8
0
    def run(self, commands):
        self.setup_files["input.deck"] = util.decks.input_deck(solver=self.solver,
            num_cells_x=36, num_cells_y=74, a_x=-1.55, b_x=1.45, a_y=-1.62, b_y=1.38,
            t_final=1.03, sigma=1.111, init_cond = self.initcond,
            gaussian_sigma=self.gaussian_sigma, num_mpi_partitions_x=self.xNodes,
            num_mpi_partitions_y=self.yNodes)
        with util.ResetFile(*(self.initial_paths + self.current_paths)):
            util.right(self.log_path, "execution time:")
            util.tee(self.log_path, " " * 10, wait=True)
            super(RegressionTest, self).run(commands)
            util.tee(self.log_path, "")
            self.initial = util.formats.Composite(self.parser,
                self.initial_path, self.xNodes, self.yNodes)
            self.current = util.formats.Composite(self.parser,
                self.current_path, self.xNodes, self.yNodes)
            self.reference = self.parser(self.reference_path)

        self.show_results()

        return self.current
def move_robot():
    global x_deviation, y_max, tolerance, arr_track_data

    print("moving robot .............!!!!!!!!!!!!!!")
    print(x_deviation, tolerance, arr_track_data)

    y = 1 - y_max  #distance from bottom of the frame

    if (abs(x_deviation) < tolerance):
        delay1 = 0
        if (y < 0.1):
            cmd = "Stop"
            ut.red_light("ON")
            ut.stop()
        else:
            cmd = "forward"
            ut.red_light("OFF")
            ut.forward()

    else:
        ut.red_light("OFF")
        if (x_deviation >= tolerance):
            cmd = "Move Left"
            delay1 = get_delay(x_deviation)

            ut.left()
            time.sleep(delay1)
            ut.stop()

        if (x_deviation <= -1 * tolerance):
            cmd = "Move Right"
            delay1 = get_delay(x_deviation)

            ut.right()
            time.sleep(delay1)
            ut.stop()

    arr_track_data[4] = cmd
    arr_track_data[5] = delay1
Beispiel #10
0
    def run(self, commands):
        self.setup_files["input.deck"] = util.decks.input_deck(solver=self.solver,
            num_cells_x=36, num_cells_y=74, a_x=-1.55, b_x=1.45, a_y=-1.62, b_y=1.38,
            t_final=1.03, sigma=1.111, init_cond = self.initcond,
            gaussian_sigma=self.gaussian_sigma)
        with util.ResetFile(self.current_path, self.initial_path):
            util.right(self.log_path, "execution time:")
            util.tee(self.log_path, " " * 10, wait=True)
            super(RegressionTest, self).run(commands)
            util.tee(self.log_path, "")
            self.initial = self.parser(self.initial_path)
            self.current = self.parser(self.current_path)
            if REGENERATE:
                try:
                    os.makedirs(os.path.dirname(self.reference_path))
                except OSError:
                    pass
                shutil.copyfile(self.current_path, self.reference_path)
            self.reference = self.parser(self.reference_path)

        self.show_results()

        return self.current