aboutsummaryrefslogtreecommitdiffstats
path: root/planner.c
AgeCommit message (Collapse)Author
2013-01-13Correctly show the planned dive in the divelistGravatar Dirk Hohndel
Previously we would simply show the first dive in the divelist - which worked fine in the default sort by trip setting and assuming that there are no dives from the future in the divelist. With this commit we actually find the correct dive in the divelist and select it instead. If you sort by depth you will see the dive move around in the divelist, but it will stay selected and visible in the profile. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-10Split up preference data structure definition into 'pref.h'Gravatar Linus Torvalds
.. and rename the badly named 'output_units/input_units' variables. We used to have this confusing thing where we had two different units (input vs output) that *look* like they are mirror images, but in fact "output_units" was the user units, and "input_units" are the XML parsing units. So this renames them to be clearer. "output_units" is now just "units" (it's the units a user would ever see), and "input_units" is now "xml_parsing_units" and set by the XML file parsers to reflect the units of the parsed file. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-09Clean up duplicated depth interpolationGravatar Linus Torvalds
We have several places where we interpolate the depth based on two samples and the time between them. Some of them use floating point, some of them don't, some of them meant to do it but didn't. Just use a common helper function for it. I seriously doubt the floating point here really matters, since doing it in integers is not going to overflow unless we're interpolating between two samples that are hours apart at hundreds of meters of depth, but hey, it gives that rounding to the nearest millimeter. Which I'm sure matters. Anyway, we can probably just get rid of the rounding and the floating point math, but it won't really hurt either, so at least do it consistently. The interpolation could be for other things than just depth, but we probably don't have anything else we'd want to interpolate. But make the function naming generic just in case. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-09Add support to planner to use additional gases during the ascentGravatar Dirk Hohndel
This change ended up being quite a bit bigger than expected as it uncovered a number of bugs in the existing code. The planner now handles gas changes correctly by creating (and later parsing) events in the simulated divecomputer. At the end of the dive specified in the input form the algorithm starts with the deepest interesting depth: either the first stop below our ceiling or the deepest depth at which we can change gases. It then traverses all the stop and all the gas change depth and at each stage ensures that we are allowed to ascend further before going on. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-08Allow special entries in diveplan for available gasesGravatar Dirk Hohndel
An entry with no time is considered special and not considered when constructing the profile. This should allow us to add support for two different ways of adding information about available gas: changedepth 0 gasmix 0 0 gasmix @ po2 The first syntax basically says "during the ascent, switch to this gas at this depth. The second one says "switch to this gas once the pO2 allows for it" Neither of these are implemented, yet, but this commit is necessary in order for the rest of the code to ignore entries with a time field of 0. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-08Set a default surface pressure for dive plan and allow simplistic printGravatar Dirk Hohndel
This commit makes sure we have a reasonable default surface pressure (we need an input field for that). It also adjusts the debug level settings so that compiling this with make CLCFLAGS=-DDEBUG_PLAN=3 will print out an almost usable dive plan. This is of course still lacking air consumption calculations and will show deco stops that we just transit through (if the ceiling lifts far enough during the transition to an intended stop that this stop can be skipped; this sometimes happens for the first stop (haven't seen it for a later one). But it's better than nothing, I guess. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-08Do planned deco stops in multiples of 1 minuteGravatar Dirk Hohndel
We may want to make this configurable, but I haven't seen any software that doesn't do deco stops in full minutes. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-08Fix the deco calculation in the dive plannerGravatar Dirk Hohndel
The existing code incorrectly started all calculation at the depth at the end of the first segment. So if you went to 50m in 5min in your first segment, you incorrectly got 5 minutes at 50m (instead of a progression from 0 to 50m, over 5 minutes). This commit fixes that and now gives us planned dives that then match what is shown in the profile. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-08Improve travel logic code for the ascent in the plannerGravatar Dirk Hohndel
This shouldn't change the the actual stops we do or the travel time how we get there, but it makes the code more logical. From the end depth of the planned dive we have ONE transition to the first stop depth (which may be the surface). And then for every stop we (potentially) have a wait and travel to the next stop. Once we are in the while loop, we know that we are at a stop level, so there is no point to keep checking if we first need to transition to the stop. It does create one additional improvement: if we don't need any stops at all, then we don't transition to the first stop and then from there to the surface. We do it in one step. The overall profile / traveltime remains the same, we just drop one intermediate sample on the way. This also improves a few ugly (and in one case, wrong) debug statements. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-08Really prevent time travel in planner dive editGravatar Dirk Hohndel
Commit c92e4535a6de "Prevent time travel in planner dive edit" almost got it right but had a stupid think-o. This commit should fix it the right way. If the duration that is passed in is before the previous timestamp, then this is most likely intended to be a relative time. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-08Fix deco planning for low oxygen mixesGravatar Jan Schubert
Not sure about the future of the current planner.c as we have new approaches now but as this annoyed me for some days now I just decided to come up with this trivial stuff to make my life easier. More a cosmetic fix than a patch, but actually it fixes a bug one might face planing a dive using low oxygen mixes and where stop levels at just 90m, 60m, 30m and nothing in between will not allow subsurface to finish a deco ceiling which ends before the universe collapses. Allows to plan 20min@130m using a 10/70 now (f.i.). Signed-off-by: Jan Schubert / Jan.Schubert@GMX.li Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-08Rewrite of the deco codeGravatar Robert C. Helling
o) Instead of using gradient factors as means of comparison, I now use pressure (as in: maximal ambient pressure). o) tissue_tolerance_calc() now computes the maximal ambient pressure now respecting gradient factors. For this, it needs to know about the surface pressure (as refernce for GF_high), thus gets *dive as an argument. It is called from add_segment() which this also needs *dive as an additional argument. o) This implies deco_allowed_depth is now mainly a ambient-pressure to depth conversion with decorations to avoid negative depth (i.e. no deco obliation), implementation of quantization (!smooth => multiples of 3m) and explicit setting of last deco depth (e.g. 6m for O2 deco). o) gf_low_pressure_this_dive (slight change of name), the max depth in pressure units is updated in add_segment. I set the minimal value in buehlmann_config to the equivalent of 20m as otherwise good values of GF_low add a lot of deco to shallow dives which do not need deep stops in the first place. o) The bogus loop is gone as well as actual_gradient_limit() and gradient_factor_calculation() and large parts of deco_allowed_depth() although I did not delete the code but put it in comments. o) The meat is in the formula in lines 147-154 of deco.c. Here is the rationale: Without gradient factors, the M-value (i.e the maximal tissue pressure) at a given depth is given by ambient_pressure / buehlmann_b + a. According to "Clearing Up The Confusion About "Deep Stops" by Erik C. Baker (as found via google) the effect of the gradient factors is no replace this by a reduced affine relation (i.e. another line) such that at the surface the difference between M-value and ambient pressure is reduced by a factor GF_high and at the maximal depth by a factor GF_low. That is, we are looking for parameters alpha and beta such that alpha surface + beta = surface + gf_high * (surface/b + a - surface) and alpha max_p + beta = max_p + gf_low * (max_p/b + a - max_p) This can be solved for alpha and beta and then inverted to obtain the max ambient pressure given tissue loadings. The result is the above mentioned formula. Signed-off-by: Robert C. Helling <helling@atdotde.de> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-08Fix gas handling in the plannerGravatar Dirk Hohndel
The dive will start with gas 0. If things change during the planned part of the dive, this will be represented by an event. Use the last gas for the ascent. Obviously this still doesn't handle deco gases, but at least we now no longer switch back to the first gas after the planned part of the dive. This also adds quite a bit of debugging code to be able to trace what's happening in the planner. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-08Avoid pointless calls to dive plannerGravatar Dirk Hohndel
Stupid Gtk. Seriously. So in order to get a notification if the user selects the drop down for the gas with the mouse I need to connect to the "changed" signal for the combobox. But that also fires whenever the user types something into the GtkEntry. Which means we once again get called for all kinds of silly partial names. Instead we want to handle the manual entry in the "focus-out" callback (the user has hit tab or something else to move away from the GtkEntry - let's assume that this is the text he wants us to use) and only respond to the changed signal on the combobox if the user selected something from the dropdown. The easiest way to do that (I think) is to check the text with the strings stored in the model. If this indeed matches a string stored in the model then most likely this is something the user selected from the dropdown. But more importantly if it isn't in the model, then we KNOW that this is just a partial string that was typed in. And we can ignore that one. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-07Prevent time travel in planner dive editGravatar Dirk Hohndel
If the user enters an absolute time that is before the previous waypoint, silently assume that this is a relative time. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-07Make Cancel work in dive planner dialogGravatar Dirk Hohndel
With this a partially planned dive is indeed thrown away when hitting Cancel. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-07Simplify dive planning codeGravatar Linus Torvalds
This simplifies the dive planning code by: - allowing empty gas mixes (which means "pick previous gas") - avoiding unnecessary strdup/free calls (this requires us to handle "const char *" in the parsers, but that was already true from a code standpoint, just not a type one) - re-use the "plan()" function for a successful dive plan, rather than open-coding the dive plan segment handling. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-07Fix two bugs with the gas entry code in the dive plannerGravatar Dirk Hohndel
First, I forgot to pass in the idx into the gas callback function - this way for the dynamically created dives we always used air for anything but the first segment. Second, when selecting a gas from the drop down (with the mouse or by typing), the GtkEntry doesn't receive that text and therfore we never picked up those gases. We now also track the 'changed' event for the GtkComboBox, but never add the text we get their to the completions (as by definition they are already there). Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-07Add simple debug function to plannerGravatar Dirk Hohndel
This allows you to dump the diveplan structure Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-07Move planner UI into planner.cGravatar Dirk Hohndel
There should be NO other changes in this commit - just moving the code and adjusting the includes (and adding the entry point to display-gtk.h). Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-07Remove the now obsolete hard coded test_planGravatar Dirk Hohndel
This was just a crutch to get something out there for people to play with. With the ability to input a plan in place this is now obsolete. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-07Dive planner: add gas change events & start dive with the correct gasGravatar Dirk Hohndel
When incrementally building dives with gas changes there are still some serious issues and inconsistencies. But at least now the gases in the dive we create appear to be correct. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-07Support relative times in diveplanner input "on the fly" modeGravatar Dirk Hohndel
This had gotten lost when updating the profile on the fly. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-06Display dive profile of the dive we plan, as we plan itGravatar Dirk Hohndel
As the user enters data into the entry fields, that data is validated and as soon as there is enough data we start constructing a dive profile, including the final ascent to the surface, including required deco stops, etc. This commit still has some serious issues. - when data is input that doesn't validate, we just print a warning to stdout - instead we need to change the backgroundcolor of the input field or something. - when we switch to the last dive in order to show the profile we don't actually search for the last dive - we just show the first one in the tree. This works for the default sort order but is of course wrong otherwise I'm sure there are many other bugs, but I want to push it out where it is right now for others to be able to take a look. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-06Add the ability to cache our deco stateGravatar Dirk Hohndel
We kept reduing all the deco calculations, including the previous dives (if any) for each segment we add to the dive plan. This simply remembers the last stage and then just adds to that. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-05Do a minimal hook-up of the dive plan tree view to theGravatar Linus Torvalds
actual planning Yes, you can actually enter your segments now. No, it's not wonderfully user-friendly. If you don't enter enough segments to create a dive plan, it will just silently fail, for example. And the <tab> key that should get you to the next editable segment doesn't. And so on. But it kind of works. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-04First stab at simplistic dive planningGravatar Dirk Hohndel
This comes with absolutely no gui - so the plan literally needs to be compiled into Subsurface. Not exactly a feature, but this allowed me to focus on the planning part instead of spending time on tedious UI work. A new menu "Planner" with entry "Test Planner" calls into the hard-coded function in planner.c. There a simple dive plan can be constructed with calls to plan_add_segment(&diveplan, duration, depth at the end, fO2, pO2) Calling plan(&diveplan) does the deco calculations and creates deco stops that keep us below the ceiling (with the GFlow/high values currently configured). The stop levels used are defined at the top of planner.c in the stoplevels array - there is no need to do the traditional multiples of 3m or anything like that. The dive including the ascents and deco stops all the way to the surface is completed and then added as simulated dive to the end of the divelist (I guess we could automatically select it later) and can be viewed. This is crude but shows the direction we can go with this. Envision a nice UI that allows you to simply enter the segments and pick the desired stops. What is missing is the ability to give the algorithm additional gases that it can use during the deco phase - right now it simply keeps using the last gas used in the diveplan. All that said, there are clear bugs here - and sadly they seem to be in the deco calculations, as with the example given the ceiling that is calculated makes no sense. When displayed in smooth mode it has very strange jumps up and down that I wouldn't expect. For example with GF 35/75 (the default) the deco ceiling when looking at the simulated dive jumps from 16m back up to 13m around 14:10 into the dive. That seems very odd. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>