예제 #1
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
예제 #2
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()
예제 #3
0
    def initComms(self, ip, port):
        # Connect the socket to the port where the server is listening
        self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        print("connecting to %s port %s" % (ip, port))
        self.sock.connect((ip, port))

        time.sleep(.5)

        # send robot id so the base knows who is connecting
        encode.sendPacket(sock=self.sock, message=self.id)

        return
예제 #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
예제 #5
0
파일: Robot.py 프로젝트: dcweber765/2017MQP
    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()