Esempio n. 1
0
    def taskpoint_completed(self, brecord1, brecord2):
        from generalFunctions import det_bearing, det_bearing_change, determine_distance, det_local_time, ss2hhmmss

        distance1 = determine_distance(brecord1, self.LCU_line, 'pnt', 'tsk')
        distance2 = determine_distance(brecord2, self.LCU_line, 'pnt', 'tsk')

        if self.line:
            if distance2 > self.r_max or distance1 > self.r_max:
                return False
            else:  # both fixes within circle
                bearing1 = det_bearing(self.LCU_line, brecord1, 'tsk', 'pnt')
                bearing2 = det_bearing(self.LCU_line, brecord2, 'tsk', 'pnt')

                angle_wrt_orientation1 = abs(
                    det_bearing_change(self.orientation_angle, bearing1))
                angle_wrt_orientation2 = abs(
                    det_bearing_change(self.orientation_angle, bearing2))

                if self.sector_orientation == "next":  # start line
                    return angle_wrt_orientation1 < 90 < angle_wrt_orientation2
                elif self.sector_orientation == "previous":  # finish line
                    return angle_wrt_orientation2 < 90 < angle_wrt_orientation1
                else:
                    print "A line with this orientation is not implemented!"
        else:  # general sector
            bearing1 = det_bearing(self.LCU_line, brecord1, 'tsk', 'pnt')
            angle_wrt_orientation1 = abs(
                det_bearing_change(self.orientation_angle, bearing1))
            bearing2 = det_bearing(self.LCU_line, brecord2, 'tsk', 'pnt')
            angle_wrt_orientation2 = abs(
                det_bearing_change(self.orientation_angle, bearing2))

            if self.sector_orientation == "next":
                if self.r_min is not None:
                    if self.r_min < distance1 < self.r_max and angle_wrt_orientation1 < self.angle_max:
                        return (not self.r_min < distance2 < self.r_max
                                ) or angle_wrt_orientation2 > self.angle_max
                    elif distance1 < self.r_min and angle_wrt_orientation1 < self.angle_min:
                        return distance2 > self.r_min or angle_wrt_orientation2 > self.angle_max
                    else:
                        return False
                else:  # self.r_min is None
                    if distance1 < self.r_max and angle_wrt_orientation1 < self.angle_max:
                        return distance2 > self.r_min or angle_wrt_orientation2 > self.angle_max
                    else:
                        return False

            else:  # normal turnpoint or finish
                if self.r_min is not None:
                    if distance2 > self.r_max:
                        return False
                    elif self.r_min < distance2 < self.r_max:
                        return angle_wrt_orientation2 < self.angle_max
                    else:  # distance_2 < self.r_min
                        return angle_wrt_orientation2 < self.angle_min
                elif distance2 > self.r_max:
                    return False
                else:  # distance2 <= self.r_max
                    return angle_wrt_orientation2 < self.angle_max
Esempio n. 2
0
    def taskpoint_completed(self, brecord1, brecord2):
        from generalFunctions import det_bearing, det_bearing_change, determine_distance, det_local_time, ss2hhmmss

        distance1 = determine_distance(brecord1, self.LCU_line, 'pnt', 'tsk')
        distance2 = determine_distance(brecord2, self.LCU_line, 'pnt', 'tsk')

        if self.line:
            if distance2 > self.r_max or distance1 > self.r_max:
                return False
            else:  # both fixes within circle
                bearing1 = det_bearing(self.LCU_line, brecord1, 'tsk', 'pnt')
                bearing2 = det_bearing(self.LCU_line, brecord2, 'tsk', 'pnt')

                angle_wrt_orientation1 = abs(det_bearing_change(self.orientation_angle, bearing1))
                angle_wrt_orientation2 = abs(det_bearing_change(self.orientation_angle, bearing2))

                if self.sector_orientation == "next":  # start line
                    return angle_wrt_orientation1 < 90 < angle_wrt_orientation2
                elif self.sector_orientation == "previous":  # finish line
                    return angle_wrt_orientation2 < 90 < angle_wrt_orientation1
                else:
                    print "A line with this orientation is not implemented!"
        else:  # general sector
            bearing1 = det_bearing(self.LCU_line, brecord1, 'tsk', 'pnt')
            angle_wrt_orientation1 = abs(det_bearing_change(self.orientation_angle, bearing1))
            bearing2 = det_bearing(self.LCU_line, brecord2, 'tsk', 'pnt')
            angle_wrt_orientation2 = abs(det_bearing_change(self.orientation_angle, bearing2))

            if self.sector_orientation == "next":
                if self.r_min is not None:
                    if self.r_min < distance1 < self.r_max and angle_wrt_orientation1 < self.angle_max:
                        return (not self.r_min < distance2 < self.r_max) or angle_wrt_orientation2 > self.angle_max
                    elif distance1 < self.r_min and angle_wrt_orientation1 < self.angle_min:
                        return distance2 > self.r_min or angle_wrt_orientation2 > self.angle_max
                    else:
                        return False
                else:  # self.r_min is None
                    if distance1 < self.r_max and angle_wrt_orientation1 < self.angle_max:
                        return distance2 > self.r_min or angle_wrt_orientation2 > self.angle_max
                    else:
                        return False

            else:  # normal turnpoint or finish
                if self.r_min is not None:
                    if distance2 > self.r_max:
                        return False
                    elif self.r_min < distance2 < self.r_max:
                        return angle_wrt_orientation2 < self.angle_max
                    else:  # distance_2 < self.r_min
                        return angle_wrt_orientation2 < self.angle_min
                elif distance2 > self.r_max:
                    return False
                else:  # distance2 <= self.r_max
                    return angle_wrt_orientation2 < self.angle_max
