Break out of infinite loops when calculating required speed, add waypoints to gpx that show when you have to start accelerating
This commit is contained in:
+15
-3
@@ -473,6 +473,11 @@ float calculateRequiredSpeed(float endSpeed, float horizontalDistance, float hei
|
||||
float numerator = 0;
|
||||
float denominator = 0.5;
|
||||
float foundEndSpeed = -100.0;
|
||||
int loopCounter = 0;
|
||||
|
||||
float closestFoundSpeed = 1e99;
|
||||
float bestNumerator = 1;
|
||||
float bestDenominator = 1;
|
||||
do {
|
||||
numerator *= 2;
|
||||
denominator *= 2;
|
||||
@@ -482,9 +487,16 @@ float calculateRequiredSpeed(float endSpeed, float horizontalDistance, float hei
|
||||
numerator += 1;
|
||||
}
|
||||
foundEndSpeed = calculate_speed(maximumSpeed * numerator / denominator, horizontalDistance, heightDifference, 0.01, 100.0, dragCoefficient);
|
||||
} while (fabs(foundEndSpeed - endSpeed) > 0.013);
|
||||
loopCounter++;
|
||||
|
||||
float requiredSpeed = maximumSpeed * numerator / denominator;
|
||||
if (fabs(foundEndSpeed - endSpeed) < closestFoundSpeed) {
|
||||
closestFoundSpeed = foundEndSpeed;
|
||||
bestNumerator = numerator;
|
||||
bestDenominator = denominator;
|
||||
}
|
||||
} while (fabs(foundEndSpeed - endSpeed) > 0.013 && loopCounter < 32);
|
||||
|
||||
float requiredSpeed = maximumSpeed * bestNumerator / bestDenominator;
|
||||
|
||||
return requiredSpeed;
|
||||
}
|
||||
@@ -546,7 +558,7 @@ std::vector<JSNodeInfo> getPathJS(uint32_t startingNode, uint32_t endNode, float
|
||||
Connection neighbour = neighbours[i];
|
||||
if (neighbour.connected_point_number == nextNodeId) {
|
||||
float horizontalDistance = neighbour.distance;
|
||||
currentRequiredSpeed = calculateRequiredSpeed(currentRequiredSpeed, horizontalDistance, heightDifference, dragCoefficient);
|
||||
currentRequiredSpeed = fmax(calculateRequiredSpeed(currentRequiredSpeed, horizontalDistance, heightDifference, dragCoefficient), minimumSpeed);
|
||||
it->requiredSpeed = currentRequiredSpeed;
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user