Combination Report Einstein Robot



Download 10.84 Mb.
Page40/41
Date conversion08.07.2018
Size10.84 Mb.
1   ...   33   34   35   36   37   38   39   40   41

Einstein, the famous theatrical Robot from PSU!

Table of contents


Einstein.py -- Python class the describes behavior of the imaginary Einstein robot

main.py -- example python program that utilizes Einstein python class


Example usage(s)


Get einsteins personality traits. Niceness - measure of how nice; Meanness - measure of how mean

python main.py --personality

This should return a tuple of (niceness, meanness)

python main.py -mood

This should return a string that indicates Einstein's "mood"

python main.py -a "integer from 1-10"

This is a action (integer from 1-10) that einstein "reacts" to. Returns a string

python main.py -c "integer from 1-15"

This issues a command to the robot
************* Einstein.py***************

from __future__ import division

import random
# python class for einstein

class Einstein:


def command(self, num):

"""


This function takes in an integer and translates it to a command to the Einstein robot

"""
if(num == 1):

return 'Stop robot'

elif(num == 2):

return 'Robot forward'

elif(num == 3):

return 'Robot backward'

elif(num == 4):

return 'Robot raises right arm'

elif(num == 5):

return 'Robot raises left arm'

elif(num == 6):

return 'Robot moves forward fastly'

elif(num == 7):

return 'Robot moves backward fastly'

elif(num == 8):

return 'Robot turns 45 degrees left'

elif(num == 9):

return 'Robot turns 90 degrees left'

elif(num == 10):

return 'Robot turns 180 degrees left'

elif(num == 11):

return 'Robot turns 360 degrees left'

elif(num == 12):

return 'Robot turns 45 degrees right'

elif(num == 13):

return 'Robot turns 90 degrees right'

elif(num == 14):

return 'Robot turns 180 degrees right'

elif(num == 15):

return 'Robot turns 360 degrees right'

else:


return 'Invalid command'
def slide(self, num):

"""


This function takes in a slide number or interaction number

it then determines what action einstein takes

"""
# generate random int, convert to percentage

chance = random.randint(1,10)/10


# interaction 1.2 or slide 1.6

if(num == 1.2 or num == 1.6):

if(chance > self.niceness):

return 'Einstein attacks, Newton keeps distance'

else:

return 'Newton attacks, Einstein keeps distance'


# interaction 1.3 or slide 1.7

if(num == 1.3 or num == 1.7):

if(chance > self.niceness):

return 'Einstein looks angrily at Bohr'

else:

return 'Einstein calmly smokes his pipe, while looking intently at Bohr'


# slide 1.11

if(num == 1.11):

return 'Einstein grabs violin, points to Mary,' \

'then looks at Newton and Bohr, and directs them to Dr. Curie salon'


# slide 1.15

if(num == 1.15):

return 'Einstein angrily jumps up and down'
# interaction 2.2 or slide 1.17

if(num == 2.2 or num == 1.17):

if(chance > self.niceness):

return 'Einstein drives always to the person who talks but keeps distance'

else:

return 'Einstein turns always to the person who talks, keeping his distance'


# slide 1.18

if(num == 1.18):

if(chance > self.niceness):

return 'Einstein flicks everybody off'

else:

return 'Einstein sticks his tongue out'


# slide 1.19

if(num == 1.19):

return 'Einstein patronizes Newton then points to Schrodingers cat'
# interaction 2.3 or slide 1.20

if(num == 2.3 or num == 1.20):

return 'Einstein communicates intensely with schrodingers cat'
# slide 1.21

if(num == 1.21):

return 'Einstein goes on long tangent regarding Dark Energy and spacetime'
# slide 1.23

if(num == 1.23):

return 'Einstein turns to schrodingers cat'
# interaction 2.5 or slide 1.27

if(num == 2.5 or num == 1.27):

return 'Einstein moves towards Bohr until he is close, then dance forward and backward'
# interaction 2.5 or slide 1.27

if(num == 2.6 or num == 1.29):

return 'Einstein moves towards Bohr until he is close, then dance forward and backward'
# slide 1.32

if(num == 1.32):

if(chance > self.niceness):

return 'Einstein speaks sarcastically, and acts surprised'

else:

return 'Einstein is genuinley surprised'


# interaction 2.7 or slide 1.33

if(num == 2.7 or num == 1.33):

return 'Einstein loses control and says loudly: SHUT UP!'
# interaction 2.8 or slide 1.35

if(num == 2.8 or num == 1.35):

return 'Einstein dances in circles in the middle'
# more slides from play need to be added
return 'Invalid slide number'

def mood(self):

"""

Function returns string that represents mood



"""

#random chance

chance = random.randint(1,10) / 10

# nicer, and chance > meanness

if(self.niceness > self.meanness and chance > self.meanness):

return 'Einstein is groovy baby'

# nicer, chance < meanness

elif(self.niceness > self.meanness and chance < self.meanness):

return 'Einstein is ok'

# meaner, chance > meanness

elif(self.niceness < self.meanness and chance > self.meanness):

return 'Einstein is meh'

# meaner, chance < meanness

elif(self.niceness < self.meanness and chance < self.meanness):

return 'Einstein says fuck off!'

def personality(self):

"""

Function returns personality traits for Einstein



"""

return (self.niceness, self.meanness)

def reaction(self, Action):

"""


Function takes Action (integer 1 to 10)

and generates a reaction from Einstein

based on some probablistic logic

"""


# keep it within the proper range

if(Action > 10 or Action < 0):

Action = random.randint(1, 10)

# initialize chance

chance = 0

# add up five random integers between 1-10

for i in range(5):

chance += random.randint(1,10)

# divide by max (10, 5 times = 50)

