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

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

refactoring driver

parent 7b788aa4
No related branches found
No related tags found
No related merge requests found
using System;
using JetBrains.Annotations;
namespace TUGraz.VectoCore.Exceptions
{
......@@ -6,5 +7,8 @@ namespace TUGraz.VectoCore.Exceptions
{
public VectoSimulationException(string msg) : base(msg) {}
public VectoSimulationException(string msg, Exception inner) : base(msg, inner) {}
[StringFormatMethod("message")]
public VectoSimulationException(string message, params object[] args) : base(message, args) {}
}
}
\ No newline at end of file
......@@ -5,6 +5,6 @@ namespace TUGraz.VectoCore.Models.Simulation.DataBus
/// <summary>
/// Defines interfaces for all different cockpits to access shared data of the powertrain.
/// </summary>
public interface IDataBus : IGearboxInfo, IEngineInfo, IVehicleInfo, IMileageCounter, IClutchInfo, IBreaks,
public interface IDataBus : IGearboxInfo, IEngineInfo, IVehicleInfo, IMileageCounter, IClutchInfo, IBrakes,
IRoadLookAhead {}
}
\ No newline at end of file
......@@ -16,7 +16,7 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl
internal IEngineInfo Engine;
internal IGearboxInfo Gearbox;
internal IVehicleInfo Vehicle;
internal IBreaks Breaks;
internal IBrakes Brakes;
internal IMileageCounter MilageCounter;
......@@ -129,9 +129,9 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl
MilageCounter = milage;
}
var breaks = component as IBreaks;
var breaks = component as IBrakes;
if (breaks != null) {
Breaks = breaks;
Brakes = breaks;
}
var road = component as IRoadLookAhead;
......@@ -196,8 +196,8 @@ namespace TUGraz.VectoCore.Models.Simulation.Impl
public Watt BreakPower
{
get { return Breaks.BreakPower; }
set { Breaks.BreakPower = value; }
get { return Brakes.BreakPower; }
set { Brakes.BreakPower = value; }
}
public ClutchState ClutchState()
......
......@@ -2,7 +2,7 @@
namespace TUGraz.VectoCore.Models.SimulationComponent
{
public interface IBreaks
public interface IBrakes
{
Watt BreakPower { get; set; }
}
......
using System;
using TUGraz.VectoCore.Exceptions;
using TUGraz.VectoCore.Models.Connector.Ports;
using TUGraz.VectoCore.Models.Simulation;
using TUGraz.VectoCore.Models.Simulation.Data;
......@@ -6,13 +7,13 @@ using TUGraz.VectoCore.Utils;
namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
{
public class Breaks : VectoSimulationComponent, IPowerTrainComponent, ITnOutPort, ITnInPort, IBreaks
public class Brakes : VectoSimulationComponent, IPowerTrainComponent, ITnOutPort, ITnInPort, IBrakes
{
protected ITnOutPort Next;
protected NewtonMeter BreakTorque;
public Breaks(IVehicleContainer dataBus) : base(dataBus) {}
public Brakes(IVehicleContainer dataBus) : base(dataBus) {}
public ITnInPort InPort()
......@@ -36,6 +37,9 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
BreakTorque = Formulas.PowerToTorque(BreakPower, angularVelocity);
}
}
if (!dryRun && BreakPower < 0) {
throw new VectoSimulationException("Negative Braking Power is not allowed!");
}
return Next.Request(absTime, dt, torque - BreakTorque, angularVelocity, dryRun);
}
......
......@@ -115,7 +115,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
public ClutchState ClutchState()
{
return _clutchState;
return DataBus.Gear == 0 ? SimulationComponent.ClutchState.ClutchOpened : _clutchState;
}
}
}
\ No newline at end of file
......@@ -32,8 +32,8 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
public DefaultDriverStrategy()
{
DrivingModes.Add(DrivingMode.DrivingModeDrive, new DriverModeDrive());
DrivingModes.Add(DrivingMode.DrivingModeBrake, new DriverModeBrake());
DrivingModes.Add(DrivingMode.DrivingModeDrive, new DriverModeDrive() { DriverStrategy = this });
DrivingModes.Add(DrivingMode.DrivingModeBrake, new DriverModeBrake() { DriverStrategy = this });
CurrentDrivingMode = DrivingMode.DrivingModeDrive;
}
......@@ -106,7 +106,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
public interface IDriverMode
{
IDriverActions Driver { get; set; }
DefaultDriverStrategy DriverStrategy { get; set; }
IResponse Request(Second absTime, Meter ds, MeterPerSecond targetVelocity, Radian gradient);
}
......@@ -115,7 +115,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
public class DriverModeDrive : IDriverMode
{
public IDriverActions Driver { get; set; }
public DefaultDriverStrategy DriverStrategy { get; set; }
public IResponse Request(Second absTime, Meter ds, MeterPerSecond targetVelocity, Radian gradient)
{
......@@ -127,7 +127,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
public class DriverModeBrake : IDriverMode
{
public IDriverActions Driver { get; set; }
public DefaultDriverStrategy DriverStrategy { get; set; }
public IResponse Request(Second absTime, Meter ds, MeterPerSecond targetVelocity, Radian gradient)
{
......
This diff is collapsed.
......@@ -78,6 +78,9 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
//Special Behaviour: When Gear is 0 (no gear set) OR the speed is 0 (not rotating) a zero-request is applied.
if (Gear == 0) {
if (dryRun) {
return new ResponseDryRun() { GearboxPowerRequest = outTorque * outEngineSpeed };
}
var resp = Next.Request(absTime, dt, 0.SI<NewtonMeter>(), 0.SI<PerSecond>(), dryRun);
resp.GearboxPowerRequest = outTorque * outEngineSpeed;
return resp;
......@@ -110,9 +113,8 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
_loss = inTorque * inEngineSpeed - outTorque * outEngineSpeed;
// DryRun Response
// DryRun Response, gear != 0
if (dryRun) {
//todo: Gearbox DryRun Request: Add the DeltaFull, DeltaDrag for Gearbox FullLoadCurve
var r = Next.Request(absTime, dt, inTorque, inEngineSpeed, true);
r.GearboxPowerRequest = outTorque * outEngineSpeed;
return r;
......@@ -141,6 +143,7 @@ namespace TUGraz.VectoCore.Models.SimulationComponent.Impl
// Normal Response
var response = Next.Request(absTime, dt, inTorque, inEngineSpeed);
response.GearboxPowerRequest = outTorque * outEngineSpeed;
return response;
}
......
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