# HG changeset patch # User Jan Mulder # Date 1554053751 -7200 # Node ID ceecabfddb57574976e8bb6039f26c6e59f57587 # Parent 5f535ef6a3dbbdf30d75d6a7059953ffc9e49699 Bugfix, deco: fix 2 (small) problems with calculated ceiling This fixes 1 trivial, and 1 not really trivial bug in the calculation of the ceiling. When simulating a bounce dive to 80m, things become clear (tried this on a CCR dive, fixed setpoint 1.2bar, about 15 minutes of bottom time). Closely watch the behavior of the ceiling data. At some point during the ascent, the ceiling begins to decrease in 10cm steps. Then suddenly (while still ascending), the ceiling increases again with 1m, does not change for some time, and then suddenly steps 1.1m less deep. While not very relevant to real deco diving, it is simply wrong. The reason for this is subtle. The algorithm used to find the ceiling is a sort of linear search, stepping down a meter, overshoot the depth, and search back in 10cm steps. It seems some numerical instability. Fixing this, was a bit more computational intensive search by stepping up down in equal steps of 10cm. But, I'm pretty sure that things can be speeded up here, as a ceiling does not change fast, so it should be not that difficult to limit the search space, or use a binary search algorithm instead. The trivial second problem fixed, is that the ceiling ends at the surface and not at 1m depth. This small issue became visible after changing the step down size above. Signed-off-by: Jan Mulder diff -r 5f535ef6a3db -r ceecabfddb57 Discovery/Src/buehlmann.c --- a/Discovery/Src/buehlmann.c Sun Mar 31 15:14:06 2019 +0200 +++ b/Discovery/Src/buehlmann.c Sun Mar 31 19:35:51 2019 +0200 @@ -16,9 +16,6 @@ #include "decom.h" -extern const float helium_time_constant[16]; -extern const float nitrogen_time_constant[16]; - extern const float buehlmann_N2_a[]; extern const float buehlmann_N2_b[]; extern const float buehlmann_He_a[]; @@ -727,18 +724,17 @@ float gf_low; float gf_high; float gf_delta; - int dv_gf_low_stop_meter; + float dv_gf_low_stop_meter; _Bool test_result; float next_gf_value; float next_pressure_absolute; - int depth_in_meter; + float depth_in_meter; gf_low = pDiveSettings->gf_low; gf_high = pDiveSettings->gf_high; - // dv_gf_low_stop_meter = (int)((pDiveSettings->internal__pressure_first_stop_ambient_bar_as_upper_limit_for_gf_low_otherwise_zero - pLifeData->pressure_surface_bar) * 10); - // + if(dv_gf_low_stop_meter < 1) { next_gf_value = gf_high; // fix hw 161024 @@ -748,9 +744,9 @@ { next_gf_value = gf_high; gf_delta = gf_high - gf_low; - gf_delta /= dv_gf_low_stop_meter; // gf_delta is delta for each meter now!! + gf_delta /= (dv_gf_low_stop_meter * 10); // gf_delta is delta for 10 cm !! } - // + depth_in_meter = 0; next_pressure_absolute = pLifeData->pressure_surface_bar; @@ -762,19 +758,18 @@ // while(!test_result && depth_in_meter < 200) { - depth_in_meter += 1; + depth_in_meter += 0.1; next_gf_value = fmaxf(gf_low, next_gf_value - gf_delta); gGF_value = next_gf_value / 100.0f; - next_pressure_absolute += 0.1f; // 1 meter down + next_pressure_absolute += 0.01f; // 0.1 meter down test_result = buehlmann_tissue_test_tolerance(next_pressure_absolute); } - // + if(test_result) { - // old direct paste pDecoInfo->output_ceiling_meter = depth_in_meter; - // new sub-meter hw 160331 - if(depth_in_meter >= 1) + + if(depth_in_meter >= 0) { for(int i = 0; i < 10; i++) {