Commit 7f49bccc authored by Chanelle Lee's avatar Chanelle Lee
Browse files

Merge branch 'cleanUp'

Forgot to merge branch on desktop end, so merging that CleanUp branch now.
parents 7c54eeb8 9d430963
......@@ -30,7 +30,20 @@ def main(numSims=1):
time.sleep(5)
logger_b.info('Now on simulation {}'.format(i))
logger_p.info('Now on simulation {}'.format(i))
run()
try:
controllerJobs = setUp()
# Start all threads
for p in controllerJobs:
p.start()
time.sleep(0.1)
# Wait for all threads to finish
for p in controllerJobs:
p.wait()
except KeyboardInterrupt:
print "Ctrl-C pressed..."
for p in controllerJobs:
p.stop()
sys.exit(1)
time.sleep(5)
eretCode = vrep.simxStopSimulation(clientID, vrep.simx_opmode_oneshot)
if eretCode > 1:
......@@ -40,28 +53,23 @@ def main(numSims=1):
time.sleep(240)
def run():
def setUp():
optionsList = [0, 1, 2, 3, 4]
w = 1.0
noise = 0.1
poolSize = 2
numEpucks = 5 # 20
ePucks = []
populationBeliefs = (1.0/len(optionsList)) * np.ones((numEpucks,
len(optionsList)))
for i, p in enumerate(populationBeliefs):
ePucks.append(EPuckSim(i, p, w, optionsList, noise))
ePucks.append(EPuckSim(i, p, w, optionsList, noise, poolSize))
time.sleep(0.1)
controllerJobs = [ControllerThread(name='controller{}'.format(e.ID),
ePuck=e) for e in ePucks]
# Start all threads
for p in controllerJobs:
p.start()
time.sleep(0.1)
# Wait for all threads to finish
for p in controllerJobs:
p.join()
return controllerJobs
if __name__ == '__main__':
......
[loggers]
keys = root, ePucks, path, joints, proxSensors, lightSensors, botSimMain, bestOfN_lightReadings, myThreads, beliefLogger, main, poolLogger
keys = root, ePucks, path, joints, proxSensors, lightSensors, botSimMain, bestOfN_lightReadings, myThreads, beliefLogger, main, evidenceLogger
[handlers]
keys = consoleHandler, fileHandler, beliefFileHandler, poolFileHandler
keys = consoleHandler, fileHandler, beliefFileHandler, evidenceFileHandler
[formatters]
keys=defaultFormatter, beliefFormatter
keys=defaultFormatter, dataFormatter
[logger_root]
handlers = consoleHandler
[logger_main]
handlers = consoleHandler
level = DEBUG
level = INFO
qualname = main
propagate = 0
......@@ -66,14 +66,14 @@ propagate = 0
[logger_beliefLogger]
handlers = beliefFileHandler
level = WARNING
level = INFO
qualname = beliefLogger
propagate = 0
[logger_poolLogger]
handlers = poolFileHandler
level = WARNING
qualname = poolLogger
[logger_evidenceLogger]
handlers = evidenceFileHandler
level = INFO
qualname = evidenceLogger
propagate = 0
[handler_consoleHandler]
......@@ -88,16 +88,16 @@ args=('botSim.log', 'w',)
[handler_beliefFileHandler]
class=logging.FileHandler
formatter=beliefFormatter
formatter=dataFormatter
args=('botSim_beliefs.log', 'w')
[handler_poolFileHandler]
[handler_evidenceFileHandler]
class=logging.FileHandler
formatter=beliefFormatter
args=('botSim_pools.log', 'w')
formatter=dataFormatter
args=('botSim_evidence.log', 'w')
[formatter_defaultFormatter]
format="%(asctime)s [%(levelname)s] (%(threadName)-10s) %(name)s: %(message)s"
[formatter_beliefFormatter]
format="%(asctime)s (%(threadName)-10s) %(name)s: %(message)s"
[formatter_dataFormatter]
format=%(asctime)s, %(message)s
This diff is collapsed.
......@@ -74,6 +74,7 @@ class LightSensor(object):
def retLightSensorReading(self):
try:
reading = self.readLightSensor()[11]
logger.info('Bare light reading is {}'.format(reading))
noise = np.random.normal(loc=0.0,
scale=self._sigma)
noisyReading = reading + noise
......
......@@ -20,6 +20,9 @@ class StoppableThread(threading.Thread):
def stopped(self):
return self._stop_event.is_set()
def wait(self):
self._stop_event.wait()
class ControllerThread(threading.Thread):
......@@ -32,11 +35,15 @@ class ControllerThread(threading.Thread):
def stop(self):
logger.debug('ControllerThread is set to stop')
self.ePuck.cleanUp()
self._stop_event.set()
def stopped(self):
return self._stop_event.is_set()
def wait(self):
self._stop_event.wait()
def run(self):
logger.debug('ControllerThread is starting.')
retFlag = False
......@@ -50,10 +57,9 @@ class ControllerThread(threading.Thread):
class BroadcastingThread(threading.Thread):
def __init__(self, name, ePuck, message, messageName):
def __init__(self, name, ePuck, messageName):
super(BroadcastingThread, self).__init__()
self.daemon = True
self.message = message
self.messageName = messageName
self.ePuck = ePuck
self._stop_event = threading.Event()
......@@ -63,12 +69,18 @@ class BroadcastingThread(threading.Thread):
logger.debug('BroadcastingThread is set to stop')
self._stop_event.set()
def wait(self):
self._stop_event.wait()
def stopped(self):
return self._stop_event.is_set()
def run(self):
logger.debug('BroadcastingThread is starting.')
while not self.stopped():
self.ePuck.sendMessage(self.message, self.messageName)
# Message is set from the ePuck side allowing for msg changes
# without having to stop and start Broacasting Threads
self.ePuck.sendMessage(self.ePuck.msgToSend,
self.messageName)
time.sleep(random.random())
logger.debug('BroadcastingThread has finished')
......@@ -15,7 +15,7 @@ class Site(object):
self._name = "Site#" + str(siteID)
self.handle = None
self.position = None
self.radius = 0.15
self.radius = 0.1
self.margin = 20
def getSiteHandle(self):
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment