Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 27 additions & 23 deletions GoPiGoConnectome.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 ###
Expand All @@ -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")
Expand All @@ -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")
Expand All @@ -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])
print(pscheck,' ',postsynaptic[pscheck][0],' ',postsynaptic[pscheck][1])
75 changes: 44 additions & 31 deletions connectome.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -4918,33 +4925,40 @@ 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
dist = 27

# 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")
Expand All @@ -4959,7 +4973,7 @@ def main():
else:
if tfood < 2:
if verbosity > 0:
print "FOOD"
print("FOOD")
dendriteAccumulate("ADFL")
dendriteAccumulate("ADFR")
dendriteAccumulate("ASGR")
Expand All @@ -4978,15 +4992,14 @@ 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])

sys.exit(0)

if __name__ == '__main__':
signal.signal(signal.SIGINT, keyboard_interrupt_handler)
main()

main()
15 changes: 8 additions & 7 deletions disembodiedConnectome.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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???
Expand All @@ -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
Expand Down Expand Up @@ -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 ###
Expand All @@ -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")
Expand All @@ -4936,7 +4937,7 @@ def runconnectome():
runconnectome()
else:
if tfood < 2:
print "FOOD"
print("FOOD")
dendriteAccumulate("ADFL")
dendriteAccumulate("ADFR")
dendriteAccumulate("ASGR")
Expand All @@ -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])

Expand Down
Loading