Files

copied

Scanning the repository...

Last update 8 years 3 weeks by Surendra Shrestha
Filesdocs
..
controller.py
controller_make_up.png
controller_pcb.pdf
controller_schematics.png
power_pcb_print.pdf
power_sch.png
controller.py
from __future__ import print_function verbose = True # Programatic solution to automatic water controller def nand(i1, i2): return not (i1 and i2) def dprint(msg): if(verbose): print (msg) class Controller(object): def __init__(self, verbose = False): self.s1 = False #For bottom sensor self.s2 = False #For top upper sensor self.s3 = False #For top lower sensor self.motor = False self.state = False self.verbose = verbose def setSensors(self, s1, s2, s3): self.s1 = s1 self.s2 = s2 self.s3 = s3 def process(self): if nand(not(self.s2) , not(self.s3)) == False: self.state = True dprint("Top tanks is empty so set to filling") if nand(self.s1, self.s2) == False: self.state = False dprint("Top tank is completely filled so set to emptying") #Here not is achieved by common input nand gate self.motor = not(nand(self.state, self.s1)) # Functions related to the Flipflop def setFlipflop(self, in1): if(in1 == False): #Negative logic self.state = True def resetFlipflop(self, in1): if(in1 == False): #Negative Logic self.state = False def getState(self): return self.state # Functions for stastistics def print_stastistics(self): if(not self.verbose): return print("--------------------------Stastistics---------------------------") #First half for i in xrange(4): if(self.s1): #Bottom tank is full print("|++++++++| ",end='') else: print("| | ",end='') #if Top tank is full if(self.s2): print("|++++++++|") else: print("| |") #Second Half for i in xrange(4): if(self.s1): #Bottom tank is full print("|++++++++| ",end='') else: print("| | ",end='') if(self.s3): print("|++++++++|") else: print("| |") print("+--------+ +--------+") print("Bottom tank Top Tank ") if(self.motor): print("Motor is running.") else: print("Motor stopped.") if(self.state): print("Currently tank is filling.") else: print("Currently tank is emptying") dprint("------------------------End of Statistics-----------------------") def get_bool(prompt): while True: try: return {"true":True,"false":False}[raw_input(prompt).lower()] except KeyError: print ("Invalid input please enter True or False!") # Main Loop if __name__ == "__main__": controller = Controller(verbose=True) while(raw_input('Press q to quit other to continue: ') != 'q'): #Get new sensor values s1 = get_bool('Enter value of S1:') s2 = get_bool('Enter Value of S2:') s3 = get_bool('Enter Value of S3:') #Set sensor values controller.setSensors(s1, s2, s3) #Process the values controller.process(); #Print current statistics controller.print_stastistics()
Report a bug