# HG changeset patch # User JeanDo # Date 1322182577 -3600 # Node ID 2a6293641d51149b36123cada504b8ecc3d82c4a # Parent 6c0bf50610f733b2e8c1c62fe5957e859350fbf5 NEW NDL NDL faster/more precise simu (but no closed formula for trimix). diff -r 6c0bf50610f7 -r 2a6293641d51 code_part1/OSTC_code_asm_part1/changelog.txt --- a/code_part1/OSTC_code_asm_part1/changelog.txt Sun Nov 20 23:27:43 2011 +0100 +++ b/code_part1/OSTC_code_asm_part1/changelog.txt Fri Nov 25 01:56:17 2011 +0100 @@ -1,6 +1,6 @@ New in 2.06 beta: BETA Version - Do NOT use for diving! -NEW: NDL analytic model (Erik Baker's formula) +CHANGE: NDL faster/more precise simu (but no closed formula for trimix). BUGFIX: CCR air mode: should not blink for my bailout (bug #66) BUGFIX: N2_ratio/He_ratio[] not inited at boot time. CHANGE: Turkish text for velocity. diff -r 6c0bf50610f7 -r 2a6293641d51 code_part1/OSTC_code_c_part2/p2_deco.c --- a/code_part1/OSTC_code_c_part2/p2_deco.c Sun Nov 20 23:27:43 2011 +0100 +++ b/code_part1/OSTC_code_c_part2/p2_deco.c Fri Nov 25 01:56:17 2011 +0100 @@ -78,6 +78,8 @@ // 2011/04/27: [jDG] Fixed char_O_gradient_factor calculation when model uses gradient-factor. // 2011/05/02: [jDG] Added "Future TTS" function (CF58). // 2011/05/17: [jDG] Various cleanups. +// 2011/08/08: [jDG] Computes CNS during deco planning ascent. +// 2011/11/24: [jDG] Slightly faster and better NDL computation. // // TODO: // + Allow to abort MD2 calculation (have to restart next time). @@ -1193,6 +1195,7 @@ // static void clear_tissue(void) { + overlay float p; flag_in_divemode = 0; int_O_DBS_bitfield = 0; int_O_DBS2_bitfield = 0; @@ -1204,15 +1207,15 @@ N2_ratio = 0.7902; pres_respiration = int_I_pres_respiration * 0.001; + p = N2_ratio * (pres_respiration - ppWater); for(ci=0; ci 100 *(short)char_I_deco_gas_change[0] ) - deco_gas_change[0] = char_I_deco_gas_change[0]; - } - if(char_I_deco_gas_change[1]) + for(g=0; g < NUM_GAS; ++g) { - if( int_temp > 100 *(short)char_I_deco_gas_change[1] ) - deco_gas_change[1] = char_I_deco_gas_change[1]; - } - if(char_I_deco_gas_change[2]) - { - if( int_temp > 100 *(short)char_I_deco_gas_change[2] ) - deco_gas_change[2] = char_I_deco_gas_change[2]; - } - if(char_I_deco_gas_change[3]) - { - if( int_temp > 100 *(short)char_I_deco_gas_change[3] ) - deco_gas_change[3] = char_I_deco_gas_change[3]; - } - if(char_I_deco_gas_change[4]) - { - if( int_temp > 100 *(short)char_I_deco_gas_change[4] ) - deco_gas_change[4] = char_I_deco_gas_change[4]; + deco_gas_change[g] = 0; + if(char_I_deco_gas_change[g]) + if( int_temp > 100 *(short)char_I_deco_gas_change[g] ) + deco_gas_change[g] = char_I_deco_gas_change[g]; } const_ppO2 = char_I_const_ppO2 * 0.01; @@ -1717,69 +1697,86 @@ // // calculates the remaining bottom time // -// 2011-11-20 jDG: Changed (beta 2.06) to use Eric Baker's direct NDL formula. +// NOTE: Erik Baker's closed formula works for Nitroxes. Trimix adds a second +// exponential term to the M-value equation, making it impossible to +// invert... So we have to make a fast-simu until we find a better way. // // Input: pres_respiration // Output: char_O_nullzeit // static void calc_nullzeit(void) { - overlay float Pin; - + //---- Compute ppN2 and ppHe --------------------------------------------- temp_deco = pres_respiration; sim_alveolar_presures(); - Pin = ppN2 + ppHe; char_O_nullzeit = 240; for(ci=0; ci p ) // Only when on-gasing + //---- Simulate for that tissue -------------------------------------- + // NOTE: No need to simulate for longuer than the already found NDL. + for(ndl=0; ndl M0 ) + //---- Simulate off-gasing while going to surface + // TODO ! + // dTN2 -= exp( ... ascent time ... ppN2...) + // dTHe -= exp( ... ascent time ... ppHe...) + + //---- Still ok to surface after 1 or 10 minutes ? + if( t + dTN2 + dTHe <= M0 ) { - overlay unsigned char indl; - - overlay float ndl = log((Pin - p)/(Pin - M0)) * var_N2_ht/0.6931; + tN2 += dTN2; // YES: apply gas loadings, + tHe += dTHe; + t = tN2 + tHe; + ndl += period; // increment NDL, + continue; // and loop. + } - // Apply non-GF model security margins: - // Saturation factor will be applied to gas loading, accelerating - // loading, hence we should decrease NDL accordingly. - if( char_I_deco_model == 0) - ndl /= float_saturation_multiplier; + //---- Should we retry with smaller steps ? + if( period == 10 ) + { + read_buhlmann_times(1); // 1min coefs. + period = 1; + continue; + } - if( ndl < 0.0f ) ndl = 0.0f; - if( ndl > 254.5f ) ndl = 255.0f; - indl = (unsigned char)(ndl + 0.5f); - if( indl < char_O_nullzeit ) - char_O_nullzeit = indl; - } + //---- ELSE make a linear approx for the last minute + // Usefull to have a meneaingfull rounding of NDL + ndl += (unsigned char)(0.5f + (M0-t)/(dTN2+dTHe)); + break; } + + // Keep the shortest NDL found + if( ndl < char_O_nullzeit ) + char_O_nullzeit = ndl; } } @@ -2209,7 +2206,7 @@ // // desaturation slowed down to 70,42%. // -static void calc_dive_interval() +static void calc_dive_interval(void) { overlay unsigned char t; overlay unsigned char backup_model; @@ -2227,7 +2224,6 @@ char_I_deco_model = 0; //---- Perform simulation ------------------------------------------------ - for(t=0; t