Esempio n. 3
0
    def distance_moved_turnpoint(self, distance, current, currentP1,
                                 moved_point):
        from math import sqrt, cos, pi, acos

        if moved_point == "current":
            moved = current
            other = currentP1
            angle_reduction = 0
        elif moved_point == "currentP1":
            moved = currentP1
            other = current
            angle_reduction = 0
        elif moved_point == "both_currentP1":
            moved = currentP1
            other = current
            original_distance = determine_distance(current.LCU_line,
                                                   currentP1.LCU_line, 'tsk',
                                                   'tsk')
            distance_moved_current = current.r_max if current.angle_max == 180 else current.r_min
            angle_reduction = abs(
                acos((distance_moved_current**2 - distance**2 -
                      original_distance**2) /
                     (-2 * distance * original_distance))) * 180 / pi
        else:
            print "Displaced point is not recognized! " + moved_point

        displacement_dist = moved.r_max if moved.angle_max == 180 else moved.r_min
        bearing1 = moved.orientation_angle
        bearing2 = det_bearing(other.LCU_line, moved.LCU_line, 'tsk', 'tsk')
        angle = abs(det_bearing_change(bearing1, bearing2)) - angle_reduction
        distance = sqrt(distance**2 + displacement_dist**2 - 2 * distance *
                        displacement_dist * cos(angle * pi / 180))

        return distance
Esempio n. 4
0
    def distance_moved_turnpoint(self, distance, current, currentP1, moved_point):
        from math import sqrt, cos, pi, acos

        if moved_point == "current":
            moved = current
            other = currentP1
            angle_reduction = 0
        elif moved_point == "currentP1":
            moved = currentP1
            other = current
            angle_reduction = 0
        elif moved_point == "both_currentP1":
            moved = currentP1
            other = current
            original_distance = determine_distance(current.LCU_line, currentP1.LCU_line, 'tsk', 'tsk')
            distance_moved_current = current.r_max if current.angle_max == 180 else current.r_min
            angle_reduction = abs(acos((distance_moved_current ** 2 - distance ** 2 - original_distance ** 2) / (-2 * distance * original_distance))) * 180 / pi
        else:
            print "Displaced point is not recognized! " + moved_point

        displacement_dist = moved.r_max if moved.angle_max == 180 else moved.r_min
        bearing1 = moved.orientation_angle
        bearing2 = det_bearing(other.LCU_line, moved.LCU_line, 'tsk', 'tsk')
        angle = abs(det_bearing_change(bearing1, bearing2)) - angle_reduction
        distance = sqrt(distance**2 + displacement_dist**2 - 2 * distance * displacement_dist * cos(angle * pi / 180))

        return distance
