Skip to content

Commit

Permalink
fixup! core: in LoA case, add maintain curve to indication curve befo…
Browse files Browse the repository at this point in the history
…re finding intersection with overlay envelope
  • Loading branch information
Erashin committed Jan 28, 2025
1 parent 7488983 commit dc70820
Showing 1 changed file with 18 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import fr.sncf.osrd.envelope_sim.*
import fr.sncf.osrd.envelope_sim.overlays.EnvelopeDeceleration
import kotlin.math.max
import kotlin.math.min
import org.slf4j.Logger
import org.slf4j.LoggerFactory

/**
* Formulas are found in `SUBSET-026-3v400.pdf` from the file at
Expand All @@ -35,6 +37,8 @@ enum class BrakingType {
ETCS_GUI
}

val etcsBrakingCurvesLogger: Logger = LoggerFactory.getLogger("EtcsBrakingCurves")

/** Compute braking curves at every end of authority. */
fun addBrakingCurvesAtEOAs(
envelope: Envelope,
Expand Down Expand Up @@ -86,6 +90,7 @@ fun addBrakingCurvesAtEOAs(

val indicationCurve =
keepBrakingCurveUnderOverlay(Envelope.make(fullIndicationCurve), envelope, beginPos)
?: continue
assert(indicationCurve.beginPos >= beginPos && indicationCurve.endPos == targetPosition)
assert(
indicationCurve.beginSpeed <= maxSpeedEnvelope &&
Expand Down Expand Up @@ -181,7 +186,7 @@ fun addBrakingCurvesAtLOAs(
fullIndCurveWithMaintain,
envelopeWithLoaBrakingCurves,
beginPos
)
) ?: continue
assert(indicationCurve.beginPos >= beginPos && indicationCurve.endPos == targetPosition)
assert(
indicationCurve.beginSpeed <= maxSpeedEnvelope &&
Expand Down Expand Up @@ -341,35 +346,38 @@ private fun computeIndicationBrakingCurveFromRef(

/**
* Keep the part of the full braking curve which is located underneath the overlay and intersects
* with it or with begin position. The curve should always intersect, throw otherwise.
* with it or with begin position. If the part has no intersection, return null.
*/
private fun keepBrakingCurveUnderOverlay(
fullBrakingCurve: Envelope,
overlay: Envelope,
beginPos: Double
): EnvelopePart {
if (fullBrakingCurve.endPos <= beginPos)
throw IllegalArgumentException(
"Expected fullBrakingCurve position range to intersect with [beginPos, +infinity[."
): EnvelopePart? {
if (fullBrakingCurve.endPos <= beginPos) {
etcsBrakingCurvesLogger.warn(
"The ETCS braking curve ending at ($beginPos, ${fullBrakingCurve.endSpeed}) does not intersect with the overlay envelope."
)
return null
}

// Remove duplicate point part transitions: the last point of the previous array is the first
// point of the next array. Otherwise, we would be adding two following identical points with
// addStep, and this would throw an exception.
val positions =
fullBrakingCurve
.map { it.clonePositions() }
.reduce { mergedArray, currentArray ->
// Remove duplicate part transitions: the last point of the previous array is the
// first point of the next array.
mergedArray + currentArray.drop(1).toDoubleArray()
}
val speeds =
fullBrakingCurve
.map { it.cloneSpeeds() }
.reduce { mergedArray, currentArray ->
// Remove duplicate part transitions: the last point of the previous array is the
// first point of the next array.
mergedArray + currentArray.drop(1).toDoubleArray()
}
val timeDeltas = fullBrakingCurve.flatMap { it.cloneTimes().asList() }
val nbPoints = positions.size

val partBuilder = EnvelopePartBuilder()
partBuilder.setAttr(EnvelopeProfile.BRAKING)
val overlayBuilder =
Expand All @@ -382,8 +390,6 @@ private fun keepBrakingCurveUnderOverlay(
for (i in nbPoints - 2 downTo 0) {
if (!overlayBuilder.addStep(positions[i], speeds[i], timeDeltas[i])) break
}
if (partBuilder.stepCount() <= 1)
throw IllegalArgumentException("Intersecting envelope only has one point.")
return partBuilder.build()
}

Expand Down

0 comments on commit dc70820

Please sign in to comment.