Mercurial > public > hwos_code
comparison src/p2_deco.c @ 115:72259a79eac2
FIX: Gas volume computation when using several travel mix.
author | heinrichsweikamp |
---|---|
date | Mon, 23 Jun 2014 17:55:27 +0200 |
parents | 109df032cc54 |
children | d076e9c02438 |
comparison
equal
deleted
inserted
replaced
114:109df032cc54 | 115:72259a79eac2 |
---|---|
83 // 2012/09/10: [mH] Fill char_O_deco_time_for_log for logbook write | 83 // 2012/09/10: [mH] Fill char_O_deco_time_for_log for logbook write |
84 // 2012/10/05: [jDG] Better deco_gas_volumes accuracy (average depth, switch between stop). | 84 // 2012/10/05: [jDG] Better deco_gas_volumes accuracy (average depth, switch between stop). |
85 // 2013/03/05: [jDG] Should vault low_depth too. | 85 // 2013/03/05: [jDG] Should vault low_depth too. |
86 // 2013/03/05: [jDG] Wrobell remark: ascent_to_first_stop works better with finer steps (2sec). | 86 // 2013/03/05: [jDG] Wrobell remark: ascent_to_first_stop works better with finer steps (2sec). |
87 // 2013/05/08: [jDG] A. Salm remark: NOAA tables for CNS are in ATA, not bar. | 87 // 2013/05/08: [jDG] A. Salm remark: NOAA tables for CNS are in ATA, not bar. |
88 // 2013/12/21: [jDG] Fix CNS calculation in decoplan w/o marked gas switch | |
89 // 2014/06/16: [jDG] Fix Helium diluant. Fix volumes with many travel mix. | |
88 // | 90 // |
89 // TODO: | 91 // TODO: |
90 // | 92 // |
91 // Literature: | 93 // Literature: |
92 // Bühlmann, Albert: Tauchmedizin; 4. Auflage [2002]; | 94 // Bühlmann, Albert: Tauchmedizin; 4. Auflage [2002]; |
2156 { | 2158 { |
2157 overlay float volumes[NUM_GAS]; | 2159 overlay float volumes[NUM_GAS]; |
2158 overlay float bottom_usage, deco_usage; | 2160 overlay float bottom_usage, deco_usage; |
2159 overlay unsigned char i, deepest_first; | 2161 overlay unsigned char i, deepest_first; |
2160 overlay unsigned char gas, depth; | 2162 overlay unsigned char gas, depth; |
2163 overlay unsigned char lastGasStop = 255; | |
2161 RESET_C_STACK | 2164 RESET_C_STACK |
2162 | 2165 |
2163 //---- initialize with bottom consumption -------------------------------- | 2166 //---- initialize with bottom consumption -------------------------------- |
2164 for(i=0; i<NUM_GAS; ++i) // Nothing yet... | 2167 for(i=0; i<NUM_GAS; ++i) // Nothing yet... |
2165 volumes[i] = 0.0; | 2168 volumes[i] = 0.0; |
2166 | 2169 |
2167 assert(1 <= char_I_first_gas && char_I_first_gas <= NUM_GAS); | 2170 assert(1 <= char_I_first_gas && char_I_first_gas <= NUM_GAS); |
2168 gas = char_I_first_gas - 1; | 2171 gas = char_I_first_gas - 1; |
2169 | 2172 |
2170 bottom_usage = (float) char_I_bottom_usage; | 2173 bottom_usage = 20; // In liter/minutes. |
2171 if( char_I_const_ppO2 == 0 && bottom_usage > 0.0 ) | 2174 if( char_I_const_ppO2 == 0 && bottom_usage > 0.0 ) |
2172 volumes[gas] | 2175 volumes[gas] |
2173 = (char_I_bottom_depth*0.1 + 1.0) // Use Psurface = 1.0 bar. | 2176 = (char_I_bottom_depth*0.1 + 1.0) // Use Psurface = 1.0 bar. |
2174 * char_I_bottom_time // in minutes. | 2177 * char_I_bottom_time // in minutes. |
2175 * bottom_usage; // In liter/minutes. | 2178 * bottom_usage; // In liter/minutes. |
2176 | 2179 |
2177 //---- Ascent usage ------------------------------------------------------ | 2180 //---- Ascent usage ------------------------------------------------------ |
2178 deco_usage = (float) char_I_deco_usage; // In liter/minutes. | 2181 deepest_first = 0; |
2182 deco_usage = 20; // In liter/minutes. | |
2179 | 2183 |
2180 depth = char_I_bottom_depth; | 2184 depth = char_I_bottom_depth; |
2181 | 2185 |
2182 for(i=0; i<NUM_STOPS; ++i) | 2186 for(i=0; i<NUM_STOPS; ++i) |
2183 { | 2187 { |
2197 if( time == 0 ) continue; // not yet: still search table. | 2201 if( time == 0 ) continue; // not yet: still search table. |
2198 | 2202 |
2199 newDepth = char_O_deco_depth[31-i]; | 2203 newDepth = char_O_deco_depth[31-i]; |
2200 } | 2204 } |
2201 | 2205 |
2202 //---- Gas switch during this step ----------------------------------- | 2206 //---- Gas switch during or before this stop -------------------------- |
2207 for(;;) | |
2203 { | 2208 { |
2204 overlay unsigned char newGas = 0; | 2209 overlay unsigned char newGas = 0; |
2205 overlay unsigned char newStop = 0; // NO CHANGE yet | 2210 overlay unsigned char newStop = 0; // NO CHANGE yet |
2206 overlay unsigned char j; | 2211 overlay unsigned char j; |
2207 | 2212 |
2208 for(j=0; j<NUM_GAS; ++j) | 2213 for(j=0; j<NUM_GAS; ++j) |
2209 { | 2214 { |
2210 // Skip gas without changing depth: | 2215 // Skip gas without changing depth: |
2211 if( ! char_I_deco_gas_change[j] ) | 2216 if( ! char_I_deco_gas_change[j] ) |
2212 continue; | 2217 continue; |
2213 // Select gas changed between [newDepth .. depth] | 2218 // Select gas changed between [newDepth .. lastGasStop[ |
2219 // Note that <= means changing gas at BEGINNING of this stop. | |
2220 // Note that < means we cant use the same gas twice | |
2214 if( newDepth <= char_I_deco_gas_change[j] | 2221 if( newDepth <= char_I_deco_gas_change[j] |
2215 && char_I_deco_gas_change[j] <= depth ) | 2222 && char_I_deco_gas_change[j] < lastGasStop ) |
2216 { | 2223 { |
2217 // Keep the DEEPEST gas in that range: | 2224 // Keep the DEEPEST gas in that range: |
2218 // Note: that = means changing gas at BEGINNING of this stop. | |
2219 if( char_I_deco_gas_change[j] >= newStop ) | 2225 if( char_I_deco_gas_change[j] >= newStop ) |
2220 { | 2226 { |
2221 newGas = j; | 2227 newGas = j; |
2222 newStop = char_I_deco_gas_change[j]; | 2228 newStop = char_I_deco_gas_change[j]; |
2223 } | 2229 } |
2224 } | 2230 } |
2225 } | 2231 } |
2226 | 2232 |
2227 if( newStop ) // Did we find something ? | 2233 // Did we find something ? |
2228 { | 2234 if( !newStop ) |
2229 // usage BEFORE gas switch (if any), at 10m/min : | 2235 break; |
2230 if( deco_usage > 0.0 && depth > newStop ) | 2236 |
2231 // Plus usage during ascent to the next stop, at 10m/min. | 2237 //---- usage BEFORE gas switch (if any), at 10m/min : |
2232 volumes[gas] += ((depth+newStop)*0.05 + 1.0) // average depth --> bar. | 2238 if( deco_usage > 0.0 && depth > newStop ) |
2233 * (depth-newStop)*0.1 // metre --> min | 2239 // Plus usage during ascent to the next stop, at 10m/min. |
2234 * deco_usage; | 2240 volumes[gas] += ((depth+newStop)*0.05 + 1.0) // average depth --> bar. |
2235 | 2241 * (depth-newStop)*0.1 // metre --> min |
2236 // Do gas switch: | 2242 * deco_usage; |
2237 gas = newGas; | 2243 |
2244 //---- Do gas switch: | |
2245 gas = newGas; | |
2246 | |
2247 lastGasStop = newStop; // Mark last used gas | |
2248 if( newStop < depth ) // ascent to gas switch, | |
2238 depth = newStop; | 2249 depth = newStop; |
2239 } | 2250 } |
2240 } | 2251 |
2241 | 2252 //---- usage AFTER gas switch (if any), at 10m/min : |
2242 // usage AFTER gas switch (if any), at 10m/min : | |
2243 if( depth > newDepth ) | 2253 if( depth > newDepth ) |
2244 volumes[gas] += ((depth+newDepth)*0.05 + 1.0) // average depth --> bar. | 2254 volumes[gas] += ((depth+newDepth)*0.05 + 1.0) // average depth --> bar. |
2245 * (depth-newDepth)*0.1 // metre --> min | 2255 * (depth-newDepth)*0.1 // metre --> min |
2246 * deco_usage; | 2256 * deco_usage; |
2247 | 2257 |
2248 // Do stop: | 2258 //---- Do stop: |
2249 depth = newDepth; | 2259 depth = newDepth; |
2250 | 2260 |
2251 // Usage at stop: | 2261 // Usage at stop: |
2252 if( deco_usage > 0.0 ) | 2262 if( deco_usage > 0.0 ) |
2253 volumes[gas] += (depth*0.1 + 1.0) // depth --> bar. | 2263 volumes[gas] += (depth*0.1 + 1.0) // depth --> bar. |