Пример #1
0
  def _update(self, c):
    ret = self.CS.update(self.cp, self.cp_loopback)

    ret.steeringRateLimited = self.CC.steer_rate_limited if self.CC is not None else False

    if self.CS.cruise_buttons != self.CS.prev_cruise_buttons and self.CS.prev_cruise_buttons != CruiseButtons.INIT:
      be = create_button_event(self.CS.cruise_buttons, self.CS.prev_cruise_buttons, BUTTONS_DICT, CruiseButtons.UNPRESS)

      # Suppress resume button if we're resuming from stop so we don't adjust speed.
      if be.type == ButtonType.accelCruise and (ret.cruiseState.enabled and ret.standstill):
        be.type = ButtonType.unknown

      ret.buttonEvents = [be]

    events = self.create_common_events(ret, pcm_enable=False)

    if ret.vEgo < self.CP.minEnableSpeed:
      events.add(EventName.belowEngageSpeed)
    if ret.cruiseState.standstill:
      events.add(EventName.resumeRequired)
    if ret.vEgo < self.CP.minSteerSpeed:
      events.add(car.CarEvent.EventName.belowSteerSpeed)

    # handle button presses
    events.events.extend(create_button_enable_events(ret.buttonEvents))

    ret.events = events.to_msg()

    return ret
Пример #2
0
  def _update(self, c):
    ret = self.CS.update(self.cp, self.cp_cam)
    ret.steeringRateLimited = self.CC.steer_rate_limited if self.CC is not None else False

    # On some newer model years, the CANCEL button acts as a pause/resume button based on the PCM state
    # To avoid re-engaging when openpilot cancels, check user engagement intention via buttons
    # Main button also can trigger an engagement on these cars
    allow_enable = any(btn in ENABLE_BUTTONS for btn in self.CS.cruise_buttons) or any(self.CS.main_buttons)
    allow_enable = allow_enable or self.CP.carFingerprint in HDA2_CAR
    events = self.create_common_events(ret, pcm_enable=self.CS.CP.pcmCruise, allow_enable=allow_enable or True)

    if self.CS.brake_error:
      events.add(EventName.brakeUnavailable)

    if self.CS.CP.openpilotLongitudinalControl and self.CS.cruise_buttons[-1] != self.CS.prev_cruise_buttons:
      buttonEvents = [create_button_event(self.CS.cruise_buttons[-1], self.CS.prev_cruise_buttons, BUTTONS_DICT)]
      # Handle CF_Clu_CruiseSwState changing buttons mid-press
      if self.CS.cruise_buttons[-1] != 0 and self.CS.prev_cruise_buttons != 0:
        buttonEvents.append(create_button_event(0, self.CS.prev_cruise_buttons, BUTTONS_DICT))

      ret.buttonEvents = buttonEvents
      events.events.extend(create_button_enable_events(ret.buttonEvents))

    # low speed steer alert hysteresis logic (only for cars with steer cut off above 10 m/s)
    if ret.vEgo < (self.CP.minSteerSpeed + 2.) and self.CP.minSteerSpeed > 10.:
      self.low_speed_alert = True
    if ret.vEgo > (self.CP.minSteerSpeed + 4.):
      self.low_speed_alert = False
    if self.low_speed_alert:
      events.add(car.CarEvent.EventName.belowSteerSpeed)

    ret.events = events.to_msg()

    return ret
