Esempio n. 1
0
def buildExperiment(net,wa,wb,wc,visibility=False):
    
    #simName = util.randomString(20);
    #simName = print(''.join(random.choice(string.ascii_uppercase) for i in range(20)))
    simName = ''.join(random.choice(string.ascii_uppercase) for i in range(20))
    net.add_to_nengo()  
    numsensors=4                                # number of agents sensors (if changed, need to read correct values in the Controller)
    
    simulator = vivae.init(net,"data/scenarios/test/walls.svg", True)
    #simulator = oneAgent(net,agentName='a',numSensors=numsensors,maxDistance=120, frictionDistance=0,nameSpace=simName,visible=visibility);
    v = simulator.getControls()
    #vivae = simulator.getControls();
    v.addAgent('a',2*numsensors,    120          ,0)
    v.callStartSimulation()
    

    # Input->LI
    controller = net.add(EventGenerator('Turn',numsensors*2+1,2,1));            # event generator
    input = net.make_input('bias1',[1])                                                     # should result in 0, 0, .33
    net.connect(input, controller.getTermination('params'))
    net.connect(simulator.getAgent('a').getOrigin(),controller.getTermination('inputs'))    # connect agent with controller

    # LII->LIII->Output
    input2 = net.make_input('bias2',[1])
    summer = net.add(Summer('Go Straight'));
    net.connect(input2,summer.getTermination('inputBias'));
    net.connect(controller.getOrigin('outputs'),summer.getTermination('inputData'))
    net.connect(summer.getOrigin('outputs'),simulator.getAgent('a').getTermination())

    saver = net.add(SpeedSaver('avg'))
    net.connect(simulator.getAgent('a').getOrigin(),saver.getTermination('data'));
    #saver = net.add(DataSaver('saver')) # save data ??
    return simulator
Esempio n. 2
0
def buildExperiment(net, wa, wb, wc, visibility=True):

    numsensors = 4  # number of agents sensors (if changed, need to read correct values in the Controller)

    simulator = vivae.init(net, "data/scenarios/test/walls.svg", True)
    # simulator = oneAgent(net,agentName='a',numSensors=numsensors,maxDistance=120, frictionDistance=0,nameSpace=simName,visible=visibility);
    v = simulator.getControls()

    v.addAgent("a", 2 * numsensors, 120, 0)
    v.callSetVisibility(False)
    v.callStartSimulation()

    # Input->LI
    controller = net.add(EventGenerator("Agent controller", numsensors * 2 + 1, 2, 1))
    # event generator
    input = net.make_input("bias1", [1])  # should result in 0, 0, .33
    net.connect(input, controller.getTermination("params"))
    net.connect(
        simulator.getAgent("a").getOrigin(), controller.getTermination("inputs")
    )  # connect agent with controller

    # LII->LIII->Output
    input2 = net.make_input("bias2", [1])
    summer = net.add(Summer("Summator"))
    net.connect(input2, summer.getTermination("inputBias"))
    net.connect(controller.getOrigin("outputs"), summer.getTermination("inputData"))
    net.connect(summer.getOrigin("outputs"), simulator.getAgent("a").getTermination())

    saver = net.add(SpeedSaver("avg"))
    net.connect(simulator.getAgent("a").getOrigin(), saver.getTermination("data"))
    # saver = net.add(DataSaver('saver')) # save data ??
    return simulator
Esempio n. 3
0
def make(net,name='Vivae Simulator', mapName="data/scenarios/arena1.svg", numSensors=4, maxdist=30,frictdist=50,independent=True, useQuick=True):
    numSensors = numSensors*2

    simulator = vivae.init(net, mapName, True)
    v = simulator.getControls()    
    v.callSetVisibility(True)

    agentNames = ['a','b','c','d','e','f','g','h','i','j','k','l','m']

    # run as many agents as map can hold (up to a-m)  
    for i in range(0, len(agentNames)):
        print 'adding this guy '+agentNames[i]
        v.tryToAddAgent(agentNames[i], numSensors, maxdist, frictdist)

    print 'starting the vivae simulation'

    v.callStartSimulation()
    print 'Vivae is started.'
Esempio n. 4
0
        sensorydata = simulator.getAgent('a').getOrigin().getValues().getValues(); # columns: time, [distance sensors from the left, friction sensors from the left]
        actuatordata = controller.getOrigin('outputs').getValues().getValues();    # columns: time, left_wheel, right_wheel

        i.write('%1.3f,%s\n'%(self.t,list(sensorydata)))
        o.write('%1.3f,%s\n'%(self.t,list(actuatordata)))
        i.close()
        o.close()
        
#################################################################################
net=nef.Network('Vivae - hardwired PI controller for agent')
net.add_to_nengo()  

numsensors=4                          # number of agents sensors (if changed, need to read correct values in the Controller)

simulator = vivae.init(net,'data/scenarios/test/wallsII.svg', True)
v = simulator.getControls()
v.addAgent('a',2*numsensors,    120          ,0)
v.callStartSimulation()

controller = net.add(Controller('Agent controller', 2*numsensors+1,2,0)); # build controller

net.connect(simulator.getAgent('a').getOrigin(),controller.getTermination('inputs'))    # connect agent with controller
net.connect(controller.getOrigin('outputs'), simulator.getAgent('a').getTermination())  # connect controller to the agent


saver = net.add(DataSaver('saver')) # save data ??

t=2;
dt=0.001;
print "OK, configuration done. Simulating network for "+repr(t)+" seconds"
Esempio n. 5
0
        sensorydata = simulator.getAgent('a').getOrigin().getValues().getValues(); # columns: time, [distance sensors from the left, friction sensors from the left]
        actuatordata = controller.getOrigin('outputs').getValues().getValues();    # columns: time, left_wheel, right_wheel

        i.write('%1.3f,%s\n'%(self.t,list(sensorydata)))
        o.write('%1.3f,%s\n'%(self.t,list(actuatordata)))
        i.close()
        o.close()

################################################################################# here is the script
net=nef.Network('Vivae - hardwired control for agent')
net.add_to_nengo()  

numsensors=4                                # number of agents sensors (if changed, need to read correct values in the Controller)

simulator = vivae.init(net,"data/scenarios/test/walls.svg", True)
v = simulator.getControls()
v.addAgent('a',2*numsensors,    120          ,0)
v.callStartSimulation()


controller = net.add(Controller('Agent controller',2*numsensors+1, 2, 0 )); # build controller

net.connect(simulator.getAgent('a').getOrigin(),controller.getTermination('inputs'))    # connect agent with controller
net.connect(controller.getOrigin('outputs'), simulator.getAgent('a').getTermination())

saver = net.add(DataSaver('saver'))         # save data??

t=0.5;
dt=0.001;
print "OK, configuration done. Simulating network for "+repr(t)+" seconds and saving data to files"