1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# Multiple brains in a single program.
from pyrobot.engine import Engine
import time
# Parameters for starting an engine:
robotfile1 = "Player6665"
brainfile1 = "ChaseRedProgram"
simulator1 = "StageSimulator"
brainargs1 = []
worldfile1 = "chase.cfg"
devices1 = []
robotfile2 = "Player6666"
brainfile2 = "ChaseGreenProgram"
simulator2 = None
brainargs2 = []
worldfile2 = ""
devices2 = []
# Create the engines:
eng1 = Engine(robotfile1, brainfile1, simulator1, brainargs1, {}, worldfile1, devices1)
eng2 = Engine(robotfile2, brainfile2, simulator2, brainargs2, {}, worldfile2, devices2)
# Wait for them to get initialized:
# (this may not be needed with Pyro4)
time.sleep(3)
# Start them up:
eng1.pleaseRun()
eng2.pleaseRun()
# Let them run for awhile:
time.sleep(20)
# stop them , and quit:
eng1.pleaseStop()
eng2.pleaseStop()
eng1.shutdown()
eng2.shutdown() |
Save this example as MultipleBrainsProgram.py. Notice that this example uses the ChaseRedProgram.py and ChaseGreenProgram.py brains from before. To execute it do:
python MultipleBrainsProgram.py
Make sure that you have the PYROBOT environment variable set, for example:
export PYROBOT=/usr/local/lib/python24/site-packages/pyrobot
Return to PyroModuleMultirobot.
