Beispiel #1
0
def happy():

    initial_pos = 8
    final_pos = 6

    anticlockwise(pwm1, initial_pos, final_pos, mtr_time)
    clockwise(pwm2, initial_pos, initial_pos + 3.5,
              mtr_time)  # Eyelid happy emotion
    #time.sleep(0.05)
    # Face motor from 90 to 126 i.e. pwm 8 to pwm 5

    #anticlockwise(pwm2,initial_pos,final_pos,mtr_time)	# Eyelid motor from 90 to 126 i.e. pwm 8 to pwm 5
    pwm1.ChangeDutyCycle(final_pos)
    time.sleep(1)
    pwm1.ChangeDutyCycle(0)
    pwm2.ChangeDutyCycle(initial_pos + 3.5)
    time.sleep(1)
    pwm2.ChangeDutyCycle(0)

    GPIO.output(green, GPIO.HIGH)  # Green LED glows
    #sound("test.wav")
    sound("happy.mp3")  #sound
    time.sleep(t)
    GPIO.output(green, GPIO.LOW)  # Green LED OFF

    clockwise(pwm1, final_pos, initial_pos, mtr_time)
    anticlockwise(pwm2, initial_pos + 3.5, initial_pos, mtr_time)
    # Return to initial

    neutral()
    neutral()

    return
Beispiel #2
0
def fear():

    pwm1.ChangeDutyCycle(0)
    anticlockwise(pwm2, 8, 7, mtr_time)

    pwm2.ChangeDutyCycle(7)
    time.sleep(1)
    pwm2.ChangeDutyCycle(0)

    ###### DC MOTOR MOTION REVERSE ####

    GPIO.output(15, GPIO.HIGH)
    GPIO.output(12, GPIO.HIGH)
    time.sleep(1)
    GPIO.output(15, GPIO.LOW)
    GPIO.output(12, GPIO.LOW)

    sound("fear.mp3")  #sound
    time.sleep(t)

    clockwise(pwm2, 7, 8, mtr_time)

    ####### DC MOTOR FORWARD #####

    GPIO.output(13, GPIO.HIGH)
    GPIO.output(11, GPIO.HIGH)
    time.sleep(1)
    GPIO.output(13, GPIO.LOW)
    GPIO.output(11, GPIO.LOW)

    neutral()
    neutral()
    return
Beispiel #3
0
def angry():

    initial_pos = 8
    final_pos = 6

    anticlockwise(pwm1, initial_pos, final_pos,
                  mtr_time)  # Face motor from 90 to 126 i.e. pwm 8 to pwm 5
    clockwise(pwm2, initial_pos, initial_pos + 2,
              mtr_time)  # Eyelid motor from 90 to 126 i.e. pwm 8 to pwm 5
    #anticlockwise(pwm2,final_pos,final_pos-1,mtr_time)	# Eyelid happy emotion

    pwm1.ChangeDutyCycle(final_pos)
    time.sleep(1)
    pwm1.ChangeDutyCycle(0)
    pwm2.ChangeDutyCycle(initial_pos + 2)
    time.sleep(1)
    pwm2.ChangeDutyCycle(0)

    GPIO.output(red, GPIO.HIGH)  # Red LED glows
    sound("angry.mp3")  #sound
    time.sleep(t)
    GPIO.output(red, GPIO.LOW)  # Red LED OFF

    clockwise(pwm1, final_pos, initial_pos, mtr_time)  # Return to initial
    anticlockwise(pwm2, initial_pos + 2, initial_pos + 1, mtr_time)
    neutral()
    neutral()

    return
Beispiel #4
0
def sleep():

    initial_pos = 8
    final_pos = 9
    clockwise(pwm1, initial_pos, final_pos, mtr_time)
    anticlockwise(pwm2, initial_pos, initial_pos - 3, mtr_time)
    #clockwise(pwm2,final_pos,final_pos+1,mtr_time)	# Eyelid sleep emotion
    sound("bye.mp3")  #sound
    GPIO.output(blue, GPIO.LOW)
    time.sleep(t)

    return