chance /= 50

Action /= 50
# initialize chance2

chance2 = 0

# this weighs the reaction towards a nice one or a mean one

if(random.randint(1,10) <= 5):

chance2 = self.niceness

else:


chance2 = self.meanness

# get reaction

if(chance*chance2 > Action):

return 'Einstein reacted nicely'

else:

return 'Einstein reacted badly'



def __init__(self, niceness, meanness):

"""


Initialization of Einstein

"""


# need to make sure we get reasonable numbers for niceness and meanness

if(niceness < 0 and meanness < 0 or niceness == meanness):

# niceness and meanness were both less than 0 which doesn't make sense

# or they were equal to each other which also doesn't make sense

# choose random number between 1 & 10 then divide by 10 for both

# this gives us a percentage of this quality

self.niceness = random.randint(1,10) / 10

self.meanness = random.randint(1,10) / 10

# need to make sure those numbers aren't equal to each other

while(self.niceness == self.meanness):

# they were so pick a new one

meanness = random.randint(1,10) / 10

# max is 10, min is 0

# convert into percentage

if(niceness > 10):

self.niceness = 1

elif(niceness < 0):

self.niceness = 0

else:

self.niceness = niceness / 10



if(meanness > 10):

self.meanness = 1

elif(meanness < 0):

self.meanness = 0

else:

self.meanness = meanness / 10


# this is some other stuff for reading text files that we will probably use later

#with open("fname.text", "r") as f:

# content = [x.strip('\n') for x in f.readlines()]

# for stuff in content:

# print stuff

************* main.py***************

"""

Example program of using command line arguments with Einstein class


Written by William Harrington for ECE478 HW1

"""


from Einstein import Einstein # grab the einstein class

import argparse # library for parsing command line arguments

import random # library for random numbers
# initialize argument parser

parser = argparse.ArgumentParser()


# these lines are here to show that we can make his personality traits customizable on the command line

#parser.add_argument('-m', action = 'store', dest = 'meanness', required = True, help = 'Meanness is a personality quality of Einstein, required for init')

#parser.add_argument('-n', action = 'store', dest = 'niceness', required = True, help = 'Niceness is a personality quality of Einstein, required for init')
# argument for getting mood of Einstein

parser.add_argument('-mood', action = 'store_true', help = 'gets einsteins mood')


# argument for getting personality traits (niceness, meanness) of Einstein

parser.add_argument('--personality', action = 'store_true', help = 'gets personality traits of Einstein')


# argument for asserting action that Einstein will react to

# should be integer between 1-10

parser.add_argument('-a', action = 'store', dest = 'Action', required = False, help = 'optional argument for action to einstein to react to')
# argument for getting robot to perform command

parser.add_argument('-c', type = int, action = 'store', dest = 'Command', required = False, help = 'optional argument for getting robot to perform command')


# parse the arguments

arguments = parser.parse_args()


# again this line just shows we can customize the personality traits from the command line

#Einstein = Einstein(arguments.niceness, arguments.meanness)


# for example sake and testing purposes, I'm just gonna make it random for now

Einstein = Einstein(random.randint(1,10), random.randint(1,10))


if(arguments.Command):

print arguments.Command

print Einstein.command(arguments.Command)
# mood argument present

if(arguments.mood):

# show his mood

print Einstein.mood()


# personality argument present

if(arguments.personality):

# show personality traits

print Einstein.personality()


# action argument present

if(arguments.Action):

# show reaction of Einstein

print Einstein.reaction(arguments.Action)



Appendix E – Powerpoint code for macros

Private Sub CommandButton1_Click() ' #1 python script

args = "C:\Users\Ultra_Dav\Downloads\einstein\main.py" & "-mood"

Debug.Print args

Call Shell("C:\Python27\python.exe " & args, vbNormalFocus)

End Sub
Private Sub CommandButton2_Click() ' #2 text file generator

Dim sPath As String

Dim sName As String

sName = "Move" ' name given to file

sPath = "C:\Users\Ultra_Dav\Downloads\einstein\" & sName & ".txt" ' save location+filename+extension

Open sPath For Output As 1

Print #1, "Sad" ' text saved into file

Close #1

End Sub
Private Sub CommandButton3_Click() ' #3 open cmd prompt and send help

Call Shell("cmd.exe /S /K" & "help", vbNormalFocus) ' /S modifies treatment of string after /K leaves window open, /C closes window

End Sub
Private Sub CommandButton4_Click() ' #4 open website

Call Shell("C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" & " -url" & " " & "stackoverflow.com", vbMaximizedFocus)

End Sub
Private Sub CommandButton5_Click() ' #5 running script

Dim retval2

'retval2 = Shell("cmd.exe /S /K" & "C:\Users\Ultra_Dav\Downloads\einstein\main.py -c 11", vbNormalFocus)

retval2 = Shell("cmd.exe /S /K" & "C:\Users\Ultra_Dav\Downloads\einstein\main.py -mood", vbNormalFocus)

End Sub
Private Sub CommandButton6_Click() ' #6 open text file

Dim retval

retval = Shell("notepad.exe C:\Users\Ultra_Dav\Downloads\einstein\Move.txt", vbNormalFocus)

End Sub

Private Sub CommandButton1_Click() ' fuzzy logic



Dim chosenNum As Integer

Randomize

chosenNum = Int(10 * Rnd) + 1

If chosenNum < 5 Then

ActivePresentation.SlideShowWindow.View.GotoSlide 11

Else


ActivePresentation.SlideShowWindow.View.GotoSlide 12

End If


End Sub

Appendix F – Fun

1   ...   33   34   35   36   37   38   39   40   41


The database is protected by copyright ©dentisty.org 2016
send message

    Main page