Exemplo n.º 1
0
        private double[] getDelta(TrackReading tr1, TrackReading tr2)
        {
            //find the change in tyre pressure respective to the change in track temperature
            double[] r         = { 0, 0, 0, 0 };
            double   tempDelta = tr1.trackTemp - tr2.trackTemp;

            r[0] = (tr1.lf - tr2.lf) / tempDelta;
            r[1] = (tr1.rf - tr2.rf) / tempDelta;
            r[2] = (tr1.lr - tr2.lr) / tempDelta;
            r[3] = (tr1.rr - tr2.rr) / tempDelta;
            return(r);
        }
Exemplo n.º 2
0
        private void btnAddReading_Click(object sender, EventArgs e)
        {
            btnSetStrats.Enabled  = true;
            btnAddReading.Enabled = false;
            TrackReading tr = new TrackReading();

            tr.trackTemp = Convert.ToInt32(udTrackTemp.Value);
            tr.lf        = Convert.ToDouble(udLf.Value);
            tr.rf        = Convert.ToDouble(udRf.Value);
            tr.lr        = Convert.ToDouble(udLr.Value);
            tr.rr        = Convert.ToDouble(udRr.Value);

            trackReadings.Add(tr);

            ListReadings();
            generatePressures();
        }
Exemplo n.º 3
0
        private void generatePressures()
        {
            //remove duplicate temps
            int tMin = Convert.ToInt32(nudTmin.Value);
            int tMax = Convert.ToInt32(nudTmax.Value);

            if (trackReadings.Count > 1)
            {
                //create a temporary list, this will become our main list later
                List <TrackReading> templist = new List <TrackReading>();

                //first extrapolate for readings below the lowest entered reading if needed
                if (trackReadings[0].trackTemp != tMin)
                {
                    double[] delta01 = getDelta(trackReadings[0], trackReadings[1]);
                    for (int i = tMin; i < trackReadings[0].trackTemp; i++)
                    {
                        //if we're here then the lowest temp reading entered is > 21
                        //extrapolate from what data we have to populate readings down to 21c
                        int          tyreDelta = trackReadings[0].trackTemp - i;
                        TrackReading tr        = new TrackReading();
                        tr.trackTemp = i;
                        //get the expected pressures based on the rate of pressure change of closest known readings
                        //and the temperature difference from the closest reading
                        //newReading.tyre = reading[0].tyre - (tempdelta * tyreDelta)
                        //minus because we're going down in temp

                        tr.lf = Math.Round(trackReadings[0].lf - (delta01[0] * tyreDelta), 1);
                        tr.rf = Math.Round(trackReadings[0].rf - (delta01[1] * tyreDelta), 1);
                        tr.lr = Math.Round(trackReadings[0].lr - (delta01[2] * tyreDelta), 1);
                        tr.rr = Math.Round(trackReadings[0].rr - (delta01[3] * tyreDelta), 1);
                        templist.Add(tr);
                    }
                }

                //next populate readings within temps provided
                //for each track reading except the last

                for (int i = 0; i < trackReadings.Count - 1; i++)
                {
                    //validate we're not working with the final temps & there is a gap between readings
                    if (trackReadings[i].trackTemp < tMax && (trackReadings[i + 1].trackTemp - trackReadings[i].trackTemp) > 1)
                    {
                        double[] delta = getDelta(trackReadings[i], trackReadings[i + 1]);
                        //create a reading for each degree between existing readings
                        for (int j = 0; j < (trackReadings[i + 1].trackTemp - trackReadings[i].trackTemp - 1); j++)
                        {
                            TrackReading tr = new TrackReading();
                            tr.trackTemp = trackReadings[i].trackTemp + j + 1;
                            tr.lf        = Math.Round(trackReadings[i].lf + (delta[0] * (j + 1)), 1);
                            tr.rf        = Math.Round(trackReadings[i].rf + (delta[1] * (j + 1)), 1);
                            tr.lr        = Math.Round(trackReadings[i].lr + (delta[2] * (j + 1)), 1);
                            tr.rr        = Math.Round(trackReadings[i].rr + (delta[3] * (j + 1)), 1);
                            templist.Add(tr);
                        }
                    }
                }

                //finaly extrapolate readings beyond the highest reading if that reading is not 42(max)

                if (trackReadings[trackReadings.Count - 1].trackTemp != tMax)
                {
                    double[] delta = getDelta(trackReadings[trackReadings.Count - 2], trackReadings[trackReadings.Count - 1]);
                    int      j     = 1;
                    for (int i = trackReadings[trackReadings.Count - 1].trackTemp + 1; i < tMax + 1; i++)
                    {
                        TrackReading tr = new TrackReading();
                        tr.trackTemp = i;
                        tr.lf        = Math.Round(trackReadings[trackReadings.Count - 1].lf + (delta[0] * j), 1);
                        tr.rf        = Math.Round(trackReadings[trackReadings.Count - 1].rf + (delta[1] * j), 1);
                        tr.lr        = Math.Round(trackReadings[trackReadings.Count - 1].lr + (delta[2] * j), 1);
                        tr.rr        = Math.Round(trackReadings[trackReadings.Count - 1].rr + (delta[3] * j), 1);
                        templist.Add(tr);
                        j++;
                    }
                }

                foreach (TrackReading r in trackReadings)
                {
                    templist.Add(r);
                }

                autoReadings.Clear();
                autoReadings.AddRange(templist);
                updateGraph();
                double[] iMin = { autoReadings.Last().lf, autoReadings.Last().lr, autoReadings.Last().rf, autoReadings.Last().rr };
                double[] iMax = { autoReadings[0].lf, autoReadings[0].lr, autoReadings[0].rf, autoReadings[0].rr };
                int      min  = Convert.ToInt32(Math.Floor(iMin.Min()));
                int      max  = Convert.ToInt32(Math.Ceiling(iMax.Max()));
                //MessageBox.Show($"min is {min} max is {max}");
                chtPressures.ChartAreas[0].AxisY.Minimum = min;
                chtPressures.ChartAreas[0].AxisY.Maximum = max;

                //chtPressures.ChartAreas[0].AxisY.Minimum = Convert.ToDouble(Math.Ceiling())
            }
        }