Beispiel #5
0
def fear():
	
	pwm1.ChangeDutyCycle(0)
	anticlockwise(pwm2,19,22,mtr_time)  #initial position at 90 & final position at 111

	pwm2.ChangeDutyCycle(22)
	time.sleep(1)
	pwm2.ChangeDutyCycle(0)
	
	###### DC MOTOR MOTION REVERSE ####
	
	
	GPIO.output(03,GPIO.LOW)
	GPIO.output(05,GPIO.HIGH)
	GPIO.output(08,GPIO.LOW)
	GPIO.output(10,GPIO.HIGH)
	pwm.ChangeDutyCycle(25)

	GPIO.output(07,GPIO.HIGH)
	GPIO.output(12,GPIO.HIGH)
	time.sleep(2)
	GPIO.output(07,GPIO.LOW)
	GPIO.output(12,GPIO.LOW)

	
	sound("fear.mp3")             #sound
	time.sleep(t)
	
	clockwise(pwm2,7,8,mtr_time)
	
	####### DC MOTOR FORWARD #####
	GPIO.output(03,GPIO.HIGH)
	GPIO.output(08,GPIO.HIGH)
	GPIO.output(05,GPIO.LOW)
	GPIO.output(10,GPIO.LOW)
	pwm.ChangeDutyCycle(25)
		
	GPIO.output(07,GPIO.HIGH)
	GPIO.output(12,GPIO.HIGH)
	time.sleep(2)
	GPIO.output(07,GPIO.LOW)
	GPIO.output(12,GPIO.LOW)

	
	
	neutral()
	neutral()
	return;
Beispiel #6
0
def sad():

    initial_pos = 8
    final_pos = 9
    clockwise(pwm1, initial_pos, final_pos, mtr_time)
    anticlockwise(pwm2, initial_pos, initial_pos - 3, mtr_time)
    #clockwise(pwm2,final_pos,final_pos+1,mtr_time)	# Eyelid sad emotion

    pwm1.ChangeDutyCycle(final_pos)
    time.sleep(1)
    pwm1.ChangeDutyCycle(0)
    pwm2.ChangeDutyCycle(initial_pos - 3)
    time.sleep(1)
    pwm2.ChangeDutyCycle(0)
    sound("sad.mp3")  #sound
    time.sleep(t)

    anticlockwise(pwm1, final_pos, initial_pos, mtr_time)
    clockwise(pwm2, initial_pos - 3, initial_pos, mtr_time)

    neutral()
    neutral()
    return
Beispiel #7
0
	def setup_sounds(self, sounds, replace=True):
		# fade out old sounds
		if replace:
			for key, sound in self.sounds.items():
				if sound.is_playing():
					print 'Fading out {}...'.format(key)
					sound.fadeout()
				del self.sounds[key]
		
		# add new sounds
		for sound in sounds:
			if sound.has_key('filename'):
				sound['filenames'] = [sound['filename']]
			self.sounds[sound['name']] = audio.sound(sound['name'], sound['filenames'], sound['volume'], sound['loop'], sound['frequency'], sound['period'])
		
		# return config
		return self.get_config()['sounds']
Beispiel #8
0
    def z2(y):

        try:

            if (p == "play songs" or p == "play music" or p == "play song"):
                sound("oka oka.mp3")  #sound
                sound("Alan Walker - Faded.mp3")

            elif (p == "stop music" or p == "stop song" or p == "stop song"):
                sound("oka oka.mp3")  #sound

            else:
                print emot

        except Exception:

            a = "Error playing song :("
            servo(3)
            print "error"

        return
