Example #1
0
def method3():
    line_num = 10
    # laser config
    laserfort = laser(precision=2)
    
    x, y = laserfort.controlLaser()
    if (not x == 0) and (not y == 0):
        print "[Error]The point is not at center."
        sys.exit()
    else:
        if (not laserfort.X_Axis == 0) and (not laserfort.Y_Axis == 0): 
            print "[Error]Not in the center"
        positions = list()
        for i in range(line_num):
            positions.append(laserfort.calculateSteps(i))
            laserfort.center()
        raw_input("[System]Press enter to write data to file")
        with open('steps.config', 'w') as fp:
            for index in range(256):
                if index >= line_num:
                    fp.write("0 0\n")
                else:
                    line = "%d %d\n" % (positions[index][0], positions[index][1])
                    fp.write(line)
    
    # laser test
    laserfort.table = laserfort.readTableFile('steps.config')
    for i in range(len(positions)):
        laserfort.shoot1((i/16), (i%16),debug=True)
    
    # return to center and shutdown
    laserfort.shutdown()
Example #2
0
def method1():
    line_num = 10
    # laser config
    laserfort = laser(precision=2)

    x, y = laserfort.controlLaser()
    if (not x == 0) and (not y == 0):
        print "[Error]The point is not at center."
        sys.exit()
    else:
        if (not laserfort.X_Axis == 0) and (not laserfort.Y_Axis == 0):
            print "[Error]Not in the center"
        positions = list()
        for i in range(line_num):
            positions.append(laserfort.calculateSteps(i))
        laserfort.center()
        raw_input("[System]Press enter to write data to file")
        with open('steps.config', 'w') as fp:
            for index in range(256):
                if index >= line_num:
                    fp.write("0 0\n")
                else:
                    line = "%d %d\n" % (positions[index][0],
                                        positions[index][1])
                    fp.write(line)

    # laser test
    laserfort.table = laserfort.readTableFile('steps.config')
    for i in range(len(positions)):
        laserfort.shoot1(0, i, debug=True)

    # return to center and shutdown
    laserfort.shutdown()
Example #3
0
 def test_cinco_soldados_em_L(self):
     soldados = [(0, 0), (0, 1), (0, 2), (1, 0), (2, 0)]
     '''
     #....
     #....
     ###..
     '''
     self.assertEqual(2, laser(soldados))
Example #4
0
 def test_cinco_soldados_em_L(self):
     soldados = [(0,0), (0,1), (0,2), (1,0), (2,0)]
     '''
     #....
     #....
     ###..
     '''
     self.assertEqual(2, laser(soldados))
Example #5
0
 def test_seis_soldados(self):
     soldados = [(0,0), (0,2), (1,2), (1,3), (2,1), (2,2)]
     #soldados = [(1,1), (1,2), (1,3), (2,1), (3,2), (4,3)]
     '''
     #.#.
     ..##
     .##.
     '''
     self.assertEqual(3, laser(soldados))
Example #6
0
 def test_seis_soldados(self):
     soldados = [(0, 0), (0, 2), (1, 2), (1, 3), (2, 1), (2, 2)]
     #soldados = [(1,1), (1,2), (1,3), (2,1), (3,2), (4,3)]
     '''
     #.#.
     ..##
     .##.
     '''
     self.assertEqual(3, laser(soldados))
Example #7
0
def method5():
    laserfort = laser()
    laserfort.controlLaser()
    while True:
        coordinate = raw_input().split()
        if coordinate[0] == "exit":
            break
        else:
            print "x : %s \t y : %s" % (coordinate[0], coordinate[1])
            laserfort.move(int(coordinate[1]), int(coordinate[0]), 1, 3000)
            laserfort.center()
    laserfort.shutdown()
Example #8
0
def method5():
    laserfort = laser()
    laserfort.controlLaser()
    while True:
        coordinate = raw_input().split()
        if coordinate[0] == "exit":
            break
        else:
            print "x : %s \t y : %s" % (coordinate[0], coordinate[1])
            laserfort.move(int(coordinate[1]), int(coordinate[0]), 1, 3000)
            laserfort.center()
    laserfort.shutdown()
Example #9
0
def method4():
    # laser config
    laserfort = laser(precision=2)

    x, y = laserfort.controlLaser()
    if (not x == 0) and (not y == 0):
        print "[Error]The point is not at center."
        sys.exit()
    else:
        if (not laserfort.X_Axis == 0) and (not laserfort.Y_Axis == 0):
            print "[Error]Not in the center"
        while True:
            ay, ax = laserfort.calculateSteps()
            laserfort.center()
