Example #1
0
def main():

    parser = argparse.ArgumentParser(description='Start the server')
    parser.add_argument('--p', help='Port number', 
                        type=int, default=8080)
    parser.add_argument('--min', help='Minimal player to start the game', 
                        type=int, default=2)
    parser.add_argument('--max', help='Maximal player to start a game', 
                        type=int, default=10)
    parser.add_argument('--lobby', help='Time to count down in the lobby in second)',
                        type=int, default=2)
    parser.add_argument('--t', help='Time to wait until kick someone in second',
                        type=int, default=30)
    parser.add_argument('--d', help='Debug flag',
                        type=int, default=1)

    args = parser.parse_args(sys.argv[1:])

    com = Com(args.p, args.d)
    game = Game(com, args.min, args.max, args.lobby, args.t, args.d)
    
    com.start_server()
    game.setup_new_game()
    while com.check_signal():
        game.check_time()
Example #2
0
def main():
    pygame.init()
    screen = pygame.display.set_mode((20, 20), 0, 32)
    
    fps = FPS()

    tello=Tello()
    com=Com()
    
    frame_skip=300
    for frame in tello.container.decode(video=0):#一定要用这个循环来获取才不会产生delay
        if 0 < frame_skip:
            frame_skip = frame_skip - 1
            continue
        fps.update()
        start_time = time.time()
        image = cv2.cvtColor(numpy.array(frame.to_image()), cv2.COLOR_RGB2BGR)
        key_list = pygame.key.get_pressed()
        userc=usec(key_list)
        comd=com.get_comd(userc)
        tello.send_comd(comd)
        pygame.display.update()
        fps.display(image)
        cv2.imshow('t',image)
        if frame.time_base < 1.0/60:
            time_base = 1.0/60
        else:
            time_base = frame.time_base
        frame_skip = int((time.time() - start_time)/time_base)
        k = cv2.waitKey(1) & 0xff
        if k == 27 : 
            pygame.display.quit()
            break
    cv2.destroyAllWindows()
Example #3
0
    def connect(self):
        # ip = textinput in QtDesigner implementieren
        #self.client = Com(ip="192.168.137.61", server=False)
        #self.send_thread.start()
        self.ui.connectionLabel.setText("<font color='green'>Connected</font>")

        self.client = Com(ip=self.ui.ipText.text(), server=False)
        self.send_thread.start()
Example #4
0
    def __init__(self, name):
        super().__init__()
        self.setName(name)

        self.start()
        self.answered_process = set()
        self.dice_result = {}

        self.com = Com(self)
Example #5
0
def comment(url):
    
    try:
        p=Com(url)
        print('-=-=-=-=-=-=-=-=-=-')
        return p.get_comment()
        print(p.get_comment())
    except:
        return ("None")
    return ""
 def __init__(self, portName):
     '''
     Constructor
     '''
     self.portName = portName
     self.com = Com("LucidIo", self.portName)
     self.id = LucidControlId()
Example #7
0
    def __init__(self, port="5555"):
        # vm ip:            172.16.137.137
        # server ip:        172.16.137.1
        # localhost ip:     127.0.0.1
        self.server = Com(port=port, server=True)
        self.data = {
            'Winkelrichtung': 0,
            'Geschwindigkeit': 0,
            'Angehoben': 0,
            'InitPosition': 0
        }

        #self.server.bind("tcp://*:"+port)

        self.direction = 0
        self.velocity = 0
        self.leghight = 0
        self.initPos = 0
Example #8
0
def main():

    parser = argparse.ArgumentParser(description='Start the server', conflict_handler='resolve')
    parser.add_argument('-p', help='Port number', 
                        type=int, default=8080)
    parser.add_argument('-h', help='Host name', 
                        type=str, default='localhost')
    parser.add_argument('-u', help='Player Name', 
                        type=str, default='R2D2')
    parser.add_argument('-auto', help='1: auto, 0: not',
                        type=int, default=0)
    parser.add_argument('--d', help='Debug flag',
                        type=int, default=1)

    args = parser.parse_args(sys.argv[1:])

    com = Com(args.h, args.p, args.u, args.d)
    game = Game(com, args.u, args.auto, args.d)
    
    com.start_client()

    while com.check_signal():
        game.check_time()
Example #9
0
class testCom:
    def __init__(self, port="5555"):
        # vm ip:            172.16.137.137
        # server ip:        172.16.137.1
        # localhost ip:     127.0.0.1
        self.server = Com(port=port, server=True)
        self.data = {
            'Winkelrichtung': 0,
            'Geschwindigkeit': 0,
            'Angehoben': 0,
            'InitPosition': 0
        }

        #self.server.bind("tcp://*:"+port)

        self.direction = 0
        self.velocity = 0
        self.leghight = 0
        self.initPos = 0

        #self.data_thread = Thread(target=self.readData, args=())
        #self.data_thread.start()

# "listen" / receive data

    def readData(self):
        while True:
            self.data = self.server.getData()

            # TODO: change reduntant variable creation, use (direction; velocity; leghight; initPos) directly
            #if self.data != None:
            self.direction = self.data['Winkelrichtung']
            self.velocity = self.data['Geschwindigkeit']
            self.leghight = self.data['Angehoben']
            self.initPos = self.data['InitPosition']
            #print("Init:", self.initPos)

            # TODO: Change print to return for the walking group
            #print("Winkel:", self.direction ,"," , "Geschwindigkeit: ", self.velocity, ",", "Angehoben: ", self.leghight, ",", "Init-Position: ", self.initPos)
            # TESTEN!!!
            print("Winkel:", self.direction, ",", "Geschwindigkeit: ",
                  self.velocity, ",", "Angehoben: ", self.leghight, ",",
                  "Init-Position: ", self.initPos)

            # TODO: Tweek this, for performance
            #  Do some 'work'
            time.sleep(0.1)