Beispiel #9
0
def anticlockwise(pwm,p1,p2,duration):		# for anticlockwise pwm goes from 31 to 6 i.e. angle 180 to 0
	
	angle1=(p1-6.)*(36./5.)
	angle2=(p2-6.)*(36./5.)
	
	angle1=int(angle1)
	angle2=int(angle2)
	for i in range(1,1000):
        angle1=180
        new_angle=(angle2)+((i*angle1)/1000.)
        p=(5./36.)*new_angle +6.
        pwm.ChangeDutyCycle(p)
        time.sleep(0.001)
	
	#for i in range(angle1,angle2,-1):
	#	p=(5./36.)*i +6
	#	print i
	#	print p
	#	pwm.ChangeDutyCycle(p)
	#	time.sleep(duration)
		
	#pwm.ChangeDutyCycle(p2)
	#time.sleep(1)
	pwm.ChangeDutyCycle(0)
	
	return;
	
def initial():
	
	# initially both motor is kept at 90
	
	pwm1.start(19)
	pwm2.start(19)
	pwm3.start(19)
	#pwm1.ChangeDutyCycle(0)		# To off the motor at required position
	#pwm2.ChangeDutyCycle(0)
	
	return;
	
	
def happiness():
	
	initial_pos = 19  #initial position at 90
	final_pos = 24    #final position at 126
	
	t1=threading.Thread(target=anticlockwise,args=(pwm1,initial_pos,final_pos,mtr_time,))
	t2=threading.Thread(target=clockwise,args=(pwm2,initial_pos,initial_pos+3.5,mtr_time,))	# Eyelid happy emotion
    t1.start()
    t2.start()
    t1.join()
    t2.join()
	#time.sleep(0.05)
		# Face motor from 90 to 126 i.e. pwm 8 to pwm 5		
	
	#anticlockwise(pwm2,initial_pos,final_pos,mtr_time)	# Eyelid motor from 90 to 126 i.e. pwm 19 to pwm 24
	pwm1.ChangeDutyCycle(final_pos)
	time.sleep(1)
	pwm1.ChangeDutyCycle(0)
	pwm2.ChangeDutyCycle(initial_pos+3.5)
	time.sleep(1)
	pwm2.ChangeDutyCycle(0)


	GPIO.output(green,GPIO.HIGH)	# Green LED glows
	#sound("test.wav")
	sound("happy.mp3")             #sound
	time.sleep(t)
	GPIO.output(green,GPIO.LOW)		# Green LED OFF
	
	clockwise(pwm1,final_pos,initial_pos,mtr_time)
	anticlockwise(pwm2,initial_pos+3.5,initial_pos,mtr_time)
		# Return to initial
	
	
	neutral()
	neutral()
	
	

	return;
