diff --git a/VectoCore/Models/SimulationComponent/Impl/Wheels.cs b/VectoCore/Models/SimulationComponent/Impl/Wheels.cs index 04a97a11a400ee4cb1b550e869790e7da0bc87fe..7f32d93926ae864d338fb9fef617b436646110fa 100644 --- a/VectoCore/Models/SimulationComponent/Impl/Wheels.cs +++ b/VectoCore/Models/SimulationComponent/Impl/Wheels.cs @@ -6,56 +6,62 @@ using TUGraz.VectoCore.Utils; namespace TUGraz.VectoCore.Models.SimulationComponent.Impl { - public class Wheels : VectoSimulationComponent, IWheels, IFvOutPort, ITnInPort - { - private ITnOutPort _outPort; + 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 + #region IRoadPortOutProvider - IFvOutPort IRoadPortOutProvider.OutPort() - { - throw new NotImplementedException(); - } + IFvOutPort IRoadPortOutProvider.OutPort() + { + return this; + } - #endregion + #endregion - #region IInShaft + #region IInShaft - ITnInPort IInShaft.InShaft() - { - throw new NotImplementedException(); - } + ITnInPort IInShaft.InShaft() + { + return this; + } - #endregion + #endregion - #region IFvOutPort + #region IFvOutPort - IResponse IFvOutPort.Request(TimeSpan absTime, TimeSpan dt, Newton force, MeterPerSecond velocity) - { - throw new NotImplementedException(); - } + IResponse IFvOutPort.Request(TimeSpan absTime, TimeSpan dt, Newton force, MeterPerSecond velocity) + { + NewtonMeter torque = (force * _dynamicWheelRadius).Cast<NewtonMeter>(); + var angularVelocity = (velocity / _dynamicWheelRadius).Cast<PerSecond>(); + return _outPort.Request(absTime, dt, torque, angularVelocity); + } - #endregion + #endregion - #region ITnInPort + #region ITnInPort - void ITnInPort.Connect(ITnOutPort other) - { - _outPort = other; - } + void ITnInPort.Connect(ITnOutPort other) + { + _outPort = other; + } - #endregion + #endregion - #region VectoSimulationComponent + #region VectoSimulationComponent - public override void CommitSimulationStep(IModalDataWriter writer) - { - throw new NotImplementedException(); - } + public override void CommitSimulationStep(IModalDataWriter writer) + { + throw new NotImplementedException(); + } - #endregion - } + #endregion + } } \ No newline at end of file diff --git a/VectoCoreTest/Models/SimulationComponent/WheelsTest.cs b/VectoCoreTest/Models/SimulationComponent/WheelsTest.cs new file mode 100644 index 0000000000000000000000000000000000000000..1fa4d4179f6df3b7b489807faf0fc4f74e38550b --- /dev/null +++ b/VectoCoreTest/Models/SimulationComponent/WheelsTest.cs @@ -0,0 +1,41 @@ +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.Impl; +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 = VehicleData.ReadFromFile(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(250.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 bb41fed9818db63be385b823be06cdcd2cf24d16..860be924a0eaa4bf4e7888a54a9a078655ff5f6b 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="Models\SimulationComponent\MockPorts.cs" />