Exemple #1
0
    def comm(self):

        if self.keepRunning:
            # recieve posn
            [self.curposKal,
             self.curgas] = encode.recievePacket(sock=self.conn)

            # print x,y,theta,velocity
            print("robot thinks position", self.curposKal)
            self.curpos = [
                self.curposAT[0], self.curposAT[1], self.curangAT[1]
            ]
            print("robot actual position", self.curpos)
            print(self.curgas)
            self.addGas()

            # send desired velocities
            print(self.desired, self.index)
            self.desired[2] = self.index
            self.desired[3] = self.curposAT[0]
            self.desired[4] = self.curposAT[1]
            self.desired[5] = self.curangAT[0]

            encode.sendPacket(sock=self.conn, message=self.desired)
            print("desired v sent", self.desired)
        else:
            # send out packet
            encode.sendPacket(sock=self.conn, message="out")
            # wait for confirmation of reception
            rcv = encode.recievePacket(sock=self.conn)
            # Clean up the connection
            print("Closing Connection")
            self.conn.close()
Exemple #2
0
    def loopComms(self):
        snd = [self.curpos, self.gas]
        print("send coordinates:", snd)
        # send curpos
        encode.sendPacket(sock=self.sock, message=snd)

        # recieve message
        rcv = encode.recievePacket(sock=self.sock)
        print("rcv:", rcv)

        # determine what to do with message
        if rcv == "out":
            encode.sendPacket(sock=self.sock, message="out")
            self.quits()  # TODO: does this work?
        elif rcv is None:  # base station not cooperating, this catches when it closes and there is an empty socket connection, and (should) gracefullly kill the robot
            print("exiting i guess :(")
            self.quits()
        else:
            self.desired[0] = rcv[0]
            self.desired[1] = rcv[1]
            self.gasindex = rcv[2]
            self.ATxytOLD = self.ATxyt
            self.ATxyt[0] = rcv[3]
            self.ATxyt[1] = rcv[4]
            self.ATxyt[2] = rcv[5]
        return
Exemple #3
0
    def comm(self):
        if self.keepRunning:
            #recieve posn
            [self.curpos, self.curgas] = encode.recievePacket(sock=self.conn)

            #print x,y,theta,velocity
            print(self.curpos)
            print(self.curgas)
            self.addGas()

            #send desired velocities
            encode.sendPacket(sock=self.conn, message=self.desired)
        else:
            #send out packet
            encode.sendPacket(sock=self.conn, message="out")
            #wait for confirmation of reception
            rcv = encode.recievePacket(sock=self.conn)
            # Clean up the connection
            print("Closing Connection")
            self.conn.close()
Exemple #4
0
    def loopComms(self):
        snd = [self.curpos, self.gas]
        # send curpos
        encode.sendPacket(sock=self.sock, message=snd)

        # recieve message
        rcv = encode.recievePacket(sock=self.sock)
        print(rcv)

        # determine what to do with message
        if rcv == "out":
            encode.sendPacket(sock=self.sock, message="out")
            quit()
        else:
            self.desired[0] = rcv[0]
            self.desired[1] = rcv[1]

        return
Exemple #5
0
    def run(self):
        #catch all robots
        #all yur robots are belong to us
        #make a thread for every robot communication
        while self.keepRunning:
            conn, client_address = self.sock.accept()
            print("Connection from", client_address)
            ID = encode.recievePacket(sock=conn)

            robot = Robot.Robot(ID, conn)
            thread = threading.Thread(target=robot.run())
            thread.start()
            thread.join()

            self.robotThreads.append(thread)
            self.robots.append(robot)

        #make sure to kill the threads!
        for thread in self.robots:
            thread.terminate()