コード例 #1
0
ファイル: message.py プロジェクト: BurakDmb/RelayRacingRobots
    def create(data):
        print("Received: " + data)
        parts = data.split(":")
        if not parts:
            return None
        if int(parts[0]) == Message.LocationMessageType:
            string = parts[1].split(",")
            a, b, c = string
            state = State(float(a), float(b), float(c))
            return LocationMessage(state)

        elif int(parts[0]) == Message.RouteMessageType:
            startStr = parts[1].split(",")
            a, b, c = startStr
            startState = State(float(a), float(b), float(c))
            targetStates = []
            for i in range(2, len(parts)):
                targetStr = parts[i].split(",")
                a, b, c = targetStr
                targetStates.append(State(float(a), float(b), float(c)))
            return RouteMessage(startState, targetStates)

        elif int(parts[0]) == Message.StartMessageType:
            return StartMessage()

        elif int(parts[0]) == Message.OkMessageType:
            return OkMessage()

        elif int(parts[0]) == Message.EndMessageType:
            return EndMessage()

        elif int(parts[0]) == Message.GetLocationMessageType:
            return GetLocationMessage()

        else:
            return None
コード例 #2
0
from main import State, light


def test_light():
    assert (light.id == '123') == ('id', '123')
    assert (light.whatever == 4) == ('whatever', 4)


state = State()
id = state.filter(light.id == "d3b2f2d97452")

for light in id:
    print(light)
