From 17be3653ae67defad72b4afea012737f2e2fc8b8 Mon Sep 17 00:00:00 2001 From: Arndt Brenschede Date: Sun, 25 Nov 2018 20:11:50 +0100 Subject: [PATCH] bike ETA: more ele-filter, energy-correction --- .../java/btools/router/RoutingContext.java | 22 ++++++------- .../src/main/java/btools/router/StdPath.java | 33 +++++++++++++++---- 2 files changed, 37 insertions(+), 18 deletions(-) diff --git a/brouter-core/src/main/java/btools/router/RoutingContext.java b/brouter-core/src/main/java/btools/router/RoutingContext.java index 7489425..8db475f 100644 --- a/brouter-core/src/main/java/btools/router/RoutingContext.java +++ b/brouter-core/src/main/java/btools/router/RoutingContext.java @@ -174,18 +174,16 @@ public final class RoutingContext turnInstructionRoundabouts = expctxGlobal.getVariableValue( "turnInstructionRoundabouts", 1.f ) != 0.f; // Speed computation model (for bikes) - if (bikeMode) { - // Mass of the biker + bike + luggages, in kg - bikeMass = expctxGlobal.getVariableValue( "bikeMass", 90.f ); - // Max speed (before braking), in km/h in profile and m/s in code - maxSpeed = expctxGlobal.getVariableValue( "maxSpeed", 45.f ) / 3.6; - // Equivalent surface for wind, S * C_x, F = -1/2 * S * C_x * v^2 = - S_C_x * v^2 - S_C_x = expctxGlobal.getVariableValue( "S_C_x", 0.5f * 0.45f ); - // Default resistance of the road, F = - m * g * C_r (for good quality road) - defaultC_r = expctxGlobal.getVariableValue( "C_r", 0.01f ); - // Constant power of the biker (in W) - bikerPower = expctxGlobal.getVariableValue( "bikerPower", 100.f ); - } + // Mass of the biker + bike + luggages, in kg + bikeMass = expctxGlobal.getVariableValue( "bikeMass", 90.f ); + // Max speed (before braking), in km/h in profile and m/s in code + maxSpeed = expctxGlobal.getVariableValue( "maxSpeed", 45.f ) / 3.6; + // Equivalent surface for wind, S * C_x, F = -1/2 * S * C_x * v^2 = - S_C_x * v^2 + S_C_x = expctxGlobal.getVariableValue( "S_C_x", 0.5f * 0.45f ); + // Default resistance of the road, F = - m * g * C_r (for good quality road) + defaultC_r = expctxGlobal.getVariableValue( "C_r", 0.01f ); + // Constant power of the biker (in W) + bikerPower = expctxGlobal.getVariableValue( "bikerPower", 100.f ); } public List nogopoints = null; diff --git a/brouter-core/src/main/java/btools/router/StdPath.java b/brouter-core/src/main/java/btools/router/StdPath.java index d0e607e..a89a349 100644 --- a/brouter-core/src/main/java/btools/router/StdPath.java +++ b/brouter-core/src/main/java/btools/router/StdPath.java @@ -606,6 +606,29 @@ final class StdPath extends OsmPath return cost > c; } + private double calcIncline( double dist ) + { + double min_delta = 3.; + double shift; + if ( elevation_buffer > min_delta ) + { + shift = -min_delta; + } + else if ( elevation_buffer < min_delta ) + { + shift = -min_delta; + } + else + { + return 0.; + } + double decayFactor = exp( - dist / 100. ); + float new_elevation_buffer = (float)( (elevation_buffer+shift) * decayFactor - shift); + double incline = ( elevation_buffer - new_elevation_buffer ) / dist; + elevation_buffer = new_elevation_buffer; + return incline; + } + @Override protected void computeKinematic( RoutingContext rc, double dist, double delta_h, boolean detailMode ) { @@ -615,13 +638,11 @@ final class StdPath extends OsmPath } // compute incline - double decayFactor = exp( - dist / 100. ); elevation_buffer += delta_h; - float new_elevation_buffer = (float)( elevation_buffer * decayFactor ); - double incline = ( elevation_buffer - new_elevation_buffer ) / dist; - elevation_buffer = new_elevation_buffer; + double incline = calcIncline( dist ); double speed; // Travel speed + double f_roll = rc.bikeMass * GRAVITY * ( rc.defaultC_r + incline ); if (rc.footMode ) { // Use Tobler's hiking function for walking sections @@ -629,7 +650,7 @@ final class StdPath extends OsmPath } else if (rc.bikeMode) { - speed = solveCubic( rc.S_C_x, rc.bikeMass * GRAVITY * ( rc.defaultC_r + incline ), rc.bikerPower ); + speed = solveCubic( f_air, f_roll, rc.bikerPower ); speed = Math.min(speed, rc.maxSpeed); } else @@ -638,7 +659,7 @@ final class StdPath extends OsmPath } float dt = (float) ( dist / speed ); totalTime += dt; - totalEnergy += dt*rc.bikerPower; + totalEnergy += dist*(rc.S_C_x*speed*speed + f_roll); } private static double solveCubic( double a, double c, double d )