diff --git a/.gitignore b/.gitignore index eb85b28f0450b6d69d46f65eba5ee6e564bba112..bb6a80f0b5ae7db4ea130d575c5e47a1d4d8ed00 100644 --- a/.gitignore +++ b/.gitignore @@ -189,3 +189,4 @@ UpgradeLog*.htm # Microsoft Fakes FakesAssemblies/ VectoCoreTest/TestData/EngineOnly/Test1/Test1_results.vmod.csv +*.orig diff --git a/VectoCore/Models/Connector/Ports/IRoadPortProvider.cs b/VectoCore/Models/Connector/Ports/IRoadPortProvider.cs index 4a55c700dd871037a00d5b15e02d2857d80a69fd..7bc3047afbcafe7f7a2bbd7ad51694e1a2d1138d 100644 --- a/VectoCore/Models/Connector/Ports/IRoadPortProvider.cs +++ b/VectoCore/Models/Connector/Ports/IRoadPortProvider.cs @@ -9,7 +9,7 @@ /// Returns the inport to connect it to another outport. /// </summary> /// <returns></returns> - IFvInPort InShaft(); + IFvInPort InPort(); } /// <summary> @@ -21,6 +21,6 @@ /// Returns the outport to send requests to. /// </summary> /// <returns></returns> - IFvOutPort OutShaft(); + IFvOutPort OutPort(); } } \ No newline at end of file diff --git a/VectoCore/Models/Simulation/Impl/SimulatorFactory.cs b/VectoCore/Models/Simulation/Impl/SimulatorFactory.cs index 064d70baa2be7da3aad967ec6b5f18637fded3b7..d56f4ac81bbd75fefd8987cf97a018a016af1267 100644 --- a/VectoCore/Models/Simulation/Impl/SimulatorFactory.cs +++ b/VectoCore/Models/Simulation/Impl/SimulatorFactory.cs @@ -122,7 +122,7 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl // connect cycle --> driver --> vehicle --> wheels --> axleGear --> gearBox --> retarder --> clutch cycle.InShaft().Connect(_driver.OutShaft()); _driver.InShaft().Connect(_vehicle.OutShaft()); - _vehicle.InShaft().Connect(_wheels.OutShaft()); + _vehicle.InPort().Connect(_wheels.OutPort()); _wheels.InShaft().Connect(_axleGear.OutShaft()); _axleGear.InShaft().Connect(_gearBox.OutShaft()); _gearBox.InShaft().Connect(_retarder.OutShaft()); @@ -219,7 +219,7 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl } var vehicleData = EngineeringModeSimulationComponentFactory.Instance().CreateVehicleData(vehicleFile); - //VehicleData.ReadFromFile(vehicleFile); + //VehicleData.ReadFromFile(vehicleFile); _vehicle = new Vehicle(_container, vehicleData); } diff --git a/VectoCore/Models/SimulationComponent/Impl/Vehicle.cs b/VectoCore/Models/SimulationComponent/Impl/Vehicle.cs index f2c0419099c74c666beb8f6d50dddb90cbe1f1b9..4a987148b6d8cbfb5716af5ffd304ec60bd69b35 100644 --- a/VectoCore/Models/SimulationComponent/Impl/Vehicle.cs +++ b/VectoCore/Models/SimulationComponent/Impl/Vehicle.cs @@ -28,7 +28,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl _previousState.Velocity = initialVelocity.SI<MeterPerSecond>(); } - public IFvInPort InShaft() + public IFvInPort InPort() { return this; } diff --git a/VectoCore/Models/SimulationComponent/Impl/Wheels.cs b/VectoCore/Models/SimulationComponent/Impl/Wheels.cs index 8be9b62a58929f7cc11df230c61b2fdb318471a2..7f32d93926ae864d338fb9fef617b436646110fa 100644 --- a/VectoCore/Models/SimulationComponent/Impl/Wheels.cs +++ b/VectoCore/Models/SimulationComponent/Impl/Wheels.cs @@ -9,15 +9,19 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl public class Wheels : VectoSimulationComponent, IWheels, IFvOutPort, ITnInPort { private ITnOutPort _outPort; + private Meter _dynamicWheelRadius; - public Wheels(IVehicleContainer cockpit) - : base(cockpit) {} + public Wheels(IVehicleContainer cockpit, Meter rdyn) + : base(cockpit) + { + _dynamicWheelRadius = rdyn; + } #region IRoadPortOutProvider - IFvOutPort IRoadPortOutProvider.OutShaft() + IFvOutPort IRoadPortOutProvider.OutPort() { - throw new NotImplementedException(); + return this; } #endregion @@ -26,7 +30,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl ITnInPort IInShaft.InShaft() { - throw new NotImplementedException(); + return this; } #endregion @@ -35,7 +39,9 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl IResponse IFvOutPort.Request(TimeSpan absTime, TimeSpan dt, Newton force, MeterPerSecond velocity) { - throw new NotImplementedException(); + NewtonMeter torque = (force * _dynamicWheelRadius).Cast<NewtonMeter>(); + var angularVelocity = (velocity / _dynamicWheelRadius).Cast<PerSecond>(); + return _outPort.Request(absTime, dt, torque, angularVelocity); } #endregion diff --git a/VectoCoreTest/Models/SimulationComponent/VehicleTest.cs b/VectoCoreTest/Models/SimulationComponent/VehicleTest.cs index 89d14cd359c2102897fe5e92060c032b3a272e6f..71fae28a04951b850088933aeb3fb5c024593418 100644 --- a/VectoCoreTest/Models/SimulationComponent/VehicleTest.cs +++ b/VectoCoreTest/Models/SimulationComponent/VehicleTest.cs @@ -20,13 +20,13 @@ namespace TUGraz.VectoCore.Tests.Models.SimulationComponent var container = new VehicleContainer(); var vehicleData = EngineeringModeSimulationComponentFactory.Instance().CreateVehicleData(VehicleDataFile); - //VehicleData.ReadFromFile(VehicleDataFile); + //VehicleData.ReadFromFile(VehicleDataFile); //vehicleData.CrossWindCorrection = VehicleData.CrossWindCorrectionMode.NoCorrection; var vehicle = new Vehicle(container, vehicleData, 17.210535); var mockPort = new MockFvOutPort(); - vehicle.InShaft().Connect(mockPort); + vehicle.InPort().Connect(mockPort); var requestPort = vehicle.OutShaft(); diff --git a/VectoCoreTest/Models/SimulationComponent/WheelsTest.cs b/VectoCoreTest/Models/SimulationComponent/WheelsTest.cs new file mode 100644 index 0000000000000000000000000000000000000000..8d5c1056c1c0454405c39b43f0a8f1ec39fe0b2e --- /dev/null +++ b/VectoCoreTest/Models/SimulationComponent/WheelsTest.cs @@ -0,0 +1,43 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using TUGraz.VectoCore.Models.Simulation.Impl; +using TUGraz.VectoCore.Models.SimulationComponent; +using TUGraz.VectoCore.Models.SimulationComponent.Data; +using TUGraz.VectoCore.Models.SimulationComponent.Factories; +using TUGraz.VectoCore.Models.SimulationComponent.Impl; +using TUGraz.VectoCore.Tests.Utils; +using TUGraz.VectoCore.Utils; + +namespace TUGraz.VectoCore.Tests.Models.SimulationComponent +{ + [TestClass] + public class WheelsTest + { + private const string VehicleDataFile = @"TestData\Components\24t Coach.vveh"; + + [TestMethod] + public void WheelsRequestTest() + { + var container = new VehicleContainer(); + var vehicleData = EngineeringModeSimulationComponentFactory.Instance().CreateVehicleData(VehicleDataFile); + + IWheels wheels = new Wheels(container, vehicleData.DynamicTyreRadius); + var mockPort = new MockTnOutPort(); + + wheels.InShaft().Connect(mockPort); + + var requestPort = wheels.OutPort(); + + var absTime = TimeSpan.FromSeconds(0); + var dt = TimeSpan.FromSeconds(1); + + var force = 5000.SI<Newton>(); + var velocity = 20.SI<MeterPerSecond>(); + + var retVal = requestPort.Request(absTime, dt, force, velocity); + + Assert.AreEqual(2600.0, mockPort.Torque.Double(), 0.0001); + Assert.AreEqual(38.4615384615, mockPort.AngularVelocity.Double(), 0.0001); + } + } +} \ No newline at end of file diff --git a/VectoCoreTest/VectoCoreTest.csproj b/VectoCoreTest/VectoCoreTest.csproj index f49aca13885f9ed8bd161723f05f27c04898b9be..f2cea47f3dfec99791be1d586451119de3513fc7 100644 --- a/VectoCoreTest/VectoCoreTest.csproj +++ b/VectoCoreTest/VectoCoreTest.csproj @@ -79,6 +79,7 @@ <Compile Include="Models\SimulationComponent\CombustionEngineTest.cs" /> <Compile Include="Models\SimulationComponent\GearboxTest.cs" /> <Compile Include="Models\SimulationComponent\RetarderTest.cs" /> + <Compile Include="Models\SimulationComponent\WheelsTest.cs" /> <Compile Include="Models\SimulationComponent\VehicleTest.cs" /> <Compile Include="Models\Simulation\DrivingCycleTests.cs" /> <Compile Include="Utils\ResultFileHelper.cs" />