'''
    def test_(self):

        def dummyFetchLights():
            resp = [{"id": "d3b2f2d97452",
                     "uuid": "8fa5f072-af97-44ed-ae54-e70fd7bd9d20",
                     "label": "Left Lamp",
                     "connected": True,
                     "power": "on",
                     "color": {"hue": 250.0,
                               "saturation": 0.5,
                               "kelvin": 3500},
                     "infrared": "1.0",
                     "brightness": 0.5,
                     "group": {"id": "1c8de82b81f445e7cfaafae49b259c71",
                               "name": "Lounge"},
                     "location": {"id": "1d6fe8ef0fde4c6d77b0012dc736662c",
                                  "name": "Home"},
コード例 #3
0
    def run(self):
        if self.state == self.Init:
            # Get the capture and identify the robots and objects.
            # Calculate the routes
            # Send the each routes to responsible robots.
            # Set current robot to zero
            # Set state to running

            (self.lowerRobot1, self.upperRobot1), (self.lowerRobot2, self.upperRobot2), \
                    (self.lowerRobot3, self.upperRobot3), (self.lowerRobot4, self.upperRobot4), \
                    (self.lowerObstacle, self.upperObstacle) = self.configure()
            

            # identify for 20 iterations and calculate the average x, y and angles for the robots
            # after this process, identify these(robot x values are scaler, but obstacles x's is a list):
            #(r1x, r1y)
            #(r2x, r2y)
            #(r3x, r3y)
            #(r4x, r4y)
            #(obsx, obsy)
            listObsx = None
            x1, y1, degree1, x2, y2, degree2, x3, y3, degree3, x4, y4, degree4, listObsx, listObsy = \
                self.findAllRobots(5, self.lowerRobot1, self.upperRobot1, self.lowerRobot2, self.upperRobot2, self.lowerRobot3, self.upperRobot3, \
                    self.lowerRobot4, self.upperRobot4, self.lowerObstacle, self.upperObstacle)
            
            print("First detection:",x1, y1, degree1, x2, y2, degree2, x3, y3, degree3, x4, y4, degree4, listObsx, listObsy)
            

            
            #while x1 == None or x2 == None or x3==None or x4 == None or listObsx == None:
            while x1 == None or x2 == None or len(listObsx)==0:
                print("Error detecting some robots or obstacles, re localizing.")
                x1, y1, degree1, x2, y2, degree2, x3, y3, degree3, x4, y4, degree4, listObsx, listObsy = \
                    self.findAllRobots(5, self.lowerRobot1, self.upperRobot1, self.lowerRobot2, self.upperRobot2, self.lowerRobot3, self.upperRobot3, \
                        self.lowerRobot4, self.upperRobot4, self.lowerObstacle, self.upperObstacle)

            
            print("Detected robots")
            #robot1start = Thing(Position(x1, y1), degree1, 3, "Start")
            #robot2end = Thing(Position(x2, y2), degree2, 3, "End")
            #robot2start = Thing(Position(x2, y2), degree1, 3, "Start")
            #robot3end = Thing(Position(x3, y3), degree1, 3, "End")
            #robot3start = Thing(Position(x3, y3), degree1, 3, "Start")
            #robot4end = Thing(Position(x4, y4), degree1, 3, "End")
            path1, path2, path3, path4 = None, None, None, None
                
            #came_from, cost_so_far, last = a_star_search(obstacles, robot1start, robot2end, 1, 1, 600)
            #path1 = createRoute(came_from, robot1start, last)
            
            # sx1,sy1 start x,y
            # gx1, gy1 goal x,y
            # ox, oy obstacles x,y
            # grid size
            
            
            grid_size = 12.0  # potential grid size [m]
            robot_radius = 5.0  # robot radius [m]
            rx1, ry1 = potential_field_planning(
                x1, y1, x2, y2, listObsx, listObsy, grid_size, robot_radius)
            #came_from, cost_so_far, last = a_star_search(obstacles, robot2start, robot3end, 3, 4, 200)
            #path2 = createRoute(came_from, robot1start, last)
            print("Calculated path planning")

            
            #came_from, cost_so_far, last = a_star_search(obstacles, robot3start, robot4end, 3, 4, 200)
            #path3 = createRoute(came_from, robot1start, last)

            #came_from, cost_so_far, last = a_star_search(obstacles, robot1start, robot2end, 3, 4, 200)
            #path4 = createRoute(came_from, robot1start, last)
            
            path1 = [(rx1[i], ry1[i]) for i in range(len(rx1))]
            path1 = path1[0::2]
            #path2=[(rx2[i], ry2[i]) for i in range(len(rx2))]
            #path3=[(rx3[i], ry3[i]) for i in range(len(rx3))]
            #path4=[(rx4[i], ry4[i]) for i in range(len(rx4))]
            
            print(path1)
            #print(path2)
            #print(path3)
            #print(path4)
            
            if path1:
                #image = drawGrid(box_count, size, things, path[1:-1])  
                start = State(path1[0][0], path1[0][1], math.radians(90))
                targets = [State(i,j, 0) for (i,j) in path1]
                del targets[0]
                self.conn1.send(Message.createRouteMessage(start, targets).__str__().encode())
            
                data = self.conn1.recv(self.BUFFER_SIZE)
                message = Message.create(data.decode())
                # TODO: Identifying the current robot location is not implemented yet
                if message.type == Message.OkMessageType:
                    self.robotIndex = 0
                    self.state = self.Start
            
            if path2:
                #image = drawGrid(box_count, size, things, path[1:-1])  
                start = State(path2[0][0], path2[0][1], math.radians(90))
                targets = [State(i,j, 0) for (i,j) in path2]
                del targets[0]
                self.conn2.send(Message.createRouteMessage(start, targets).__str__().encode())
            
                data = self.conn2.recv(self.BUFFER_SIZE)
                message = Message.create(data.decode())
                # TODO: Identifying the current robot location is not implemented yet
                if message.type == Message.OkMessageType:
                    self.robotIndex = 0
                    self.state = self.Start
            
            if path3:
                #image = drawGrid(box_count, size, things, path[1:-1])  
                start = State(path3[0][0], path3[0][1], math.radians(90))
                targets = [State(i,j, 0) for (i,j) in path3]
                del targets[0]
                self.conn3.send(Message.createRouteMessage(start, targets).__str__().encode())
            
                data = self.conn3.recv(self.BUFFER_SIZE)
                message = Message.create(data.decode())
                # TODO: Identifying the current robot location is not implemented yet
                if message.type == Message.OkMessageType:
                    self.robotIndex = 0
                    self.state = self.Start
            
            if path4:
                #image = drawGrid(box_count, size, things, path[1:-1])  
                start = State(path4[0][0], path4[0][1], math.radians(90))
                targets = [State(i,j, 0) for (i,j) in path4]
                del targets[0]
                self.conn4.send(Message.createRouteMessage(start, targets).__str__().encode())
            
                data = self.conn4.recv(self.BUFFER_SIZE)
                message = Message.create(data.decode())
                # TODO: Identifying the current robot location is not implemented yet
                if message.type == Message.OkMessageType:
                    self.robotIndex = 0
                    self.state = self.Start
                
            # after that, send these information to route calculator.
            #start, targets = routeCalculator(r1x, r1y, r2x, r2y, r3x, r3y, r4x, r4y, obsx, obsy)

            #TODO: these start and target values will be calculated in route calculator.
            #start = State(-20.0, 15.0, math.radians(90))
            #targets = [State(-20.0, 16.0, 0.0)]


        elif self.state == self.Start:
            # If current robot index is over than number of robots:
                # switch state to init TODO: or finish
            # else:
                # send start message to the current robot
                # set state to running

            if self.robotIndex == self.totalRobotCount:
                self.close()
            else:
                #TODO:In sending message, later we need to implement which robot we are sending the message
                if self.robotIndex == 0:
                    self.conn1.send(Message.createStartMessage().__str__().encode())
                elif self.robotIndex == 1:
                    self.conn2.send(Message.createStartMessage().__str__().encode())
                elif self.robotIndex == 2:
                    self.con3.send(Message.createStartMessage().__str__().encode())
                elif self.robotIndex == 3:
                    self.conn4.send(Message.createStartMessage().__str__().encode())
                
                self.state = self.Running
            

        elif self.state == self.Running:
            # Listen the socket until received a message
            # If the message is a GetLocationMessage:
                # Then identify the current robot
                # Send a LocationMessage to the robot including the location of the robot
            # else if the message is EndMessage:
                # set current robot index to next robot index
                # set state to start
            # else do nothing, pass

            if self.robotIndex == 0:
                data = self.conn1.recv(self.BUFFER_SIZE)
            elif self.robotIndex == 1:
                data = self.conn2.recv(self.BUFFER_SIZE)
            elif self.robotIndex == 2:
                data = self.conn3.recv(self.BUFFER_SIZE)
            elif self.robotIndex == 3:
                data = self.conn4.recv(self.BUFFER_SIZE)
            
            message = Message.create(data.decode())
            # TODO: Identifying the current robot location is not implemented yet
            if message.type == Message.GetLocationMessageType:

                # Calculate the robot location for 20 iteration and send the average values
                # self.robotIndex can help to identify robot color
                x1, y1, degree1, x2, y2, degree2, x3, y3, degree3, x4, y4, degree4, listObsx, listObsy = \
                self.findAllRobots(2, self.lowerRobot1, self.upperRobot1, self.lowerRobot2, self.upperRobot2, self.lowerRobot3, self.upperRobot3, \
                    self.lowerRobot4, self.upperRobot4, self.lowerObstacle, self.upperObstacle)

                if self.robotIndex == 0:
                    if not(x1 and y1 and degree1):
                        x1, y1, degree1 = 0, 0, 0

                    self.conn1.send(Message.createLocationMessage(State(x1, y1, math.radians(degree1))).__str__().encode())

                elif self.robotIndex == 1:
                    if not(x2 and y2 and degree2):
                        x2, y2, degree2 = 0, 0, 0
                    self.conn2.send(Message.createLocationMessage(State(x2, y2, math.radians(degree2))).__str__().encode())

                elif self.robotIndex == 2:
                    if not(x3 and y3 and degree3):
                        x3, y3, degree3 = 0, 0, 0
                    self.conn3.send(Message.createLocationMessage(State(x3, y3, math.radians(degree3))).__str__().encode())

                else:
                    if not(x4 and y4 and degree4):
                        x4, y4, degree4 = 0, 0, 0
                    self.conn4.send(Message.createLocationMessage(State(x4, y4, math.radians(degree4))).__str__().encode())

            elif message.type == Message.EndMessageType:
                self.robotIndex = self.robotIndex + 1
                self.state = self.Start

            else:
                pass

        else:
            pass
コード例 #4
0
def final_state2_c():
    state = State()
    state.can_be_one_symbol_word = False
    state.max_one_symbol_length = 0
    state.max_one_symbol_prefix = 0
    return state
コード例 #5
0
def final_state2_a():
    state = State()
    state.can_be_one_symbol_word = True
    state.max_one_symbol_length = 1
    state.max_one_symbol_prefix = 1
    return state
コード例 #6
0
def second_few_symbols_word_state():
    state = State()
    state.can_be_one_symbol_word = False
    state.max_one_symbol_length = 0
    state.max_one_symbol_prefix = 2
    return state
コード例 #7
0
def one_symbol_word_zero_length_state():
    state = State()
    state.can_be_one_symbol_word = False
    state.max_one_symbol_length = 0
    state.max_one_symbol_prefix = 3
    return state
コード例 #8
0
def one_symbol_word_with_long_prefix_state():
    state = State()
    state.can_be_one_symbol_word = True
    state.max_one_symbol_length = 1
    state.max_one_symbol_prefix = 6
    return state
コード例 #9
0
def one_symbol_word_state():
    state = State()
    state.can_be_one_symbol_word = True
    state.max_one_symbol_length = 1
    state.max_one_symbol_prefix = 2
    return state
コード例 #10
0
def result1():
    state = State()
    state.can_be_one_symbol_word = True
    state.max_one_symbol_length = 2
    state.max_one_symbol_prefix = 3
    return state
コード例 #11
0
def result3():
    state = State()
    state.can_be_one_symbol_word = False
    state.max_one_symbol_length = 0
    state.max_one_symbol_prefix = 5
    return state
コード例 #12
0
ファイル: query_funcs.py プロジェクト: kkktch/ECE650-Project4
def add_state(session, name_in):
    from main import State, Team, Color, Player
    new_state = State(name=name_in)
    session.add(new_state)
    session.commit()
    return
コード例 #13
0
    def run(self):
        if self.state == self.Init:
            # Get the capture and identify the robots and objects.
            # Calculate the routes
            # Send the each routes to responsible robots.
            # Set current robot to zero
            # Set state to running

            # For now, skipping the capture and identifying process
            # These will be implemented later
            start = State(-20.0, 15.0, math.radians(90))
            targets = [State(-20.0, 16.0, 0.0)]

            self.conn.send(
                Message.createRouteMessage(start, targets).__str__().encode())

            data = self.conn.recv(self.BUFFER_SIZE)
            message = Message.create(data.decode())
            # TODO: Identifying the current robot location is not implemented yet
            if message.type == Message.OkMessageType:
                self.robotIndex = 0
                self.state = self.Start

        elif self.state == self.Start:
            # If current robot index is over than number of robots:
            # switch state to init TODO: or finish
            # else:
            # send start message to the current robot
            # set state to running

            if self.robotIndex == self.totalRobotCount:
                self.close()
            else:
                #TODO:In sending message, later we need to implement which robot we are sending the message
                self.conn.send(Message.createStartMessage().__str__().encode())
                self.state = self.Running

        elif self.state == self.Running:
            # Listen the socket until received a message
            # If the message is a GetLocationMessage:
            # Then identify the current robot
            # Send a LocationMessage to the robot including the location of the robot
            # else if the message is EndMessage:
            # set current robot index to next robot index
            # set state to start
            # else do nothing, pass

            data = self.conn.recv(self.BUFFER_SIZE)
            message = Message.create(data.decode())
            # TODO: Identifying the current robot location is not implemented yet
            if message.type == Message.GetLocationMessageType:
                self.conn.send(
                    Message.createLocationMessage(
                        State(-20.0, 15.3,
                              math.radians(135))).__str__().encode())

            elif message.type == Message.EndMessageType:
                self.robotIndex = self.robotIndex + 1
                self.state = self.Start

            else:
                pass

        else:
            pass