diff --git a/GoPiGoConnectome.py b/GoPiGoConnectome.py index fe950a2..b2d9894 100644 --- a/GoPiGoConnectome.py +++ b/GoPiGoConnectome.py @@ -1,10 +1,14 @@ # GoPiGo Connectome # Written by Timothy Busbice, Gabriel Garrett, Geoffrey Churchill (c) 2014, in Python 2.7 +# Modified by John Cole in 2019 to work with Python 3.x and the GoPiGo3 # The GoPiGo Connectome uses a Postsynaptic dictionary based on the C Elegans Connectome Model # This application can be ran on the Raspberry Pi GoPiGo robot with a Sonar that represents Nose Touch when activated # To run standalone without a GoPiGo robot, simply comment out the sections with Start and End comments ## Start Comment -from gopigo import * +from easygopigo3 import EasyGoPiGo3 # importing the EasyGoPiGo3 class +gpg = EasyGoPiGo3() # instantiating a EasyGoPiGo3 object +gpg.reset_all() # Unconfigure the sensors, disable the motors, and restore the LED to the control of the GoPiGo3 firmware. +my_distance_sensor = gpg.init_distance_sensor() ## End Comment import time @@ -4801,42 +4805,42 @@ def motorcontrol(): new_speed = 150 elif new_speed < 75: new_speed = 75 - print "Left: ", accumleft, "Right:", accumright, "Speed: ", new_speed + print("Left: ", accumleft, "Right:", accumright, "Speed: ", new_speed) ## Start Commented section - set_speed(new_speed) + gpg.set_speed(new_speed) if accumleft == 0 and accumright == 0: - stop() + gpg.stop() elif accumright <= 0 and accumleft < 0: - set_speed(150) + gpg.set_speed(150) turnratio = float(accumright) / float(accumleft) # print "Turn Ratio: ", turnratio if turnratio <= 0.6: - left_rot() + gpg.left() time.sleep(0.8) elif turnratio >= 2: - right_rot() + gpg.right() time.sleep(0.8) - bwd() + gpg.backward() time.sleep(0.5) elif accumright <= 0 and accumleft >= 0: - right_rot() + gpg.right() time.sleep(.8) elif accumright >= 0 and accumleft <= 0: - left_rot() + gpg.left() time.sleep(.8) elif accumright >= 0 and accumleft > 0: turnratio = float(accumright) / float(accumleft) # print "Turn Ratio: ", turnratio if turnratio <= 0.6: - left_rot() + gpg.left() time.sleep(0.8) elif turnratio >= 2: - right_rot() + gpg.right() time.sleep(0.8) - fwd() + gpg.forward() time.sleep(0.5) else: - stop() + gpg.stop() ## End Commented section accumleft = 0 accumright = 0 @@ -4872,8 +4876,8 @@ def runconnectome(): # Create the dictionary createpostsynaptic() dist=0 -set_speed(120) -print "Voltage: ", volt() +gpg.set_speed(120) +print("Voltage: ", gpg.volt()) tfood = 0 try: ### Here is where you would put in a method to stimulate the neurons ### @@ -4883,13 +4887,13 @@ def runconnectome(): while True: ## Start comment - use a fixed value if you want to stimulte nose touch ## use something like "dist = 27" if you want to stop nose stimulation - dist = us_dist(15) + dist = my_distance_sensor.read_mm() ## End Comment #Do we need to switch states at the end of each loop? No, this is done inside the runconnectome() #function, called inside each loop. - if dist>0 and dist<30: - print "OBSTACLE (Nose Touch)", dist + if dist>0 and dist<100: + print("OBSTACLE (Nose Touch)", dist) dendriteAccumulate("FLPR") dendriteAccumulate("FLPL") dendriteAccumulate("ASHL") @@ -4903,8 +4907,8 @@ def runconnectome(): runconnectome() else: if tfood < 2: - print "FOOD" - print (thisState) + print("FOOD") + print(thisState) dendriteAccumulate("ADFL") dendriteAccumulate("ADFR") dendriteAccumulate("ASGR") @@ -4925,6 +4929,6 @@ def runconnectome(): ## Start Comment stop() ## End Comment - print "Ctrl+C detected. Program Stopped!" + print("Ctrl+C detected. Program Stopped!") for pscheck in postsynaptic: - print (pscheck,' ',postsynaptic[pscheck][0],' ',postsynaptic[pscheck][1]) \ No newline at end of file + print(pscheck,' ',postsynaptic[pscheck][0],' ',postsynaptic[pscheck][1]) \ No newline at end of file diff --git a/connectome.py b/connectome.py index 1a15220..6f2b633 100644 --- a/connectome.py +++ b/connectome.py @@ -1,5 +1,6 @@ # GoPiGo Connectome # Written by Timothy Busbice, Gabriel Garrett, Geoffrey Churchill (c) 2014, in Python 2.7 +# Modified by John Cole in 2019 to work with Python 3.x and the GoPiGo3 # The GoPiGo Connectome uses a postSynaptic dictionary based on the C Elegans Connectome Model # This application can be ran on the Raspberry Pi GoPiGo robot with a Sonar that represents Nose Touch when activated # To run standalone without a GoPiGo robot, simply comment out the sections with Start and End comments @@ -21,10 +22,13 @@ disembodied = parser.parse_args().disembodied verbosity = parser.parse_args().verbose -print "Running on Robot: " + str(not disembodied) +print("Running on Robot: " + str(not disembodied)) if not disembodied: - from gopigo import fwd, bwd, left_rot, right_rot, stop, set_speed, us_dist, volt + # from gopigo import , bwd, left_rot, right_rot, stop, set_speed, us_dist, volt + from easygopigo3 import EasyGoPiGo3 # importing the EasyGoPiGo3 class + gpg = EasyGoPiGo3() # instantiating a EasyGoPiGo3 object + my_distance_sensor = gpg.init_distance_sensor() import time import copy @@ -40,6 +44,9 @@ thisState = 0 nextState = 1 +dist=0 +tfood = 0 + # The Threshold is the maximum sccumulated value that must be exceeded before # the Neurite will fire threshold = 30 @@ -4827,48 +4834,48 @@ def motorcontrol(): # We turn the wheels according to the motor weight accumulation new_speed = abs(accumleft) + abs(accumright) - if new_speed > 150: - new_speed = 150 + if new_speed > 300: + new_speed = 300 elif new_speed < 75: new_speed = 75 if verbosity > 1: - print "Left: ", accumleft, "Right:", accumright, "Speed: ", new_speed + print("Left: ", accumleft, "Right:", accumright, "Speed: ", new_speed) if not disembodied: - set_speed(new_speed) + gpg.set_speed(new_speed) if accumleft == 0 and accumright == 0: - stop() + gpg.stop() elif accumright <= 0 and accumleft < 0: - set_speed(150) + gpg.set_speed(300) turnratio = float(accumright) / float(accumleft) # print "Turn Ratio: ", turnratio if turnratio <= 0.6: - left_rot() + gpg.left() # left_rot() time.sleep(0.8) elif turnratio >= 2: - right_rot() + gpg.right() # right_rot() time.sleep(0.8) - bwd() + gpg.backward() time.sleep(0.5) elif accumright <= 0 and accumleft >= 0: - right_rot() + gpg.right() # right_rot() time.sleep(.8) elif accumright >= 0 and accumleft <= 0: - left_rot() + gpg.left() # left_rot() time.sleep(.8) elif accumright >= 0 and accumleft > 0: turnratio = float(accumright) / float(accumleft) # print "Turn Ratio: ", turnratio if turnratio <= 0.6: - left_rot() + gpg.left() # left_rot() time.sleep(0.8) elif turnratio >= 2: - right_rot() + gpg.right() # right_rot() time.sleep(0.8) - fwd() + gpg.forward() # fwd() time.sleep(0.5) else: - stop() + gpg.stop() # stop() accumleft = 0 accumright = 0 @@ -4918,23 +4925,29 @@ def runconnectome(): # Create the dictionary createpostSynaptic() -dist=0 - if not disembodied: - set_speed(120) - print "Voltage: ", volt() + gpg.set_speed(250) + print("Voltage: ", gpg.volt()) + -tfood = 0 def main(): """Here is where you would put in a method to stimulate the neurons We stimulate chemosensory neurons constantly unless nose touch (sonar) is stimulated and then we fire nose touch neurites. """ - + + tfood = 0 + while True: + # print("GOING!") + if not disembodied: - dist = us_dist(15) + # dist = us_dist(15) + print("Distance Sensor Reading: {} mm ".format(my_distance_sensor.read_mm())) + dist = my_distance_sensor.read_mm() + + else: # use a fixed value if you want to stimulte nose touch # use something like "dist = 27" if you want to stop nose stimulation @@ -4942,9 +4955,10 @@ def main(): # Do we need to switch states at the end of each loop? No, this is done inside the runconnectome() # function, called inside each loop. - if dist>0 and dist<30: + if dist>0 and dist < 100: + # if dist < 50: if verbosity > 0: - print "OBSTACLE (Nose Touch)", dist + print("OBSTACLE (Nose Touch)", dist) dendriteAccumulate("FLPR") dendriteAccumulate("FLPL") dendriteAccumulate("ASHL") @@ -4959,7 +4973,7 @@ def main(): else: if tfood < 2: if verbosity > 0: - print "FOOD" + print("FOOD") dendriteAccumulate("ADFL") dendriteAccumulate("ADFR") dendriteAccumulate("ASGR") @@ -4978,9 +4992,9 @@ def keyboard_interrupt_handler(a, b): """Use CNTRL-C to stop the program.""" if not disembodied: - stop() + gpg.stop() - print "Ctrl+C detected. Program Stopped!" + print("Ctrl+C detected. Program Stopped!") for pscheck in postSynaptic: print (pscheck,' ',postSynaptic[pscheck][0],' ',postSynaptic[pscheck][1]) @@ -4988,5 +5002,4 @@ def keyboard_interrupt_handler(a, b): if __name__ == '__main__': signal.signal(signal.SIGINT, keyboard_interrupt_handler) - main() - + main() \ No newline at end of file diff --git a/disembodiedConnectome.py b/disembodiedConnectome.py index bbe8c3b..0ebab9a 100644 --- a/disembodiedConnectome.py +++ b/disembodiedConnectome.py @@ -1,5 +1,6 @@ # GoPiGo Connectome # Written by Timothy Busbice, Gabriel Garrett, Geoffrey Churchill (c) 2014, in Python 2.7 +# Modified by John Cole in 2019 to work with Python 3.x and the GoPiGo3 # The GoPiGo Connectome uses a postSynaptic dictionary based on the C Elegans Connectome Model # This application can be ran on the Raspberry Pi GoPiGo robot with a Sonar that represents Nose Touch when activated # To run standalone without a GoPiGo robot, simply comment out the sections with Start and End comments @@ -4805,9 +4806,9 @@ def motorcontrol(): accumleft += postSynaptic[muscle][nextState] #accumleft = accumleft + postSynaptic[muscle][thisState] #what??? For some reason, thisState weight is always 0. #postSynaptic[muscle][thisState] = 0 - print muscle, "Before", postSynaptic[muscle][thisState], accumleft #Both states have to be set to 0 once the muscle is fired, or + print(muscle, "Before", postSynaptic[muscle][thisState], accumleft) #Both states have to be set to 0 once the muscle is fired, or postSynaptic[muscle][nextState] = 0 - print muscle, "After", postSynaptic[muscle][thisState], accumleft # it will keep returning beyond the threshold within one iteration. + print(muscle, "After", postSynaptic[muscle][thisState], accumleft) # it will keep returning beyond the threshold within one iteration. elif muscle in mRight: accumright += postSynaptic[muscle][nextState] #accumleft = accumright + postSynaptic[muscle][thisState] #what??? @@ -4820,7 +4821,7 @@ def motorcontrol(): new_speed = 150 elif new_speed < 75: new_speed = 75 - print "Left: ", accumleft, "Right:", accumright, "Speed: ", new_speed + print("Left: ", accumleft, "Right:", accumright, "Speed: ", new_speed) accumleft = 0 accumright = 0 ## Start Commented section @@ -4907,7 +4908,7 @@ def runconnectome(): createpostSynaptic() dist=0 #set_speed(120) -print "Voltage: "#, volt() +print("Voltage: ")#, volt()) tfood = 0 try: ### Here is where you would put in a method to stimulate the neurons ### @@ -4922,7 +4923,7 @@ def runconnectome(): #Do we need to switch states at the end of each loop? No, this is done inside the runconnectome() #function, called inside each loop. if dist>0 and dist<30: - print "OBSTACLE (Nose Touch)", dist + print("OBSTACLE (Nose Touch)", dist ) dendriteAccumulate("FLPR") dendriteAccumulate("FLPL") dendriteAccumulate("ASHL") @@ -4936,7 +4937,7 @@ def runconnectome(): runconnectome() else: if tfood < 2: - print "FOOD" + print("FOOD") dendriteAccumulate("ADFL") dendriteAccumulate("ADFR") dendriteAccumulate("ASGR") @@ -4956,7 +4957,7 @@ def runconnectome(): ## Start Comment #stop() ## End Comment - print "Ctrl+C detected. Program Stopped!" + print("Ctrl+C detected. Program Stopped!") for pscheck in postSynaptic: print (pscheck,' ',postSynaptic[pscheck][0],' ',postSynaptic[pscheck][1]) diff --git a/disembodiedEO.py b/disembodiedEO.py index fb5138a..87ba72b 100644 --- a/disembodiedEO.py +++ b/disembodiedEO.py @@ -1,5 +1,6 @@ # GoPiGo Connectome # Written by Timothy Busbice, Gabriel Garrett, Geoffrey Churchill (c) 2015 in Python 2.7 +# Modified by John Cole in 2019 to work with Python 3.x and the GoPiGo3 # The GoPiGo Connectome uses a Postsynaptic dictionary based on the C Elegans Connectome Model # This application can be ran on the Raspberry Pi GoPiGo robot with a Sonar that represents Nose Touch when activated # To run standalone without a GoPiGo robot, simply comment out the sections with Start and End comments @@ -4822,7 +4823,7 @@ def motorcontrol(): new_speed = 150 elif new_speed < 75: new_speed = 75 - print "Left: ", accumleft, "Right:", accumright, "Speed: ", new_speed + print("Left: ", accumleft, "Right:", accumright, "Speed: ", new_speed) ## Start Commented section # set_speed(new_speed) # if accumleft == 0 and accumright == 0: @@ -4917,7 +4918,7 @@ def runconnectome(): #Do we need to switch states at the end of each loop? No, this is done inside the runconnectome() #function, called inside each loop. if dist>0 and dist<30: - print "OBSTACLE (Nose Touch)", dist + print("OBSTACLE (Nose Touch)", dist) dendriteAccumulate("FLPR") dendriteAccumulate("FLPL") dendriteAccumulate("ASHL") @@ -4931,8 +4932,8 @@ def runconnectome(): runconnectome() else: if tfood < 2: - print "FOOD" - print (thisState) + print("FOOD") + print(thisState) dendriteAccumulate("ADFL") dendriteAccumulate("ADFR") dendriteAccumulate("ASGR") @@ -4953,6 +4954,6 @@ def runconnectome(): ## Start Comment #stop() ## End Comment - print "Ctrl+C detected. Program Stopped!" + print("Ctrl+C detected. Program Stopped!") for pscheck in postsynaptic: print (pscheck,' ',postsynaptic[pscheck][0],' ',postsynaptic[pscheck][1]) diff --git a/experimentalOptimization.py b/experimentalOptimization.py index a9d15e6..a038ef4 100644 --- a/experimentalOptimization.py +++ b/experimentalOptimization.py @@ -1,5 +1,6 @@ # GoPiGo Connectome -# Written by Timothy Busbice, Gabriel Garrett, Geoffrey Churchill (c) 2015 in Python 2.7 +# Originally Written by Timothy Busbice, Gabriel Garrett, Geoffrey Churchill (c) 2015 in Python 2.7 +# Modified by John Cole in 2019 to work with Python 3.x and the GoPiGo3 # The GoPiGo Connectome uses a Postsynaptic dictionary based on the C Elegans Connectome Model # This application can be ran on the Raspberry Pi GoPiGo robot with a Sonar that represents Nose Touch when activated # To run standalone without a GoPiGo robot, simply comment out the sections with Start and End comments @@ -10,7 +11,9 @@ ### in order to find and fire the neurons exceeding the threshold. ## Start Comment -from gopigo import * +from easygopigo3 import EasyGoPiGo3 # importing the EasyGoPiGo3 class +gpg = EasyGoPiGo3() # instantiating a EasyGoPiGo3 object +my_distance_sensor = gpg.init_distance_sensor() ## End Comment import time @@ -4822,43 +4825,43 @@ def motorcontrol(): new_speed = 150 elif new_speed < 75: new_speed = 75 - print "Left: ", accumleft, "Right:", accumright, "Speed: ", new_speed + print("Left: ", accumleft, "Right:", accumright, "Speed: ", new_speed) ## Start Commented section - set_speed(new_speed) - print "Speed set: ", new_speed + gpg.set_speed(new_speed) + print("Speed set: ", new_speed) if accumleft == 0 and accumright == 0: - stop() + gpg.stop() elif accumright <= 0 and accumleft < 0: - set_speed(150) + gpg.set_speed(150) turnratio = float(accumright) / float(accumleft) # print "Turn Ratio: ", turnratio if turnratio <= 0.6: - left_rot() + gpg.left() time.sleep(0.8) elif turnratio >= 2: - right_rot() + gpg.right() time.sleep(0.8) - bwd() + gpg.backward() time.sleep(0.5) elif accumright <= 0 and accumleft >= 0: - right_rot() + gpg.right() time.sleep(.8) elif accumright >= 0 and accumleft <= 0: - left_rot() + gpg.left() time.sleep(.8) elif accumright >= 0 and accumleft > 0: turnratio = float(accumright) / float(accumleft) # print "Turn Ratio: ", turnratio if turnratio <= 0.6: - left_rot() + gpg.left() time.sleep(0.8) elif turnratio >= 2: - right_rot() + gpg.right() time.sleep(0.8) - fwd() + gpg.forward() time.sleep(0.5) else: - stop() + gpg.stop() ## End Commented section accumleft = 0 accumright = 0 @@ -4900,8 +4903,8 @@ def runconnectome(): createpostsynaptic() dist=0 ## Start comment -set_speed(120) -print "Voltage: ", volt() +gpg.set_speed(120) +print("Voltage: ", gpg.volt()) ## End comment tfood = 0 try: @@ -4912,13 +4915,14 @@ def runconnectome(): while True: ## Start comment - use a fixed value if you want to stimulte nose touch ## use something like "dist = 27" if you want to stop nose stimulation - dist = us_dist(15) + # print("Distance Sensor Reading: {} mm ".format(my_distance_sensor.read_mm())) + dist = my_distance_sensor.read_mm() ## End Comment #Do we need to switch states at the end of each loop? No, this is done inside the runconnectome() #function, called inside each loop. - if dist>0 and dist<30: - print "OBSTACLE (Nose Touch)", dist + if dist>0 and dist<100: + print("OBSTACLE (Nose Touch)", dist) dendriteAccumulate("FLPR") dendriteAccumulate("FLPL") dendriteAccumulate("ASHL") @@ -4932,8 +4936,8 @@ def runconnectome(): runconnectome() else: if tfood < 2: - print "FOOD" - print (thisState) + print("FOOD") + print(thisState) dendriteAccumulate("ADFL") dendriteAccumulate("ADFR") dendriteAccumulate("ASGR") @@ -4952,6 +4956,6 @@ def runconnectome(): except KeyboardInterrupt: ## Start Comment - stop() + gpg.stop() ## End Comment - print "Ctrl+C detected. Program Stopped!" \ No newline at end of file + print("Ctrl+C detected. Program Stopped!") \ No newline at end of file