Code development platform for open source projects from the European Union institutions

Skip to content
Snippets Groups Projects
Commit acd144c5 authored by Markus Quaritsch's avatar Markus Quaritsch
Browse files

Merge pull request #502 in VECTO/vecto-sim from...

Merge pull request #502 in VECTO/vecto-sim from ~EMKRISPMI/vecto-sim:feature/Export-Shift-Curve to develop

* commit '83d756ea':
  Added Button in Gearbox-Form to export currently selected ShiftPolygon to a new .VGBS file in the job-file directory
parents 299e7842 83d756ea
No related branches found
No related tags found
No related merge requests found
This diff is collapsed.
This diff is collapsed.
......@@ -26,7 +26,9 @@ Imports TUGraz.VectoCore.Models.Declaration
Imports TUGraz.VectoCore.Models.SimulationComponent.Data
Imports TUGraz.VectoCore.Models.SimulationComponent.Data.Engine
Imports TUGraz.VectoCore.Models.SimulationComponent.Data.Gearbox
Imports TUGraz.VectoCore.OutputData.FileIO
Imports TUGraz.VectoCore.OutputData.XML
Imports TUGraz.VectoCore.Utils
''' <summary>
''' Gearbox Editor
......@@ -72,12 +74,12 @@ Public Class GearboxForm
If (Cfg.DeclMode) Then
CbGStype.DataSource = [Enum].GetValues(GetType(GearboxType)) _
.Cast(Of GearboxType)() _
.Cast (Of GearboxType)() _
.Where(Function(type) type.ManualTransmission() OrElse type = GearboxType.ATSerial) _
.Select(Function(type) New With {Key .Value = type, .Label = type.GetLabel()}).ToList()
Else
CbGStype.DataSource = [Enum].GetValues(GetType(GearboxType)) _
.Cast(Of GearboxType)() _
.Cast (Of GearboxType)() _
.Where(Function(type) type.ManualTransmission() OrElse type.AutomaticTransmission()) _
.Select(Function(type) New With {Key .Value = type, .Label = type.GetLabel()}).ToList()
End If
......@@ -102,8 +104,8 @@ Public Class GearboxForm
TbMinTimeBetweenShifts.Text = DeclarationData.Gearbox.MinTimeBetweenGearshifts.ToGUIFormat()
'cDeclaration.MinTimeBetweenGearshift(GStype)
TbTqResv.Text = (DeclarationData.Gearbox.TorqueReserve * 100).ToGUIFormat() ' cDeclaration.TqResv
TbTqResvStart.Text = (DeclarationData.Gearbox.TorqueReserveStart * 100).ToGUIFormat() 'cDeclaration.TqResvStart
TbTqResv.Text = (DeclarationData.Gearbox.TorqueReserve*100).ToGUIFormat() ' cDeclaration.TqResv
TbTqResvStart.Text = (DeclarationData.Gearbox.TorqueReserveStart*100).ToGUIFormat() 'cDeclaration.TqResvStart
TbStartSpeed.Text = DeclarationData.Gearbox.StartSpeed.ToGUIFormat() 'cDeclaration.StartSpeed
TbStartAcc.Text = DeclarationData.Gearbox.StartAcceleration.ToGUIFormat() ' cDeclaration.StartAcc
......@@ -198,9 +200,9 @@ Public Class GearboxForm
'Me.ChSkipGears.Checked = False 'set by CbGStype.SelectedIndexChanged
'Me.ChShiftInside.Checked = False 'set by CbGStype.SelectedIndexChanged
TbTqResv.Text = (DeclarationData.Gearbox.TorqueReserve * 100).ToGUIFormat()
TbTqResv.Text = (DeclarationData.Gearbox.TorqueReserve*100).ToGUIFormat()
TbMinTimeBetweenShifts.Text = DeclarationData.Gearbox.MinTimeBetweenGearshifts.ToGUIFormat()
TbTqResvStart.Text = (DeclarationData.Gearbox.TorqueReserveStart * 100).ToGUIFormat()
TbTqResvStart.Text = (DeclarationData.Gearbox.TorqueReserveStart*100).ToGUIFormat()
TbStartSpeed.Text = DeclarationData.Gearbox.StartSpeed.ToGUIFormat() ' in m/s!
TbStartAcc.Text = DeclarationData.Gearbox.StartAcceleration.ToGUIFormat()
......@@ -235,7 +237,7 @@ Public Class GearboxForm
If ChangeCheckCancel() Then Exit Sub
Dim inputData As IEngineeringInputDataProvider = TryCast(JSONInputDataFactory.ReadComponentData(file),
Dim inputData As IEngineeringInputDataProvider = TryCast(JSONInputDataFactory.ReadComponentData(file),
IEngineeringInputDataProvider)
Dim gearbox As IGearboxEngineeringInputData = inputData.GearboxInputData
Dim axlegear As IAxleGearInputData = inputData.AxleGearInputData
......@@ -248,7 +250,7 @@ Public Class GearboxForm
Close()
MainForm.RbDecl.Checked = Not MainForm.RbDecl.Checked
MainForm.OpenVectoFile(file)
Case -1
Case - 1
Exit Sub
End Select
End If
......@@ -283,9 +285,9 @@ Public Class GearboxForm
If(gear.MaxInputSpeed Is Nothing, "", gear.MaxInputSpeed.AsRPM.ToGUIFormat())))
Next
TbTqResv.Text = (gearbox.TorqueReserve * 100).ToGUIFormat()
TbTqResv.Text = (gearbox.TorqueReserve*100).ToGUIFormat()
TbMinTimeBetweenShifts.Text = gearbox.MinTimeBetweenGearshift.ToGUIFormat()
TbTqResvStart.Text = (gearbox.StartTorqueReserve * 100).ToGUIFormat()
TbTqResvStart.Text = (gearbox.StartTorqueReserve*100).ToGUIFormat()
TbStartSpeed.Text = gearbox.StartSpeed.ToGUIFormat()
TbStartAcc.Text = gearbox.StartAcceleration.ToGUIFormat()
......@@ -524,7 +526,7 @@ Public Class GearboxForm
Dim ratio1 As Double = LvGears.Items.Item(1).SubItems(GearboxTbl.Ratio).Text.ToDouble(0)
Dim ratio2 As Double = LvGears.Items.Item(2).SubItems(GearboxTbl.Ratio).Text.ToDouble(0)
If ratio1 / ratio2 >= DeclarationData.Gearbox.TorqueConverterSecondGearThreshold(_vehicleCategory) Then
If ratio1/ratio2 >= DeclarationData.Gearbox.TorqueConverterSecondGearThreshold(_vehicleCategory) Then
text = "Torque converter is used in 1st and 2nd gear"
Else
text = "Torque converter is used in 1st gear only"
......@@ -539,7 +541,9 @@ Public Class GearboxForm
Handles LvGears.SelectedIndexChanged
Try
UpdatePic()
btExportVGBS.Enabled = True
Catch
btExportVGBS.Enabled = False
End Try
End Sub
......@@ -798,7 +802,7 @@ Public Class GearboxForm
Dim jobFile As String = VectoJobForm.VectoFile
If Not jobFile Is Nothing AndAlso File.Exists(jobFile) Then
Dim inputData As IEngineeringInputDataProvider = TryCast(JSONInputDataFactory.ReadJsonJob(jobFile),
Dim inputData As IEngineeringInputDataProvider = TryCast(JSONInputDataFactory.ReadJsonJob(jobFile),
IEngineeringInputDataProvider)
If (inputData Is Nothing) Then
Exit Sub
......@@ -897,7 +901,7 @@ Public Class GearboxForm
As ShiftPolygon
Dim maxTqStr As String = LvGears.Items(gear).SubItems(GearboxTbl.MaxTorque).Text
Dim engine As CombustionEngineData = ConvertToEngineData(engineFullLoadCurve, idleSpeed, gear,
If(String.IsNullOrWhiteSpace(maxTqStr), Nothing, maxTqStr.ToDouble(0).SI(Of NewtonMeter)))
If(String.IsNullOrWhiteSpace(maxTqStr), Nothing, maxTqStr.ToDouble(0).SI (Of NewtonMeter)))
If gears.Count <= 1 Then
Return Nothing
End If
......@@ -1017,6 +1021,51 @@ Public Class GearboxForm
export.Save(Path.Combine(filePath, data.ModelName + ".xml"))
End If
End Sub
Private Sub btExportVGBS_Click(sender As Object, e As EventArgs) Handles btExportVGBS.Click
If LvGears.Items.Count <= 1 Then Exit Sub
Dim shiftPolygon As ShiftPolygon = Nothing
Dim path As String
Dim gear As Integer
Try
If LvGears.SelectedItems.Count > 0 AndAlso LvGears.SelectedIndices(0) > 0 Then
path = FileRepl(LvGears.SelectedItems(0).SubItems(GearboxTbl.ShiftPolygons).Text, GetPath(_gbxFile))
gear = LvGears.SelectedIndices(0)
Else
path = FileRepl(LvGears.Items(1).SubItems(GearboxTbl.ShiftPolygons).Text, GetPath(_gbxFile))
gear = 1
End If
If File.Exists(path) Then shiftPolygon = ShiftPolygonReader.ReadFromFile(path)
If Not shiftPolygon Is Nothing Then
ShiftPolygonExport.WriteShiftPolygon(shiftPolygon, path & ".vgbs")
End If
Catch ex As Exception
End Try
Dim jobFile As String = VectoJobForm.VectoFile
If Not jobFile Is Nothing AndAlso File.Exists(jobFile) Then
Dim inputData As IEngineeringInputDataProvider = TryCast(JSONInputDataFactory.ReadJsonJob(jobFile),
IEngineeringInputDataProvider)
If (inputData Is Nothing) Then
Exit Sub
End If
Dim vehicle As IVehicleEngineeringInputData = inputData.VehicleInputData
Dim engine As IEngineEngineeringInputData = inputData.EngineInputData
Dim engineFld As EngineFullLoadCurve = FullLoadCurveReader.Create(engine.FullLoadCurve)
If VectoJobForm.Visible AndAlso engine.IdleSpeed > 0 Then
Dim gears As IList(Of ITransmissionInputData) = ConvertToGears(LvGears.Items)
Dim shiftLines As ShiftPolygon = GetShiftLines(engine.IdleSpeed, engineFld, vehicle, gears, gear)
If (Not IsNothing(shiftLines)) Then
ShiftPolygonExport.WriteShiftPolygon(shiftLines, jobFile & "_Gear " & gear & ".vgbs")
End If
End If
End If
End Sub
End Class
......@@ -194,5 +194,29 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Data.Gearbox
return VectoMath.Interpolate(section.Item1.AngularSpeed, section.Item2.AngularSpeed, section.Item1.Torque,
section.Item2.Torque, inAngularVelocity);
}
public PerSecond InterpolateDownshiftSpeed(NewtonMeter torque)
{
var section = Downshift.GetSection(entry => entry.Torque < torque);
if (section.Item1.Torque.IsEqual(section.Item2.Torque)) {
// vertical line
return double.MaxValue.SI<PerSecond>();
}
return VectoMath.Interpolate(section.Item1.Torque, section.Item2.Torque, section.Item1.AngularSpeed,
section.Item2.AngularSpeed, torque);
}
public PerSecond InterpolateUpshiftSpeed(NewtonMeter torque)
{
var section = Upshift.GetSection(entry => entry.Torque < torque);
if (section.Item1.Torque.IsEqual(section.Item2.Torque)) {
// vertical line
return double.MaxValue.SI<PerSecond>();
}
return VectoMath.Interpolate(section.Item1.Torque, section.Item2.Torque, section.Item1.AngularSpeed,
section.Item2.AngularSpeed, torque);
}
}
}
\ No newline at end of file
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using TUGraz.VectoCommon.Utils;
using TUGraz.VectoCore.Models.SimulationComponent.Data.Gearbox;
namespace TUGraz.VectoCore.OutputData.FileIO
{
public static class ShiftPolygonExport
{
public static void WriteShiftPolygon(ShiftPolygon shiftPolygon, string fileName)
{
var lines = new SortedList<double, ShiftPolygonFileEntry>(10);
foreach (var entry in shiftPolygon.Downshift) {
lines.Add(Math.Round(entry.Torque.Value(), 4),
new ShiftPolygonFileEntry {
Torque = entry.Torque,
DownShift = entry.AngularSpeed,
UpShift = shiftPolygon.Upshift.Count > 0 ? shiftPolygon.InterpolateUpshiftSpeed(entry.Torque) : null
});
}
foreach (var entry in shiftPolygon.Upshift) {
var torque = Math.Round(entry.Torque.Value(), 4);
if (lines.ContainsKey(torque))
lines[torque].UpShift = entry.AngularSpeed;
else {
lines.Add(torque, new ShiftPolygonFileEntry {
Torque = entry.Torque,
DownShift = shiftPolygon.Downshift.Count > 0 ? shiftPolygon.InterpolateDownshiftSpeed(entry.Torque) : null,
UpShift = entry.AngularSpeed
});
}
}
var sb = new StringBuilder(lines.Count + 1);
sb.AppendLine("engine torque [Nm],downshift rpm [1/min],upshift rpm [1/min]");
foreach (var line in lines.Values) {
if (line.DownShift == null)
sb.AppendLine(string.Format("{0},,{1:0.0000}", line.Torque.ToOutputFormat(), line.UpShift.AsRPM));
else if (line.UpShift == null)
sb.AppendLine(string.Format("{0},{1:0.0000},", line.Torque.ToOutputFormat(), line.DownShift.AsRPM));
else
sb.AppendLine(string.Format("{0},{1:0.0000},{2:0.0000}", line.Torque.ToOutputFormat(), line.DownShift.AsRPM,
line.UpShift.AsRPM));
}
File.WriteAllText(fileName, sb.ToString());
}
private class ShiftPolygonFileEntry
{
public NewtonMeter Torque;
public PerSecond DownShift;
public PerSecond UpShift;
}
}
}
\ No newline at end of file
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment