コード例 #1
0
  def update(self, enabled, CS, frame, actuators):
    """ Controls thread """

    can_sends = []

    ### STEER ###

    if enabled:
      # calculate steer and also set limits due to driver torque
      new_steer = int(round(actuators.steer * CarControllerParams.STEER_MAX))
      apply_steer = apply_std_steer_torque_limits(new_steer, self.apply_steer_last,
                                                  CS.out.steeringTorque, CarControllerParams)
      self.steer_rate_limited = new_steer != apply_steer

      if CS.out.standstill and frame % 5 == 0:
        # Mazda Stop and Go requires a RES button (or gas) press if the car stops more than 3 seconds
        # Send Resume button at 20hz if we're engaged at standstill to support full stop and go!
        # TODO: improve the resume trigger logic by looking at actual radar data
        can_sends.append(mazdacan.create_button_cmd(self.packer, CS.CP.carFingerprint, Buttons.RESUME))
    else:
      apply_steer = 0
      self.steer_rate_limited = False
      if CS.out.cruiseState.enabled and frame % 20 == 0:
        # Cancel Stock ACC if it's enabled while OP is disengaged
        # Send at a rate of 5hz until we sync with stock ACC state
        can_sends.append(mazdacan.create_button_cmd(self.packer, CS.CP.carFingerprint, Buttons.CANCEL))

    self.apply_steer_last = apply_steer

    can_sends.append(mazdacan.create_steering_control(self.packer, CS.CP.carFingerprint,
                                                      frame, apply_steer, CS.cam_lkas))
    return can_sends
コード例 #2
0
ファイル: carcontroller.py プロジェクト: nickn17/openpilot
    def update(self, c, CS, frame):
        can_sends = []

        apply_steer = 0
        self.steer_rate_limited = False

        if c.enabled:
            # calculate steer and also set limits due to driver torque
            new_steer = int(
                round(c.actuators.steer * CarControllerParams.STEER_MAX))
            apply_steer = apply_std_steer_torque_limits(
                new_steer, self.apply_steer_last, CS.out.steeringTorque,
                CarControllerParams)
            self.steer_rate_limited = new_steer != apply_steer

            if CS.out.standstill and frame % 5 == 0:
                # Mazda Stop and Go requires a RES button (or gas) press if the car stops more than 3 seconds
                # Send Resume button at 20hz if we're engaged at standstill to support full stop and go!
                # TODO: improve the resume trigger logic by looking at actual radar data
                can_sends.append(
                    mazdacan.create_button_cmd(self.packer,
                                               CS.CP.carFingerprint,
                                               CS.crz_btns_counter,
                                               Buttons.RESUME))

        if c.cruiseControl.cancel or (CS.out.cruiseState.enabled
                                      and not c.enabled):
            # if brake is pressed, let us wait >20ms before trying to disable crz to avoid
            # a race condition with the stock system, where the second cancel from openpilot
            # will disable the crz 'main on'
            self.brake_counter = self.brake_counter + 1
            if frame % 20 == 0 and not (CS.out.brakePressed
                                        and self.brake_counter < 3):
                # Cancel Stock ACC if it's enabled while OP is disengaged
                # Send at a rate of 5hz until we sync with stock ACC state
                can_sends.append(
                    mazdacan.create_button_cmd(self.packer,
                                               CS.CP.carFingerprint,
                                               CS.crz_btns_counter,
                                               Buttons.CANCEL))
        else:
            self.brake_counter = 0

        self.apply_steer_last = apply_steer

        # send HUD alerts
        if frame % 50 == 0:
            ldw = c.hudControl.visualAlert == VisualAlert.ldw
            steer_required = c.hudControl.visualAlert == VisualAlert.steerRequired
            can_sends.append(
                mazdacan.create_alert_command(self.packer, CS.cam_laneinfo,
                                              ldw, steer_required))

        # send steering command
        can_sends.append(
            mazdacan.create_steering_control(self.packer, CS.CP.carFingerprint,
                                             frame, apply_steer, CS.cam_lkas))
        return can_sends
