mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-10-04 21:33:58 +08:00
Wire stopped-motion presentation into optional normal runtime policy
This commit is contained in:
@@ -13,6 +13,7 @@ from event_music import EventDSP
|
||||
from input_clock import InputClock
|
||||
from presentation_policy import effective_config,selected as presentation_policy_selected
|
||||
from engagement_presentation import EngagementPresentation,PresentationConfig,engagement_active
|
||||
from motion_presentation import MotionPresentation
|
||||
from signal_shaker import SignalShaker,assess_grid,profile_tempo_prior
|
||||
from core_apex import CoreApex
|
||||
from alert_accent import AlertAccent
|
||||
@@ -76,11 +77,14 @@ config=effective_config(configuration());validate_render_mode(render_mode,compos
|
||||
rolling_mode=config.get('rolling',False);rolling_anchors={k:anchor_options(root,k) for k in styles if (root/f'assets/source_{k}.wav').exists()} if rolling_mode and composer!='ace' else {}
|
||||
drive_events=config.get('drive_events',False) or config.get('event_music',False);phrase_runway=config.get('phrase_runway',False)
|
||||
presentation_config=PresentationConfig.read(config.get('engagement_presentation'))
|
||||
motion_enabled=config.get('stopped_motion',{}).get('enabled') is True
|
||||
motion=MotionPresentation(rate,enabled=motion_enabled) if motion_enabled else None
|
||||
shaker_enabled=config.get('signal_shaker',{}).get('enabled') is True
|
||||
apex_enabled=config.get('core_apex',{}).get('enabled') is True
|
||||
alert_enabled=config.get('alert_accent',{}).get('enabled') is True
|
||||
if (presentation_config.enabled or shaker_enabled or apex_enabled or alert_enabled) and render_mode!='gold-core':raise ValueError('Optional presentation layers require gold-core baseline')
|
||||
if (motion_enabled or presentation_config.enabled or shaker_enabled or apex_enabled or alert_enabled) and render_mode!='gold-core':raise ValueError('Optional presentation layers require gold-core baseline')
|
||||
presentation=EngagementPresentation(rate,block) if presentation_config.enabled else None
|
||||
motion_state=(0.,False,0,0.,0)
|
||||
engagement=(False,False,0,0.,0);signal_state=(False,False,0,0.,0);alert_state=(None,False)
|
||||
initial_identity=identity;musical_mode=config.get('musical',False);arrival=Arrival();ending_start=None;ending_audio=None;ending_info={};playing_identity=identity;identity_queue=[];last_requested_identity=identity
|
||||
usable_frames=WINDOW if rolling_mode else (301 if musical_mode else 323)
|
||||
@@ -208,9 +212,12 @@ def callback(out,n,ti,status):
|
||||
alert_key,meaningful=alert_state
|
||||
competing=bool((shaker is not None and shaker.active) or (apex is not None and apex.rendered_active) or (presentation is not None and abs(presentation.mix-float(active))>.01))
|
||||
rendered=alert_accent.process(rendered,frames-n,alert_key,meaningful,fresh,competing)
|
||||
if motion is not None:
|
||||
_,motion_fresh=engagement_active(motion_state[1],True,motion_state[2],motion_state[4],motion_state[3],callback_wall)
|
||||
rendered=motion.process(rendered,speed=motion_state[0],source_fresh=motion_fresh)
|
||||
if presentation is not None:rendered=presentation.process(rendered,active,presentation_config)
|
||||
out[:]=0 if a.mute else rendered
|
||||
try:capture.put_nowait((rendered,chunk,{'signal_shaker_enabled':shaker_enabled,'signal_on':signal_on,'signal_fresh':signal_fresh,'engagement_presentation_enabled':presentation_config.enabled,'engagement_active':active,'engagement_fresh':fresh,'audio_s':(frames-n)/rate,'callback_wall':callback_wall,'command_received_wall':command_wall,'replay_origin_wall':replay_origin_wall,'dac_delay':float(ti.outputBufferDacTime-ti.currentTime),'route_t':source_time,'amount':amount,'phase':event_state['phase'],'strength':event_state.get('strength',0),'predicted_peak':event_state.get('predicted_peak'),'activation':event_state.get('activation'),'kind':event_state.get('kind','curve'),'cadence_entry_audio_s':None if ending_start is None else ending_start/rate,'runway_active':ending_start is not None and frames-n<ending_start,'muted':a.mute,'portaudio_status':str(status),'callback_processing_seconds':time.monotonic()-callback_wall}))
|
||||
try:capture.put_nowait((rendered,chunk,{'motion_presentation':motion.snapshot() if motion is not None else None,'signal_shaker_enabled':shaker_enabled,'signal_on':signal_on,'signal_fresh':signal_fresh,'engagement_presentation_enabled':presentation_config.enabled,'engagement_active':active,'engagement_fresh':fresh,'audio_s':(frames-n)/rate,'callback_wall':callback_wall,'command_received_wall':command_wall,'replay_origin_wall':replay_origin_wall,'dac_delay':float(ti.outputBufferDacTime-ti.currentTime),'route_t':source_time,'amount':amount,'phase':event_state['phase'],'strength':event_state.get('strength',0),'predicted_peak':event_state.get('predicted_peak'),'activation':event_state.get('activation'),'kind':event_state.get('kind','curve'),'cadence_entry_audio_s':None if ending_start is None else ending_start/rate,'runway_active':ending_start is not None and frames-n<ending_start,'muted':a.mute,'portaudio_status':str(status),'callback_processing_seconds':time.monotonic()-callback_wall}))
|
||||
except queue.Full:underflows+=1
|
||||
# Optional prewarmed continuation gives ~52 seconds before replay starts.
|
||||
warm=root/'generated/job_-1.wav'
|
||||
@@ -246,8 +253,11 @@ try:
|
||||
engagement=(bool(sm['selfdriveState'].active),bool(sm.valid['selfdriveState']),sm.logMonoTime['selfdriveState'],control_wall,latest_source)
|
||||
else:engagement=(*engagement[:4],latest_source)
|
||||
if sm.updated['carState']:
|
||||
motion_state=(float(sm['carState'].vEgo),bool(sm.valid['carState']),sm.logMonoTime['carState'],control_wall,latest_source)
|
||||
signal_state=(bool(sm['carState'].leftBlinker or sm['carState'].rightBlinker),bool(sm.valid['carState']),sm.logMonoTime['carState'],control_wall,latest_source)
|
||||
else:signal_state=(*signal_state[:4],latest_source)
|
||||
else:
|
||||
signal_state=(*signal_state[:4],latest_source)
|
||||
motion_state=(*motion_state[:4],latest_source)
|
||||
clock=clock_source.read(sm)
|
||||
if clock is None:continue
|
||||
if clock['done']:
|
||||
@@ -386,6 +396,7 @@ try:
|
||||
if presentation is not None:
|
||||
engagement_on,engagement_fresh=engagement_active(engagement[1],engagement[0],engagement[2],engagement[4],engagement[3],time.monotonic())
|
||||
snapshot.update(presentation.snapshot(presentation_config,engagement_on,engagement_fresh))
|
||||
if motion is not None:snapshot.update(motion.snapshot())
|
||||
if shaker is not None:snapshot['signal_shaker']=shaker.snapshot()
|
||||
if apex is not None:snapshot['core_apex']=apex.snapshot()
|
||||
if alert_accent is not None:snapshot['alert_accent']=alert_accent.snapshot()
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
import copy
|
||||
import os
|
||||
|
||||
POLICIES = ('conservative-v1', 'conservative-v2', 'off', 'frozen')
|
||||
POLICIES = ('conservative-v1', 'conservative-v2', 'conservative-v3', 'off', 'frozen')
|
||||
CONSERVATIVE = {
|
||||
'presentation_policy_version': 'conservative-v1',
|
||||
'signal_shaker': {'enabled': True},
|
||||
@@ -12,6 +12,8 @@ CONSERVATIVE = {
|
||||
|
||||
CONSERVATIVE_V2 = {**copy.deepcopy(CONSERVATIVE), 'presentation_policy_version':'conservative-v2', 'alert_accent':{'enabled':True}, 'core_apex':{'enabled':True,'dip_db':-3.}}
|
||||
|
||||
CONSERVATIVE_V3 = {**copy.deepcopy(CONSERVATIVE_V2), 'presentation_policy_version':'conservative-v3', 'stopped_motion':{'enabled':True}}
|
||||
|
||||
def select_launch(composer, profile, replay=False, judging=False, render_mode=None, policy=None):
|
||||
if policy is not None and policy not in POLICIES:raise ValueError('Unknown presentation policy')
|
||||
if render_mode is not None and render_mode not in ('current','gold-core'):raise ValueError('Unknown rendering mode')
|
||||
@@ -28,7 +30,7 @@ def select_launch(composer, profile, replay=False, judging=False, render_mode=No
|
||||
normal_prism=composer=='ace' and profile=='prism'
|
||||
mode=render_mode or ('gold-core' if normal_prism else 'current')
|
||||
chosen=policy or ('conservative-v2' if normal_prism and mode=='gold-core' else 'off')
|
||||
if chosen in ('conservative-v1','conservative-v2') and (composer!='ace' or mode!='gold-core'):
|
||||
if chosen in ('conservative-v1','conservative-v2','conservative-v3') and (composer!='ace' or mode!='gold-core'):
|
||||
raise ValueError('Conservative presentation requires ACE gold-core rendering')
|
||||
return {'render_mode':mode,'policy':chosen}
|
||||
|
||||
@@ -41,9 +43,9 @@ def effective_config(config,environ=None):
|
||||
"""Return a copy; never mutate the global runtime file or an archived policy."""
|
||||
result=copy.deepcopy(config);policy=selected(environ)
|
||||
if policy=='frozen':return result
|
||||
if policy in ('conservative-v1','conservative-v2'):
|
||||
result.update(copy.deepcopy(CONSERVATIVE_V2 if policy=='conservative-v2' else CONSERVATIVE))
|
||||
if policy in ('conservative-v1','conservative-v2','conservative-v3'):
|
||||
result.update(copy.deepcopy(CONSERVATIVE_V3 if policy=='conservative-v3' else CONSERVATIVE_V2 if policy=='conservative-v2' else CONSERVATIVE))
|
||||
if policy=='conservative-v1':result['alert_accent']={'enabled':False}
|
||||
else:
|
||||
result.update(presentation_policy_version='off',alert_accent={'enabled':False},signal_shaker={'enabled':False},core_apex={'enabled':False},engagement_presentation={'version':2,'enabled':False})
|
||||
result.update(presentation_policy_version='off',stopped_motion={'enabled':False},alert_accent={'enabled':False},signal_shaker={'enabled':False},core_apex={'enabled':False},engagement_presentation={'version':2,'enabled':False})
|
||||
return result
|
||||
|
||||
@@ -34,6 +34,13 @@ class PolicyTests(unittest.TestCase):
|
||||
latest=effective_config({}, {'ROADSCORE_PRESENTATION_POLICY':'conservative-v2'})
|
||||
self.assertTrue(latest['alert_accent']['enabled'])
|
||||
self.assertEqual(latest['core_apex']['dip_db'],-3.)
|
||||
def test_stopped_motion_candidate_preserves_default_and_optout(self):
|
||||
self.assertEqual(select_launch('ace','prism')['policy'],'conservative-v2')
|
||||
candidate=effective_config({}, {'ROADSCORE_PRESENTATION_POLICY':'conservative-v3'})
|
||||
self.assertTrue(candidate['stopped_motion']['enabled'])
|
||||
self.assertTrue(candidate['engagement_presentation']['enabled'])
|
||||
self.assertFalse(effective_config(candidate, {'ROADSCORE_PRESENTATION_POLICY':'off'})['stopped_motion']['enabled'])
|
||||
with self.assertRaises(ValueError):select_launch('sa3','prism',policy='conservative-v3')
|
||||
def test_other_backend_and_legacy_incompatibility(self):
|
||||
self.assertEqual(select_launch('sa3','prism'),{'render_mode':'current','policy':'off'})
|
||||
with self.assertRaises(ValueError):select_launch('ace','prism',render_mode='current',policy='conservative-v1')
|
||||
|
||||
Reference in New Issue
Block a user