Exemplo n.º 1
0
def count_steps(data):
    print 'count_steps'
    plot_data(data)
    mag = vector_magnitude(data)
    plot_mag(mag)
    average = moving_average(data, 100)
    plot_mag(average)
    num_steps = 0
    '''
    This function counts the number of steps in data and returns the number of steps
    '''
    i = 0
    found = False
    stepArray = []
    for x in average:
        if (x >= 4 and x <= 4.03):
            if found == False:
                num_steps = num_steps + 1
                stepArray.append(i)
                found = True
            else:
                found = False
        i = i + 1

    plot_steps(average, stepArray)

    return num_steps
Exemplo n.º 2
0
    def sum_sensors(self, prey_list, predator_list):
        vectors = []

        cohesion_vector = self.cohesion_vector(prey_list)
        vectors.append(util.multiply_vector(cohesion_vector, self.COHESION_WEIGHT))

        follow_vector = self.follow_vector(prey_list)
        vectors.append(util.multiply_vector(follow_vector, self.FOLLOW_WEIGHT))

        separation_vector = self.separation_vector(prey_list)
        vectors.append(util.multiply_vector(separation_vector, self.SEPARATION_WEIGHT))

        predator_vector = self.predator_vector(predator_list)
        vectors.append(util.multiply_vector(predator_vector, self.PREDATOR_WEIGHT))

        vectors.append(self.edge_repulsion_sensor())

        x_comp = 0
        y_comp = 0

        for x, y in vectors:
            x_comp += x
            y_comp += y

        vector_magnitude = util.vector_magnitude((x_comp, y_comp))

        if vector_magnitude > self.MAX_SPEED:
            x_comp /= vector_magnitude
            y_comp /= vector_magnitude

            x_comp *= self.MAX_SPEED
            y_comp *= self.MAX_SPEED

        return (x_comp, y_comp)
Exemplo n.º 3
0
    def sum_sensors(self, prey_list, predator_list):
        vectors = []

        prey_pos_vector = self.get_closest_prey_position(prey_list)
        vectors.append(util.multiply_vector(prey_pos_vector, self.PREY_POS_WEIGHT))

        prey_vel_vector = self.get_closest_prey_velocity(prey_list)
        vectors.append(util.multiply_vector(prey_vel_vector, self.PREY_VEL_WEIGHT))

        vectors.append(util.multiply_vector(self.edge_repulsion_sensor(), 100))

        print vectors

        print """Prey_Pos: {}
        Prey_Vel: {}
        Repulsion: {}""".format(*vectors)

        x_comp = 0
        y_comp = 0

        for x, y in vectors:
            x_comp += x
            y_comp += y

        vector_magnitude = util.vector_magnitude((x_comp, y_comp))

        if vector_magnitude > self.MAX_SPEED:
            x_comp /= vector_magnitude
            y_comp /= vector_magnitude

            x_comp *= self.MAX_SPEED
            y_comp *= self.MAX_SPEED

        return (x_comp, y_comp)
Exemplo n.º 4
0
def count_steps(data):
    print 'count_steps'
    # Different Algo 
    num_steps = 0
    plot_data(data)
    plot_mag(vector_magnitude(data))
    plot_mag(moving_average((data),230))

    '''
    This function counts the number of steps in data and returns the number of steps
    '''
    return num_steps
Exemplo n.º 5
0
def run():
    # Get data
    file_name = "data.txt"  # Change to your file name
    data = iosParser.get_data(file_name)
    # print data
    number_of_steps = count_steps(data)
    magnitudes = util.vector_magnitude(data)
    plot_mag(magnitudes)
    moving_avg = util.moving_average(magnitudes, 10)
    plot_mag(moving_avg)

    print "Number of steps counted are :", number_of_steps
Exemplo n.º 6
0
def count_steps(data):
    print "Accelerometer data graph"
    plot_data(data)
    mag = vector_magnitude(data)
    plot_mag(mag)
    average = moving_average(data, 10)
    plot_mag(average)
    num_steps = 0
    '''
    ADD YOUR CODE HERE. This function counts the number of steps in data and returns the number of steps
    '''

    return num_steps
Exemplo n.º 7
0
    def sum_sensors(self, prey_list, predator_list):
        vectors = []

        prey_pos_vector = self.get_closest_prey_position(prey_list)
        vectors.append(
            util.multiply_vector(prey_pos_vector, self.PREY_POS_WEIGHT))

        prey_vel_vector = self.get_closest_prey_velocity(prey_list)
        vectors.append(
            util.multiply_vector(prey_vel_vector, self.PREY_VEL_WEIGHT))

        vectors.append(util.multiply_vector(self.edge_repulsion_sensor(), 100))

        print vectors

        print """Prey_Pos: {}
        Prey_Vel: {}
        Repulsion: {}""".format(*vectors)

        x_comp = 0
        y_comp = 0

        for x, y in vectors:
            x_comp += x
            y_comp += y

        vector_magnitude = util.vector_magnitude((x_comp, y_comp))

        if vector_magnitude > self.MAX_SPEED:
            x_comp /= vector_magnitude
            y_comp /= vector_magnitude

            x_comp *= self.MAX_SPEED
            y_comp *= self.MAX_SPEED

        return (x_comp, y_comp)