Example #10
0
#from serial.tools.list_ports import comports as serial_comports
from Com import Com
from Tomo import Tomo
from Gui import ScanWin

try :
    com = Com("/dev/ttyUSB0")
except Exception as e:
    print(e)
    com = None
finally :
    win = ScanWin()
    Tomo(win, com)
    win.mainloop()
Example #11
0
class Process(BaseProcess):
    """Exemple of a process that use the Com module, each process will try to play dice with other"""
    def __init__(self, name):
        super().__init__()
        self.setName(name)

        self.start()
        self.answered_process = set()
        self.dice_result = {}

        self.com = Com(self)

    def __repr__(self):
        return f"[⚙ {self.name}]"

    def run(self):
        """Method run for the roll dice """

        sleep(0.1)
        self.com.join_sync()
        sleep(0.1)
        self.com.register_function(self.receive_dice_value, tag="dice_value")

        if self.name == "0":
            t = Token(lamport_clock=self.lamport_clock,
                      author="",
                      recipient="",
                      min_wait=1)
            self.com.send_token(t)
        sleep(int(self.name))
        self.com.synchronize()
        print("Synchronize !")

        loop = 0
        while self.alive:

            # roll dice
            dice_value = roll_dice()
            self.lamport_clock.increment()
            self.dice_result = {self.name: dice_value}
            self.com.broadcast(f"dice_value:{dice_value}", tag="dice_value")

            sleep(1)  # wait that all players have play
            # Retrieve all scores in the letterbox
            for i in range(len(self.com.letterbox)):
                m: BroadcastMessage = self.com.letterbox.popleft()
                data = m.payload
                if "dice_value" in data:
                    self.dice_result[m.author] = int(data.split(":")[1])

            if self.alive:
                # look at who is the winner and write his result in a file
                process, res = who_is_winner(self.dice_result)
                if self.name == process:
                    self.write_result(process, res)
                self.com.synchronize()
            loop += 1
        print(f"{self} stopped")

    def receive_dice_value(self, m):
        data = m.payload
        print(
            f"{self} Receive_dice_value from {m.author} => received : {data} + {self.lamport_clock}"
        )
        # to use the letterbox, we do nothing here

    def write_result(self, process, result):
        """ write in a file the winner's result of the last roll dice """
        print(f"{self} writing result {self.lamport_clock}")
        self.com.request_sc()
        if self.alive:
            self.lamport_clock.increment()
            with open(RESULT_FILENAME, "a+") as f:
                f.write(f"{process} : {result}\n")
            self.com.release_sc()
            print(f"{self} result writed {self.lamport_clock}")

    def stop(self):
        print(f"{self} RECEIVED stop message {self.lamport_clock}")
        self.alive = False
        self.join()
Example #12
0
class MyWindow(QtWidgets.QMainWindow):
    def __init__(self):

        # Controller Thread Variable (z.B. um den Thread zu beenden)
        self.con_Thread_var = True

        # Client
        self.client = None

        # Connected Thread Variable
        self.connected = False

        # initialise controller
        self.controller1 = Controller()

        # Data to be packed and processed
        self.direction = 0
        self.leghight = 0
        self.velocity = 0

        # Create window
        super(MyWindow, self).__init__()
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)

        # Connect button
        self.ui.connectButton.clicked.connect(self.connect)

        # Threads
        self.con_thread = Thread(target=self.conReact, args=())
        self.con_thread.start()
        self.data_thread = Thread(target=self.dataReact, args=())
        self.data_thread.start()
        self.send_thread = Thread(target=self.sendReact, args=())

    # Set direction to 0
    def setDirection0(self):
        self.direction = 0

    # Elevate hexapod
    def setAnheben(self):
        self.leghight = 1

    # Delevate hexapod
    def setAbsenken(self):
        self.leghight = 0

    # Set velocity
    def setSpeed(self):

        if (self.controller1.getVelocity() < 0.01):
            self.velocity = 0
        else:
            self.velocity = self.controller1.getVelocity() * 100

    # Connect to server
    def connect(self):
        # ip = textinput in QtDesigner implementieren
        #self.client = Com(ip="192.168.137.61", server=False)
        #self.send_thread.start()
        self.ui.connectionLabel.setText("<font color='green'>Connected</font>")

        self.client = Com(ip=self.ui.ipText.text(), server=False)
        self.send_thread.start()

    # Set direction
    def setDirection(self):
        self.direction = math.degrees(-self.controller1.getAngleDirection())

    # Controller Thread
    def conReact(self):

        while True:
            if (self.controller1.getVelocity() != 0 and self.con_Thread_var):
                self.setSpeed()
            if (self.controller1.getAngleDirection() != 0
                    and self.con_Thread_var):
                self.setDirection()
            if (self.controller1.getButtonLeghight() == 1
                    and self.con_Thread_var):
                self.setAnheben()
            if (self.controller1.getButtonLeghight() == 0
                    and self.con_Thread_var):
                self.setAbsenken()

    # Data Thread
    def dataReact(self):

        while True:
            # Pack data
            self.data = {
                'Winkelrichtung': self.direction,
                'Geschwindigkeit': self.velocity,
                'Angehoben': self.leghight
            }
            # print(self.data) //local testen

    # Send data Thread
    def sendReact(self):

        while True:
            self.client.send(self.data)