예제 #1
0
def getTransitionConnectingStates(graph, s1, s2):
    '''
    Get transition edge connecting two states of the constraint graph
    Input:
      - graph: the manipulation constraint graph,
      - s1, s2: states of the constraint graph
    '''
    # Filter out waypoint and levelset edges from the constraint graph
    p = re.compile('\|.*_.*')
    _edges = set(filter(lambda s: p.search(s) is None, graph.edges.keys()))
    for edge in _edges:
        node1, node2 = cg.getNodesConnectedByEdge(edge)
        if StateName(node1) == s1 and StateName(node2) == s2:
            return edge
예제 #2
0
def getEdges(graph, nodes, exploreNodes):
    '''
  Build list of edges linking a list of nodes

  Input:
    - graph: the manipulation constraint graph,
    - nodes: list of nodes the solution path should visit,
    - exploreNodes: states in which to perform path planning to cross an edge
                    this list contains the same number of element as the
                    resulting list of edges.
  Return
    - edges: list of edges the resulting path should cross,
    - loops: list of loop transitions of each element of list "exploreNodes".
             These transitions are used to perform exploration in order to cross
             edges of list "edges".
  '''
    edges = list()
    loops = list()
    # Filter out waypoint and levelset edges from the constraint graph
    p = re.compile('\|.*_.*')
    _edges = set(filter(lambda s: p.search(s) is None, graph.edges.keys()))
    for n1, n2, n3 in zip(nodes, nodes[1:], exploreNodes):
        edgeFound = False
        loopFound = False
        for edge in _edges:
            node1, node2 = cg.getNodesConnectedByEdge(edge)
            if StateName(node1) == n1 and StateName(node2) == n2:
                edges.append(edge)
                edgeFound = True
            if StateName(node1) == n3 and StateName(node2) == n3:
                loops.append(edge)
                loopFound = True
            if edgeFound and loopFound:
                break
        if not edgeFound:            raise RuntimeError \
('cannot find edge from node "{0}" to "{1}"'.format (n1, n2))
        if not loopFound:            raise RuntimeError \
('cannot find edge from node "{0}" to "{1}"'.format (n1, n1))
    return edges, loops
예제 #3
0
    y = -y

q0 = q0_r0 + q0_r1 + sum(q0_spheres, []) + sum(q0_cylinders, [])
if display:
    v(q0)

# List of nodes composing the assembly sequence
nodes = list()
# List of rules that define all the nodes
rules = list()
# List of grasps for each node. From any node to the next one, one grasp is
# added or removed
grasps = set()
# list of nodes that are explored to cross each edge
exploreNodes = list()
nodes.append(StateName(grasps))
rules.append(makeRule(grasps=grasps))
# grasp sphere0
grasps.add(('r0/gripper', 'sphere0/handle'))
nodes.append(StateName(grasps))
rules.append(makeRule(grasps=grasps))
exploreNodes.append(nodes[-2])

# grasp cylinder0
grasps.add(('r1/gripper', 'cylinder0/handle'))
nodes.append(StateName(grasps))
rules.append(makeRule(grasps=grasps))
exploreNodes.append(nodes[-2])

# assemble cylinder0 and sphere0
grasps.add(('cylinder0/magnet0', 'sphere0/magnet'))
예제 #4
0
 def getState (cg, nodeName) :
     for n in cg.nodes:
         if StateName (n) == nodeName : return n
     raise KeyError (nodeName)
예제 #5
0
turtle.shape(image)
screen.setup(width=725, height=491)

correct_answer_count = 0
correct_answers = []
input_box_title = "Guess the State"
states_data = pandas.read_csv("50_states.csv")
all_states = states_data.state.tolist()
while correct_answer_count != 50:
    answer_state = screen.textinput(
        title=input_box_title, prompt="What's another state's name?").title()
    # print(states_data.state)
    # print(answer_state in states_data.state.tolist())
    if answer_state == "Exit":
        missing_states = [
            state for state in all_states if state not in correct_answers
        ]
        missing_states_df = pandas.DataFrame(missing_states)
        missing_states_df.to_csv("missing_states.csv")
        break

    if answer_state in all_states:
        state_name = StateName()
        state_x = int(states_data[states_data.state == answer_state].x)
        state_y = int(states_data[states_data.state == answer_state].y)
        state_name.update_state_name(answer_state, state_x, state_y)
        if answer_state not in correct_answers:
            correct_answer_count += 1
            correct_answers.append(answer_state)
    input_box_title = f"{correct_answer_count}/50 States Correct"