Files
StarPilot/openpilot/starpilot/controllers/runtime.py
T
Claude 7dbbb43c3b Add Tesla Model 3/Y wheel controls and comma-set dashboard speed
Everything here is limited to Tesla Model 3 and Model Y; other cars are unchanged. Most of it needs the Tesla CAN
add-on cable (Vehicle CAN).

Wheel Controls
- Right scroll wheel nudge left / right and holding either, right stalk half and full press while engaged, and a
  three-finger tap on the Tesla screen as assignable actions. Scroll up / down and stalk Down / Up are shown grayed,
  the scroll rows with their step (1, or to the next 5 for a fast scroll).
  Nudge right starts on Cycle Driving Personality.
- The three-finger tap's Always On Lateral on/off is chosen on its own row here: the Three-Finger AOL Tap row leaves
  Vehicle Settings, and TeslaAOLScreenTap is saved on by default.
- The Short press and Hold step rows are left out on a Model 3/Y, where StarPilot never steps the set speed from
  cruise buttons.
- A receive-only worker reads the wheel, stalk and screen frames. It only runs on a Model 3/Y with the cable.

Vehicle Settings
- Tesla CAN add-on cable row: detected or not, with buy and install links.
- Comma can set speed on Tesla dashboard (TeslaSpeedSync): off by default, experimental, needs the cable and Alpha
  Longitudinal, not offered on release builds. Takes effect within a second, without a restart.

With the switch on
- StarPilot keeps its own set speed; the right scroll wheel changes it by 1, or to the next multiple of 5.
- The Tesla's set speed is scrolled to match with right-scroll-wheel frames on Vehicle CAN, and scrolled back if the
  Tesla changes it.
- Speed Limit Controller writes the limit plus offset into the set speed instead of capping beneath it. Adopt limits
  early writes it early, and back again if the Maps preview is withdrawn. After an accelerator override: with Hold the
  speed you reached, lifting off above the limit makes the speed reached the set speed until the limit changes.

With the switch off, Speed Limit Controller and the set speed behave as before.

Also adds the Tesla dashboard speed limit (DAS_fusedSpeedLimit) as a Speed Limit Controller Dashboard source.

Panda: adds opendbc/safety/modes/tesla_speed_sync.h and safety-param bit 4096 (debug builds only), with tests. The bit
is set at startup on every eligible Model 3/Y so the switch works without a restart, so the images need rebuilding.
Always On Lateral's two exact-word checks accept the new bit. test_screen_recovery_callers.py and
test_tesla_screen_integration.py expect the bit on a car with the cable and StarPilot longitudinal.

Schema: SlcAction.ControllerCruiseAction gains stepUnits @13 and sourceTeslaGesture @14 (new TeslaGesture struct),
SlcAction.Kind gains cruiseStep @13. Settings keys: TeslaSpeedSync, CarControlAssignments.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-23 18:32:41 +00:00

74 lines
2.6 KiB
Python

import logging
import time
from openpilot.starpilot.controllers.input import InputReader
from openpilot.starpilot.controllers.owner import ControllerOwner
from openpilot.starpilot.controllers.transport import ControllerService
from openpilot.starpilot.galaxy.settings import LiveContextSource
LOGGER = logging.getLogger(__name__)
class ControllerRuntime:
def __init__(self, params, *, actions, favorites, invoke_favorite, authority=None, reader=None, socket_path=None,
vehicle=lambda: None, messages=lambda: None, input_capture=lambda: None, speed_actions=None, keyed_actions=None):
self.authority = authority if authority is not None else LiveContextSource(params)
self.reader = reader if reader is not None else InputReader()
self.owner = ControllerOwner(params, parked=self.authority.parked, actions=actions, favorites=favorites,
invoke_favorite=invoke_favorite)
from openpilot.starpilot.controllers.tesla_receiver import TeslaReceiver
self.tesla = TeslaReceiver(params, actions, vehicle, messages=messages, speed_actions=speed_actions,
keyed_actions=keyed_actions)
self.service = ControllerService(self.owner, socket_path)
self.input_capture = input_capture
self._closed = False
self._next_warm = 0.0
self._warm_until = time.monotonic() + 2.0
try:
self.service.start()
except (OSError, RuntimeError):
LOGGER.exception('Controller input could not start')
self.close()
def poll(self):
if self._closed:
return
try:
self.tesla.poll()
except Exception:
LOGGER.exception('Tesla input stopped')
self.tesla.close()
self.tesla.next_start = time.monotonic() + 2.
try:
now = time.monotonic()
if now >= self._next_warm:
self.authority.parked()
self._next_warm = now + (0.1 if now < self._warm_until else 1.0)
presses = self.reader.poll(time.monotonic_ns())
self.owner.set_devices(self.reader.devices())
self.owner.tick()
# Process input before configuration so queued presses cannot activate a new binding.
capture = self.input_capture()
for press in presses:
if capture is None:
self.owner.feed(press)
else:
self.owner.feed(press, capture=capture)
self.service.poll()
except Exception:
LOGGER.exception('Controller input stopped')
self.close()
def close(self):
if self._closed:
return
self._closed = True
self.tesla.close()
try:
self.service.close()
finally:
try:
self.reader.close()
finally:
self.authority.close()