openpilot is an open source driver assistance system. openpilot performs the functions of Automated Lane Centering and Adaptive Cruise Control for over 200 supported car makes and models.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

787 lines
32 KiB

#!/usr/bin/env python3
import os
import math
from numbers import Number
from cereal import car, log
from common.numpy_fast import clip
from common.realtime import sec_since_boot, config_realtime_process, Priority, Ratekeeper, DT_CTRL
from common.profiler import Profiler
from common.params import Params, put_nonblocking
import cereal.messaging as messaging
from common.conversions import Conversions as CV
from selfdrive.swaglog import cloudlog
from selfdrive.boardd.boardd import can_list_to_can_capnp
from selfdrive.car.car_helpers import get_car, get_startup_event, get_one_can
from selfdrive.controls.lib.lane_planner import CAMERA_OFFSET
from selfdrive.controls.lib.drive_helpers import update_v_cruise, initialize_v_cruise
from selfdrive.controls.lib.drive_helpers import get_lag_adjusted_curvature
from selfdrive.controls.lib.longcontrol import LongControl
from selfdrive.controls.lib.latcontrol_pid import LatControlPID
from selfdrive.controls.lib.latcontrol_indi import LatControlINDI
from selfdrive.controls.lib.latcontrol_lqr import LatControlLQR
from selfdrive.controls.lib.latcontrol_angle import LatControlAngle
from selfdrive.controls.lib.events import Events, ET
from selfdrive.controls.lib.alertmanager import AlertManager, set_offroad_alert
from selfdrive.controls.lib.vehicle_model import VehicleModel
from selfdrive.locationd.calibrationd import Calibration
from selfdrive.hardware import HARDWARE, TICI, EON
from selfdrive.manager.process_config import managed_processes
SOFT_DISABLE_TIME = 3 # seconds
LDW_MIN_SPEED = 31 * CV.MPH_TO_MS
LANE_DEPARTURE_THRESHOLD = 0.1
REPLAY = "REPLAY" in os.environ
dockerize carla + openpilot (#2011) * dockerize carla + openpilot * separate dockerfile * bring back CI dockerfile * cleanup bridge * add op docker build and start script * build container in CI * fix camerad hack * remove most magic numbers from bridge.py * openpilot-sim docker build and run scripts * fix dmonitoring hacks * revert controlsd hacks * clean up build scripts * singular * fix path * fix image name * modify sim readme * sim readme and start script changes * dockerfile with working opengl * working opengl + passing panda build_st in docker * fix bug in sim docker file * bugfix sim docker file * bugfix all op-sim docker issues * modify readme + run script * IT DRIVES * clean this up * more cleanup * cleanup docker stuff * more cleanup * start with openpilot-base * install carla python package * Script is not in lib * chmod * everything should be running in docker now, the code may not be nice though * works locally... * rhdChecked is deprecated * Checkout using git lfs when building sim container * try to pass the tests * pull latest docker * gps should not throw an error on openpilot launch in bridge.py * fixed a coding style error * Only start ubloxd in car * fixed more style problems * revert typo * Use enviromental variable to prevent errors in a simulator * Remove unused import * Attempt to fix missing enviromental variable * fix typo * less work for users, auto tmux engagement * less work for users, auto tmux engagement * fix check for nvidia * clean up nvidia check * remove typo, shorted dockerfile Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> Co-authored-by: Willem Melching <willem.melching@gmail.com> Co-authored-by: Bruce Wayne <batman@workstation-eu-gregor.eu.local> Co-authored-by: Gregor Kikelj <gregor1234567890@gmail.com> old-commit-hash: c5dfbe7a72c6f31a0aa3a32b6df3f81409b40faf
5 years ago
SIMULATION = "SIMULATION" in os.environ
NOSENSOR = "NOSENSOR" in os.environ
IGNORE_PROCESSES = {"rtshield", "uploader", "deleter", "loggerd", "logmessaged", "tombstoned",
"logcatd", "proclogd", "clocksd", "updated", "timezoned", "manage_athenad",
"statsd", "shutdownd"} | \
{k for k, v in managed_processes.items() if not v.enabled}
ThermalStatus = log.DeviceState.ThermalStatus
State = log.ControlsState.OpenpilotState
PandaType = log.PandaState.PandaType
Desire = log.LateralPlan.Desire
LaneChangeState = log.LateralPlan.LaneChangeState
LaneChangeDirection = log.LateralPlan.LaneChangeDirection
EventName = car.CarEvent.EventName
ButtonEvent = car.CarState.ButtonEvent
SafetyModel = car.CarParams.SafetyModel
IGNORED_SAFETY_MODES = (SafetyModel.silent, SafetyModel.noOutput)
CSID_MAP = {"0": EventName.roadCameraError, "1": EventName.wideRoadCameraError, "2": EventName.driverCameraError}
ACTUATOR_FIELDS = tuple(car.CarControl.Actuators.schema.fields.keys())
ACTIVE_STATES = (State.enabled, State.softDisabling)
ENABLED_STATES = (State.preEnabled, *ACTIVE_STATES)
class Controls:
def __init__(self, sm=None, pm=None, can_sock=None, CI=None):
config_realtime_process(4 if TICI else 3, Priority.CTRL_HIGH)
# Setup sockets
self.pm = pm
if self.pm is None:
self.pm = messaging.PubMaster(['sendcan', 'controlsState', 'carState',
'carControl', 'carEvents', 'carParams'])
self.camera_packets = ["roadCameraState", "driverCameraState"]
if TICI:
self.camera_packets.append("wideRoadCameraState")
Fixup joystick (#21129) * some common changes * rename to joystick * add alert and update controlsd to work with joystick * update joystickd * Update Joystick readme * assume we have inputs * only send gb or steer when engaged_toggle is true * Update instructions * fix --ip * Easier to understand at a glance * much better * -a * receive events and send msg in same loop * always import * Update selfdrive/controls/lib/events.py Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> * Update selfdrive/controls/lib/events.py Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> * combine logic and clean up * use argparse * outdated, and use normal class * rm * bit of a refactor * refactor part 2 / 3 * much better (3 / 3) * Simplify * bump cereal and update readme * capitalize * Update tools/joystick/joystickd.py Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> * Update tools/joystick/joystickd.py Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> * make joystick abstraction class clearer * use interp, clearer without comments * no need to use apply_deadzone * more explicit * define btns and axes once * split function by use_keyboard again, but simpler * we can use handle_button as a reset function * need to flip sign * remove * invert axes map for kb, easier to read the button mapping * apply changes from review * new lateral log for debug mode * bump * add saturated * static alert * joystick_mode * conditionally subscribe * Update selfdrive/controls/controlsd.py Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> * move params instantiation * Spoof active and enabled * Only allow car to engage * no startup alert if joystick * Update controlsd.py * Should be orange not enabled, green enabled * no more button states * should work * blue * submaster conflates, so only send when we have an update * final change * remove msg * clean up a bit sort of clean up clean up a bit remove msg * this was right * Apply suggestions from code review Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> * lowercase * suggestions from code review * forgot laptop * bump to latest * fixes Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> Co-authored-by: vanillagorillaa <31773928+vanillagorillaa@users.noreply.github.com> old-commit-hash: ae77f693a26527ffbee044f852cc4185718c2433
4 years ago
params = Params()
self.joystick_mode = params.get_bool("JoystickDebugMode")
joystick_packet = ['testJoystick'] if self.joystick_mode else []
self.sm = sm
if self.sm is None:
ignore = ['driverCameraState', 'managerState'] if SIMULATION else None
self.sm = messaging.SubMaster(['deviceState', 'pandaStates', 'peripheralState', 'modelV2', 'liveCalibration',
'driverMonitoringState', 'longitudinalPlan', 'lateralPlan', 'liveLocationKalman',
Fixup joystick (#21129) * some common changes * rename to joystick * add alert and update controlsd to work with joystick * update joystickd * Update Joystick readme * assume we have inputs * only send gb or steer when engaged_toggle is true * Update instructions * fix --ip * Easier to understand at a glance * much better * -a * receive events and send msg in same loop * always import * Update selfdrive/controls/lib/events.py Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> * Update selfdrive/controls/lib/events.py Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> * combine logic and clean up * use argparse * outdated, and use normal class * rm * bit of a refactor * refactor part 2 / 3 * much better (3 / 3) * Simplify * bump cereal and update readme * capitalize * Update tools/joystick/joystickd.py Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> * Update tools/joystick/joystickd.py Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> * make joystick abstraction class clearer * use interp, clearer without comments * no need to use apply_deadzone * more explicit * define btns and axes once * split function by use_keyboard again, but simpler * we can use handle_button as a reset function * need to flip sign * remove * invert axes map for kb, easier to read the button mapping * apply changes from review * new lateral log for debug mode * bump * add saturated * static alert * joystick_mode * conditionally subscribe * Update selfdrive/controls/controlsd.py Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> * move params instantiation * Spoof active and enabled * Only allow car to engage * no startup alert if joystick * Update controlsd.py * Should be orange not enabled, green enabled * no more button states * should work * blue * submaster conflates, so only send when we have an update * final change * remove msg * clean up a bit sort of clean up clean up a bit remove msg * this was right * Apply suggestions from code review Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> * lowercase * suggestions from code review * forgot laptop * bump to latest * fixes Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> Co-authored-by: vanillagorillaa <31773928+vanillagorillaa@users.noreply.github.com> old-commit-hash: ae77f693a26527ffbee044f852cc4185718c2433
4 years ago
'managerState', 'liveParameters', 'radarState'] + self.camera_packets + joystick_packet,
ignore_alive=ignore, ignore_avg_freq=['radarState', 'longitudinalPlan'])
self.can_sock = can_sock
if can_sock is None:
can_timeout = None if os.environ.get('NO_CAN_TIMEOUT', False) else 100
self.can_sock = messaging.sub_sock('can', timeout=can_timeout)
if TICI:
self.log_sock = messaging.sub_sock('androidLog')
if CI is None:
# wait for one pandaState and one CAN packet
print("Waiting for CAN messages...")
get_one_can(self.can_sock)
self.CI, self.CP = get_car(self.can_sock, self.pm.sock['sendcan'])
else:
self.CI, self.CP = CI, CI.CP
self.CP.alternativeExperience = 0 # see panda/board/safety_declarations.h for allowed values
# read params
self.is_metric = params.get_bool("IsMetric")
self.is_ldw_enabled = params.get_bool("IsLdwEnabled")
openpilot_enabled_toggle = params.get_bool("OpenpilotEnabledToggle")
passive = params.get_bool("Passive") or not openpilot_enabled_toggle
# detect sound card presence and ensure successful init
sounds_available = HARDWARE.get_sound_card_online()
car_recognized = self.CP.carName != 'mock'
controller_available = self.CI.CC is not None and not passive and not self.CP.dashcamOnly
self.read_only = not car_recognized or not controller_available or self.CP.dashcamOnly
if self.read_only:
safety_config = car.CarParams.SafetyConfig.new_message()
safety_config.safetyModel = car.CarParams.SafetyModel.noOutput
self.CP.safetyConfigs = [safety_config]
# Write CarParams for radard
cp_bytes = self.CP.to_bytes()
params.put("CarParams", cp_bytes)
put_nonblocking("CarParamsCache", cp_bytes)
self.CC = car.CarControl.new_message()
self.CS_prev = car.CarState.new_message()
self.AM = AlertManager()
self.events = Events()
self.LoC = LongControl(self.CP)
self.VM = VehicleModel(self.CP)
if self.CP.steerControlType == car.CarParams.SteerControlType.angle:
self.LaC = LatControlAngle(self.CP, self.CI)
elif self.CP.lateralTuning.which() == 'pid':
self.LaC = LatControlPID(self.CP, self.CI)
elif self.CP.lateralTuning.which() == 'indi':
self.LaC = LatControlINDI(self.CP, self.CI)
elif self.CP.lateralTuning.which() == 'lqr':
self.LaC = LatControlLQR(self.CP, self.CI)
self.initialized = False
self.state = State.disabled
self.enabled = False
self.active = False
self.can_rcv_error = False
self.soft_disable_timer = 0
self.v_cruise_kph = 255
self.v_cruise_kph_last = 0
self.mismatch_counter = 0
self.cruise_mismatch_counter = 0
self.can_rcv_error_counter = 0
self.last_blinker_frame = 0
self.distance_traveled = 0
self.last_functional_fan_frame = 0
self.events_prev = []
self.current_alert_types = [ET.PERMANENT]
self.logged_comm_issue = False
self.button_timers = {ButtonEvent.Type.decelCruise: 0, ButtonEvent.Type.accelCruise: 0}
self.last_actuators = car.CarControl.Actuators.new_message()
# TODO: no longer necessary, aside from process replay
self.sm['liveParameters'].valid = True
self.startup_event = get_startup_event(car_recognized, controller_available, len(self.CP.carFw) > 0)
if not sounds_available:
self.events.add(EventName.soundsUnavailable, static=True)
if not car_recognized:
self.events.add(EventName.carUnrecognized, static=True)
if len(self.CP.carFw) > 0:
set_offroad_alert("Offroad_CarUnrecognized", True)
else:
set_offroad_alert("Offroad_NoFirmware", True)
elif self.read_only:
self.events.add(EventName.dashcamMode, static=True)
Fixup joystick (#21129) * some common changes * rename to joystick * add alert and update controlsd to work with joystick * update joystickd * Update Joystick readme * assume we have inputs * only send gb or steer when engaged_toggle is true * Update instructions * fix --ip * Easier to understand at a glance * much better * -a * receive events and send msg in same loop * always import * Update selfdrive/controls/lib/events.py Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> * Update selfdrive/controls/lib/events.py Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> * combine logic and clean up * use argparse * outdated, and use normal class * rm * bit of a refactor * refactor part 2 / 3 * much better (3 / 3) * Simplify * bump cereal and update readme * capitalize * Update tools/joystick/joystickd.py Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> * Update tools/joystick/joystickd.py Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> * make joystick abstraction class clearer * use interp, clearer without comments * no need to use apply_deadzone * more explicit * define btns and axes once * split function by use_keyboard again, but simpler * we can use handle_button as a reset function * need to flip sign * remove * invert axes map for kb, easier to read the button mapping * apply changes from review * new lateral log for debug mode * bump * add saturated * static alert * joystick_mode * conditionally subscribe * Update selfdrive/controls/controlsd.py Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> * move params instantiation * Spoof active and enabled * Only allow car to engage * no startup alert if joystick * Update controlsd.py * Should be orange not enabled, green enabled * no more button states * should work * blue * submaster conflates, so only send when we have an update * final change * remove msg * clean up a bit sort of clean up clean up a bit remove msg * this was right * Apply suggestions from code review Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> * lowercase * suggestions from code review * forgot laptop * bump to latest * fixes Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> Co-authored-by: vanillagorillaa <31773928+vanillagorillaa@users.noreply.github.com> old-commit-hash: ae77f693a26527ffbee044f852cc4185718c2433
4 years ago
elif self.joystick_mode:
self.events.add(EventName.joystickDebug, static=True)
self.startup_event = None
# controlsd is driven by can recv, expected at 100Hz
self.rk = Ratekeeper(100, print_delay_threshold=None)
self.prof = Profiler(False) # off by default
def update_events(self, CS):
"""Compute carEvents from carState"""
self.events.clear()
# Add startup event
if self.startup_event is not None:
self.events.add(self.startup_event)
self.startup_event = None
# Don't add any more events if not initialized
if not self.initialized:
self.events.add(EventName.controlsInitializing)
return
# Disable on rising edge of gas or brake. Also disable on brake when speed > 0
if (CS.gasPressed and not self.CS_prev.gasPressed) or \
(CS.brakePressed and (not self.CS_prev.brakePressed or not CS.standstill)):
self.events.add(EventName.pedalPressed)
self.events.add_from_msg(CS.events)
if not self.CP.notCar:
self.events.add_from_msg(self.sm['driverMonitoringState'].events)
# Create events for battery, temperature, disk space, and memory
if EON and (self.sm['peripheralState'].pandaType != PandaType.uno) and \
self.sm['deviceState'].batteryPercent < 1 and self.sm['deviceState'].chargingError:
# at zero percent battery, while discharging, OP should not allowed
self.events.add(EventName.lowBattery)
if self.sm['deviceState'].thermalStatus >= ThermalStatus.red:
self.events.add(EventName.overheat)
if self.sm['deviceState'].freeSpacePercent < 7 and not SIMULATION:
# under 7% of space free no enable allowed
self.events.add(EventName.outOfSpace)
# TODO: make tici threshold the same
if self.sm['deviceState'].memoryUsagePercent > (90 if TICI else 65) and not SIMULATION:
self.events.add(EventName.lowMemory)
# TODO: enable this once loggerd CPU usage is more reasonable
#cpus = list(self.sm['deviceState'].cpuUsagePercent)[:(-1 if EON else None)]
#if max(cpus, default=0) > 95 and not SIMULATION:
# self.events.add(EventName.highCpuUsage)
# Alert if fan isn't spinning for 5 seconds
if self.sm['peripheralState'].pandaType in (PandaType.uno, PandaType.dos):
if self.sm['peripheralState'].fanSpeedRpm == 0 and self.sm['deviceState'].fanSpeedPercentDesired > 50:
if (self.sm.frame - self.last_functional_fan_frame) * DT_CTRL > 5.0:
self.events.add(EventName.fanMalfunction)
else:
self.last_functional_fan_frame = self.sm.frame
# Handle calibration status
cal_status = self.sm['liveCalibration'].calStatus
if cal_status != Calibration.CALIBRATED:
if cal_status == Calibration.UNCALIBRATED:
self.events.add(EventName.calibrationIncomplete)
else:
self.events.add(EventName.calibrationInvalid)
# Handle lane change
if self.sm['lateralPlan'].laneChangeState == LaneChangeState.preLaneChange:
direction = self.sm['lateralPlan'].laneChangeDirection
if (CS.leftBlindspot and direction == LaneChangeDirection.left) or \
(CS.rightBlindspot and direction == LaneChangeDirection.right):
self.events.add(EventName.laneChangeBlocked)
else:
if direction == LaneChangeDirection.left:
self.events.add(EventName.preLaneChangeLeft)
else:
self.events.add(EventName.preLaneChangeRight)
elif self.sm['lateralPlan'].laneChangeState in (LaneChangeState.laneChangeStarting,
LaneChangeState.laneChangeFinishing):
self.events.add(EventName.laneChange)
if not CS.canValid:
self.events.add(EventName.canError)
for i, pandaState in enumerate(self.sm['pandaStates']):
# All pandas must match the list of safetyConfigs, and if outside this list, must be silent or noOutput
if i < len(self.CP.safetyConfigs):
safety_mismatch = pandaState.safetyModel != self.CP.safetyConfigs[i].safetyModel or \
pandaState.safetyParam != self.CP.safetyConfigs[i].safetyParam or \
pandaState.alternativeExperience != self.CP.alternativeExperience
else:
safety_mismatch = pandaState.safetyModel not in IGNORED_SAFETY_MODES
if safety_mismatch or self.mismatch_counter >= 200:
self.events.add(EventName.controlsMismatch)
if log.PandaState.FaultType.relayMalfunction in pandaState.faults:
self.events.add(EventName.relayMalfunction)
# Check for HW or system issues
if len(self.sm['radarState'].radarErrors):
self.events.add(EventName.radarFault)
elif not self.sm.valid["pandaStates"]:
self.events.add(EventName.usbError)
elif not self.sm.all_alive_and_valid() or self.can_rcv_error:
self.events.add(EventName.commIssue)
if not self.logged_comm_issue:
invalid = [s for s, valid in self.sm.valid.items() if not valid]
not_alive = [s for s, alive in self.sm.alive.items() if not alive]
cloudlog.event("commIssue", invalid=invalid, not_alive=not_alive, can_error=self.can_rcv_error, error=True)
self.logged_comm_issue = True
else:
self.logged_comm_issue = False
if not self.sm['liveParameters'].valid:
self.events.add(EventName.vehicleModelInvalid)
if not self.sm['lateralPlan'].mpcSolutionValid:
self.events.add(EventName.plannerError)
if not self.sm['liveLocationKalman'].sensorsOK and not NOSENSOR:
if self.sm.frame > 5 / DT_CTRL: # Give locationd some time to receive all the inputs
self.events.add(EventName.sensorDataInvalid)
if not self.sm['liveLocationKalman'].posenetOK:
self.events.add(EventName.posenetInvalid)
if not self.sm['liveLocationKalman'].deviceStable:
self.events.add(EventName.deviceFalling)
if not REPLAY:
# Check for mismatch between openpilot and car's PCM
cruise_mismatch = CS.cruiseState.enabled and (not self.enabled or not self.CP.pcmCruise)
self.cruise_mismatch_counter = self.cruise_mismatch_counter + 1 if cruise_mismatch else 0
if self.cruise_mismatch_counter > int(3. / DT_CTRL):
self.events.add(EventName.cruiseMismatch)
# Check for FCW
stock_long_is_braking = self.enabled and not self.CP.openpilotLongitudinalControl and CS.aEgo < -1.25
model_fcw = self.sm['modelV2'].meta.hardBrakePredicted and not CS.brakePressed and not stock_long_is_braking
planner_fcw = self.sm['longitudinalPlan'].fcw and self.enabled
if planner_fcw or model_fcw:
self.events.add(EventName.fcw)
if TICI:
for m in messaging.drain_sock(self.log_sock, wait_for_one=False):
try:
msg = m.androidLog.message
if any(err in msg for err in ("ERROR_CRC", "ERROR_ECC", "ERROR_STREAM_UNDERFLOW", "APPLY FAILED")):
csid = msg.split("CSID:")[-1].split(" ")[0]
evt = CSID_MAP.get(csid, None)
if evt is not None:
self.events.add(evt)
except UnicodeDecodeError:
pass
# TODO: fix simulator
if not SIMULATION:
if not NOSENSOR:
if not self.sm['liveLocationKalman'].gpsOK and (self.distance_traveled > 1000):
# Not show in first 1 km to allow for driving out of garage. This event shows after 5 minutes
self.events.add(EventName.noGps)
if not self.sm.all_alive(self.camera_packets):
self.events.add(EventName.cameraMalfunction)
if self.sm['modelV2'].frameDropPerc > 20:
self.events.add(EventName.modeldLagging)
if self.sm['liveLocationKalman'].excessiveResets:
self.events.add(EventName.localizerMalfunction)
# Check if all manager processes are running
not_running = {p.name for p in self.sm['managerState'].processes if not p.running}
if self.sm.rcv_frame['managerState'] and (not_running - IGNORE_PROCESSES):
self.events.add(EventName.processNotRunning)
# Only allow engagement with brake pressed when stopped behind another stopped car
speeds = self.sm['longitudinalPlan'].speeds
if len(speeds) > 1:
v_future = speeds[-1]
else:
v_future = 100.0
if CS.brakePressed and v_future >= self.CP.vEgoStarting \
and self.CP.openpilotLongitudinalControl and CS.vEgo < 0.3:
self.events.add(EventName.noTarget)
def data_sample(self):
"""Receive data from sockets and update carState"""
# Update carState from CAN
can_strs = messaging.drain_sock_raw(self.can_sock, wait_for_one=True)
CS = self.CI.update(self.CC, can_strs)
self.sm.update(0)
if not self.initialized:
all_valid = CS.canValid and self.sm.all_alive_and_valid()
if all_valid or self.sm.frame * DT_CTRL > 3.5 or SIMULATION:
if not self.read_only:
self.CI.init(self.CP, self.can_sock, self.pm.sock['sendcan'])
self.initialized = True
if REPLAY and self.sm['pandaStates'][0].controlsAllowed:
self.state = State.enabled
Params().put_bool("ControlsReady", True)
# Check for CAN timeout
if not can_strs:
self.can_rcv_error_counter += 1
self.can_rcv_error = True
else:
self.can_rcv_error = False
# When the panda and controlsd do not agree on controls_allowed
# we want to disengage openpilot. However the status from the panda goes through
# another socket other than the CAN messages and one can arrive earlier than the other.
# Therefore we allow a mismatch for two samples, then we trigger the disengagement.
if not self.enabled:
self.mismatch_counter = 0
# All pandas not in silent mode must have controlsAllowed when openpilot is enabled
if self.enabled and any(not ps.controlsAllowed for ps in self.sm['pandaStates']
if ps.safetyModel not in IGNORED_SAFETY_MODES):
self.mismatch_counter += 1
self.distance_traveled += CS.vEgo * DT_CTRL
return CS
def state_transition(self, CS):
"""Compute conditional state transitions and execute actions on state transitions"""
self.v_cruise_kph_last = self.v_cruise_kph
# if stock cruise is completely disabled, then we can use our own set speed logic
if not self.CP.pcmCruise:
self.v_cruise_kph = update_v_cruise(self.v_cruise_kph, CS.buttonEvents, self.button_timers, self.enabled, self.is_metric)
else:
if CS.cruiseState.available:
self.v_cruise_kph = CS.cruiseState.speed * CV.MS_TO_KPH
else:
self.v_cruise_kph = 0
# decrement the soft disable timer at every step, as it's reset on
# entrance in SOFT_DISABLING state
self.soft_disable_timer = max(0, self.soft_disable_timer - 1)
self.current_alert_types = [ET.PERMANENT]
controlsState: add override state with grey border (#24030) * Squashed commit of the following: commit f0cf822666fb8f78a486d721fe474e8f37da6970 Author: Shane Smiskol <shane@smiskol.com> Date: Mon Apr 4 17:24:00 2022 -0700 clean up commit 4364bdb79b1b055daa7542267eb3f37740723fd4 Merge: d448664cf e85f82af3 Author: Shane Smiskol <shane@smiskol.com> Date: Mon Apr 4 17:21:41 2022 -0700 Merge remote-tracking branch 'upstream/master' into override-alert-type commit d448664cfdacbdfd3c99f8e12d96f2ba7b24abb5 Author: Shane Smiskol <shane@smiskol.com> Date: Mon Apr 4 17:20:44 2022 -0700 revert tests changes commit 40ab8c2d912ccbeb12286ca272e3737656388ac8 Author: Shane Smiskol <shane@smiskol.com> Date: Fri Apr 1 19:03:39 2022 -0700 sort commit 5abd4448b420e91eda57e3c4edb6794893dab42f Author: Shane Smiskol <shane@smiskol.com> Date: Fri Apr 1 19:02:59 2022 -0700 bump cereal commit fcffc42082b1460676554924461c63c881c31501 Author: Shane Smiskol <shane@smiskol.com> Date: Fri Apr 1 19:02:25 2022 -0700 pass in CI commit f47dd63bc597e18c05d2d9365eb996c13ec70c17 Author: Shane Smiskol <shane@smiskol.com> Date: Fri Apr 1 12:06:00 2022 -0700 update refs commit f1c54e16ccfa37f770b422ad77e2fc940f8ea7f2 Author: Shane Smiskol <shane@smiskol.com> Date: Fri Apr 1 11:51:04 2022 -0700 move to tuple commit bebafc6ed223a67e59daa7c2105f8cb28c4f9c5f Merge: b0578dc54 0e983562d Author: Shane Smiskol <shane@smiskol.com> Date: Fri Apr 1 11:45:19 2022 -0700 Merge remote-tracking branch 'upstream/master' into override-alert-type commit b0578dc54f9d943e0ab2182b0b79d076129468a7 Author: Shane Smiskol <shane@smiskol.com> Date: Fri Apr 1 11:44:37 2022 -0700 make global variables of states in controlsd make global variables of states in controlsd commit 32b7e293e88f001ef44c9197dfc68b7240ae129e Author: Shane Smiskol <shane@smiskol.com> Date: Thu Mar 31 23:41:41 2022 -0700 test individual event types fix commit 1fbf66fc8ba7e5a0a25d34a1f30a2cb3ccb86a02 Author: Shane Smiskol <shane@smiskol.com> Date: Thu Mar 31 23:03:09 2022 -0700 clean up test state machine test state machine commit 33856bef69b1c2e637e58032b1358f275a6cd6bb Author: Shane Smiskol <shane@smiskol.com> Date: Thu Mar 31 22:59:05 2022 -0700 clean up commit d64cd664980edd6cff0038379a5c3965409ebda0 Author: Shane Smiskol <shane@smiskol.com> Date: Thu Mar 31 22:40:25 2022 -0700 test few more things commit 72a3e57a9a8813b348a8ae9648e283983f7ba56b Author: Shane Smiskol <shane@smiskol.com> Date: Thu Mar 31 22:17:22 2022 -0700 default transitions commit ce0051fde8296dab6417d9ef175fdf039d09a8f3 Author: Shane Smiskol <shane@smiskol.com> Date: Thu Mar 31 22:05:21 2022 -0700 remove commit 56de4f8a87e9b96dd99739772da1dddaa873ceb1 Author: Shane Smiskol <shane@smiskol.com> Date: Thu Mar 31 22:05:15 2022 -0700 this way we can test any combo of event types commit bdfd47738e5a3c0e22817047cc2d804ca0fe2785 Author: Shane Smiskol <shane@smiskol.com> Date: Thu Mar 31 21:36:33 2022 -0700 add some state machine tests commit 81a72d1773b204cc984fb0631ac30fb00555962d Author: Shane Smiskol <shane@smiskol.com> Date: Thu Mar 31 17:43:03 2022 -0700 update refs commit 00018708714b156c29f963011a6193fa9028b308 Merge: fa97ffa67 fa934d846 Author: Shane Smiskol <shane@smiskol.com> Date: Thu Mar 31 17:31:51 2022 -0700 Merge remote-tracking branch 'upstream/master' into override-alert-type commit fa97ffa67eec1556b2b255ee68bdf46fc101596e Author: Shane Smiskol <shane@smiskol.com> Date: Thu Mar 31 17:30:23 2022 -0700 revert todo commit b0dcd49b0b0254a4754ddc5ea61618246686327d Author: Shane Smiskol <shane@smiskol.com> Date: Wed Mar 30 00:07:11 2022 -0700 move back commit ef12853ceed8c8aa37b16af406e510d172269226 Author: Shane Smiskol <shane@smiskol.com> Date: Tue Mar 29 23:09:05 2022 -0700 bump cereal commit 2658f557e2fac79563b74385b8676a659f31f7dc Author: Shane Smiskol <shane@smiskol.com> Date: Mon Mar 28 20:54:48 2022 -0700 fix commit ed2db85acd34cd78017c6bae0db5df3356c2c19c Author: Shane Smiskol <shane@smiskol.com> Date: Mon Mar 28 20:47:18 2022 -0700 add alert to pass unit tests commit dc970f55f5f69ecbca7095099bd50ff21ba02610 Author: Shane Smiskol <shane@smiskol.com> Date: Mon Mar 28 20:26:18 2022 -0700 bump commit e9a3c73d61590120cc5e5c16a3d1a0bbbd51e19d Author: Shane Smiskol <shane@smiskol.com> Date: Mon Mar 28 20:25:33 2022 -0700 normal commit 4ecfbf18d5e6436f9be6bd3b1c4ea3bca8c1a572 Merge: 47e0ad3cb 02b968ed9 Author: Shane Smiskol <shane@smiskol.com> Date: Mon Mar 28 20:14:08 2022 -0700 Merge remote-tracking branch 'upstream/master' into override-alert-type commit 47e0ad3cbe4fee81b7a6e4c284973c25b144ddf7 Author: Shane Smiskol <shane@smiskol.com> Date: Thu Mar 24 10:50:34 2022 -0700 only rename commit 8c46435630c1bfba5c5b911bc1d3c8d4b24c9fdd Author: Shane Smiskol <shane@smiskol.com> Date: Thu Mar 24 10:49:26 2022 -0700 bump cereal commit eb48440843d6a4b09e1f34d8eb2ed4c7f7a8274c Author: Shane Smiskol <shane@smiskol.com> Date: Thu Mar 24 10:29:49 2022 -0700 fix commit 231afe3e6f211e866216a557f2ec2787760d2607 Author: Shane Smiskol <shane@smiskol.com> Date: Wed Mar 23 23:57:40 2022 -0700 clean up commit 7a3f49db1bdb58c8ef59a9376306ef1157ba2e57 Author: Shane Smiskol <shane@smiskol.com> Date: Wed Mar 23 23:57:10 2022 -0700 fix logic commit eab4f8b46e6c22033ac4ae433b6ba94e6a4ff322 Author: Shane Smiskol <shane@smiskol.com> Date: Wed Mar 23 21:05:05 2022 -0700 clean up commit 51e189a27268364e051c6d9231ae6f181ec7f95b Author: Shane Smiskol <shane@smiskol.com> Date: Wed Mar 23 20:51:23 2022 -0700 override state testing * clean up old-commit-hash: 2624b4cb27f7f2bd184bac5dd7b2c718767da583
3 years ago
# ENABLED, SOFT DISABLING, PRE ENABLING, OVERRIDING
if self.state != State.disabled:
# user and immediate disable always have priority in a non-disabled state
if self.events.any(ET.USER_DISABLE):
self.state = State.disabled
self.current_alert_types.append(ET.USER_DISABLE)
elif self.events.any(ET.IMMEDIATE_DISABLE):
self.state = State.disabled
self.current_alert_types.append(ET.IMMEDIATE_DISABLE)
else:
# ENABLED
if self.state == State.enabled:
if self.events.any(ET.SOFT_DISABLE):
self.state = State.softDisabling
self.soft_disable_timer = int(SOFT_DISABLE_TIME / DT_CTRL)
self.current_alert_types.append(ET.SOFT_DISABLE)
controlsState: add override state with grey border (#24030) * Squashed commit of the following: commit f0cf822666fb8f78a486d721fe474e8f37da6970 Author: Shane Smiskol <shane@smiskol.com> Date: Mon Apr 4 17:24:00 2022 -0700 clean up commit 4364bdb79b1b055daa7542267eb3f37740723fd4 Merge: d448664cf e85f82af3 Author: Shane Smiskol <shane@smiskol.com> Date: Mon Apr 4 17:21:41 2022 -0700 Merge remote-tracking branch 'upstream/master' into override-alert-type commit d448664cfdacbdfd3c99f8e12d96f2ba7b24abb5 Author: Shane Smiskol <shane@smiskol.com> Date: Mon Apr 4 17:20:44 2022 -0700 revert tests changes commit 40ab8c2d912ccbeb12286ca272e3737656388ac8 Author: Shane Smiskol <shane@smiskol.com> Date: Fri Apr 1 19:03:39 2022 -0700 sort commit 5abd4448b420e91eda57e3c4edb6794893dab42f Author: Shane Smiskol <shane@smiskol.com> Date: Fri Apr 1 19:02:59 2022 -0700 bump cereal commit fcffc42082b1460676554924461c63c881c31501 Author: Shane Smiskol <shane@smiskol.com> Date: Fri Apr 1 19:02:25 2022 -0700 pass in CI commit f47dd63bc597e18c05d2d9365eb996c13ec70c17 Author: Shane Smiskol <shane@smiskol.com> Date: Fri Apr 1 12:06:00 2022 -0700 update refs commit f1c54e16ccfa37f770b422ad77e2fc940f8ea7f2 Author: Shane Smiskol <shane@smiskol.com> Date: Fri Apr 1 11:51:04 2022 -0700 move to tuple commit bebafc6ed223a67e59daa7c2105f8cb28c4f9c5f Merge: b0578dc54 0e983562d Author: Shane Smiskol <shane@smiskol.com> Date: Fri Apr 1 11:45:19 2022 -0700 Merge remote-tracking branch 'upstream/master' into override-alert-type commit b0578dc54f9d943e0ab2182b0b79d076129468a7 Author: Shane Smiskol <shane@smiskol.com> Date: Fri Apr 1 11:44:37 2022 -0700 make global variables of states in controlsd make global variables of states in controlsd commit 32b7e293e88f001ef44c9197dfc68b7240ae129e Author: Shane Smiskol <shane@smiskol.com> Date: Thu Mar 31 23:41:41 2022 -0700 test individual event types fix commit 1fbf66fc8ba7e5a0a25d34a1f30a2cb3ccb86a02 Author: Shane Smiskol <shane@smiskol.com> Date: Thu Mar 31 23:03:09 2022 -0700 clean up test state machine test state machine commit 33856bef69b1c2e637e58032b1358f275a6cd6bb Author: Shane Smiskol <shane@smiskol.com> Date: Thu Mar 31 22:59:05 2022 -0700 clean up commit d64cd664980edd6cff0038379a5c3965409ebda0 Author: Shane Smiskol <shane@smiskol.com> Date: Thu Mar 31 22:40:25 2022 -0700 test few more things commit 72a3e57a9a8813b348a8ae9648e283983f7ba56b Author: Shane Smiskol <shane@smiskol.com> Date: Thu Mar 31 22:17:22 2022 -0700 default transitions commit ce0051fde8296dab6417d9ef175fdf039d09a8f3 Author: Shane Smiskol <shane@smiskol.com> Date: Thu Mar 31 22:05:21 2022 -0700 remove commit 56de4f8a87e9b96dd99739772da1dddaa873ceb1 Author: Shane Smiskol <shane@smiskol.com> Date: Thu Mar 31 22:05:15 2022 -0700 this way we can test any combo of event types commit bdfd47738e5a3c0e22817047cc2d804ca0fe2785 Author: Shane Smiskol <shane@smiskol.com> Date: Thu Mar 31 21:36:33 2022 -0700 add some state machine tests commit 81a72d1773b204cc984fb0631ac30fb00555962d Author: Shane Smiskol <shane@smiskol.com> Date: Thu Mar 31 17:43:03 2022 -0700 update refs commit 00018708714b156c29f963011a6193fa9028b308 Merge: fa97ffa67 fa934d846 Author: Shane Smiskol <shane@smiskol.com> Date: Thu Mar 31 17:31:51 2022 -0700 Merge remote-tracking branch 'upstream/master' into override-alert-type commit fa97ffa67eec1556b2b255ee68bdf46fc101596e Author: Shane Smiskol <shane@smiskol.com> Date: Thu Mar 31 17:30:23 2022 -0700 revert todo commit b0dcd49b0b0254a4754ddc5ea61618246686327d Author: Shane Smiskol <shane@smiskol.com> Date: Wed Mar 30 00:07:11 2022 -0700 move back commit ef12853ceed8c8aa37b16af406e510d172269226 Author: Shane Smiskol <shane@smiskol.com> Date: Tue Mar 29 23:09:05 2022 -0700 bump cereal commit 2658f557e2fac79563b74385b8676a659f31f7dc Author: Shane Smiskol <shane@smiskol.com> Date: Mon Mar 28 20:54:48 2022 -0700 fix commit ed2db85acd34cd78017c6bae0db5df3356c2c19c Author: Shane Smiskol <shane@smiskol.com> Date: Mon Mar 28 20:47:18 2022 -0700 add alert to pass unit tests commit dc970f55f5f69ecbca7095099bd50ff21ba02610 Author: Shane Smiskol <shane@smiskol.com> Date: Mon Mar 28 20:26:18 2022 -0700 bump commit e9a3c73d61590120cc5e5c16a3d1a0bbbd51e19d Author: Shane Smiskol <shane@smiskol.com> Date: Mon Mar 28 20:25:33 2022 -0700 normal commit 4ecfbf18d5e6436f9be6bd3b1c4ea3bca8c1a572 Merge: 47e0ad3cb 02b968ed9 Author: Shane Smiskol <shane@smiskol.com> Date: Mon Mar 28 20:14:08 2022 -0700 Merge remote-tracking branch 'upstream/master' into override-alert-type commit 47e0ad3cbe4fee81b7a6e4c284973c25b144ddf7 Author: Shane Smiskol <shane@smiskol.com> Date: Thu Mar 24 10:50:34 2022 -0700 only rename commit 8c46435630c1bfba5c5b911bc1d3c8d4b24c9fdd Author: Shane Smiskol <shane@smiskol.com> Date: Thu Mar 24 10:49:26 2022 -0700 bump cereal commit eb48440843d6a4b09e1f34d8eb2ed4c7f7a8274c Author: Shane Smiskol <shane@smiskol.com> Date: Thu Mar 24 10:29:49 2022 -0700 fix commit 231afe3e6f211e866216a557f2ec2787760d2607 Author: Shane Smiskol <shane@smiskol.com> Date: Wed Mar 23 23:57:40 2022 -0700 clean up commit 7a3f49db1bdb58c8ef59a9376306ef1157ba2e57 Author: Shane Smiskol <shane@smiskol.com> Date: Wed Mar 23 23:57:10 2022 -0700 fix logic commit eab4f8b46e6c22033ac4ae433b6ba94e6a4ff322 Author: Shane Smiskol <shane@smiskol.com> Date: Wed Mar 23 21:05:05 2022 -0700 clean up commit 51e189a27268364e051c6d9231ae6f181ec7f95b Author: Shane Smiskol <shane@smiskol.com> Date: Wed Mar 23 20:51:23 2022 -0700 override state testing * clean up old-commit-hash: 2624b4cb27f7f2bd184bac5dd7b2c718767da583
3 years ago
elif self.events.any(ET.OVERRIDE):
self.state = State.overriding
self.current_alert_types.append(ET.OVERRIDE)
# SOFT DISABLING
elif self.state == State.softDisabling:
if not self.events.any(ET.SOFT_DISABLE):
# no more soft disabling condition, so go back to ENABLED
self.state = State.enabled
elif self.soft_disable_timer > 0:
self.current_alert_types.append(ET.SOFT_DISABLE)
elif self.soft_disable_timer <= 0:
self.state = State.disabled
# PRE ENABLING
elif self.state == State.preEnabled:
if self.events.any(ET.NO_ENTRY):
self.state = State.disabled
self.current_alert_types.append(ET.NO_ENTRY)
elif not self.events.any(ET.PRE_ENABLE):
self.state = State.enabled
else:
self.current_alert_types.append(ET.PRE_ENABLE)
controlsState: add override state with grey border (#24030) * Squashed commit of the following: commit f0cf822666fb8f78a486d721fe474e8f37da6970 Author: Shane Smiskol <shane@smiskol.com> Date: Mon Apr 4 17:24:00 2022 -0700 clean up commit 4364bdb79b1b055daa7542267eb3f37740723fd4 Merge: d448664cf e85f82af3 Author: Shane Smiskol <shane@smiskol.com> Date: Mon Apr 4 17:21:41 2022 -0700 Merge remote-tracking branch 'upstream/master' into override-alert-type commit d448664cfdacbdfd3c99f8e12d96f2ba7b24abb5 Author: Shane Smiskol <shane@smiskol.com> Date: Mon Apr 4 17:20:44 2022 -0700 revert tests changes commit 40ab8c2d912ccbeb12286ca272e3737656388ac8 Author: Shane Smiskol <shane@smiskol.com> Date: Fri Apr 1 19:03:39 2022 -0700 sort commit 5abd4448b420e91eda57e3c4edb6794893dab42f Author: Shane Smiskol <shane@smiskol.com> Date: Fri Apr 1 19:02:59 2022 -0700 bump cereal commit fcffc42082b1460676554924461c63c881c31501 Author: Shane Smiskol <shane@smiskol.com> Date: Fri Apr 1 19:02:25 2022 -0700 pass in CI commit f47dd63bc597e18c05d2d9365eb996c13ec70c17 Author: Shane Smiskol <shane@smiskol.com> Date: Fri Apr 1 12:06:00 2022 -0700 update refs commit f1c54e16ccfa37f770b422ad77e2fc940f8ea7f2 Author: Shane Smiskol <shane@smiskol.com> Date: Fri Apr 1 11:51:04 2022 -0700 move to tuple commit bebafc6ed223a67e59daa7c2105f8cb28c4f9c5f Merge: b0578dc54 0e983562d Author: Shane Smiskol <shane@smiskol.com> Date: Fri Apr 1 11:45:19 2022 -0700 Merge remote-tracking branch 'upstream/master' into override-alert-type commit b0578dc54f9d943e0ab2182b0b79d076129468a7 Author: Shane Smiskol <shane@smiskol.com> Date: Fri Apr 1 11:44:37 2022 -0700 make global variables of states in controlsd make global variables of states in controlsd commit 32b7e293e88f001ef44c9197dfc68b7240ae129e Author: Shane Smiskol <shane@smiskol.com> Date: Thu Mar 31 23:41:41 2022 -0700 test individual event types fix commit 1fbf66fc8ba7e5a0a25d34a1f30a2cb3ccb86a02 Author: Shane Smiskol <shane@smiskol.com> Date: Thu Mar 31 23:03:09 2022 -0700 clean up test state machine test state machine commit 33856bef69b1c2e637e58032b1358f275a6cd6bb Author: Shane Smiskol <shane@smiskol.com> Date: Thu Mar 31 22:59:05 2022 -0700 clean up commit d64cd664980edd6cff0038379a5c3965409ebda0 Author: Shane Smiskol <shane@smiskol.com> Date: Thu Mar 31 22:40:25 2022 -0700 test few more things commit 72a3e57a9a8813b348a8ae9648e283983f7ba56b Author: Shane Smiskol <shane@smiskol.com> Date: Thu Mar 31 22:17:22 2022 -0700 default transitions commit ce0051fde8296dab6417d9ef175fdf039d09a8f3 Author: Shane Smiskol <shane@smiskol.com> Date: Thu Mar 31 22:05:21 2022 -0700 remove commit 56de4f8a87e9b96dd99739772da1dddaa873ceb1 Author: Shane Smiskol <shane@smiskol.com> Date: Thu Mar 31 22:05:15 2022 -0700 this way we can test any combo of event types commit bdfd47738e5a3c0e22817047cc2d804ca0fe2785 Author: Shane Smiskol <shane@smiskol.com> Date: Thu Mar 31 21:36:33 2022 -0700 add some state machine tests commit 81a72d1773b204cc984fb0631ac30fb00555962d Author: Shane Smiskol <shane@smiskol.com> Date: Thu Mar 31 17:43:03 2022 -0700 update refs commit 00018708714b156c29f963011a6193fa9028b308 Merge: fa97ffa67 fa934d846 Author: Shane Smiskol <shane@smiskol.com> Date: Thu Mar 31 17:31:51 2022 -0700 Merge remote-tracking branch 'upstream/master' into override-alert-type commit fa97ffa67eec1556b2b255ee68bdf46fc101596e Author: Shane Smiskol <shane@smiskol.com> Date: Thu Mar 31 17:30:23 2022 -0700 revert todo commit b0dcd49b0b0254a4754ddc5ea61618246686327d Author: Shane Smiskol <shane@smiskol.com> Date: Wed Mar 30 00:07:11 2022 -0700 move back commit ef12853ceed8c8aa37b16af406e510d172269226 Author: Shane Smiskol <shane@smiskol.com> Date: Tue Mar 29 23:09:05 2022 -0700 bump cereal commit 2658f557e2fac79563b74385b8676a659f31f7dc Author: Shane Smiskol <shane@smiskol.com> Date: Mon Mar 28 20:54:48 2022 -0700 fix commit ed2db85acd34cd78017c6bae0db5df3356c2c19c Author: Shane Smiskol <shane@smiskol.com> Date: Mon Mar 28 20:47:18 2022 -0700 add alert to pass unit tests commit dc970f55f5f69ecbca7095099bd50ff21ba02610 Author: Shane Smiskol <shane@smiskol.com> Date: Mon Mar 28 20:26:18 2022 -0700 bump commit e9a3c73d61590120cc5e5c16a3d1a0bbbd51e19d Author: Shane Smiskol <shane@smiskol.com> Date: Mon Mar 28 20:25:33 2022 -0700 normal commit 4ecfbf18d5e6436f9be6bd3b1c4ea3bca8c1a572 Merge: 47e0ad3cb 02b968ed9 Author: Shane Smiskol <shane@smiskol.com> Date: Mon Mar 28 20:14:08 2022 -0700 Merge remote-tracking branch 'upstream/master' into override-alert-type commit 47e0ad3cbe4fee81b7a6e4c284973c25b144ddf7 Author: Shane Smiskol <shane@smiskol.com> Date: Thu Mar 24 10:50:34 2022 -0700 only rename commit 8c46435630c1bfba5c5b911bc1d3c8d4b24c9fdd Author: Shane Smiskol <shane@smiskol.com> Date: Thu Mar 24 10:49:26 2022 -0700 bump cereal commit eb48440843d6a4b09e1f34d8eb2ed4c7f7a8274c Author: Shane Smiskol <shane@smiskol.com> Date: Thu Mar 24 10:29:49 2022 -0700 fix commit 231afe3e6f211e866216a557f2ec2787760d2607 Author: Shane Smiskol <shane@smiskol.com> Date: Wed Mar 23 23:57:40 2022 -0700 clean up commit 7a3f49db1bdb58c8ef59a9376306ef1157ba2e57 Author: Shane Smiskol <shane@smiskol.com> Date: Wed Mar 23 23:57:10 2022 -0700 fix logic commit eab4f8b46e6c22033ac4ae433b6ba94e6a4ff322 Author: Shane Smiskol <shane@smiskol.com> Date: Wed Mar 23 21:05:05 2022 -0700 clean up commit 51e189a27268364e051c6d9231ae6f181ec7f95b Author: Shane Smiskol <shane@smiskol.com> Date: Wed Mar 23 20:51:23 2022 -0700 override state testing * clean up old-commit-hash: 2624b4cb27f7f2bd184bac5dd7b2c718767da583
3 years ago
# OVERRIDING
elif self.state == State.overriding:
if not self.events.any(ET.OVERRIDE):
self.state = State.enabled
else:
self.current_alert_types.append(ET.OVERRIDE)
# DISABLED
elif self.state == State.disabled:
if self.events.any(ET.ENABLE):
if self.events.any(ET.NO_ENTRY):
self.current_alert_types.append(ET.NO_ENTRY)
else:
if self.events.any(ET.PRE_ENABLE):
self.state = State.preEnabled
controlsState: add override state with grey border (#24030) * Squashed commit of the following: commit f0cf822666fb8f78a486d721fe474e8f37da6970 Author: Shane Smiskol <shane@smiskol.com> Date: Mon Apr 4 17:24:00 2022 -0700 clean up commit 4364bdb79b1b055daa7542267eb3f37740723fd4 Merge: d448664cf e85f82af3 Author: Shane Smiskol <shane@smiskol.com> Date: Mon Apr 4 17:21:41 2022 -0700 Merge remote-tracking branch 'upstream/master' into override-alert-type commit d448664cfdacbdfd3c99f8e12d96f2ba7b24abb5 Author: Shane Smiskol <shane@smiskol.com> Date: Mon Apr 4 17:20:44 2022 -0700 revert tests changes commit 40ab8c2d912ccbeb12286ca272e3737656388ac8 Author: Shane Smiskol <shane@smiskol.com> Date: Fri Apr 1 19:03:39 2022 -0700 sort commit 5abd4448b420e91eda57e3c4edb6794893dab42f Author: Shane Smiskol <shane@smiskol.com> Date: Fri Apr 1 19:02:59 2022 -0700 bump cereal commit fcffc42082b1460676554924461c63c881c31501 Author: Shane Smiskol <shane@smiskol.com> Date: Fri Apr 1 19:02:25 2022 -0700 pass in CI commit f47dd63bc597e18c05d2d9365eb996c13ec70c17 Author: Shane Smiskol <shane@smiskol.com> Date: Fri Apr 1 12:06:00 2022 -0700 update refs commit f1c54e16ccfa37f770b422ad77e2fc940f8ea7f2 Author: Shane Smiskol <shane@smiskol.com> Date: Fri Apr 1 11:51:04 2022 -0700 move to tuple commit bebafc6ed223a67e59daa7c2105f8cb28c4f9c5f Merge: b0578dc54 0e983562d Author: Shane Smiskol <shane@smiskol.com> Date: Fri Apr 1 11:45:19 2022 -0700 Merge remote-tracking branch 'upstream/master' into override-alert-type commit b0578dc54f9d943e0ab2182b0b79d076129468a7 Author: Shane Smiskol <shane@smiskol.com> Date: Fri Apr 1 11:44:37 2022 -0700 make global variables of states in controlsd make global variables of states in controlsd commit 32b7e293e88f001ef44c9197dfc68b7240ae129e Author: Shane Smiskol <shane@smiskol.com> Date: Thu Mar 31 23:41:41 2022 -0700 test individual event types fix commit 1fbf66fc8ba7e5a0a25d34a1f30a2cb3ccb86a02 Author: Shane Smiskol <shane@smiskol.com> Date: Thu Mar 31 23:03:09 2022 -0700 clean up test state machine test state machine commit 33856bef69b1c2e637e58032b1358f275a6cd6bb Author: Shane Smiskol <shane@smiskol.com> Date: Thu Mar 31 22:59:05 2022 -0700 clean up commit d64cd664980edd6cff0038379a5c3965409ebda0 Author: Shane Smiskol <shane@smiskol.com> Date: Thu Mar 31 22:40:25 2022 -0700 test few more things commit 72a3e57a9a8813b348a8ae9648e283983f7ba56b Author: Shane Smiskol <shane@smiskol.com> Date: Thu Mar 31 22:17:22 2022 -0700 default transitions commit ce0051fde8296dab6417d9ef175fdf039d09a8f3 Author: Shane Smiskol <shane@smiskol.com> Date: Thu Mar 31 22:05:21 2022 -0700 remove commit 56de4f8a87e9b96dd99739772da1dddaa873ceb1 Author: Shane Smiskol <shane@smiskol.com> Date: Thu Mar 31 22:05:15 2022 -0700 this way we can test any combo of event types commit bdfd47738e5a3c0e22817047cc2d804ca0fe2785 Author: Shane Smiskol <shane@smiskol.com> Date: Thu Mar 31 21:36:33 2022 -0700 add some state machine tests commit 81a72d1773b204cc984fb0631ac30fb00555962d Author: Shane Smiskol <shane@smiskol.com> Date: Thu Mar 31 17:43:03 2022 -0700 update refs commit 00018708714b156c29f963011a6193fa9028b308 Merge: fa97ffa67 fa934d846 Author: Shane Smiskol <shane@smiskol.com> Date: Thu Mar 31 17:31:51 2022 -0700 Merge remote-tracking branch 'upstream/master' into override-alert-type commit fa97ffa67eec1556b2b255ee68bdf46fc101596e Author: Shane Smiskol <shane@smiskol.com> Date: Thu Mar 31 17:30:23 2022 -0700 revert todo commit b0dcd49b0b0254a4754ddc5ea61618246686327d Author: Shane Smiskol <shane@smiskol.com> Date: Wed Mar 30 00:07:11 2022 -0700 move back commit ef12853ceed8c8aa37b16af406e510d172269226 Author: Shane Smiskol <shane@smiskol.com> Date: Tue Mar 29 23:09:05 2022 -0700 bump cereal commit 2658f557e2fac79563b74385b8676a659f31f7dc Author: Shane Smiskol <shane@smiskol.com> Date: Mon Mar 28 20:54:48 2022 -0700 fix commit ed2db85acd34cd78017c6bae0db5df3356c2c19c Author: Shane Smiskol <shane@smiskol.com> Date: Mon Mar 28 20:47:18 2022 -0700 add alert to pass unit tests commit dc970f55f5f69ecbca7095099bd50ff21ba02610 Author: Shane Smiskol <shane@smiskol.com> Date: Mon Mar 28 20:26:18 2022 -0700 bump commit e9a3c73d61590120cc5e5c16a3d1a0bbbd51e19d Author: Shane Smiskol <shane@smiskol.com> Date: Mon Mar 28 20:25:33 2022 -0700 normal commit 4ecfbf18d5e6436f9be6bd3b1c4ea3bca8c1a572 Merge: 47e0ad3cb 02b968ed9 Author: Shane Smiskol <shane@smiskol.com> Date: Mon Mar 28 20:14:08 2022 -0700 Merge remote-tracking branch 'upstream/master' into override-alert-type commit 47e0ad3cbe4fee81b7a6e4c284973c25b144ddf7 Author: Shane Smiskol <shane@smiskol.com> Date: Thu Mar 24 10:50:34 2022 -0700 only rename commit 8c46435630c1bfba5c5b911bc1d3c8d4b24c9fdd Author: Shane Smiskol <shane@smiskol.com> Date: Thu Mar 24 10:49:26 2022 -0700 bump cereal commit eb48440843d6a4b09e1f34d8eb2ed4c7f7a8274c Author: Shane Smiskol <shane@smiskol.com> Date: Thu Mar 24 10:29:49 2022 -0700 fix commit 231afe3e6f211e866216a557f2ec2787760d2607 Author: Shane Smiskol <shane@smiskol.com> Date: Wed Mar 23 23:57:40 2022 -0700 clean up commit 7a3f49db1bdb58c8ef59a9376306ef1157ba2e57 Author: Shane Smiskol <shane@smiskol.com> Date: Wed Mar 23 23:57:10 2022 -0700 fix logic commit eab4f8b46e6c22033ac4ae433b6ba94e6a4ff322 Author: Shane Smiskol <shane@smiskol.com> Date: Wed Mar 23 21:05:05 2022 -0700 clean up commit 51e189a27268364e051c6d9231ae6f181ec7f95b Author: Shane Smiskol <shane@smiskol.com> Date: Wed Mar 23 20:51:23 2022 -0700 override state testing * clean up old-commit-hash: 2624b4cb27f7f2bd184bac5dd7b2c718767da583
3 years ago
elif self.events.any(ET.OVERRIDE):
self.state = State.overriding
else:
self.state = State.enabled
self.current_alert_types.append(ET.ENABLE)
if not self.CP.pcmCruise:
self.v_cruise_kph = initialize_v_cruise(CS.vEgo, CS.buttonEvents, self.v_cruise_kph_last)
# Check if openpilot is engaged and actuators are enabled
self.enabled = self.state in ENABLED_STATES
self.active = self.state in ACTIVE_STATES
if self.active:
self.current_alert_types.append(ET.WARNING)
def state_control(self, CS):
"""Given the state, this function returns a CarControl packet"""
# Update VehicleModel
params = self.sm['liveParameters']
x = max(params.stiffnessFactor, 0.1)
sr = max(params.steerRatio, 0.1)
self.VM.update_params(x, sr)
lat_plan = self.sm['lateralPlan']
long_plan = self.sm['longitudinalPlan']
CC = car.CarControl.new_message()
CC.enabled = self.enabled
# Check which actuators can be enabled
CC.latActive = self.active and not CS.steerFaultTemporary and not CS.steerFaultPermanent and \
CS.vEgo > self.CP.minSteerSpeed and not CS.standstill
controlsState: add override state with grey border (#24030) * Squashed commit of the following: commit f0cf822666fb8f78a486d721fe474e8f37da6970 Author: Shane Smiskol <shane@smiskol.com> Date: Mon Apr 4 17:24:00 2022 -0700 clean up commit 4364bdb79b1b055daa7542267eb3f37740723fd4 Merge: d448664cf e85f82af3 Author: Shane Smiskol <shane@smiskol.com> Date: Mon Apr 4 17:21:41 2022 -0700 Merge remote-tracking branch 'upstream/master' into override-alert-type commit d448664cfdacbdfd3c99f8e12d96f2ba7b24abb5 Author: Shane Smiskol <shane@smiskol.com> Date: Mon Apr 4 17:20:44 2022 -0700 revert tests changes commit 40ab8c2d912ccbeb12286ca272e3737656388ac8 Author: Shane Smiskol <shane@smiskol.com> Date: Fri Apr 1 19:03:39 2022 -0700 sort commit 5abd4448b420e91eda57e3c4edb6794893dab42f Author: Shane Smiskol <shane@smiskol.com> Date: Fri Apr 1 19:02:59 2022 -0700 bump cereal commit fcffc42082b1460676554924461c63c881c31501 Author: Shane Smiskol <shane@smiskol.com> Date: Fri Apr 1 19:02:25 2022 -0700 pass in CI commit f47dd63bc597e18c05d2d9365eb996c13ec70c17 Author: Shane Smiskol <shane@smiskol.com> Date: Fri Apr 1 12:06:00 2022 -0700 update refs commit f1c54e16ccfa37f770b422ad77e2fc940f8ea7f2 Author: Shane Smiskol <shane@smiskol.com> Date: Fri Apr 1 11:51:04 2022 -0700 move to tuple commit bebafc6ed223a67e59daa7c2105f8cb28c4f9c5f Merge: b0578dc54 0e983562d Author: Shane Smiskol <shane@smiskol.com> Date: Fri Apr 1 11:45:19 2022 -0700 Merge remote-tracking branch 'upstream/master' into override-alert-type commit b0578dc54f9d943e0ab2182b0b79d076129468a7 Author: Shane Smiskol <shane@smiskol.com> Date: Fri Apr 1 11:44:37 2022 -0700 make global variables of states in controlsd make global variables of states in controlsd commit 32b7e293e88f001ef44c9197dfc68b7240ae129e Author: Shane Smiskol <shane@smiskol.com> Date: Thu Mar 31 23:41:41 2022 -0700 test individual event types fix commit 1fbf66fc8ba7e5a0a25d34a1f30a2cb3ccb86a02 Author: Shane Smiskol <shane@smiskol.com> Date: Thu Mar 31 23:03:09 2022 -0700 clean up test state machine test state machine commit 33856bef69b1c2e637e58032b1358f275a6cd6bb Author: Shane Smiskol <shane@smiskol.com> Date: Thu Mar 31 22:59:05 2022 -0700 clean up commit d64cd664980edd6cff0038379a5c3965409ebda0 Author: Shane Smiskol <shane@smiskol.com> Date: Thu Mar 31 22:40:25 2022 -0700 test few more things commit 72a3e57a9a8813b348a8ae9648e283983f7ba56b Author: Shane Smiskol <shane@smiskol.com> Date: Thu Mar 31 22:17:22 2022 -0700 default transitions commit ce0051fde8296dab6417d9ef175fdf039d09a8f3 Author: Shane Smiskol <shane@smiskol.com> Date: Thu Mar 31 22:05:21 2022 -0700 remove commit 56de4f8a87e9b96dd99739772da1dddaa873ceb1 Author: Shane Smiskol <shane@smiskol.com> Date: Thu Mar 31 22:05:15 2022 -0700 this way we can test any combo of event types commit bdfd47738e5a3c0e22817047cc2d804ca0fe2785 Author: Shane Smiskol <shane@smiskol.com> Date: Thu Mar 31 21:36:33 2022 -0700 add some state machine tests commit 81a72d1773b204cc984fb0631ac30fb00555962d Author: Shane Smiskol <shane@smiskol.com> Date: Thu Mar 31 17:43:03 2022 -0700 update refs commit 00018708714b156c29f963011a6193fa9028b308 Merge: fa97ffa67 fa934d846 Author: Shane Smiskol <shane@smiskol.com> Date: Thu Mar 31 17:31:51 2022 -0700 Merge remote-tracking branch 'upstream/master' into override-alert-type commit fa97ffa67eec1556b2b255ee68bdf46fc101596e Author: Shane Smiskol <shane@smiskol.com> Date: Thu Mar 31 17:30:23 2022 -0700 revert todo commit b0dcd49b0b0254a4754ddc5ea61618246686327d Author: Shane Smiskol <shane@smiskol.com> Date: Wed Mar 30 00:07:11 2022 -0700 move back commit ef12853ceed8c8aa37b16af406e510d172269226 Author: Shane Smiskol <shane@smiskol.com> Date: Tue Mar 29 23:09:05 2022 -0700 bump cereal commit 2658f557e2fac79563b74385b8676a659f31f7dc Author: Shane Smiskol <shane@smiskol.com> Date: Mon Mar 28 20:54:48 2022 -0700 fix commit ed2db85acd34cd78017c6bae0db5df3356c2c19c Author: Shane Smiskol <shane@smiskol.com> Date: Mon Mar 28 20:47:18 2022 -0700 add alert to pass unit tests commit dc970f55f5f69ecbca7095099bd50ff21ba02610 Author: Shane Smiskol <shane@smiskol.com> Date: Mon Mar 28 20:26:18 2022 -0700 bump commit e9a3c73d61590120cc5e5c16a3d1a0bbbd51e19d Author: Shane Smiskol <shane@smiskol.com> Date: Mon Mar 28 20:25:33 2022 -0700 normal commit 4ecfbf18d5e6436f9be6bd3b1c4ea3bca8c1a572 Merge: 47e0ad3cb 02b968ed9 Author: Shane Smiskol <shane@smiskol.com> Date: Mon Mar 28 20:14:08 2022 -0700 Merge remote-tracking branch 'upstream/master' into override-alert-type commit 47e0ad3cbe4fee81b7a6e4c284973c25b144ddf7 Author: Shane Smiskol <shane@smiskol.com> Date: Thu Mar 24 10:50:34 2022 -0700 only rename commit 8c46435630c1bfba5c5b911bc1d3c8d4b24c9fdd Author: Shane Smiskol <shane@smiskol.com> Date: Thu Mar 24 10:49:26 2022 -0700 bump cereal commit eb48440843d6a4b09e1f34d8eb2ed4c7f7a8274c Author: Shane Smiskol <shane@smiskol.com> Date: Thu Mar 24 10:29:49 2022 -0700 fix commit 231afe3e6f211e866216a557f2ec2787760d2607 Author: Shane Smiskol <shane@smiskol.com> Date: Wed Mar 23 23:57:40 2022 -0700 clean up commit 7a3f49db1bdb58c8ef59a9376306ef1157ba2e57 Author: Shane Smiskol <shane@smiskol.com> Date: Wed Mar 23 23:57:10 2022 -0700 fix logic commit eab4f8b46e6c22033ac4ae433b6ba94e6a4ff322 Author: Shane Smiskol <shane@smiskol.com> Date: Wed Mar 23 21:05:05 2022 -0700 clean up commit 51e189a27268364e051c6d9231ae6f181ec7f95b Author: Shane Smiskol <shane@smiskol.com> Date: Wed Mar 23 20:51:23 2022 -0700 override state testing * clean up old-commit-hash: 2624b4cb27f7f2bd184bac5dd7b2c718767da583
3 years ago
CC.longActive = self.active and self.state != State.overriding
actuators = CC.actuators
actuators.longControlState = self.LoC.long_control_state
if CS.leftBlinker or CS.rightBlinker:
self.last_blinker_frame = self.sm.frame
# State specific actions
if not CC.latActive:
self.LaC.reset()
if not CC.longActive:
self.LoC.reset(v_pid=CS.vEgo)
Fixup joystick (#21129) * some common changes * rename to joystick * add alert and update controlsd to work with joystick * update joystickd * Update Joystick readme * assume we have inputs * only send gb or steer when engaged_toggle is true * Update instructions * fix --ip * Easier to understand at a glance * much better * -a * receive events and send msg in same loop * always import * Update selfdrive/controls/lib/events.py Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> * Update selfdrive/controls/lib/events.py Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> * combine logic and clean up * use argparse * outdated, and use normal class * rm * bit of a refactor * refactor part 2 / 3 * much better (3 / 3) * Simplify * bump cereal and update readme * capitalize * Update tools/joystick/joystickd.py Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> * Update tools/joystick/joystickd.py Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> * make joystick abstraction class clearer * use interp, clearer without comments * no need to use apply_deadzone * more explicit * define btns and axes once * split function by use_keyboard again, but simpler * we can use handle_button as a reset function * need to flip sign * remove * invert axes map for kb, easier to read the button mapping * apply changes from review * new lateral log for debug mode * bump * add saturated * static alert * joystick_mode * conditionally subscribe * Update selfdrive/controls/controlsd.py Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> * move params instantiation * Spoof active and enabled * Only allow car to engage * no startup alert if joystick * Update controlsd.py * Should be orange not enabled, green enabled * no more button states * should work * blue * submaster conflates, so only send when we have an update * final change * remove msg * clean up a bit sort of clean up clean up a bit remove msg * this was right * Apply suggestions from code review Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> * lowercase * suggestions from code review * forgot laptop * bump to latest * fixes Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> Co-authored-by: vanillagorillaa <31773928+vanillagorillaa@users.noreply.github.com> old-commit-hash: ae77f693a26527ffbee044f852cc4185718c2433
4 years ago
if not self.joystick_mode:
# accel PID loop
pid_accel_limits = self.CI.get_pid_accel_limits(self.CP, CS.vEgo, self.v_cruise_kph * CV.KPH_TO_MS)
t_since_plan = (self.sm.frame - self.sm.rcv_frame['longitudinalPlan']) * DT_CTRL
actuators.accel = self.LoC.update(CC.longActive, CS, self.CP, long_plan, pid_accel_limits, t_since_plan)
Fixup joystick (#21129) * some common changes * rename to joystick * add alert and update controlsd to work with joystick * update joystickd * Update Joystick readme * assume we have inputs * only send gb or steer when engaged_toggle is true * Update instructions * fix --ip * Easier to understand at a glance * much better * -a * receive events and send msg in same loop * always import * Update selfdrive/controls/lib/events.py Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> * Update selfdrive/controls/lib/events.py Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> * combine logic and clean up * use argparse * outdated, and use normal class * rm * bit of a refactor * refactor part 2 / 3 * much better (3 / 3) * Simplify * bump cereal and update readme * capitalize * Update tools/joystick/joystickd.py Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> * Update tools/joystick/joystickd.py Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> * make joystick abstraction class clearer * use interp, clearer without comments * no need to use apply_deadzone * more explicit * define btns and axes once * split function by use_keyboard again, but simpler * we can use handle_button as a reset function * need to flip sign * remove * invert axes map for kb, easier to read the button mapping * apply changes from review * new lateral log for debug mode * bump * add saturated * static alert * joystick_mode * conditionally subscribe * Update selfdrive/controls/controlsd.py Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> * move params instantiation * Spoof active and enabled * Only allow car to engage * no startup alert if joystick * Update controlsd.py * Should be orange not enabled, green enabled * no more button states * should work * blue * submaster conflates, so only send when we have an update * final change * remove msg * clean up a bit sort of clean up clean up a bit remove msg * this was right * Apply suggestions from code review Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> * lowercase * suggestions from code review * forgot laptop * bump to latest * fixes Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> Co-authored-by: vanillagorillaa <31773928+vanillagorillaa@users.noreply.github.com> old-commit-hash: ae77f693a26527ffbee044f852cc4185718c2433
4 years ago
# Steering PID loop and lateral MPC
desired_curvature, desired_curvature_rate = get_lag_adjusted_curvature(self.CP, CS.vEgo,
lat_plan.psis,
lat_plan.curvatures,
lat_plan.curvatureRates)
actuators.steer, actuators.steeringAngleDeg, lac_log = self.LaC.update(CC.latActive, CS, self.CP, self.VM,
params, self.last_actuators, desired_curvature,
desired_curvature_rate)
Fixup joystick (#21129) * some common changes * rename to joystick * add alert and update controlsd to work with joystick * update joystickd * Update Joystick readme * assume we have inputs * only send gb or steer when engaged_toggle is true * Update instructions * fix --ip * Easier to understand at a glance * much better * -a * receive events and send msg in same loop * always import * Update selfdrive/controls/lib/events.py Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> * Update selfdrive/controls/lib/events.py Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> * combine logic and clean up * use argparse * outdated, and use normal class * rm * bit of a refactor * refactor part 2 / 3 * much better (3 / 3) * Simplify * bump cereal and update readme * capitalize * Update tools/joystick/joystickd.py Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> * Update tools/joystick/joystickd.py Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> * make joystick abstraction class clearer * use interp, clearer without comments * no need to use apply_deadzone * more explicit * define btns and axes once * split function by use_keyboard again, but simpler * we can use handle_button as a reset function * need to flip sign * remove * invert axes map for kb, easier to read the button mapping * apply changes from review * new lateral log for debug mode * bump * add saturated * static alert * joystick_mode * conditionally subscribe * Update selfdrive/controls/controlsd.py Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> * move params instantiation * Spoof active and enabled * Only allow car to engage * no startup alert if joystick * Update controlsd.py * Should be orange not enabled, green enabled * no more button states * should work * blue * submaster conflates, so only send when we have an update * final change * remove msg * clean up a bit sort of clean up clean up a bit remove msg * this was right * Apply suggestions from code review Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> * lowercase * suggestions from code review * forgot laptop * bump to latest * fixes Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> Co-authored-by: vanillagorillaa <31773928+vanillagorillaa@users.noreply.github.com> old-commit-hash: ae77f693a26527ffbee044f852cc4185718c2433
4 years ago
else:
lac_log = log.ControlsState.LateralDebugState.new_message()
if self.sm.rcv_frame['testJoystick'] > 0:
if CC.longActive:
actuators.accel = 4.0*clip(self.sm['testJoystick'].axes[0], -1, 1)
Fixup joystick (#21129) * some common changes * rename to joystick * add alert and update controlsd to work with joystick * update joystickd * Update Joystick readme * assume we have inputs * only send gb or steer when engaged_toggle is true * Update instructions * fix --ip * Easier to understand at a glance * much better * -a * receive events and send msg in same loop * always import * Update selfdrive/controls/lib/events.py Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> * Update selfdrive/controls/lib/events.py Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> * combine logic and clean up * use argparse * outdated, and use normal class * rm * bit of a refactor * refactor part 2 / 3 * much better (3 / 3) * Simplify * bump cereal and update readme * capitalize * Update tools/joystick/joystickd.py Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> * Update tools/joystick/joystickd.py Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> * make joystick abstraction class clearer * use interp, clearer without comments * no need to use apply_deadzone * more explicit * define btns and axes once * split function by use_keyboard again, but simpler * we can use handle_button as a reset function * need to flip sign * remove * invert axes map for kb, easier to read the button mapping * apply changes from review * new lateral log for debug mode * bump * add saturated * static alert * joystick_mode * conditionally subscribe * Update selfdrive/controls/controlsd.py Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> * move params instantiation * Spoof active and enabled * Only allow car to engage * no startup alert if joystick * Update controlsd.py * Should be orange not enabled, green enabled * no more button states * should work * blue * submaster conflates, so only send when we have an update * final change * remove msg * clean up a bit sort of clean up clean up a bit remove msg * this was right * Apply suggestions from code review Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> * lowercase * suggestions from code review * forgot laptop * bump to latest * fixes Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> Co-authored-by: vanillagorillaa <31773928+vanillagorillaa@users.noreply.github.com> old-commit-hash: ae77f693a26527ffbee044f852cc4185718c2433
4 years ago
if CC.latActive:
steer = clip(self.sm['testJoystick'].axes[1], -1, 1)
# max angle is 45 for angle-based cars
actuators.steer, actuators.steeringAngleDeg = steer, steer * 45.
Fixup joystick (#21129) * some common changes * rename to joystick * add alert and update controlsd to work with joystick * update joystickd * Update Joystick readme * assume we have inputs * only send gb or steer when engaged_toggle is true * Update instructions * fix --ip * Easier to understand at a glance * much better * -a * receive events and send msg in same loop * always import * Update selfdrive/controls/lib/events.py Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> * Update selfdrive/controls/lib/events.py Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> * combine logic and clean up * use argparse * outdated, and use normal class * rm * bit of a refactor * refactor part 2 / 3 * much better (3 / 3) * Simplify * bump cereal and update readme * capitalize * Update tools/joystick/joystickd.py Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> * Update tools/joystick/joystickd.py Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> * make joystick abstraction class clearer * use interp, clearer without comments * no need to use apply_deadzone * more explicit * define btns and axes once * split function by use_keyboard again, but simpler * we can use handle_button as a reset function * need to flip sign * remove * invert axes map for kb, easier to read the button mapping * apply changes from review * new lateral log for debug mode * bump * add saturated * static alert * joystick_mode * conditionally subscribe * Update selfdrive/controls/controlsd.py Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> * move params instantiation * Spoof active and enabled * Only allow car to engage * no startup alert if joystick * Update controlsd.py * Should be orange not enabled, green enabled * no more button states * should work * blue * submaster conflates, so only send when we have an update * final change * remove msg * clean up a bit sort of clean up clean up a bit remove msg * this was right * Apply suggestions from code review Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> * lowercase * suggestions from code review * forgot laptop * bump to latest * fixes Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> Co-authored-by: vanillagorillaa <31773928+vanillagorillaa@users.noreply.github.com> old-commit-hash: ae77f693a26527ffbee044f852cc4185718c2433
4 years ago
lac_log.active = self.active
Fixup joystick (#21129) * some common changes * rename to joystick * add alert and update controlsd to work with joystick * update joystickd * Update Joystick readme * assume we have inputs * only send gb or steer when engaged_toggle is true * Update instructions * fix --ip * Easier to understand at a glance * much better * -a * receive events and send msg in same loop * always import * Update selfdrive/controls/lib/events.py Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> * Update selfdrive/controls/lib/events.py Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> * combine logic and clean up * use argparse * outdated, and use normal class * rm * bit of a refactor * refactor part 2 / 3 * much better (3 / 3) * Simplify * bump cereal and update readme * capitalize * Update tools/joystick/joystickd.py Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> * Update tools/joystick/joystickd.py Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> * make joystick abstraction class clearer * use interp, clearer without comments * no need to use apply_deadzone * more explicit * define btns and axes once * split function by use_keyboard again, but simpler * we can use handle_button as a reset function * need to flip sign * remove * invert axes map for kb, easier to read the button mapping * apply changes from review * new lateral log for debug mode * bump * add saturated * static alert * joystick_mode * conditionally subscribe * Update selfdrive/controls/controlsd.py Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> * move params instantiation * Spoof active and enabled * Only allow car to engage * no startup alert if joystick * Update controlsd.py * Should be orange not enabled, green enabled * no more button states * should work * blue * submaster conflates, so only send when we have an update * final change * remove msg * clean up a bit sort of clean up clean up a bit remove msg * this was right * Apply suggestions from code review Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> * lowercase * suggestions from code review * forgot laptop * bump to latest * fixes Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> Co-authored-by: vanillagorillaa <31773928+vanillagorillaa@users.noreply.github.com> old-commit-hash: ae77f693a26527ffbee044f852cc4185718c2433
4 years ago
lac_log.steeringAngleDeg = CS.steeringAngleDeg
lac_log.output = actuators.steer
lac_log.saturated = abs(actuators.steer) >= 0.9
# Send a "steering required alert" if saturation count has reached the limit
if lac_log.active and lac_log.saturated and not CS.steeringPressed:
dpath_points = lat_plan.dPathPoints
if len(dpath_points):
# Check if we deviated from the path
# TODO use desired vs actual curvature
left_deviation = actuators.steer > 0 and dpath_points[0] < -0.20
right_deviation = actuators.steer < 0 and dpath_points[0] > 0.20
if left_deviation or right_deviation:
self.events.add(EventName.steerSaturated)
# Ensure no NaNs/Infs
for p in ACTUATOR_FIELDS:
attr = getattr(actuators, p)
if not isinstance(attr, Number):
continue
if not math.isfinite(attr):
cloudlog.error(f"actuators.{p} not finite {actuators.to_dict()}")
setattr(actuators, p, 0.0)
return CC, lac_log
def update_button_timers(self, buttonEvents):
# increment timer for buttons still pressed
for k in self.button_timers:
if self.button_timers[k] > 0:
self.button_timers[k] += 1
for b in buttonEvents:
if b.type.raw in self.button_timers:
self.button_timers[b.type.raw] = 1 if b.pressed else 0
def publish_logs(self, CS, start_time, CC, lac_log):
"""Send actuators and hud commands to the car, send controlsstate and MPC logging"""
# Orientation and angle rates can be useful for carcontroller
# Only calibrated (car) frame is relevant for the carcontroller
orientation_value = list(self.sm['liveLocationKalman'].calibratedOrientationNED.value)
if len(orientation_value) > 2:
CC.orientationNED = orientation_value
angular_rate_value = list(self.sm['liveLocationKalman'].angularVelocityCalibrated.value)
if len(angular_rate_value) > 2:
CC.angularVelocity = angular_rate_value
CC.cruiseControl.cancel = CS.cruiseState.enabled and (not self.enabled or not self.CP.pcmCruise)
Fixup joystick (#21129) * some common changes * rename to joystick * add alert and update controlsd to work with joystick * update joystickd * Update Joystick readme * assume we have inputs * only send gb or steer when engaged_toggle is true * Update instructions * fix --ip * Easier to understand at a glance * much better * -a * receive events and send msg in same loop * always import * Update selfdrive/controls/lib/events.py Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> * Update selfdrive/controls/lib/events.py Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> * combine logic and clean up * use argparse * outdated, and use normal class * rm * bit of a refactor * refactor part 2 / 3 * much better (3 / 3) * Simplify * bump cereal and update readme * capitalize * Update tools/joystick/joystickd.py Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> * Update tools/joystick/joystickd.py Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> * make joystick abstraction class clearer * use interp, clearer without comments * no need to use apply_deadzone * more explicit * define btns and axes once * split function by use_keyboard again, but simpler * we can use handle_button as a reset function * need to flip sign * remove * invert axes map for kb, easier to read the button mapping * apply changes from review * new lateral log for debug mode * bump * add saturated * static alert * joystick_mode * conditionally subscribe * Update selfdrive/controls/controlsd.py Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> * move params instantiation * Spoof active and enabled * Only allow car to engage * no startup alert if joystick * Update controlsd.py * Should be orange not enabled, green enabled * no more button states * should work * blue * submaster conflates, so only send when we have an update * final change * remove msg * clean up a bit sort of clean up clean up a bit remove msg * this was right * Apply suggestions from code review Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> * lowercase * suggestions from code review * forgot laptop * bump to latest * fixes Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> Co-authored-by: vanillagorillaa <31773928+vanillagorillaa@users.noreply.github.com> old-commit-hash: ae77f693a26527ffbee044f852cc4185718c2433
4 years ago
if self.joystick_mode and self.sm.rcv_frame['testJoystick'] > 0 and self.sm['testJoystick'].buttons[0]:
CC.cruiseControl.cancel = True
hudControl = CC.hudControl
hudControl.setSpeed = float(self.v_cruise_kph * CV.KPH_TO_MS)
hudControl.speedVisible = self.enabled
hudControl.lanesVisible = self.enabled
hudControl.leadVisible = self.sm['longitudinalPlan'].hasLead
hudControl.rightLaneVisible = True
hudControl.leftLaneVisible = True
recent_blinker = (self.sm.frame - self.last_blinker_frame) * DT_CTRL < 5.0 # 5s blinker cooldown
ldw_allowed = self.is_ldw_enabled and CS.vEgo > LDW_MIN_SPEED and not recent_blinker \
and not CC.latActive and self.sm['liveCalibration'].calStatus == Calibration.CALIBRATED
model_v2 = self.sm['modelV2']
desire_prediction = model_v2.meta.desirePrediction
if len(desire_prediction) and ldw_allowed:
right_lane_visible = self.sm['lateralPlan'].rProb > 0.5
left_lane_visible = self.sm['lateralPlan'].lProb > 0.5
l_lane_change_prob = desire_prediction[Desire.laneChangeLeft - 1]
r_lane_change_prob = desire_prediction[Desire.laneChangeRight - 1]
lane_lines = model_v2.laneLines
l_lane_close = left_lane_visible and (lane_lines[1].y[0] > -(1.08 + CAMERA_OFFSET))
r_lane_close = right_lane_visible and (lane_lines[2].y[0] < (1.08 - CAMERA_OFFSET))
hudControl.leftLaneDepart = bool(l_lane_change_prob > LANE_DEPARTURE_THRESHOLD and l_lane_close)
hudControl.rightLaneDepart = bool(r_lane_change_prob > LANE_DEPARTURE_THRESHOLD and r_lane_close)
if hudControl.rightLaneDepart or hudControl.leftLaneDepart:
self.events.add(EventName.ldw)
clear_event_types = set()
if ET.WARNING not in self.current_alert_types:
clear_event_types.add(ET.WARNING)
if self.enabled:
clear_event_types.add(ET.NO_ENTRY)
alerts = self.events.create_alerts(self.current_alert_types, [self.CP, self.sm, self.is_metric, self.soft_disable_timer])
self.AM.add_many(self.sm.frame, alerts)
current_alert = self.AM.process_alerts(self.sm.frame, clear_event_types)
if current_alert:
hudControl.visualAlert = current_alert.visual_alert
if not self.read_only and self.initialized:
# send car controls over can
self.last_actuators, can_sends = self.CI.apply(CC)
self.pm.send('sendcan', can_list_to_can_capnp(can_sends, msgtype='sendcan', valid=CS.canValid))
CC.actuatorsOutput = self.last_actuators
force_decel = (self.sm['driverMonitoringState'].awarenessStatus < 0.) or \
(self.state == State.softDisabling)
# Curvature & Steering angle
params = self.sm['liveParameters']
steer_angle_without_offset = math.radians(CS.steeringAngleDeg - params.angleOffsetDeg)
curvature = -self.VM.calc_curvature(steer_angle_without_offset, CS.vEgo, params.roll)
# controlsState
dat = messaging.new_message('controlsState')
dat.valid = CS.canValid
controlsState = dat.controlsState
if current_alert:
controlsState.alertText1 = current_alert.alert_text_1
controlsState.alertText2 = current_alert.alert_text_2
controlsState.alertSize = current_alert.alert_size
controlsState.alertStatus = current_alert.alert_status
controlsState.alertBlinkingRate = current_alert.alert_rate
controlsState.alertType = current_alert.alert_type
controlsState.alertSound = current_alert.audible_alert
controlsState.canMonoTimes = list(CS.canMonoTimes)
controlsState.longitudinalPlanMonoTime = self.sm.logMonoTime['longitudinalPlan']
controlsState.lateralPlanMonoTime = self.sm.logMonoTime['lateralPlan']
controlsState.enabled = self.enabled
controlsState.active = self.active
controlsState.curvature = curvature
controlsState.state = self.state
controlsState.engageable = not self.events.any(ET.NO_ENTRY)
controlsState.longControlState = self.LoC.long_control_state
controlsState.vPid = float(self.LoC.v_pid)
controlsState.vCruise = float(self.v_cruise_kph)
controlsState.upAccelCmd = float(self.LoC.pid.p)
controlsState.uiAccelCmd = float(self.LoC.pid.i)
controlsState.ufAccelCmd = float(self.LoC.pid.f)
controlsState.cumLagMs = -self.rk.remaining * 1000.
controlsState.startMonoTime = int(start_time * 1e9)
controlsState.forceDecel = bool(force_decel)
controlsState.canErrorCounter = self.can_rcv_error_counter
lat_tuning = self.CP.lateralTuning.which()
Fixup joystick (#21129) * some common changes * rename to joystick * add alert and update controlsd to work with joystick * update joystickd * Update Joystick readme * assume we have inputs * only send gb or steer when engaged_toggle is true * Update instructions * fix --ip * Easier to understand at a glance * much better * -a * receive events and send msg in same loop * always import * Update selfdrive/controls/lib/events.py Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> * Update selfdrive/controls/lib/events.py Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> * combine logic and clean up * use argparse * outdated, and use normal class * rm * bit of a refactor * refactor part 2 / 3 * much better (3 / 3) * Simplify * bump cereal and update readme * capitalize * Update tools/joystick/joystickd.py Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> * Update tools/joystick/joystickd.py Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> * make joystick abstraction class clearer * use interp, clearer without comments * no need to use apply_deadzone * more explicit * define btns and axes once * split function by use_keyboard again, but simpler * we can use handle_button as a reset function * need to flip sign * remove * invert axes map for kb, easier to read the button mapping * apply changes from review * new lateral log for debug mode * bump * add saturated * static alert * joystick_mode * conditionally subscribe * Update selfdrive/controls/controlsd.py Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> * move params instantiation * Spoof active and enabled * Only allow car to engage * no startup alert if joystick * Update controlsd.py * Should be orange not enabled, green enabled * no more button states * should work * blue * submaster conflates, so only send when we have an update * final change * remove msg * clean up a bit sort of clean up clean up a bit remove msg * this was right * Apply suggestions from code review Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> * lowercase * suggestions from code review * forgot laptop * bump to latest * fixes Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com> Co-authored-by: vanillagorillaa <31773928+vanillagorillaa@users.noreply.github.com> old-commit-hash: ae77f693a26527ffbee044f852cc4185718c2433
4 years ago
if self.joystick_mode:
controlsState.lateralControlState.debugState = lac_log
elif self.CP.steerControlType == car.CarParams.SteerControlType.angle:
controlsState.lateralControlState.angleState = lac_log
elif lat_tuning == 'pid':
controlsState.lateralControlState.pidState = lac_log
elif lat_tuning == 'lqr':
controlsState.lateralControlState.lqrState = lac_log
elif lat_tuning == 'indi':
controlsState.lateralControlState.indiState = lac_log
self.pm.send('controlsState', dat)
# carState
car_events = self.events.to_msg()
cs_send = messaging.new_message('carState')
cs_send.valid = CS.canValid
cs_send.carState = CS
cs_send.carState.events = car_events
self.pm.send('carState', cs_send)
# carEvents - logged every second or on change
if (self.sm.frame % int(1. / DT_CTRL) == 0) or (self.events.names != self.events_prev):
ce_send = messaging.new_message('carEvents', len(self.events))
ce_send.carEvents = car_events
self.pm.send('carEvents', ce_send)
self.events_prev = self.events.names.copy()
# carParams - logged every 50 seconds (> 1 per segment)
if (self.sm.frame % int(50. / DT_CTRL) == 0):
cp_send = messaging.new_message('carParams')
cp_send.carParams = self.CP
self.pm.send('carParams', cp_send)
# carControl
cc_send = messaging.new_message('carControl')
cc_send.valid = CS.canValid
cc_send.carControl = CC
self.pm.send('carControl', cc_send)
# copy CarControl to pass to CarInterface on the next iteration
self.CC = CC
def step(self):
start_time = sec_since_boot()
self.prof.checkpoint("Ratekeeper", ignore=True)
# Sample data from sockets and get a carState
CS = self.data_sample()
self.prof.checkpoint("Sample")
self.update_events(CS)
if not self.read_only and self.initialized:
# Update control state
self.state_transition(CS)
self.prof.checkpoint("State transition")
# Compute actuators (runs PID loops and lateral MPC)
CC, lac_log = self.state_control(CS)
self.prof.checkpoint("State Control")
# Publish data
self.publish_logs(CS, start_time, CC, lac_log)
self.prof.checkpoint("Sent")
self.update_button_timers(CS.buttonEvents)
self.CS_prev = CS
def controlsd_thread(self):
while True:
self.step()
self.rk.monitor_time()
self.prof.display()
def main(sm=None, pm=None, logcan=None):
controls = Controls(sm, pm, logcan)
controls.controlsd_thread()
if __name__ == "__main__":
main()