Commit graph

174 commits

Author SHA1 Message Date
Dirk Hohndel
c0ce218df4 Add support to planner to use additional gases during the ascent
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-09 16:01:15 -08:00
Dirk Hohndel
fbea5e31ca Allow special entries in diveplan for available gases
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-08 15:03:37 -08:00
Dirk Hohndel
e903fa966e Set a default surface pressure for dive plan and allow simplistic print
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-08 14:05:25 -08:00
Dirk Hohndel
2ffeff9a2c Do planned deco stops in multiples of 1 minute
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-08 13:59:48 -08:00
Dirk Hohndel
1bec821c73 Fix the deco calculation in the dive planner
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-08 13:54:29 -08:00
Dirk Hohndel
bad7882ae1 Improve travel logic code for the ascent in the planner
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-08 13:53:57 -08:00
Dirk Hohndel
8eb92c576c Really prevent time travel in planner dive edit
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-08 13:43:25 -08:00
Jan Schubert
d864f5cdfa Fix deco planning for low oxygen mixes
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-08 12:04:59 -08:00
Robert C. Helling
67d59ff018 Rewrite of the deco code
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-08 08:59:20 -08:00
Dirk Hohndel
e3bdbb7c0f Fix gas handling in the planner
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-08 08:52:48 -08:00
Dirk Hohndel
bf395ebf45 Avoid pointless calls to dive planner
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-08 08:48:13 -08:00
Dirk Hohndel
7a18edddbb Prevent time travel in planner dive edit
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-07 16:22:38 -08:00
Dirk Hohndel
ae3886b987 Make Cancel work in dive planner dialog
With this a partially planned dive is indeed thrown away when hitting
Cancel.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-07 14:52:31 -08:00
Linus Torvalds
ab7aecf16e Simplify dive planning code
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-07 14:10:44 -08:00
Dirk Hohndel
e6afd055d8 Fix two bugs with the gas entry code in the dive planner
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-07 12:53:54 -08:00
Dirk Hohndel
d396f4afd8 Add simple debug function to planner
This allows you to dump the diveplan structure

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-07 12:49:07 -08:00
Dirk Hohndel
d3570508b1 Move planner UI into planner.c
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-07 11:23:14 -08:00
Dirk Hohndel
989cf37fcf Remove the now obsolete hard coded test_plan
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-07 08:51:26 -08:00
Dirk Hohndel
1b0ddfbbe2 Dive planner: add gas change events & start dive with the correct gas
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-07 08:38:55 -08:00
Dirk Hohndel
85ed689dc0 Support relative times in diveplanner input "on the fly" mode
This had gotten lost when updating the profile on the fly.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-01-07 08:13:23 -08:00
Dirk Hohndel
be9be189f7 Display dive profile of the dive we plan, as we plan it
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-06 22:15:03 -08:00
Dirk Hohndel
c8830ffe48 Add the ability to cache our deco state
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-06 11:40:21 -08:00
Linus Torvalds
92a8fde9c2 Do a minimal hook-up of the dive plan tree view to the
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-05 15:51:57 -08:00
Dirk Hohndel
cca847791a First stab at simplistic dive planning
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>
2013-01-04 23:56:55 -08:00