Esempio n. 1
0
    def perform_gesture(self):
        done = False

        if len(self.known_gestures) == 0:
            return
        i = 0
        frames = []
        while not done:
            r = wiiuse.poll(self.wiimotes, self.num_motes)
            if r != 0:

                if wiiuse.is_held(self.first_wm[0], wiiuse.button['B']):
                    roll = self.first_wm[0].orient.roll
                    pitch = self.first_wm[0].orient.pitch
                    acc_x = self.first_wm[0].gforce.x
                    acc_y = self.first_wm[0].gforce.y
                    acc_z = self.first_wm[0].gforce.z

                    frame = (roll, pitch, acc_x, acc_y, acc_z)

                    # Only add every nth frame to the list.
                    if i % self.frame_freq == 0:
                        frames.append(frame)

                if wiiuse.is_released(self.first_wm[0], wiiuse.button['B']):
                    done = True
                i += 1

        gesture = PerformedGesture(frames)
        return gesture
Esempio n. 2
0
    def perform_gesture(self):
        done = False

        if len(self.known_gestures) == 0:
            return
        i = 0
        frames = []
        while not done:
            r = wiiuse.poll(self.wiimotes, self.num_motes)
            if r != 0:

                if wiiuse.is_held(self.first_wm[0], wiiuse.button['B']):
                    roll = self.first_wm[0].orient.roll
                    pitch = self.first_wm[0].orient.pitch
                    acc_x = self.first_wm[0].gforce.x
                    acc_y = self.first_wm[0].gforce.y
                    acc_z = self.first_wm[0].gforce.z

                    frame = (roll, pitch, acc_x, acc_y, acc_z)

                    # Only add every nth frame to the list.
                    if i % self.frame_freq == 0:
                        frames.append(frame)

                if wiiuse.is_released(self.first_wm[0], wiiuse.button['B']):
                    done = True
                i += 1

        gesture = PerformedGesture(frames)
        return gesture
Esempio n. 3
0
    def learn_gesture(self, rep_limit):

        repetitions = 0         # How many times a gesture has been repeated.
        done = False
        confirmed = False

        while not confirmed:
            gest_name = raw_input("Please name your gesture: ")

            if not (self.get_gesture_names().__contains__(gest_name) or
                    len(gest_name) > 15):
                confirmed = True
            else:
                print "\nGesture name taken or too long.  Please choose another.\n"
        gest_action = raw_input("Please specify an command for your gesture: ")

        gest_arg_arr = shlex.split(gest_action)
        frame_arr = []

        print "\nPress and hold B, perform your gesture, and then release B."

        i = 0
        while not done:
            r = wiiuse.poll(self.wiimotes, self.num_motes)
            if r != 0:

                if wiiuse.is_just_pressed(self.first_wm[0], wiiuse.button['B']):
                    print "Learning gesture, round " + str(repetitions+1) + "."

                    frames = []

                if wiiuse.is_held(self.first_wm[0], wiiuse.button['B']):
                    roll = self.first_wm[0].orient.roll
                    pitch = self.first_wm[0].orient.pitch
                    acc_x = self.first_wm[0].gforce.x
                    acc_y = self.first_wm[0].gforce.y
                    acc_z = self.first_wm[0].gforce.z

                    frame = (roll, pitch, acc_x, acc_y, acc_z)

                    # Only add every nth frame to the list.
                    if i%self.frame_freq == 0:
                        frames.append(frame)

                if repetitions >= rep_limit:
                    done = True
                    print "Good! Press A to see your gesture added to the list of known gestures."
                    continue

                if wiiuse.is_released(self.first_wm[0], wiiuse.button['B']):
                    repetitions += 1
                    frame_arr.append(frames)
                    print str(rep_limit-repetitions) + " repetition(s) remaining."

                i += 1

        # Creating the average of the repetitions to create the learned gesture.
        gesture_average = self.average_gesture(frame_arr)

        # Writing Gesture to the gesture file.
        gesture = LearnedGesture(gest_name, gesture_average, gest_arg_arr, 0, 0, frame_arr)
        self.writer_reader.write_gesture(gesture)

        # Update the current known gestures.
        self.update_gestures()
Esempio n. 4
0
    def learn_gesture(self, rep_limit):

        repetitions = 0  # How many times a gesture has been repeated.
        done = False
        confirmed = False

        while not confirmed:
            gest_name = raw_input("Please name your gesture: ")

            if not (self.get_gesture_names().__contains__(gest_name)
                    or len(gest_name) > 15):
                confirmed = True
            else:
                print "\nGesture name taken or too long.  Please choose another.\n"
        gest_action = raw_input("Please specify an command for your gesture: ")

        gest_arg_arr = shlex.split(gest_action)
        frame_arr = []

        print "\nPress and hold B, perform your gesture, and then release B."

        i = 0
        while not done:
            r = wiiuse.poll(self.wiimotes, self.num_motes)
            if r != 0:

                if wiiuse.is_just_pressed(self.first_wm[0],
                                          wiiuse.button['B']):
                    print "Learning gesture, round " + str(repetitions +
                                                           1) + "."

                    frames = []

                if wiiuse.is_held(self.first_wm[0], wiiuse.button['B']):
                    roll = self.first_wm[0].orient.roll
                    pitch = self.first_wm[0].orient.pitch
                    acc_x = self.first_wm[0].gforce.x
                    acc_y = self.first_wm[0].gforce.y
                    acc_z = self.first_wm[0].gforce.z

                    frame = (roll, pitch, acc_x, acc_y, acc_z)

                    # Only add every nth frame to the list.
                    if i % self.frame_freq == 0:
                        frames.append(frame)

                if repetitions >= rep_limit:
                    done = True
                    print "Good! Press A to see your gesture added to the list of known gestures."
                    continue

                if wiiuse.is_released(self.first_wm[0], wiiuse.button['B']):
                    repetitions += 1
                    frame_arr.append(frames)
                    print str(rep_limit -
                              repetitions) + " repetition(s) remaining."

                i += 1

        # Creating the average of the repetitions to create the learned gesture.
        gesture_average = self.average_gesture(frame_arr)

        # Writing Gesture to the gesture file.
        gesture = LearnedGesture(gest_name, gesture_average, gest_arg_arr, 0,
                                 0, frame_arr)
        self.writer_reader.write_gesture(gesture)

        # Update the current known gestures.
        self.update_gestures()