Esempio n. 1
0
    def recompute_route(self):
        if self.last_position is None:
            return

        new_destination = coordinate_from_param("NavDestination", self.params)
        if new_destination is None:
            self.clear_route()
            return

        should_recompute = self.should_recompute()
        if new_destination != self.nav_destination:
            cloudlog.warning(
                f"Got new destination from NavDestination param {new_destination}"
            )
            should_recompute = True

        # Don't recompute when GPS drifts in tunnels
        if not self.gps_ok and self.step_idx is not None:
            return

        if self.recompute_countdown == 0 and should_recompute:
            self.recompute_countdown = 2**self.recompute_backoff
            self.recompute_backoff = min(6, self.recompute_backoff + 1)
            self.calculate_route(new_destination)
        else:
            self.recompute_countdown = max(0, self.recompute_countdown - 1)
Esempio n. 2
0
  def __init__(self, sm, pm):
    self.sm = sm
    self.pm = pm

    self.params = Params()

    # Get last gps position from params
    self.last_position = coordinate_from_param("LastGPSPosition", self.params)
    self.last_bearing = None

    self.gps_ok = False

    self.nav_destination = None
    self.step_idx = None
    self.route = None
    self.route_geometry = None

    self.recompute_backoff = 0
    self.recompute_countdown = 0

    self.ui_pid = None

    if "MAPBOX_TOKEN" in os.environ:
      self.mapbox_token = os.environ["MAPBOX_TOKEN"]
      self.mapbox_host = "https://api.mapbox.com"
    else:
      try:
        self.mapbox_token = Api(self.params.get("DongleId", encoding='utf8')).get_token(expiry_hours=4 * 7 * 24)
      except FileNotFoundError:
        cloudlog.exception("Failed to generate mapbox token due to missing private key. Ensure device is registered.")
        self.mapbox_token = ""
      self.mapbox_host = "https://maps.comma.ai"