Example #10
0
def method4():
    # laser config
    laserfort = laser(precision=2)
    
    x,y = laserfort.controlLaser()
    if (not x == 0) and (not y == 0):
        print "[Error]The point is not at center."
        sys.exit()
    else:
        if (not laserfort.X_Axis == 0) and (not laserfort.Y_Axis == 0): 
            print "[Error]Not in the center"
        while True:
            ay, ax= laserfort.calculateSteps()
            laserfort.center()
Example #11
0
 def generate_powerup(self, x, y, x_vel, y_vel):
     num = random.randint(0, 1)
     if num:
         return
     num = random.randint(0, 7)
     # num=7
     if num == 0:
         return expandpaddle(x, y, x_vel, y_vel)
     elif num == 1:
         return shrinkpaddle(x, y, x_vel, y_vel)
     elif num == 2:
         return ballmultiplier(x, y, x_vel, y_vel)
     elif num == 3:
         return fastball(x, y, x_vel, y_vel)
     elif num == 4:
         return paddlegrab(x, y, x_vel, y_vel)
     elif num == 5:
         return thruball(x, y, x_vel, y_vel)
     elif num == 6:
         return laser(x, y, x_vel, y_vel)
     elif num == 7:
         return fireball(x, y, x_vel, y_vel)
Example #12
0
 def test_nenhum_soldado(self):
     soldados = []
     self.assertEqual(0, laser(soldados))
