Exemple #1
0
    def NextSegment(self):
        Log("simgps*","SimGps::NextSegment()")
        p1 = self.index + 1
        if p1 >= len(self.route):
            p1 = 0
        self.index = p1

        p2 = p1 + 1
        if p2 >= len(self.route):
            p2 = 0

        kmPerHour = self.speed
        metersPerSecond = kmPerHour * 1000/3600
        distance,heading = datums.CalculateDistanceAndBearing( self.route[p1], self.route[p2] )

        lat1,lon1,alt1 = self.route[p1]
        lat2,lon2,alt2 = self.route[p2]

        self.steps = int(distance/metersPerSecond)
        self.count = 0
        self.dlat = (lat2 - lat1)/float(self.steps)
        self.dlon = (lon2 - lon1)/float(self.steps)
        self.dalt = (alt2 - alt1)/float(self.steps)

        self.position["heading"] = heading
        self.position["speed"] = kmPerHour
Exemple #2
0
    def CalculateDistance(self):
        Log("gps*", "Gps::CalculateDistance()")
        distance = 0
        bearing = 0

        if self.previous != None:
            lat1, lon1 = (self.position["latitude"],
                          self.position["longitude"])
            lat2, lon2 = (self.previous["latitude"],
                          self.previous["longitude"])
            if lat1 != None and lon1 != None:
                distance, bearing = datums.CalculateDistanceAndBearing(
                    (lat1, lon1), (lat2, lon2))
                self.position["distance"] = distance
                self.previous = self.position.copy()

        Log(
            "gps#", "Gps::CalculateDistance() result: %s" %
            str(self.position["distance"]))
Exemple #3
0
    def CalculateDistance(self):
        Log("gps*", "Gps::CalculateDistance()")
        distance = 0
        bearing = 0

        time, lat1, lon1, alt = self.position
        if self.previous != None:
            time, lat2, lon2, alt = self.previous
            distance, bearing = datums.CalculateDistanceAndBearing(
                (lat1, lon1), (lat2, lon2))
            if distance > self.mindistance:
                self.previous = self.position
            else:
                distance = 0
        else:
            self.previous = self.position

        Log("gps#", "Gps::CalculateDistance() result: %f" % distance)
        return distance
Exemple #4
0
    def SignalExpiredRequests(self):
        Log("gps*", "Gps::SignalExpiredRequests()")
        self.CalculateDistance()
        for k in self.requests.keys():
            r = self.requests[k]
            if "previous" in r.keys():
                lat1, lon1 = (self.position["latitude"],
                              self.position["longitude"])
                lat2, lon2 = (r["previous"]["latitude"],
                              r["previous"]["longitude"])
                if lat1 != None and lon1 != None and lat2 != None and lon2 != None:
                    distance, bearing = datums.CalculateDistanceAndBearing(
                        (lat1, lon1), (lat2, lon2))
                else:
                    distance, bearing = None, None

                if r["tolerance"] == None:
                    p = self.position.copy()
                    p["distance"] = distance
                    p["ref"] = k
                    self.registry.Signal(p)
                    r["previous"] = p
                else:
                    if distance == None or distance >= r["tolerance"]:
                        Log(
                            "gps#",
                            "Gps::SignalExpiredRequests(): distance %s > tolerance %s"
                            % (str(distance), str(r["tolerance"])))
                        p = self.position.copy()
                        p["distance"] = distance
                        p["ref"] = k
                        self.registry.Signal(p)
                        r["previous"] = p

            else:
                p = self.position.copy()
                p["ref"] = k
                self.registry.Signal(p)
                r["previous"] = p
Exemple #5
0
 def DistanceAndBearing(self,point):
     return datums.CalculateDistanceAndBearing(
         (self.latitude,self.longitude),
         (point.latitude,point.longitude)
         )