コード例 #3
0
ファイル: carcontroller.py プロジェクト: c180/dragonpilot
    def update(self, enabled, CS, frame, actuators, dragonconf):
        """ Controls thread """

        can_sends = []

        ### STEER ###

        if enabled:
            # calculate steer and also set limits due to driver torque
            new_steer = int(round(actuators.steer *
                                  SteerLimitParams.STEER_MAX))
            apply_steer = apply_std_steer_torque_limits(
                new_steer, self.apply_steer_last, CS.out.steeringTorque,
                SteerLimitParams)
            self.steer_rate_limited = new_steer != apply_steer

            if CS.out.standstill and frame % 20 == 0:
                # Mazda Stop and Go requires a RES button (or gas) press if the car stops more than 3 seconds
                # Send Resume button at 5hz if we're engaged at standstill to support full stop and go!
                # TODO: improve the resume trigger logic by looking at actual radar data
                can_sends.append(
                    mazdacan.create_button_cmd(self.packer,
                                               CS.CP.carFingerprint,
                                               Buttons.RESUME))
        else:
            apply_steer = 0
            self.steer_rate_limited = False
            if CS.out.cruiseState.enabled and frame % 20 == 0:
                # Cancel Stock ACC if it's enabled while OP is disengaged
                # Send at a rate of 5hz until we sync with stock ACC state
                can_sends.append(
                    mazdacan.create_button_cmd(self.packer,
                                               CS.CP.carFingerprint,
                                               Buttons.CANCEL))

        # dp
        blinker_on = CS.out.leftBlinker or CS.out.rightBlinker
        if not enabled:
            self.blinker_end_frame = 0
        if self.last_blinker_on and not blinker_on:
            self.blinker_end_frame = frame + dragonconf.dpSignalOffDelay
        apply_steer = common_controller_ctrl(
            enabled, dragonconf, blinker_on or frame < self.blinker_end_frame,
            apply_steer, CS.out.vEgo)
        self.last_blinker_on = blinker_on

        self.apply_steer_last = apply_steer

        can_sends.append(
            mazdacan.create_steering_control(self.packer, CS.CP.carFingerprint,
                                             frame, apply_steer, CS.cam_lkas))
        return can_sends
コード例 #4
0
  def update(self, CC, CS):
    can_sends = []

    apply_steer = 0
    self.steer_rate_limited = False

    if CC.latActive:
      # calculate steer and also set limits due to driver torque
      new_steer = int(round(CC.actuators.steer * CarControllerParams.STEER_MAX))
      apply_steer = apply_std_steer_torque_limits(new_steer, self.apply_steer_last,
                                                  CS.out.steeringTorque, CarControllerParams)
      self.steer_rate_limited = new_steer != apply_steer

    if CC.cruiseControl.cancel:
      # If brake is pressed, let us wait >70ms before trying to disable crz to avoid
      # a race condition with the stock system, where the second cancel from openpilot
      # will disable the crz 'main on'. crz ctrl msg runs at 50hz. 70ms allows us to
      # read 3 messages and most likely sync state before we attempt cancel.
      self.brake_counter = self.brake_counter + 1
      if self.frame % 10 == 0 and not (CS.out.brakePressed and self.brake_counter < 7):
        # Cancel Stock ACC if it's enabled while OP is disengaged
        # Send at a rate of 10hz until we sync with stock ACC state
        can_sends.append(mazdacan.create_button_cmd(self.packer, self.CP.carFingerprint, CS.crz_btns_counter, Buttons.CANCEL))
    else:
      self.brake_counter = 0
      if CC.cruiseControl.resume and self.frame % 5 == 0:
        # Mazda Stop and Go requires a RES button (or gas) press if the car stops more than 3 seconds
        # Send Resume button when planner wants car to move
        can_sends.append(mazdacan.create_button_cmd(self.packer, self.CP.carFingerprint, CS.crz_btns_counter, Buttons.RESUME))

    self.apply_steer_last = apply_steer

    # send HUD alerts
    if self.frame % 50 == 0:
      ldw = CC.hudControl.visualAlert == VisualAlert.ldw
      steer_required = CC.hudControl.visualAlert == VisualAlert.steerRequired
      # TODO: find a way to silence audible warnings so we can add more hud alerts
      steer_required = steer_required and CS.lkas_allowed_speed
      can_sends.append(mazdacan.create_alert_command(self.packer, CS.cam_laneinfo, ldw, steer_required))

    # send steering command
    can_sends.append(mazdacan.create_steering_control(self.packer, self.CP.carFingerprint,
                                                      self.frame, apply_steer, CS.cam_lkas))

    new_actuators = CC.actuators.copy()
    new_actuators.steer = apply_steer / CarControllerParams.STEER_MAX

    self.frame += 1
    return new_actuators, can_sends