Esempio n. 5
0
    def determine_phases(self, settings, competitionday, flight):

        b_record_m1 = flight.b_records[flight.tsk_i[0] - 2]
        time_m1 = det_local_time(b_record_m1, competitionday.utc_to_local)

        b_record = flight.b_records[flight.tsk_i[0] - 1]
        time = det_local_time(b_record, competitionday.utc_to_local)
        bearing = det_bearing(b_record_m1, b_record, 'pnt', 'pnt')

        cruise = True
        possible_cruise_start = 0
        possible_thermal_start = 0
        cruise_distance = 0
        temp_bearing_change = 0
        possible_turn_dir = 'left'
        sharp_thermal_entry_found = False
        bearing_change_tot = 0
        leg = 0

        self.create_entry(flight.tsk_i[0], time_m1, 'cruise', -2)
        self.create_entry(flight.tsk_i[0], time_m1, 'cruise', leg)

        for i in range(len(flight.b_records)):
            if flight.tsk_i[0] < i < flight.tsk_i[-1]:

                time_m2 = time_m1

                time_m1 = time
                bearing_m1 = bearing
                b_record_m1 = b_record

                b_record = flight.b_records[i]
                time = det_local_time(b_record, competitionday.utc_to_local)

                bearing = det_bearing(b_record_m1, b_record, 'pnt', 'pnt')
                bearing_change = det_bearing_change(bearing_m1, bearing)
                bearing_change_rate = bearing_change / (time - 0.5*time_m1 - 0.5*time_m2)

                if i == flight.tsk_i[leg+1]:
                    phase = 'cruise' if cruise else 'thermal'
                    leg += 1
                    self.close_entry(i, time, leg-1)
                    self.create_entry(i, time, phase, leg)

                if cruise:

                    if (possible_turn_dir == 'left' and bearing_change_rate < 1e-2) or\
                            (possible_turn_dir == 'right' and bearing_change_rate > -1e-2):

                        bearing_change_tot += det_bearing_change(bearing_m1, bearing)

                        if possible_thermal_start == 0:
                            possible_thermal_start = i
                        elif (not sharp_thermal_entry_found) and abs(bearing_change_rate) > settings.cruise_threshold_bearingRate:
                            sharp_thermal_entry_found = True
                            possible_thermal_start = i

                    else:  # sign change
                        bearing_change_tot = det_bearing_change(bearing_m1, bearing)

                        if bearing_change_rate < 0:
                            possible_turn_dir = 'left'
                        else:
                            possible_turn_dir = 'right'

                        possible_thermal_start = i

                    if abs(bearing_change_tot) > settings.cruise_threshold_bearingTot:
                        cruise = False
                        thermal_start_time = det_local_time(flight.b_records[possible_thermal_start], competitionday.utc_to_local)
                        self.close_entry(possible_thermal_start, thermal_start_time, -2)
                        self.close_entry(possible_thermal_start, thermal_start_time, leg)
                        self.create_entry(possible_thermal_start, thermal_start_time, 'thermal', -2)
                        self.create_entry(possible_thermal_start, thermal_start_time, 'thermal', leg)
                        possible_thermal_start = 0
                        sharp_thermal_entry_found = False
                        bearing_change_tot = 0

                else:  # thermal
                    if abs(bearing_change_rate) > settings.thermal_threshold_bearingRate:
                        if possible_cruise_start != 0:
                            cruise_distance = 0
                            temp_bearing_change = 0
                    else:  # possible cruise
                        if cruise_distance == 0:
                            possible_cruise_start = i
                            possible_cruise_t = time
                            temp_bearing_change += bearing_change
                            temp_bearing_rate_avg = 0
                        else:
                            temp_bearing_change += bearing_change
                            temp_bearing_rate_avg = temp_bearing_change / (time-possible_cruise_t)

                        cruise_distance = determine_distance(flight.b_records[possible_cruise_start-1], b_record,
                                                             'pnt', 'pnt')

                        if cruise_distance > settings.thermal_threshold_distance and \
                                        abs(temp_bearing_rate_avg) < settings.thermal_threshold_bearingRateAvg:

                            cruise = True
                            self.close_entry(possible_cruise_start, possible_cruise_t, -2)
                            self.close_entry(possible_cruise_start, possible_cruise_t, leg)
                            self.create_entry(possible_cruise_start, possible_cruise_t, 'cruise', -2)
                            self.create_entry(possible_cruise_start, possible_cruise_t, 'cruise', leg)
                            possible_cruise_start = 0
                            cruise_distance = 0
                            temp_bearing_change = 0
                            bearing_change_tot = 0

        time = det_local_time(flight.b_records[flight.tsk_i[-1]], competitionday.utc_to_local)
        self.close_entry(flight.tsk_i[-1], time, -2)
        self.close_entry(flight.tsk_i[-1], time, leg)