Example #13
0
"""
Example #14
0
    def level_run(self, running):

        # Initial variable set
        self.level_count = 0
        color_setting = ColorSet()
        color = color_setting.get_colors()
        old_color = color
        counter = 0
        score = 0
        finalScore = 0
        top = 0
        bottom = self.height - 1
        refresh_start = False
        refresh_count = 0
        calc_start = False
        calc_count = 0
        new_level = 0
        level_length = 100
        score_label = "Score: "
        laser_label = "Laser: "
        laser_interval = 30  # number of steps before laser replinishes
        laser_max = 5  # max number of lasers player can have
        laser_count = 5
        self.place_hero()
        moveH = 0
        moveV = 0
        createLaser = False

        # place score label in bottom left hand corner
        self.stdscr.move(self.height, 0)
        self.stdscr.addstr(score_label)
        
        # Primary loop
        while running:
            asyncore.loop(timeout = 1, count = 1)

            timer = int(round(time.clock() * 1000)) # Referenced to maintain updates and refresh rate
            
            p = self.socket.getData()
            
            while p != "":
                client, cmd, val = p.split('*')
                val = int(val)
                if cmd == "mH":
                    if  client == str(self.socket.clientB):
                        moveH += val
                elif cmd == "mV":
                    if client == str(self.socket.clientA):
                        moveV += val
                elif cmd == "fL":
                    createLaser = True
                                  
                p = self.socket.getData()
                
            #move hero after all packets processed
            if self.heroCol + moveH < self.width and self.heroCol + moveH > 0:
                if self.level_grid[self.heroRow + moveV][self.heroCol + moveH] != '&' and self.level_grid[self.heroRow + moveV][self.heroCol + moveH] != '#' :
                    self.move_hero(moveV, moveH)
                    self.socket.buildPacket("mP", "-1," + str(moveH) + "," + str(moveV))
                    moveV = 0
                    moveH = 0
                else:
                    self.socket.buildPacket("end", score)
                    asyncore.loop(timeout = 1, count = 1)
                    return score
                
            #fire laser
            if createLaser:
                createLaser = False
                if  client == str(self.socket.clientB) and laser_count > 0:
                    l = laser(self.currID, self.heroRow, self.heroCol + 1, self.width - 1)
                    self.lasers.append(l)
                    self.socket.buildPacket("cL", str(self.currID))
                    laser_count -= 1
                    self.currID += 1

            player_height = self.heroRow
            player_depth = self.heroCol

            # Update all aspects of game at designated intervals
            if calc_start is False:
                calc_count = timer
                calc_start = True
            elif calc_start and (timer - calc_count) > 100:  # Interval to update game elements(milliseconds)
                counter += 1
                new_level += 1
                if counter == level_length:
                    if bottom - top > 7:
                        top += 1
                        bottom -= 1
                    counter = 0
                    self.level_count += 1

                # Change color palette upon reaching new level
                elif counter == level_length - 1:
                    old_color = color
                    while old_color == color:
                        color = color_setting.get_colors()
                    new_level = 0

                self.level_update(top, bottom, player_height, player_depth)
                score += 1 # update score whenever level updates
                
                if (score % laser_interval == 0) and laser_count < laser_max:
                    laser_count = laser_count + 1

                calc_start = False

            # Refreash screen at designated intervals
            if refresh_start is False:
                refresh_count = timer
                refresh_start = True
                
                self.level_draw(color, old_color, new_level)
                self.stdscr.move(self.height, len(score_label))
                self.stdscr.addstr(str(score))
                self.stdscr.move(self.height, self.width-(len(score_label)+10))
                self.stdscr.addstr(laser_label)
                # add a red bar for each laser
                for i in range(laser_count):
                    self.stdscr.addstr('|', curses.color_pair(10))
                    self.stdscr.addstr(' ')
                # make sure rest of laser bar is blacked out
                for i in range(laser_max - laser_count): 
                    self.stdscr.addstr('  ')
                    
                # check for collisions after drawing level
                if self.level_grid[self.heroRow][self.heroCol] != '@':
                    self.socket.buildPacket("end", score)
                    asyncore.loop(timeout = 1, count = 1)
                    return score

            elif refresh_start and (timer - refresh_count) > 16:  # Interval to refresh game screen(milliseconds)
                refresh_start = False
                self.stdscr.refresh()
Example #15
0
 def test_tres_soldados_em_L(self):
     soldados = [(1, 2), (1, 1), (2, 1)]
     self.assertEqual(2, laser(soldados))
Example #16
0
 def test_tres_soldados_em_linha(self):
     soldados = [(1,2), (1,1), (1,3)]
     self.assertEqual(1, laser(soldados))
Example #17
0
        for event in pygame.event.get():
            if event == pygame.QUIT:
                pygame.quit()
            if event.type == pygame.KEYDOWN:
                if (event.key == pygame.K_LEFT):
                    movement = -2
                elif (event.key == pygame.K_RIGHT):
                    movement = 2
                if event.key == pygame.K_SPACE:
                    bool = True
                if event.key == pygame.K_SPACE:
                    if timer > 600:
                        timer = 0
                        elote.append(
                            laser(natalia.sisterMidX(), natalia.sisterMidY()))
            elif (event.type == pygame.KEYUP):
                if event.key == pygame.K_RIGHT or pygame.K_LEFT:
                    movement = 0
        count = 0
        for e in emis:
            if (e != None):
                screen.blit(e.getEmi(), (e.getX(), e.getY()))
                if (timer2 > 1000) & (emis.index(e) % 2 == 0):
                    el.append(laser(e.getX() + 16, e.getY() + 32))
                elif (timer2 == 500) & emis.index(e) % 2 != 0:
                    el.append(laser(e.getX() + 16, e.getY() + 32))
            elif (e == None):
                count += 1

            if (count == len(emis)):
Example #18
0
    def level_run(self, running):

        # Initial variable set
        self.level_count = 0
        color_setting = ColorSet()
        color = color_setting.get_colors()
        old_color = color
        counter = 0
        score = 0
        top = 0
        bottom = self.height - 1
        refresh_start = False
        refresh_count = 0
        calc_start = False
        calc_count = 0
        new_level = 0
        level_length = 100
        score_label = "Score: "
        laser_label = "Laser: "
        laser_interval = 30  # number of steps before laser replinishes
        laser_max = 5  # max number of lasers player can have
        laser_count = 5
        self.place_hero()

        # place score label in bottom left hand corner
        self.stdscr.move(self.height, 0)
        self.stdscr.addstr(score_label)
        
        # Primary loop
        while running:
            asyncore.loop(timeout = 1, count = 1)
			
            timer = int(round(time.clock() * 1000)) # Referenced to maintain updates and refresh rate

            p = self.socket.getData()
            
            while p != "":
                cmd, val = p.split('*')
                if ',' in val:
                    id, x, y = val.split(',')
                    id = int(id)
                    x = int(x)
                    y = int(y)
                else:
                    val = int(val)
                    
                if cmd == "mP":
                    self.move_hero(y, x)
                #move enemy
                elif cmd == "mE":
                    for e in self.enemies:
                        if e.ID == id:
                            if e.width >= 0 and e.width < self.width:
                                self.level_grid[e.height][e.width] = ' '
                            e.height = y
                            e.width = x
                            self.level_grid[e.height][e.width] = '&'
                            break
                #move wall
                elif cmd == "mW":
                    for o in self.obstacles:
                        if o.ID == id:
                            if o.width >= 0 and o.width < self.width:
                                self.level_grid[o.height][o.width] = ' '
                            o.height = y
                            o.width = x
                            self.level_grid[o.height][o.width] = '#'
                            break
                #move laser
                elif cmd == "mL":
                    for l in self.lasers:
                        if l.ID == id:
                            if l.col >= 0 and l.col < self.width:
                                self.level_grid[l.row][l.col] = ' '
                            l.row = y
                            l.col = x
                            self.level_grid[l.row][l.col] = '-'
                #create enemy
                elif cmd == "cE":
                    enemy = EnemyGen(id, y, x, top, bottom, self.level_grid, player_height, player_depth, self.level_count)
                    self.enemies.append(enemy)
                #create wall
                elif cmd == "cW":
                    wall = Obstacle(id, y, x, self)
                    self.obstacles.append(wall)
                #create laser
                elif cmd == "cL":
                    l = laser(val, self.heroRow, self.heroCol + 1, self.width - 1)
                    self.lasers.append(l)
                    laser_count -= 1
                #delete enemy
                elif cmd == "delE":
                    for e in self.enemies[:]:
                        if e.ID == id:
                            e.width = x
                            e.height = y
                            EnemyGen.enemy_death(e, self, top, bottom)
                            self.del_enemies.append(e)
                            self.enemies.remove(e)
                            break
                #delete laser
                if cmd == "delL":
                    for l in self.lasers[:]:
                        if l.ID == id:
                            if l.col >= 0 and l.col < self.width:
                                self.level_grid[l.row][l.col] = ' '
                            self.lasers.remove(l)
                            break
                #delete wall
                elif cmd == "delW":
                    for o in self.obstacles[:]:
                        if o.ID == id:
                            if o.width >= 0 and o.width < self.width:
                                self.level_grid[o.height][o.width] = ' '
                            self.obstacles.remove(o)
                            break
                #laser enemy
                elif cmd == "eE":
                    for e in self.enemies[:]:
                        if e.ID == id:
                            if e.width >= 0 and e.width < self.width:
                                self.level_grid[e.height][e.width] = ' '
                            e.height = y
                            e.width = x
                            self.level_grid[e.height][e.width] = '}'
                            self.del_enemies.append(e)
                            self.enemies.remove(e)
                            break
                #explode wall
                elif cmd == "eW":
                    for o in self.obstacles[:]:
                        if o.ID == id:
                            if o.width >= 0 and o.width < self.width:
                                self.level_grid[o.height][o.width] = ' '
                            o.height = y
                            o.width = x
                            self.del_obstacles.append(o)
                            self.obstacles.remove(o)
                            break
                elif cmd == "end":
                    return val
                                
                p = self.socket.getData()
                
                
            #get user input
            vIn, hIn = self.getInput()
            
            #fire laser
            if vIn == 2:
                self.socket.buildPacket("fL", vIn)
            else:
                #vertical movement
                if vIn != 0:
                    self.socket.buildPacket("mV", vIn)
                #horizontal movement
                if hIn != 0:
                    self.socket.buildPacket("mH", hIn)
                
            player_height = self.heroRow
            player_depth = self.heroCol

            # Update all aspects of game at designated intervals
            if calc_start is False:
                calc_count = timer
                calc_start = True
            elif calc_start and (timer - calc_count) > 100:  # Interval to update game elements(milliseconds)
                counter += 1
                new_level += 1
                if counter == level_length:
                    if bottom - top > 7:
                        top += 1
                        bottom -= 1
                    counter = 0
                    self.level_count += 1

                # Change color palette upon reaching new level
                elif counter == level_length - 1:
                    old_color = color
                    while old_color == color:
                        color = color_setting.get_colors()
                    new_level = 0

                self.level_update(top, bottom, player_height, player_depth)
                score += 1 # update score whenever level updates
                
                if (score % laser_interval == 0) and laser_count < laser_max:
                    laser_count += 1

                calc_start = False

            # Refreash screen at designated intervals
            if refresh_start is False:
                refresh_count = timer
                refresh_start = True
                self.level_draw(color, old_color, new_level)
                # add score and laser count
                self.stdscr.move(self.height, len(score_label))
                self.stdscr.addstr(str(score))
                self.stdscr.move(self.height, self.width-(len(score_label)+10))
                self.stdscr.addstr(laser_label)
                # add a red bar for each laser
                for i in range(laser_count):
                    self.stdscr.addstr('|', curses.color_pair(10))
                    self.stdscr.addstr(' ')
                # make sure rest of laser bar is blacked out
                for i in range(laser_max - laser_count): 
                    self.stdscr.addstr('  ')
            elif refresh_start and (timer - refresh_count) > 16:  # Interval to refresh game screen(milliseconds)
                refresh_start = False
                self.stdscr.refresh()
Example #19
0
 def test_dois_soldados_em_fila(self):
     soldados = [(1, 1), (1, 2)]
     self.assertEqual(1, laser(soldados))
Example #20
0
    # show the forwarding time
    print "It cost %f sec" % (tEnd - tStart)

    # show the output tables
    dt.print_catagory_table(output)
    dt.print_probability_table(output)

    # get targets coordinates
    coordinates = dt.get_coordinates(output)

    # save video snapshots
    if args.save:
        images = list()
        images_name = sorted(os.listdir('/tmp/crops/'))
        for image_name in images_name:
            tmp = cv2.imread('/tmp/crops/' + image_name)
            images.append(cv2.imread('/tmp/crops/' + image_name))
        sri.saveImage(images)
        del images, images_path

    # send the message to laser fort via ROS
    if args.ros:
        laser = laser()
        for coordinate in coordinates:
            laser.shoot1(coordinate['X-Axis'], coordinate['Y-Axis'])
        laser.shutdown()

    # free memory
    del img_list
    del net
Example #21
0
import sys
import cv2
from target import *
from display import draw
import laser

print('Iniciando RADAR')

x = pygame.init()
pygame.font.init()
defaultFont = pygame.font.get_default_font()
fontRenderer = pygame.font.Font(defaultFont, 20)
radarDisplay = pygame.display.set_mode((1400, 800))
pygame.display.set_caption('Tela do RADAR')

ls = laser.laser()

servoPIN = 16
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)

GPIO.setup(servoPIN, GPIO.OUT)
p = GPIO.PWM(servoPIN, 50)
p.start(0)

targets = {}

try:
    while True:

        for a in range(0, 180):
Example #22
0
 def test_nenhum_soldado(self):
     soldados = []
     self.assertEqual(0, laser(soldados))
Example #23
0
 def test_dois_soldados_em_fila(self):
     soldados = [(1,1), (1,2)]
     self.assertEqual(1, laser(soldados))
Example #24
0
 def test_dois_soldados_em_diagonal(self):
     soldados = [(1,1), (2,2)]
     self.assertEqual(2, laser(soldados))
Example #25
0
 def test_tres_soldados_em_L(self):
     soldados = [(1,2), (1,1), (2,1)]
     self.assertEqual(2, laser(soldados))
from music import music
from laser import laser




lasernumber = 5
device = 1
dummy = 0
instrument = 61


mc = music(lasernumber ,0,60,True, instrument);
mc.test();

harfe = laser(lasernumber, device, dummy);
harfe.calibration()


while(1):
#	ak = cv2.waitKey(1)
#	if ak != -1:
#		ak = chr(ak)
#		if ak == 'c':
#			sys.exit()
	keylist = harfe.readInputUntilRecognition(0)
	
	for i in range(lasernumber):
		harfe.beams[i] = 0;
	
	for key in keylist:
Example #27
0
 def test_dois_soldados_em_diagonal(self):
     soldados = [(1, 1), (2, 2)]
     self.assertEqual(2, laser(soldados))
Example #28
0
 def test_tres_soldados_em_coluna(self):
     soldados = [(1, 1), (2, 1), (3, 1)]
     self.assertEqual(1, laser(soldados))
Example #29
0
def cria_lasers(L, janela, nave):
    if len(L) < 4:
        novo_laser = laser(janela, nave)
        L.append(novo_laser)
Example #30
0
 def test_tres_soldados_em_linha(self):
     soldados = [(1, 2), (1, 1), (1, 3)]
     self.assertEqual(1, laser(soldados))
Example #31
0
 def test_um_soldado(self):
     soldados = [(1,1)]
     self.assertEqual(1, laser(soldados))
Example #32
0
 def test_tres_soldados_em_coluna(self):
     soldados = [(1,1), (2,1), (3,1)]
     self.assertEqual(1, laser(soldados))
Example #33
0
 def test_um_soldado(self):
     soldados = [(1, 1)]
     self.assertEqual(1, laser(soldados))
Example #34
0
    # show the forwarding time
    print "It cost %f sec" % (tEnd - tStart) 

    # show the output tables
    dt.print_catagory_table(output)
    dt.print_probability_table(output)

    # get targets coordinates 
    coordinates = dt.get_coordinates(output)

    # save video snapshots
    if args.save:
        images = list()
        images_name = sorted(os.listdir('/tmp/crops/'))
        for image_name in images_name:
            tmp = cv2.imread('/tmp/crops/' + image_name)
            images.append(cv2.imread('/tmp/crops/' + image_name))
        sri.saveImage(images)
        del images, images_path
            
    # send the message to laser fort via ROS
    if args.ros:
        laser = laser()
        for coordinate in coordinates:
            laser.shoot1(coordinate['X-Axis'], coordinate['Y-Axis'])
        laser.shutdown() 

    # free memory
    del img_list
    del net