def _get_average_absolute_velocity(self, calculated_velocity, now): if calculated_velocity is None: return None current_velocity = calculated_velocity if current_velocity.magnitude() < 0.09: return Vector2D(0, 0) if current_velocity.magnitude() < 0.14: return current_velocity * 0.5 avg_magnitude = current_velocity.magnitude() * 1.4 avg_direction_delta = 0 total_weight = 1.4 previous_time = now points_used = 0 for i, velocity_and_time in enumerate(self.velocity_history.list): velocity = velocity_and_time[0] time = velocity_and_time[1] if velocity.magnitude() < 0.05: break weight = max(1.0, (1.4 - (i + 1) * 0.1)) time_delta = previous_time - time projected_velocity: Vector2D = velocity.decayed( BALL_DECAY, now - time) angle_delta = smallest_angle_difference( from_angle=current_velocity.direction(), to_angle=projected_velocity.direction()) speed_delta = projected_velocity.magnitude( ) - current_velocity.magnitude() MAX_ANGLE_DELTA = 8 MAX_SPEED_DELTA = 0.3 MAX_TIME_DELTA = 7 if abs(angle_delta) > MAX_ANGLE_DELTA or abs( speed_delta ) > MAX_SPEED_DELTA or time_delta > MAX_TIME_DELTA: ##print("DELTA TOO BIG. Angle: ", angle_delta, "| Speed:", speed_delta, "time delta", time_delta) break avg_magnitude += projected_velocity.magnitude() * weight avg_direction_delta += angle_delta * weight total_weight += weight points_used += 1 avg_magnitude /= total_weight avg_direction_delta /= total_weight avg_direction = (current_velocity.direction() + avg_direction_delta) % 360 final_projection = Vector2D.velocity_to_xy(velocity=avg_magnitude, degrees=avg_direction) """print("HISTORY (used {0}): ".format(points_used), list(map(lambda v: v[0].world_direction(), self.velocity_history.list))) print("HISTORY (used {0}): ".format(points_used), list(map(lambda v: v[0].magnitude(), self.velocity_history.list))) print("AVERAGE vector:", final_projection, "| angle: ", final_projection.world_direction(), "| speed:", final_projection.magnitude()) """ return final_projection
def get_y_north_velocity_vector(self): return Vector2D.velocity_to_xy( self.body_state.speed, inverse_y_axis(self.body_angle.get_value()))