Mercurial > public > ostc4
comparison Discovery/Src/simulation.c @ 910:7bd347bdaa81 Evo_2_23
Devbugfix Sample time resolution for longer dives:
If a dive is longer than the provided replay buffer then the sample data is compressed. This compression was not considered in the previous version. As result the dive was replayed with double speed because a single sample were interpretated as 2 seconds instead of e.g. 4 seconds for a compressed sample. The comprassion rate is now considered in the simulator replay function
author | Ideenmodellierer |
---|---|
date | Tue, 15 Oct 2024 19:12:05 +0200 |
parents | 46a21ff3f5ab |
children | 4d98fb2a178e |
comparison
equal
deleted
inserted
replaced
909:6902bb4b6b2e | 910:7bd347bdaa81 |
---|---|
378 //Calc next depth | 378 //Calc next depth |
379 uint8_t actual_deco_stop = decom_get_actual_deco_stop(pDiveState); | 379 uint8_t actual_deco_stop = decom_get_actual_deco_stop(pDiveState); |
380 float depth_meter = pDiveState->lifeData.depth_meter; | 380 float depth_meter = pDiveState->lifeData.depth_meter; |
381 float surface_pressure_bar = pDiveState->lifeData.pressure_surface_bar; | 381 float surface_pressure_bar = pDiveState->lifeData.pressure_surface_bar; |
382 static uint8_t sampleToggle = 0; | 382 static uint8_t sampleToggle = 0; |
383 | 383 static float sim_ascent_rate_meter_per_min_local = 0; |
384 if(simReplayActive) /* precondition: function is called once per second, sample rate is 2 seconds */ | 384 uint8_t sampleTime = getReplayDataResolution(); |
385 | |
386 if(simReplayActive) /* precondition: function is called once per second, sample rate is a multiple of second */ | |
385 { | 387 { |
386 if(sampleToggle == 0) | 388 if(sampleToggle == 0) |
387 { | 389 { |
388 sampleToggle = 1; | 390 sampleToggle = sampleTime - 1; |
389 sim_aim_depth_meter = (float)(*pReplayData++/100.0); | 391 sim_aim_depth_meter = (float)(*pReplayData++/100.0); |
390 sim_descent_rate_meter_per_min = (sim_aim_depth_meter - depth_meter) * 30; | 392 if(sim_aim_depth_meter > depth_meter) |
393 { | |
394 sim_descent_rate_meter_per_min = (sim_aim_depth_meter - depth_meter) * (60 / sampleTime); | |
395 } | |
396 else | |
397 { | |
398 sim_ascent_rate_meter_per_min_local = (depth_meter - sim_aim_depth_meter) * (60 / sampleTime); | |
399 } | |
391 } | 400 } |
392 else | 401 else |
393 { | 402 { |
394 sampleToggle = 0; | 403 sampleToggle--; |
395 } | 404 } |
405 } | |
406 else | |
407 { | |
408 sim_ascent_rate_meter_per_min_local = pDiveState->diveSettings.ascentRate_meterperminute; | |
396 } | 409 } |
397 | 410 |
398 if(depth_meter < sim_aim_depth_meter) | 411 if(depth_meter < sim_aim_depth_meter) |
399 { | 412 { |
400 depth_meter = depth_meter + sim_descent_rate_meter_per_min / 60; | 413 depth_meter = depth_meter + sim_descent_rate_meter_per_min / 60; |
402 depth_meter = sim_aim_depth_meter; | 415 depth_meter = sim_aim_depth_meter; |
403 } | 416 } |
404 else if(depth_meter > sim_aim_depth_meter) | 417 else if(depth_meter > sim_aim_depth_meter) |
405 { | 418 { |
406 | 419 |
407 depth_meter -= pDiveState->diveSettings.ascentRate_meterperminute / 60; | 420 depth_meter -= sim_ascent_rate_meter_per_min_local / 60; |
408 if(depth_meter < sim_aim_depth_meter) | 421 if(depth_meter < sim_aim_depth_meter) |
409 depth_meter = sim_aim_depth_meter; | 422 depth_meter = sim_aim_depth_meter; |
410 | 423 |
411 if(sim_heed_decostops && depth_meter < actual_deco_stop) | 424 if(sim_heed_decostops && depth_meter < actual_deco_stop) |
412 { | 425 { |
413 if(actual_deco_stop < (depth_meter + pDiveState->diveSettings.ascentRate_meterperminute / 60)) | 426 if(actual_deco_stop < (depth_meter + sim_ascent_rate_meter_per_min_local / 60)) |
414 depth_meter = actual_deco_stop; | 427 depth_meter = actual_deco_stop; |
415 else | 428 else |
416 depth_meter += pDiveState->diveSettings.ascentRate_meterperminute / 60; | 429 depth_meter += sim_ascent_rate_meter_per_min_local / 60; |
417 } | 430 } |
418 | 431 |
419 } | 432 } |
420 | 433 |
421 return surface_pressure_bar + depth_meter / 10; | 434 return surface_pressure_bar + depth_meter / 10; |
550 else | 563 else |
551 { | 564 { |
552 /* this does modify the cns now 11.06.2015 */ | 565 /* this does modify the cns now 11.06.2015 */ |
553 vpm_calc(&pDiveState->lifeData,&pDiveState->diveSettings,&pDiveState->vpm,&pDiveState->decolistVPM, DECOSTOPS); | 566 vpm_calc(&pDiveState->lifeData,&pDiveState->diveSettings,&pDiveState->vpm,&pDiveState->decolistVPM, DECOSTOPS); |
554 pDiveState->lifeData.cns += vpm_get_CNS(); | 567 pDiveState->lifeData.cns += vpm_get_CNS(); |
568 | |
569 while(decoLock == DECO_CALC_FINSHED_vpm) | |
570 { | |
571 HAL_Delay(2); /* The deco data is copied during the timer ISR => wait till this has happened */ | |
572 } | |
555 return &pDiveState->decolistVPM; | 573 return &pDiveState->decolistVPM; |
556 } | 574 } |
557 } | 575 } |
558 | 576 |
559 static float sGChelper_bar(uint16_t depth_meter) | 577 static float sGChelper_bar(uint16_t depth_meter) |