comparison code_part1/OSTC_code_c_part2/p2_deco.c @ 234:bb8940caebe1

BUGFIX Gas Usage when stops are shallowest first: CF54 (bug BB24).
author JeanDo
date Thu, 17 Mar 2011 18:32:16 +0100
parents 2cbaa01dac26
children ade0848c8b8b
comparison
equal deleted inserted replaced
233:2cbaa01dac26 234:bb8940caebe1
2130 // calculates volumes for each gas. 2130 // calculates volumes for each gas.
2131 // 2131 //
2132 // Input: char_I_bottom_depth, char_I_bottom_time for planned dive. 2132 // Input: char_I_bottom_depth, char_I_bottom_time for planned dive.
2133 /// Gas list. First gas is the bottom gas. 2133 /// Gas list. First gas is the bottom gas.
2134 // decoplan (char_O_deco_depth, char_O_deco_time). 2134 // decoplan (char_O_deco_depth, char_O_deco_time).
2135 // CF#54 == TRUE if shallowest stop first.
2135 // CF#56 == bottom deci-liters/minutes (0.5 .. 50.0) 2136 // CF#56 == bottom deci-liters/minutes (0.5 .. 50.0)
2136 // CF#57 == deco deci-liters/minutes (0.5 .. 50.0). 2137 // CF#57 == deco deci-liters/minutes (0.5 .. 50.0).
2137 // Output: int_O_gas_volumes[0..4] in litters * 0.1 2138 // Output: int_O_gas_volumes[0..4] in litters * 0.1
2138 // 2139 //
2139 void deco_gas_volumes(void) 2140 void deco_gas_volumes(void)
2140 { 2141 {
2141 overlay float volumes[5]; 2142 overlay float volumes[5];
2142 overlay float ascent_usage; 2143 overlay float ascent_usage;
2143 overlay unsigned char i; 2144 overlay unsigned char i, deepest_first;
2144 RESET_C_STACK 2145 RESET_C_STACK
2145 2146
2146 //---- initialize with bottom consumption -------------------------------- 2147 //---- initialize with bottom consumption --------------------------------
2147 volumes[0] = (char_I_bottom_depth*0.1 + 1.0) // Use Psurface = 1.0 bar. 2148 volumes[0] = (char_I_bottom_depth*0.1 + 1.0) // Use Psurface = 1.0 bar.
2148 * char_I_bottom_time // in minutes. 2149 * char_I_bottom_time // in minutes.
2152 for(i=1; i<5; ++i) // Nothing yet... 2153 for(i=1; i<5; ++i) // Nothing yet...
2153 volumes[i] = 0.0; 2154 volumes[i] = 0.0;
2154 2155
2155 //---- Ascent usage ------------------------------------------------------ 2156 //---- Ascent usage ------------------------------------------------------
2156 2157
2157 ascent_usage = read_custom_function(57) * 0.1; // In litter/minutes. 2158 deepest_first = read_custom_function(54) == 0;
2159 ascent_usage = read_custom_function(57) * 0.1; // In litter/minutes.
2158 2160
2159 // Usage up to the first stop: 2161 // Usage up to the first stop:
2160 // - computed at MAX depth (easier, safer), 2162 // - computed at MAX depth (easier, safer),
2161 // - with an ascent speed of 10m/min. 2163 // - with an ascent speed of 10m/min.
2162 // - with ascent litter / minutes. 2164 // - with ascent litter / minutes.
2163 // - still using bottom gas: 2165 // - still using bottom gas:
2164 volumes[0] += (char_I_bottom_depth* 0.1 + 1.0) 2166 volumes[0] += (char_I_bottom_depth*0.1 + 1.0) // Depth -> bar
2165 * (char_I_bottom_depth - char_O_first_deco_depth) * 0.1 2167 * (char_I_bottom_depth - char_O_first_deco_depth) * 0.1 // ascent time (min)
2166 * ascent_usage; 2168 * ascent_usage; // Consumption ( xxx / min @ 1 bar)
2167 2169
2168 for(i=0; i<32 && char_O_deco_depth[i] > 0; ++i) 2170 for(i=0; i<32; ++i)
2169 { 2171 {
2170 overlay unsigned char j, gas; 2172 overlay unsigned char j, gas;
2173 overlay unsigned char depth, time, ascent;
2174
2175 // Manage stops in reverse order (CF#54)
2176 if( deepest_first )
2177 {
2178 time = char_O_deco_time[i];
2179 if( time == 0 ) break; // End of table: done.
2180
2181 ascent = depth = char_O_deco_depth[i];
2182 if( i < 31 )
2183 ascent -= char_O_deco_depth[i+1];
2184 }
2185 else
2186 {
2187 time = char_O_deco_time[31-i];
2188 if( time == 0 ) continue; // not yet: still searh table.
2189
2190 ascent = depth = char_O_deco_depth[31-i];
2191 if( i < 31 )
2192 ascent -= char_O_deco_depth[30-i];
2193 }
2194
2171 // Gas switch depth ? 2195 // Gas switch depth ?
2172 for(gas=j=0; j<5; ++j) 2196 for(gas=j=0; j<5; ++j)
2173 { 2197 {
2174 if( char_O_deco_depth[i] <= char_I_deco_gas_change[j] ) 2198 if( depth <= char_I_deco_gas_change[j] )
2175 if( (gas == 0) || (char_I_deco_gas_change[gas] > char_I_deco_gas_change[j]) ) 2199 if( (gas == 0) || (char_I_deco_gas_change[gas] > char_I_deco_gas_change[j]) )
2176 gas = j; 2200 gas = j;
2177 } 2201 }
2178 2202
2179 // usage during stop: 2203 // usage during stop:
2180 // Note: because first gas is not in there, increment gas+1 2204 // Note: because first gas is not in there, increment gas+1
2181 volumes[gas] += (char_O_deco_depth[i]*0.1 + 1.0)// Use Psurface = 1.0 bar. 2205 volumes[gas] += (depth*0.1 + 1.0) // depth --> bar.
2182 * char_O_deco_time[i] // in minutes. 2206 * time // in minutes.
2183 * ascent_usage 2207 * ascent_usage // in xxx / min @ 1bar.
2184 // Plus usage during ascent to the next stop, at 10m/min. 2208 // Plus usage during ascent to the next stop, at 10m/min.
2185 + (char_O_deco_depth[i]*0.1 + 1.0) 2209 + (depth*0.1 + 1.0)
2186 * (char_O_deco_depth[i] - char_O_deco_depth[i+1]) * 0.1 2210 * ascent*0.1 // meter --> min
2187 * ascent_usage; 2211 * ascent_usage;
2188 } 2212 }
2189 2213
2190 //---- convert results for the ASM interface ----------------------------- 2214 //---- convert results for the ASM interface -----------------------------
2191 for(i=0; i<5; ++i) 2215 for(i=0; i<5; ++i)