Пример #3
0
    def _update(self, c):
        ret = self.CS.update(self.cp, self.cp_cam, self.cp_body)

        buttonEvents = []

        if self.CS.cruise_buttons != self.CS.prev_cruise_buttons:
            buttonEvents.append(
                create_button_event(self.CS.cruise_buttons,
                                    self.CS.prev_cruise_buttons, BUTTONS_DICT))

        if self.CS.cruise_setting != self.CS.prev_cruise_setting:
            buttonEvents.append(
                create_button_event(self.CS.cruise_setting,
                                    self.CS.prev_cruise_setting,
                                    {1: ButtonType.altButton1}))

        ret.buttonEvents = buttonEvents

        # events
        events = self.create_common_events(ret, pcm_enable=False)
        if self.CS.brake_error:
            events.add(EventName.brakeUnavailable)

        if self.CP.pcmCruise and ret.vEgo < self.CP.minEnableSpeed:
            events.add(EventName.belowEngageSpeed)

        if self.CP.pcmCruise:
            # we engage when pcm is active (rising edge)
            if ret.cruiseState.enabled and not self.CS.out.cruiseState.enabled:
                events.add(EventName.pcmEnable)
            elif not ret.cruiseState.enabled and (
                    c.actuators.accel >= 0.
                    or not self.CP.openpilotLongitudinalControl):
                # it can happen that car cruise disables while comma system is enabled: need to
                # keep braking if needed or if the speed is very low
                if ret.vEgo < self.CP.minEnableSpeed + 2.:
                    # non loud alert if cruise disables below 25mph as expected (+ a little margin)
                    events.add(EventName.speedTooLow)
                else:
                    events.add(EventName.cruiseDisabled)
        if self.CS.CP.minEnableSpeed > 0 and ret.vEgo < 0.001:
            events.add(EventName.manualRestart)

        # handle button presses
        events.events.extend(
            create_button_enable_events(ret.buttonEvents, self.CP.pcmCruise))

        ret.events = events.to_msg()

        return ret
Пример #4
0
    def create_common_events(self,
                             cs_out,
                             extra_gears=None,
                             pcm_enable=True,
                             allow_enable=True):
        events = Events()

        if cs_out.doorOpen:
            events.add(EventName.doorOpen)
        if cs_out.seatbeltUnlatched:
            events.add(EventName.seatbeltNotLatched)
        if cs_out.gearShifter != GearShifter.drive and (
                extra_gears is None or cs_out.gearShifter not in extra_gears):
            events.add(EventName.wrongGear)
        if cs_out.gearShifter == GearShifter.reverse:
            events.add(EventName.reverseGear)
        if not cs_out.cruiseState.available:
            events.add(EventName.wrongCarMode)
        if cs_out.espDisabled:
            events.add(EventName.espDisabled)
        if cs_out.stockFcw:
            events.add(EventName.stockFcw)
        if cs_out.stockAeb:
            events.add(EventName.stockAeb)
        if cs_out.vEgo > MAX_CTRL_SPEED:
            events.add(EventName.speedTooHigh)
        if cs_out.cruiseState.nonAdaptive:
            events.add(EventName.wrongCruiseMode)
        if cs_out.brakeHoldActive and self.CP.openpilotLongitudinalControl:
            events.add(EventName.brakeHold)
        if cs_out.parkingBrake:
            events.add(EventName.parkBrake)
        if cs_out.accFaulted:
            events.add(EventName.accFaulted)

        # Handle button presses
        events.events.extend(
            create_button_enable_events(cs_out.buttonEvents,
                                        pcm_cruise=self.CP.pcmCruise))

        # Handle permanent and temporary steering faults
        self.steering_unpressed = 0 if cs_out.steeringPressed else self.steering_unpressed + 1
        if cs_out.steerFaultTemporary:
            # if the user overrode recently, show a less harsh alert
            if self.silent_steer_warning or cs_out.standstill or self.steering_unpressed < int(
                    1.5 / DT_CTRL):
                self.silent_steer_warning = True
                events.add(EventName.steerTempUnavailableSilent)
            else:
                events.add(EventName.steerTempUnavailable)
        else:
            self.silent_steer_warning = False
        if cs_out.steerFaultPermanent:
            events.add(EventName.steerUnavailable)

        # we engage when pcm is active (rising edge)
        # enabling can optionally be blocked by the car interface
        if pcm_enable:
            if cs_out.cruiseState.enabled and not self.CS.out.cruiseState.enabled and allow_enable:
                events.add(EventName.pcmEnable)
            elif not cs_out.cruiseState.enabled:
                events.add(EventName.pcmDisable)

        return events