def generateTwoTestAngleData(): ''' This creates a list of data samples to be tested. Theses samples are from participants 2 and 3 and the calculated angles are used as features. ''' testSamples = [] index = 0 for filename in sub2: #Open the file fIn = open(filename, 'r') #For each line of the file calculate the # angles inbetween joints and use the resulting # array as the feature vector. Add that to the list. for line in fIn: features = generateAngles(line) testSamples.append(sample(features, labels[index])) fIn.close() index += 1 index = 0 for filename in sub3: #Open the file fIn = open(filename, 'r') #For each line of the file calculate the # angles inbetween joints and use the resulting # array as the feature vector. Add that to the list. for line in fIn: features = generateAngles(line) testSamples.append(sample(features, labels[index])) fIn.close() index += 1 return testSamples
def generateTwoAngleTrainingData(): ''' This function creates training data using the first two participants' data and has joint angles as features for the samples. ''' trainingData = TrainingData("Testing Data") index = 0 for i in xrange(len(labels)): #Open the file fIn = open(sub1[i], 'r') f2In = open(sub2[i], 'r') #For each line of the files calculate the # angles inbetween joints and use the resulting # array as the feature vector. Add that to the trainingData. for line in fIn: features = generateAngles(line) trainingData.addSampleFromFeatures(features, labels[index]) fIn.close() for line in f2In: features = generateAngles(line) trainingData.addSampleFromFeatures(features, labels[index]) f2In.close() index += 1 return trainingData
def generateTwoTestAngleData(): ''' This creates a list of data samples to be tested. Theses samples are from participants 2 and 3 and the calculated angles are used as features. ''' testSamples = [] index = 0 for filename in sub2: #Open the file fIn = open(filename, 'r') #For each line of the file calculate the # angles inbetween joints and use the resulting # array as the feature vector. Add that to the list. for line in fIn: features = generateAngles(line) testSamples.append(sample(features, labels[index])) fIn.close() index += 1 index = 0 for filename in sub3: #Open the file fIn = open(filename, 'r') #For each line of the file calculate the # angles inbetween joints and use the resulting # array as the feature vector. Add that to the list. for line in fIn: features = generateAngles(line) testSamples.append(sample(features, labels[index])) fIn.close() index += 1 return testSamples
def generateTwoAngleTrainingData(): ''' This function creates training data using the first two participants' data and has joint angles as features for the samples. ''' trainingData = TrainingData("Testing Data") index = 0 for i in xrange(len(labels)): #Open the file fIn = open(sub1[i], 'r') f2In = open(sub2[i], 'r') #For each line of the files calculate the # angles inbetween joints and use the resulting # array as the feature vector. Add that to the trainingData. for line in fIn: features = generateAngles(line) trainingData.addSampleFromFeatures(features, labels[index]) fIn.close() for line in f2In: features = generateAngles(line) trainingData.addSampleFromFeatures(features, labels[index]) f2In.close() index += 1 return trainingData
def publishJointAngles(self): #Get a list of frames and turn it into a list of angles values = self.kinect.get_posture() angleString = jsonMaker((values,)) angles = generateAngles(angleString) #Offset the angles appropriately index = 0 stringNums = "" print len(angles) for val in angles: newValue = float(val) - self.offsets[index] #Adjust to keep values in safe joint angles if newValue > self.upper[index]: newValue = self.upper[index] if newValue < self.lower[index]: newValue = self.lower[index] #Filter the value newValue = (self.alpha * newValue) + ((1-self.alpha) * self.oldFilter[index]) self.oldFilter[index] = newValue stringNums += str(newValue) + " " index += 1 stringNums = stringNums[:-1] #Publish the angles service = rospy.ServiceProxy("setProperties", setProperties) service("REB LEB RSY LSY RSR LSR", "position position position position position position", stringNums) print stringNums
def generateAllAngleTrainingData(): ''' This function creates one large TrainingData object containing data from all three participants but uses calculated angles as the features for each data sample. ''' #Maybe TODO: Make this so it's easier to add lists of data. trainingData = [] trainingLabels = [] index = 0 for i in xrange(len(labels)): #Open the file fIn = open(sub1[i], 'r') f2In = open(sub2[i], 'r') f3In = open(sub3[i], 'r') #For each line of the files calculate the # angles inbetween joints and use the resulting # array as the feature vector. Add that to the trainingData. for line in fIn: features = generateAngles(line) trainingData.append(features) trainingLabels.append(labels[index]) fIn.close() for line in f2In: features = generateAngles(line) trainingData.append(features) trainingLabels.append(labels[index]) f2In.close() for line in f3In: features = generateAngles(line) trainingData.append(features) trainingLabels.append(labels[index]) f3In.close() index += 1 #Return the data object return trainingData, trainingLabels
def generateAllAngleTrainingData(): ''' This function creates one large TrainingData object containing data from all three participants but uses calculated angles as the features for each data sample. ''' trainingData = TrainingData("Testing Data") index = 0 for i in xrange(len(labels)): #Open the file fIn = open(sub1[i], 'r') f2In = open(sub2[i], 'r') f3In = open(sub3[i], 'r') #For each line of the files calculate the # angles inbetween joints and use the resulting # array as the feature vector. Add that to the trainingData. for line in fIn: features = generateAngles(line) trainingData.addSampleFromFeatures(features, labels[index]) fIn.close() for line in f2In: features = generateAngles(line) trainingData.addSampleFromFeatures(features, labels[index]) f2In.close() for line in f3In: features = generateAngles(line) trainingData.addSampleFromFeatures(features, labels[index]) f3In.close() index += 1 #Return the data object return trainingData
def generateAllAngleTrainingData(): ''' This function creates one large TrainingData object containing data from all three participants but uses calculated angles as the features for each data sample. ''' trainingData = TrainingData("Testing Data") index = 0 for i in xrange(len(labels)): #Open the file fIn = open(sub1[i], 'r') f2In = open(sub2[i], 'r') f3In = open(sub3[i], 'r') #For each line of the files calculate the # angles inbetween joints and use the resulting # array as the feature vector. Add that to the trainingData. for line in fIn: features = generateAngles(line) trainingData.addSampleFromFeatures(features, labels[index]) fIn.close() for line in f2In: features = generateAngles(line) trainingData.addSampleFromFeatures(features, labels[index]) f2In.close() for line in f3In: features = generateAngles(line) trainingData.addSampleFromFeatures(features, labels[index]) f3In.close() index += 1 #Return the data object return trainingData
def MainAngle(): #run the simulation showing the angles that change global continuing signal.signal(signal.SIGINT, endDemo) kinect = Kinect() plotter = SkeletonPlotter() continuing = True while continuing: time.sleep(.05) value = kinect.get_posture() if value is None: continue jointString = jsonMaker((value, )) anglesList = generateAngles(jointString) plotter.showSkeletonAngles(jointString, anglesList, 'b')
def checkSlidingWindow(self, f): #Get a list of frames and turn it into a list of angles values = self.kinect.get_posture() if values is None: return None angleString = jsonMaker((values, )) angles = generateAngles(angleString) f.write(str(angles) + "\n") #Add the angle list to the list of angles in the sliding # window list. If the window if above capacity pop the oldest # set of angles. self.slidingWindow.append(angles) if len(self.slidingWindow) > self.capacity: self.slidingWindow.pop(0) #Let the window fill up before we start trying to classify if len(self.slidingWindow) != self.capacity: return angles #Get the average of the sliding window angles and run them # through the classifier avgAngles = self.getAvgAngles() #Classify the average angles result = classifySample(avgAngles) print "Result: " + str(result) if result is None: return angles result = result[0] if result == "Disco": stayAliveRobot(self.robot) elif result == "ChickenDance": chickenDanceRobot(self.robot) elif result == "WalkLikeAnEgyptian": walkLikeAnEgyptianRobot(self.robot) elif result == "YMCA": doTheYMCARobot(self.robot) #Reset the sliding window after a dance was recognized self.slidingWindow = [] return angles
def checkSlidingWindow(self, f): #Get a list of frames and turn it into a list of angles values = self.kinect.get_posture() if values is None: return None angleString = jsonMaker((values,)) angles = generateAngles(angleString) f.write(str(angles) + "\n") #Add the angle list to the list of angles in the sliding # window list. If the window if above capacity pop the oldest # set of angles. self.slidingWindow.append(angles) if len(self.slidingWindow) > self.capacity: self.slidingWindow.pop(0) #Let the window fill up before we start trying to classify if len(self.slidingWindow) != self.capacity: return angles #Get the average of the sliding window angles and run them # through the classifier avgAngles = self.getAvgAngles() #Classify the average angles result = classifySample(avgAngles) print "Result: " + str(result) if result is None: return angles result = result[0] if result == "Disco": stayAliveRobot(self.robot) elif result == "ChickenDance": chickenDanceRobot(self.robot) elif result == "WalkLikeAnEgyptian": walkLikeAnEgyptianRobot(self.robot) elif result == "YMCA": doTheYMCARobot(self.robot) #Reset the sliding window after a dance was recognized self.slidingWindow = [] return angles
def generateOneTrainAngleData(): ''' This creates a data set to be used to train a classifier. The data is from participant 1 and uses the calculated joint angles as features. ''' trainingData = TrainingData("Angle Data") index = 0 for filename in sub1: #Open the file fIn = open(filename, 'r') #For each line of the file calculate the # angles inbetween joints and use the resulting # array as the feature vector. Add that to the trainingData. for line in fIn: features = generateAngles(line) trainingData.addSampleFromFeatures(features, labels[index]) fIn.close() index += 1 return trainingData
def recordJointAngles(self): #Get the values from the kinect values = self.kinect.get_posture() if values is None: #recursivly try again self.recordJointAngles() return None angleString = jsonMaker((values,)) #Make them into angles angles = generateAngles(angleString) #Parse angles stringNums = "" for angle in angles: stringNums += str(angle) + " " stringNums = stringNums[:-1] #Write the angles to a file self.output.write(" robot.setProperties(\"REP LEP RSY LSY RSR LSR RSP LSP\", \"position position position position position position position position\", " + stringNums + ")")
def generateOneTrainAngleData(): ''' This creates a data set to be used to train a classifier. The data is from participant 1 and uses the calculated joint angles as features. ''' trainingData = TrainingData("Angle Data") index = 0 for filename in sub1: #Open the file fIn = open(filename, 'r') #For each line of the file calculate the # angles inbetween joints and use the resulting # array as the feature vector. Add that to the trainingData. for line in fIn: features = generateAngles(line) trainingData.addSampleFromFeatures(features, labels[index]) fIn.close() index += 1 return trainingData
def generateOneTestAngleData(): ''' This creates a list of sample objects that can be used for testing. This list is built from the third participant's data and uses angles as features. ''' testSamples = [] index = 0 for filename in sub3: #Open the file fIn = open(filename, 'r') #For each line of the file calculate the # angles inbetween joints and use the resulting # array as the feature vector. Add that to the list. for line in fIn: features = generateAngles(line) testSamples.append(sample(features, labels[index])) fIn.close() index += 1 return testSamples
def generateOneTestAngleData(): ''' This creates a list of sample objects that can be used for testing. This list is built from the third participant's data and uses angles as features. ''' testSamples = [] index = 0 for filename in sub3: #Open the file fIn = open(filename, 'r') #For each line of the file calculate the # angles inbetween joints and use the resulting # array as the feature vector. Add that to the list. for line in fIn: features = generateAngles(line) testSamples.append(sample(features, labels[index])) fIn.close() index += 1 return testSamples
def recordJointAngles(self): #Get the values from the kinect values = self.kinect.get_posture() if values is None: #recursivly try again self.recordJointAngles() return None angleString = jsonMaker((values, )) #Make them into angles angles = generateAngles(angleString) #Parse angles stringNums = "" for angle in angles: stringNums += str(angle) + " " stringNums = stringNums[:-1] #Write the angles to a file self.output.write( " robot.setProperties(\"REP LEP RSY LSY RSR LSR RSP LSP\", \"position position position position position position position position\", " + stringNums + ")")