/// <summary> /// Constructor /// </summary> /// <param name="efsSystem"></param> public Targets(EfsSystem efsSystem) : base(efsSystem, "TARGETS") { SpeedRestrictions = (Parameter)acceptor.getFactory().createParameter(); SpeedRestrictions.Name = "SpeedRestrictions"; SpeedRestrictions.Type = EFSSystem.AnyType; SpeedRestrictions.setFather(this); FormalParameters.Add(SpeedRestrictions); }
/// <summary> /// Constructor /// </summary> /// <param name="efsSystem"></param> /// <param name="name">the name of the cast function</param> public DecelerationProfile(EFSSystem efsSystem) : base(efsSystem, "DecelerationProfile") { SpeedRestrictions = (Parameter)Generated.acceptor.getFactory().createParameter(); SpeedRestrictions.Name = "SpeedRestrictions"; SpeedRestrictions.Type = EFSSystem.AnyType; SpeedRestrictions.setFather(this); FormalParameters.Add(SpeedRestrictions); DecelerationFactor = (Parameter)Generated.acceptor.getFactory().createParameter(); DecelerationFactor.Name = "DecelerationFactor"; DecelerationFactor.Type = EFSSystem.AnyType; DecelerationFactor.setFather(this); FormalParameters.Add(DecelerationFactor); }
/// <summary> /// Provides the graph of this function if it has been statically defined /// </summary> /// <param name="context">the context used to create the graph</param> /// <returns></returns> public override Graph createGraph(Interpreter.InterpretationContext context, Parameter parameter) { Graph retVal = null; Graph MRSPGraph = null; Function speedRestriction = context.findOnStack(SpeedRestrictions).Value as Function; if (speedRestriction != null) { Parameter p = (Parameter)speedRestriction.FormalParameters[0]; int token = context.LocalScope.PushContext(); context.LocalScope.setGraphParameter(p); MRSPGraph = createGraphForValue(context, context.findOnStack(SpeedRestrictions).Value, p); context.LocalScope.PopContext(token); } if (MRSPGraph != null) { Function deceleratorFactor = context.findOnStack(DecelerationFactor).Value as Function; if (deceleratorFactor != null) { Surface DecelerationSurface = deceleratorFactor.createSurface(context); if (DecelerationSurface != null) { FlatSpeedDistanceCurve MRSPCurve = MRSPGraph.FlatSpeedDistanceCurve(MRSPGraph.ExpectedEndX()); AccelerationSpeedDistanceSurface accelerationSurface = DecelerationSurface.createAccelerationSpeedDistanceSurface(double.MaxValue, double.MaxValue); QuadraticSpeedDistanceCurve BrakingCurve = null; try { BrakingCurve = EtcsBrakingCurveBuilder.Build_A_Safe_Backward(accelerationSurface, MRSPCurve); } catch (System.Exception e) { retVal = new Graph(); retVal.addSegment(new Graph.Segment(0, double.MaxValue, new Graph.Segment.Curve(0, 0, 0))); } if (BrakingCurve != null) { retVal = new Graph(); // TODO : Remove the distinction between linear curves and quadratic curves bool isLinear = true; for (int i = 0; i < BrakingCurve.SegmentCount; i++) { QuadraticCurveSegment segment = BrakingCurve[i]; if (segment.A.ToUnits() != 0.0 || segment.V0.ToUnits() != 0.0) { isLinear = false; break; } } for (int i = 0; i < BrakingCurve.SegmentCount; i++) { QuadraticCurveSegment segment = BrakingCurve[i]; Graph.Segment newSegment; if (isLinear) { newSegment = new Graph.Segment( segment.X.X0.ToUnits(), segment.X.X1.ToUnits(), new Graph.Segment.Curve(0.0, segment.V0.ToSubUnits(SiSpeed_SubUnits.KiloMeter_per_Hour), 0.0)); } else { newSegment = new Graph.Segment( segment.X.X0.ToUnits(), segment.X.X1.ToUnits(), new Graph.Segment.Curve( segment.A.ToSubUnits(SiAcceleration_SubUnits.Meter_per_SecondSquare), segment.V0.ToSubUnits(SiSpeed_SubUnits.KiloMeter_per_Hour), segment.D0.ToSubUnits(SiDistance_SubUnits.Meter) ) ); } retVal.addSegment(newSegment); } } } else { Log.Error("Cannot create surface for " + DecelerationFactor.ToString()); } } else { Log.Error("Cannot evaluate " + DecelerationFactor.ToString() + " as a function"); } } else { Log.Error("Cannot create graph for " + SpeedRestrictions.ToString()); } return(retVal); }