Beispiel #1
0
def makeMotor(emf, nodes):
    return [cc.Resistor(Rm, nodes[0], 'emf'),
            cc.VSrc(emf, 'emf', nodes[1])]
Beispiel #2
0
def makeVoltage(value, nodes):
    return [cc.VSrc(value, nodes[0], nodes[1])]
Beispiel #3
0
def verifyCircuit(componentList):
    circuit = Circ()
    cdict = componentDict(componentList)
    circuit.componentDictFull = cdict
    discard = []
    powerNodes = traceElement('Power', componentList, cdict)
    groundNodes = traceElement('Ground', componentList, cdict)
    powerSrc = []
    groundSrc = []
    probePos = []
    probeNeg = []
    print 'powerNodes=', powerNodes
    print 'groundNodes=', groundNodes
    for element in componentList:
        name = element.__class__.__name__
        if name == 'GroundInput':
            discard.append(element)
            node = element.v1Name
            if not connectedTo(cdict[node], groundNodes):
                warn('%s ground at %s not connected to ground'%(element.type, node))
                return None
        elif name == 'PowerInput':
            discard.append(element)
            node = element.v1Name
            if not connectedTo(cdict[node], powerNodes):
                warn('%s power at %s not connected to power'%(element.type, node))
                return None
        elif name == 'Power':
            discard.append(element)
            powerSrc.append(element.v1Name)
        elif name == 'Ground':
            discard.append(element)
            groundSrc.append(element.v1Name)
        elif name == 'Probe':
            discard.append(element)
            if element.type == 'Pos':
                probePos.append(element.v1Name)
            elif element.type == 'Neg':
                probeNeg.append(element.v1Name)
        elif name == 'Pot':
            discard.append(element)
            circuit.pots.append(element.nodeNames)
        elif name == 'Connector':
            discard.append(element)
            if element.type == 'Robot':
                circuit.robotConnections = element.nodeNames
            if element.type == 'Head':
                circuit.headConnections = element.nodeNames
            elif element.type == 'Motor':
                circuit.motorConnections = element.nodeNames
        else:
            connection = False
            for node in element.nodeNames:
                connections = cdict[node]
                if len(connections) == 1:
                    warn('Element %s not connected to anything at node %s'%(str(element), node))
                else:
                    connection = True
            if connection == False:
                warn('Element %s is disconnected, discarding it'%(str(element)))
                discard.append(element)
            if hasDuplicate(element.nodeNames):
                warn('Element %s has duplicate nodes, discarding it'%(str(element)))
                discard.append(element)
                return None

    # print componentList
    
    if len(groundSrc) != 1:
        warn('There should be exactly one ground!')
        return None
    else:
        circuit.groundNode = groundSrc[0]

    if len(powerSrc) < 1:
        warn('There should be power going to the circuit!')
        return None

    if len(probePos) == 1 and len(probeNeg) == 1:
        circuit.probes = [probePos[0], probeNeg[0]]
    else:
        if len(probePos) > 1 or len(probeNeg) > 1:
            warn('Only one set of probes is supported.')
            return None
        if len(probePos) != len(probeNeg):
            warn('There must be exactly one positive and one negative probe.')
            return None
    # add Vsrcs
    for power in powerSrc:
        componentList.append(cc.VSrc(sourceVoltage, power, groundSrc[0]))

    if circuit.headConnections and circuit.motorConnections:
        warn('Only one motor connector at a time is supported.')
        return None

    circuit.components = [element for element in componentList if not element in discard]
    circuit.componentDict = componentDict(circuit.components)

    return circuit