/// <summary> /// Algorithm to calculate the safe breaking distance /// for a single piece of track /// </summary> /// <param name="brakeLocation"></param> /// <param name="targetLocation"></param> /// <param name="gradeWorst"></param> /// <param name="speedMax"></param> /// <param name="overspeed"></param> /// <param name="vehicleAccel"></param> /// <param name="reactionTime"></param> /// <param name="brakeRate"></param> /// <param name="runwayAccelSec"></param> /// <param name="propulsionRemSec"></param> /// <param name="brakeBuildUpSec"></param> /// <param name="overhangDist"></param> /// <param name="safetyFact"></param> /// <returns></returns> public static double SafeBrakingDistanceCalculations(TrackSegment obj) { double availStopDist = Math.Abs(obj.TargetLocation - obj.brakeLocation); //Console.WriteLine(availStopDist); double overspeedTotal = obj.OverSpeed + obj.SpeedMax; //Console.WriteLine(overspeedTotal); double velocityFinal = (obj.VehicleAccel * 1.2) + overspeedTotal; //Console.WriteLine(velocityFinal); double reactionDist = obj.ReactionTime * overspeedTotal * 1.467; //Console.WriteLine(reactionDist); double negGradeAdjBrakeDist = 0.733 * velocityFinal * velocityFinal / (obj.BrakeRate + (0.219 * obj.GradeWorst)); //Console.WriteLine(negGradeAdjBrakeDist); double posGradeAdjBrakeDist = 0.733 * velocityFinal * velocityFinal / (obj.BrakeRate - (0.219 * obj.GradeWorst)); //Console.WriteLine(posGradeAdjBrakeDist); double runwayAccelFt = 1.467 * (0.5 * obj.VehicleAccel * obj.RunwayAccelSec + overspeedTotal) * obj.RunwayAccelSec; //Console.WriteLine(runwayAccelFt); double propulsionRemFt = velocityFinal * 1.467 * obj.PropulsionRemSec; //Console.WriteLine(propulsionRemFt); double brakeBuildUpFt = velocityFinal * 1.467 * obj.BrakeBuildUpSec; //Console.WriteLine(brakeBuildUpFt); double SBD = Math.Round(reactionDist + runwayAccelFt + propulsionRemFt + brakeBuildUpFt + negGradeAdjBrakeDist + obj.OverhangDist, 1); bool isSafe = SBD < availStopDist; if (!isSafe) { obj.IsSafe = false; } else { obj.IsSafe = true; } obj.SafeBreakingDistanceRequired = availStopDist; return SBD; }
public static void removeFromDatabase(DatabaseConnection conn, Query q, TrackSegment obj) { MySqlCommand cmd = new MySqlCommand(); cmd.CommandText = @"Delete from track_segments (trackCircuit, brakeLocation, targetLocation, worst_case_grade_during_stop, max_entry_speed, overSpeed, vehicleAccel, reactionTime, brakeRate, runwayAccel, propulsion, build_up_brake, overhang) VALUES (@trackCircuit, @brakeLocation, @targetLocation, @worst_case_grade_during_stop, @max_entry_speed, @overSpeed, @vehicleAccel, @reactionTime, @brakeRate, @runwayAccel, @propulsion, @build_up_brake, @overhang)"; cmd.Parameters.AddWithValue("@trackCircuit", obj.TrackCircuit); cmd.Parameters.AddWithValue("@brakeLocation", obj.StartPoint); cmd.Parameters.AddWithValue("@targetLocation", obj.EndPoint); cmd.Parameters.AddWithValue("@worst_case_grade_during_stop", obj.GradeWorst); cmd.Parameters.AddWithValue("@max_entry_speed", obj.SpeedMax); cmd.Parameters.AddWithValue("@overSpeed", obj.OverSpeed); cmd.Parameters.AddWithValue("@vehicleAccel", obj.VehicleAccel); cmd.Parameters.AddWithValue("@reactionTime", obj.ReactionTime); cmd.Parameters.AddWithValue("@brakeRate", obj.BrakeRate); cmd.Parameters.AddWithValue("@runwayAccel", obj.RunwayAccelSec); cmd.Parameters.AddWithValue("@propulsion", obj.PropulsionRemSec); cmd.Parameters.AddWithValue("@build_up_brake", obj.BrakeBuildUpSec); cmd.Parameters.AddWithValue("@overhang", obj.OverhangDist); cmd.Connection = conn.getConnection(); cmd.ExecuteNonQuery(); }
/// <summary> /// Draws the track segment to the screen /// </summary> /// <param name="segment">The track segment to draw</param> /// <param name="i">The Y off set for the track segment</param> private void DrawTrackSegment(TrackSegment segment, int i) { if (!segment.IsSafe) { GL.Color3(Color.Red); } else { GL.Color3(Color.Blue); } DrawLine(segment.BrakeLocation, i * TRACKOFFSET, segment.TargetLocation, i * TRACKOFFSET); DrawLine(segment.BrakeLocation, i * TRACKOFFSET + ENDTRACKSIZE, segment.BrakeLocation, i * TRACKOFFSET - ENDTRACKSIZE); DrawLine(segment.TargetLocation, i * TRACKOFFSET + ENDTRACKSIZE, segment.TargetLocation, i * TRACKOFFSET - ENDTRACKSIZE); }
/// <summary> /// /// </summary> /// <param name="worksheet"></param> public void FillTrack() { ProgressBoxForm progressBox = new ProgressBoxForm(); progressBox.Show(); try { ExcelSheet sheet = new ExcelSheet(); using (StreamReader file = new StreamReader(mFilename)) { string line = null; string[] row; string tempDir = null; string tempMove = null; // Get to the data while (line == null || line.Split(',')[1] != "Track") { line = file.ReadLine(); } // Parse the data while ((line = file.ReadLine()) != null) { row = line.Split(','); // If this cell does not have data then there is no more data. if (row[4] == "") { break; } if (row[2] != "") { tempDir = row[2]; } if(row[3] != "") { tempMove = row[3]; } /* * Column Name | Column Number * Direction | 1 * Move | 2 * Track | 3 * Circuit | 4 * Brake Location | 5 * Target Location | 6 * Worst Grade | 8 * Entry Speed | 9 * Overspeed | 10 * Acceleration | 12 * Reaction Time | 14 * Brake Rate | 16 * Runaway Accel | 19 * Propulsion Remov | 21 * Brake Build up | 23 * Overhang Dist | 25 */ TrackSegment curRow = new TrackSegment( tempDir, tempMove, row[4], // Circuit Convert.ToInt32(row[5]), // Brake Location Convert.ToInt32(row[6]), // Target Location Convert.ToDouble(row[7]), // Worst Grade Convert.ToDouble(row[8]), // Entry Speed Convert.ToDouble(row[9]), // Overspeed Convert.ToDouble(row[10]), // Acceleration Convert.ToDouble(row[11]), // Reaction Time Convert.ToDouble(row[12]), // Brake Rate Convert.ToDouble(row[13]), // Runaway Accel Convert.ToDouble(row[14]), // Propulsion Removal Convert.ToInt32(row[15]), // Brake Build Up Convert.ToInt32(row[16])); // Overhand Distance TrackLayout.Track.Add(curRow); progressBox.progressBar1.PerformStep(); } } } catch (Exception e) { MessageBox.Show("Error Loading File: " + e.ToString()); } progressBox.Close(); }
/// <summary> /// /// </summary> public static void LoadFromDatabase() { TrackLayout.Track.Clear(); LoadFromDatabaseForm databaseForm = new LoadFromDatabaseForm(); if (databaseForm.ShowDialog() == System.Windows.Forms.DialogResult.OK) { try { // TODO: Set up the database Database.DatabaseConnection conn = new Database.DatabaseConnection(databaseForm.ServerNameBox.Text, Convert.ToUInt32(databaseForm.PortBox.Text), databaseForm.DatabaseNameBox.Text, databaseForm.UserNameBox.Text, databaseForm.PasswordBox.Text); Query q = new Query(); List<string> list; String p = Prompt.ShowDialog("Enter A Track Circuit\n\n Type 'ALL' to Display Every Track Circuit", "Track Information Needed!"); if (p.Trim().ToUpper() == "ALL") { list = q.runQuery(conn, "SELECT * FROM track_segments"); } else { list = q.runQuery(conn, "SELECT * FROM track_segments where trackCircuit = '" + p.Trim() + "'"); } int numRows = list.Count / 15; TrackSegment ts; for (int i = 0; i < numRows; i++) { var offset = 15*i; bool exists = false; ts = new TrackSegment(list[offset + 0].ToString(), list[offset + 1].ToString(), list[offset + 2].ToString(), Convert.ToInt32(list[offset + 3].ToString()), Convert.ToInt32(list[offset + 4].ToString()), Convert.ToDouble(list[offset + 5].ToString()), Convert.ToDouble(list[offset + 6].ToString()), Convert.ToDouble(list[offset + 7].ToString()), Convert.ToDouble(list[offset + 8].ToString()), Convert.ToDouble(list[offset + 9].ToString()), Convert.ToDouble(list[offset + 10].ToString()), Convert.ToDouble(list[offset + 11].ToString()), Convert.ToDouble(list[offset + 12].ToString()), Convert.ToInt32(list[offset + 13].ToString()), Convert.ToInt32(list[offset + 14].ToString())); foreach(TrackSegment segment in TrackLayout.Track) { if (ts.IsSame(segment)) { exists = true; } } if(!exists) { TrackLayout.Track.Add(ts); } } } catch (Exception ex) { LogManager.Logger.Log(ex); } } }
public bool IsSame(TrackSegment ts) { return (this.BrakeBuildUpSec == ts.BrakeBuildUpSec) && (this.BrakeLocation == ts.BrakeLocation) && (this.BrakeRate == ts.BrakeRate) && (this.Direction == ts.Direction) && (this.GradeWorst == ts.GradeWorst) && (this.Move == ts.Move) && (this.OverhangDist == ts.OverhangDist) && (this.OverSpeed == ts.OverSpeed) && (this.PropulsionRemSec == ts.PropulsionRemSec) && (this.ReactionTime == ts.ReactionTime) && (this.RunwayAccelSec == ts.RunwayAccelSec) && (this.SpeedMax == ts.SpeedMax) && (this.TargetLocation == ts.TargetLocation) && (this.TrackCircuit == ts.TrackCircuit) && (this.VehicleAccel == ts.VehicleAccel); }