Beispiel #10
0
def querytest():

    param1 = request.query.param1

    test = 0

    pro = 0
    a = "Sorry I couldn't get you! :("
    p = param1  # input text
    emot = 6  # 6 and others = blink , 5 = neutral , 4 = disgusted , 3 = sad , 2 = scared , 1 = happy , 0 = angry
    #servo(emot)                               # 7 = sleep

    try:
        t = float(p)
    except Exception:
        test = 1

    p = p.lower()
    parray = p.split()

    #print p + '*'

    if (test == 0):

        emot = 1
        #servo(emot)

        if (len(p) == 10):

            print "Thanks! I'll call you at night!"  #for fun
            a = "Thanks! I'll call you at night!"

        else:

            print 'I would rather have your phone number! :)'  #for fun
            a = 'I would rather have your phone number! :)'

    else:

        parray = p.split()

        try:
            if (parray[0] == 'motion'):
                #a = dcmotor(parray[1])
                print parray[1].upper()
                a = "MOVING " + parray[1].upper()
                #servo(6)

            else:
                try:

                    if (p == "sleep" or p == "bye" or p == "off"
                            or p == "good night"):

                        a = "Good Byee!"
                        emot = 7
                        #servo(emot)

                    elif (p == "hi" or p == "hi mino" or p == "hello"
                          or p == "hello mino" or p == "hey" or p == "hii"
                          or p == "namaste" or p == "heya"):

                        a = "Hi! I am Mino! Lets talk!"
                        emot = 1

                    elif (p == "blink"):

                        a = "blinking"
                        emot = 6

                    elif (p == "play songs" or p == "play music"
                          or p == "play song"):

                        a = "Playing Faded by Alan Walker"
                        emot = 6

                    elif (p == "stop songs" or p == "stop music"
                          or p == "stop song"):

                        a = "Stopping music"
                        emot = 6

                    elif (p == "switch 1 on" or p == "switch one on"
                          or p == "on switch one" or p == "on switch1"
                          or p == "switch1 on" or p == "on switch 1"):

                        a = "Switching on switch 1"
                        emot = 8
                        sound("oka oka.mp3")  #sound

                    elif (p == "switch 2 on" or p == "switch two on"
                          or p == "on switch two" or p == "switch to on"
                          or p == "on switch to" or p == "on switch2"
                          or p == "switch2 on" or p == "on switch 2"):

                        a = "Switching on switch 2"
                        emot = 8
                        sound("oka oka.mp3")  #sound

                    elif (p == "switch 3 on" or p == "switch three on"
                          or p == "on switch three" or p == "on switch3"
                          or p == "switch3 on" or p == "on switch 3"):

                        a = "Switching on switch 3"
                        emot = 8
                        sound("oka oka.mp3")  #sound

                    elif (p == "switch 1 off" or p == "switch one off"
                          or p == "off switch one" or p == "off switch1"
                          or p == "switch1 off" or p == "off switch 1"
                          or p == "switch 1 of" or p == "switch one of"
                          or p == "of switch one" or p == "of switch1"
                          or p == "switch1 of" or p == "of switch 1"):

                        a = "Switching off switch 1"
                        emot = 8
                        sound("oka oka.mp3")  #sound

                    elif (p == "switch 2 of" or p == "switch two of"
                          or p == "of switch two" or p == "switch to of"
                          or p == "of switch to" or p == "of switch2"
                          or p == "switch2 of" or p == "of switch 2"
                          or p == "switch 2 off" or p == "switch two off"
                          or p == "off switch two" or p == "switch to off"
                          or p == "off switch to" or p == "off switch2"
                          or p == "switch2 off" or p == "off switch 2"):

                        a = "Switching off switch 2"
                        emot = 8
                        sound("oka oka.mp3")  #sound

                    elif (p == "switch 3 off" or p == "switch three off"
                          or p == "off switch three" or p == "off switch3"
                          or p == "switch3 off" or p == "off switch 3"
                          or p == "switch 3 of" or p == "switch three of"
                          or p == "of switch three" or p == "of switch3"
                          or p == "switch3 of" or p == "of switch 3"):

                        a = "Switching off switch 3"
                        emot = 8
                        sound("oka oka.mp3")  #sound

                    else:
                        a, emot = alchemyL(p)
                        #servo(emot)

                except Exception:
                    emot = 1
                    #servo(emot)

                    print 'I am unaware of this language, I\'ll be happy to learn it from you'
                    a = 'I am unaware of this language, I\'ll be happy to learn it from you'
        except Exception:
            emot = 5
            #servo(emot)
            print 'I am Neutral'

            a = 'I am Neutral'

    def z1(x):

        print emot

        if (parray[0] == 'motion'):

            try:
                a = dcmotor(parray[1])
                servo(emot)

            except Exception:
                a = "My joints are jammed :("

        else:

            try:
                servo(emot)

            except Exception:
                a = "I think I have a neck pain :("

        #sound("test.wav")
        return

    def z2(y):

        try:

            if (p == "play songs" or p == "play music" or p == "play song"):
                sound("oka oka.mp3")  #sound
                sound("Alan Walker - Faded.mp3")

            elif (p == "stop music" or p == "stop song" or p == "stop song"):
                sound("oka oka.mp3")  #sound

            else:
                print emot

        except Exception:

            a = "Error playing song :("
            servo(3)
            print "error"

        return

    try:

        thread.start_new_thread(z1, (5, ))
        thread.start_new_thread(z2, ("z2", ))

    except:
        print "Error: unable to start thread"
        a = "I think I have a neck pain :("

    return a

    while 1:
        pass