Code development platform for open source projects from the European Union institutions :large_blue_circle: EU Login authentication by SMS has been phased out. To see alternatives please check here

Skip to content
Snippets Groups Projects
Select Git revision
  • 63d80d0c63761dccf142b9d8421561654ed54bf5
  • stable default
  • feat-fchv-bus
  • fix-h2-ice-bus
  • powertrains-multiple-axles
  • amdm3/develop
  • issue-1039
  • amdm3/main
  • test/nuget_publish
  • IEPC-experiments
  • amdm2/main
  • amdm2/develop
  • aptngearbox-not-auto
  • playground
  • official/main
  • official/develop
  • issue-templates
  • pdf-reports
  • HEV-timeruns-dev
  • timerun-empower-hybrids
  • timerun-pwheel-hybrids
  • Release/v5.0.3
  • Release/v5.0.1
  • Release/5.0.0-RC
  • Nuget/v0.11.4-DEV
  • Release/v0.11.4-DEV
  • Release/4.3.4-DEV
  • Release/4.3.3
  • Release/4.3.2-RC
  • Release/v4.3.0-DEV
  • Release/4.2.7
  • XMLConverterTool/4.2.6.0
  • Release/4.2.6-RC
  • Release/v4.2.5
  • Release/v4.2.3
  • Release/v4.2.2.3539-RC
  • Release/v4.2.1.3469
  • Release/v0.11.2.3456-DEV
  • Release/v4.2.0.3448-RC
  • Release/v4.1.3.3415
  • Release/v4.1.1.3413
41 results

Vehicle.cs

Blame
  • Forked from VECTO / VECTO Sim
    11482 commits behind the upstream repository.
    Markus QUARITSCH's avatar
    Markus Quaritsch authored
    - introduce dry-run parameter for point of operation search
    - add parameters for initialize methods
    - add point of operation search in case of engine overload
    63d80d0c
    History
    Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    Vehicle.cs 4.34 KiB
    using System;
    using TUGraz.VectoCore.Models.Connector.Ports;
    using TUGraz.VectoCore.Models.Simulation.Data;
    using TUGraz.VectoCore.Models.Simulation.DataBus;
    using TUGraz.VectoCore.Models.Simulation.Impl;
    using TUGraz.VectoCore.Models.SimulationComponent.Data;
    using TUGraz.VectoCore.Utils;
    
    namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
    {
    	public class Vehicle : VectoSimulationComponent, IVehicle, IMileageCounter, IFvInPort, IDriverDemandOutPort
    	{
    		private IFvOutPort _nextInstance;
    
    		private VehicleState _previousState;
    		private VehicleState _currentState;
    
    		private readonly VehicleData _data;
    
    		public Vehicle(VehicleContainer container, VehicleData data) : base(container)
    		{
    			_data = data;
    			_previousState = new VehicleState { Velocity = 0.SI<MeterPerSecond>() };
    			_currentState = new VehicleState();
    		}
    
    		public Vehicle(VehicleContainer container, VehicleData data, double initialVelocity) : this(container, data)
    		{
    			_previousState.Velocity = initialVelocity.SI<MeterPerSecond>();
    		}
    
    		public IFvInPort InPort()
    		{
    			return this;
    		}
    
    		public IDriverDemandOutPort OutPort()
    		{
    			return this;
    		}
    
    		public void Connect(IFvOutPort other)
    		{
    			_nextInstance = other;
    		}
    
    		protected override void DoWriteModalResults(IModalDataWriter writer)
    		{
    			writer[ModalResultField.v_act] = (_currentState.Velocity + _previousState.Velocity) / 2;
    			writer[ModalResultField.dist] = _previousState.Distance + (_currentState.Distance - _previousState.Distance) / 2;
    		}
    
    		protected override void DoCommitSimulationStep()
    		{
    			_previousState = _currentState;
    			_currentState = new VehicleState();
    		}
    
    		public IResponse Request(Second absTime, Second dt, MeterPerSquareSecond accelleration, Radian gradient, bool dryRun)
    		{
    			_currentState.Velocity = (_previousState.Velocity + (accelleration * dt)).Cast<MeterPerSecond>();
    			_currentState.dt = dt;
    			_currentState.Distance = _previousState.Distance +
    									((_previousState.Velocity + _currentState.Velocity) / 2 * _currentState.dt).Cast<Meter>();
    
    			// DriverAcceleration = vehicleAccelerationForce - RollingResistance - AirDragResistance - SlopeResistance
    			var vehicleAccelerationForce = DriverAcceleration(accelleration) + RollingResistance(gradient) +
    											AirDragResistance() +
    											SlopeResistance(gradient);
    
    			return _nextInstance.Request(absTime, dt, vehicleAccelerationForce, _currentState.Velocity, dryRun);
    		}
    
    		public IResponse Initialize(MeterPerSecond vehicleSpeed, Radian roadGradient)
    		{
    			_previousState = new VehicleState() { Distance = 0.SI<Meter>(), Velocity = vehicleSpeed };
    			_currentState = new VehicleState() { Distance = 0.SI<Meter>(), Velocity = vehicleSpeed };
    
    			var vehicleAccelerationForce = RollingResistance(roadGradient) + AirDragResistance() + SlopeResistance(roadGradient);
    			return _nextInstance.Initialize(vehicleAccelerationForce, vehicleSpeed);
    		}
    
    		protected Newton RollingResistance(Radian gradient)
    		{
    			return (Math.Cos(gradient.Value()) * _data.TotalVehicleWeight() *
    					Physics.GravityAccelleration *
    					_data.TotalRollResistanceCoefficient).Cast<Newton>();
    		}
    
    
    		protected Newton AirDragResistance()
    		{
    			// TODO different types of cross-wind correction...
    			var vAir = _currentState.Velocity;
    			var Cd = _data.DragCoefficient;
    			switch (_data.CrossWindCorrection) {
    				case CrossWindCorrectionMode.SpeedDependent:
    					//Cd = 
    					break;
    				case CrossWindCorrectionMode.VAirBeta:
    					break;
    			}
    
    			return (Cd * _data.CrossSectionArea * Physics.AirDensity / 2 * vAir * vAir).Cast<Newton>();
    		}
    
    		protected Newton DriverAcceleration(MeterPerSquareSecond accelleration)
    		{
    			return ((_data.TotalVehicleWeight() + _data.ReducedMassWheels) * accelleration).Cast<Newton>();
    		}
    
    
    		protected Newton SlopeResistance(Radian gradient)
    		{
    			return (_data.TotalVehicleWeight() * Physics.GravityAccelleration * Math.Sin(gradient.Value())).Cast<Newton>();
    		}
    
    		public MeterPerSecond VehicleSpeed()
    		{
    			return _previousState.Velocity;
    		}
    
    		public Kilogram VehicleMass()
    		{
    			return _data.TotalCurbWeight();
    		}
    
    		public Kilogram VehicleLoading()
    		{
    			return _data.Loading;
    		}
    
    		public Kilogram TotalMass()
    		{
    			return _data.TotalVehicleWeight();
    		}
    
    
    		public class VehicleState
    		{
    			public MeterPerSecond Velocity;
    			public Second dt;
    			public Meter Distance;
    		}
    
    		public Meter Distance()
    		{
    			return _previousState.Distance;
    		}
    	}
    }