Home ]Software ]Curriculum ]Hardware ]Community ]News ]Publications ]Search ]


Here is an all-Python solution for starting two robots in one simulator, letting it run for 20 seconds, and then stopping both of them:


# 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()


[ download] [ edit]

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.


Home ]Software ]Curriculum ]Hardware ]Community ]News ]Publications ]Search ]

CreativeCommons View Wiki Source | Edit Wiki Source | Mail Webmaster