aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Tango.Integration
diff options
context:
space:
mode:
authorVictoria Plitt <Victoria.Plitt@twine-s.com>2020-01-16 12:53:26 +0200
committerVictoria Plitt <Victoria.Plitt@twine-s.com>2020-01-16 12:53:26 +0200
commit9f6dd0def55b3fc55b84fa5025e41972d36df7ae (patch)
treeb8d3711c6aaf64052c1df7f7544c5f897749add9 /Software/Visual_Studio/Tango.Integration
parentfd0d8d7668aefea359dad4d7737bb4c71344a292 (diff)
downloadTango-9f6dd0def55b3fc55b84fa5025e41972d36df7ae.tar.gz
Tango-9f6dd0def55b3fc55b84fa5025e41972d36df7ae.zip
Implemented JobRun Liquid Quantities calculation.
Diffstat (limited to 'Software/Visual_Studio/Tango.Integration')
-rw-r--r--Software/Visual_Studio/Tango.Integration/Operation/IMachineOperator.cs5
-rw-r--r--Software/Visual_Studio/Tango.Integration/Operation/JobLiquidQuantityCalculationMode.cs23
-rw-r--r--Software/Visual_Studio/Tango.Integration/Operation/MachineOperator.cs147
-rw-r--r--Software/Visual_Studio/Tango.Integration/Tango.Integration.csproj3
4 files changed, 177 insertions, 1 deletions
diff --git a/Software/Visual_Studio/Tango.Integration/Operation/IMachineOperator.cs b/Software/Visual_Studio/Tango.Integration/Operation/IMachineOperator.cs
index 8156ef8c7..8adb61750 100644
--- a/Software/Visual_Studio/Tango.Integration/Operation/IMachineOperator.cs
+++ b/Software/Visual_Studio/Tango.Integration/Operation/IMachineOperator.cs
@@ -49,6 +49,11 @@ namespace Tango.Integration.Operation
JobUnitsMethods JobUnitsMethod { get; set; }
/// <summary>
+ /// Gets or sets the way of calculating how much liquid was spent during the job.
+ /// </summary>
+ JobLiquidQuantityCalculationMode JobLiquidQuantityCalculationMode { get; set; }
+
+ /// <summary>
/// Gets the current machine status.
/// </summary>
MachineStatuses Status { get; }
diff --git a/Software/Visual_Studio/Tango.Integration/Operation/JobLiquidQuantityCalculationMode.cs b/Software/Visual_Studio/Tango.Integration/Operation/JobLiquidQuantityCalculationMode.cs
new file mode 100644
index 000000000..0c2cc1bb3
--- /dev/null
+++ b/Software/Visual_Studio/Tango.Integration/Operation/JobLiquidQuantityCalculationMode.cs
@@ -0,0 +1,23 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Tango.Integration.Operation
+{
+ /// <summary>
+ /// Represents a machine operator liquid quantity calculation mode which will determine the amount of liquid spent when job has stopped.
+ /// </summary>
+ public enum JobLiquidQuantityCalculationMode
+ {
+ /// <summary>
+ /// Calculates the liquid quantities using the <see cref="PMR.MachineStatus.MachineStatus.IDSPacksLevels"/> before and after job run.
+ /// </summary>
+ MachineStatus,
+ /// <summary>
+ /// Calculates the liquid quantities using the job details, stop position and an integral.
+ /// </summary>
+ Integral
+ }
+}
diff --git a/Software/Visual_Studio/Tango.Integration/Operation/MachineOperator.cs b/Software/Visual_Studio/Tango.Integration/Operation/MachineOperator.cs
index effd76dd2..dba1e0149 100644
--- a/Software/Visual_Studio/Tango.Integration/Operation/MachineOperator.cs
+++ b/Software/Visual_Studio/Tango.Integration/Operation/MachineOperator.cs
@@ -73,6 +73,7 @@ namespace Tango.Integration.Operation
private static RunningJobStatus _last_job_status;
private bool _isPowerDownRequestInProgress;
private List<BL.ValueObjects.JobRunLiquidQuantity> _currentJobLiquidQuantities;
+ private MachineStatus _machineStatusBeforeJobStart;
public static String EmbeddedLogsFolder { get; private set; }
public static String EmbeddedLogsTag { get; private set; }
@@ -285,6 +286,11 @@ namespace Tango.Integration.Operation
/// </summary>
public JobUnitsMethods JobUnitsMethod { get; set; }
+ /// <summary>
+ /// Gets or sets the way of calculating how much liquid was spent during the job.
+ /// </summary>
+ public JobLiquidQuantityCalculationMode JobLiquidQuantityCalculationMode { get; set; }
+
private MachineStatuses _status;
/// <summary>
/// Gets the current machine status.
@@ -1827,6 +1833,142 @@ namespace Tango.Integration.Operation
}
}
+ /// <summary>
+ /// Assign the liquid quantities spent by the last job using the job and the handler last status.
+ /// </summary>
+ /// <param name="job">The job.</param>
+ /// <param name="configuration">The configuration.</param>
+ /// <param name="handler">The handler.</param>
+ private void SaveLastJobLiquidQuantities(Job job, Configuration configuration, JobHandler handler)
+ {
+ _currentJobLiquidQuantities = new List<BL.ValueObjects.JobRunLiquidQuantity>();
+
+ if (JobLiquidQuantityCalculationMode == JobLiquidQuantityCalculationMode.MachineStatus)
+ {
+ foreach (var pack in configuration.NoneEmptyIdsPacks.ToList())
+ {
+ var packLevelAfter = MachineStatus.IDSPacksLevels.SingleOrDefault(x => x.Index == pack.PackIndex);
+ var packLevelBefore = _machineStatusBeforeJobStart.IDSPacksLevels.SingleOrDefault(x => x.Index == pack.PackIndex);
+
+ if (packLevelAfter != null && packLevelBefore != null)
+ {
+ _currentJobLiquidQuantities.Add(new BL.ValueObjects.JobRunLiquidQuantity()
+ {
+ LiquidType = pack.LiquidType.Type,
+ Quantity = packLevelAfter.DispenserLevel - packLevelBefore.DispenserLevel,
+ });
+ }
+ }
+ }
+ else
+ {
+ double total = handler.Status.TotalProgress;
+ double position_cm = handler.Status.Progress * 100d;
+ double total_length = 0;
+
+ Dictionary<int, double> liquidQuantities = new Dictionary<int, double>();
+
+ foreach (var pack in configuration.NoneEmptyIdsPacks.OrderBy(x => x.PackIndex))
+ {
+ liquidQuantities.Add(pack.PackIndex, 0);
+ }
+
+ int resolution = GradientGenerationConfiguration.ResolutionCM;
+ bool stop_calc = false;
+
+ for (int i = 0; i < Math.Max(job.NumberOfUnits, 1) && !stop_calc; i++)
+ {
+ for (int segmentIndex = 0; segmentIndex < job.Segments.Count && !stop_calc; segmentIndex++)
+ {
+ var segment = job.Segments[segmentIndex];
+ var segment_length_cm = segment.Length * 100d;
+
+ List<BrushStop> orderedBrushCollection = segment.BrushStops.OrderBy(x => x.OffsetMeters).ToList();
+
+ int solid_gradient_oeff = orderedBrushCollection.Count == 1 ? 1 : 2;
+ double prev_offset_cm = 0;
+ double delta_brushLenghtToStopPosition = 0d;
+
+ double position_interval_centimeters = 0d;//interval for calculation where the stop occurred
+ for (int brushIndex = 0; brushIndex < orderedBrushCollection.Count && !stop_calc; brushIndex++)
+ {
+ var brush = orderedBrushCollection[brushIndex];
+ double brush_length_centimeters = 0d;
+ double brush_offset_cm = 0;
+
+ if ((brushIndex + 1) < orderedBrushCollection.Count)
+ {
+ brush_offset_cm = (brush.OffsetMeters * 100d);
+ double next_brush_offset_cm = (orderedBrushCollection[brushIndex + 1].OffsetMeters * 100d);
+ brush_length_centimeters = (next_brush_offset_cm - prev_offset_cm);
+ double brush_length_centimeters_before_calc = brush_length_centimeters;
+
+ if (delta_brushLenghtToStopPosition > 0)//calculate second brush
+ {
+ brush_length_centimeters = ((position_interval_centimeters - delta_brushLenghtToStopPosition) * (position_interval_centimeters - delta_brushLenghtToStopPosition)) / position_interval_centimeters;
+ stop_calc = true;
+ }
+ else if (total_length + prev_offset_cm + brush_length_centimeters > position_cm)//calculate first brush
+ {
+ position_interval_centimeters = brush_length_centimeters;
+ delta_brushLenghtToStopPosition = (total_length + prev_offset_cm + brush_length_centimeters) - position_cm;
+ brush_length_centimeters = brush_length_centimeters - (delta_brushLenghtToStopPosition * delta_brushLenghtToStopPosition / brush_length_centimeters);
+ }
+ if (brushIndex == 0)// add a resolution step for first brush
+ {
+ brush_length_centimeters += resolution;
+ }
+ }
+ else//last brush or solid brush
+ {
+ brush_length_centimeters = (segment_length_cm - prev_offset_cm);
+ if (delta_brushLenghtToStopPosition > 0)//second brush
+ {
+ brush_length_centimeters = ((position_interval_centimeters - delta_brushLenghtToStopPosition) * (position_interval_centimeters - delta_brushLenghtToStopPosition)) / position_interval_centimeters;
+ stop_calc = true;
+ }
+ else if (orderedBrushCollection.Count == 1 && (total_length + segment_length_cm) > position_cm)// solid brush
+ {
+ brush_length_centimeters = position_cm - total_length;
+ stop_calc = true;
+ }
+ // add a resolution for last brush , not solid brush
+ if (orderedBrushCollection.Count > 1)
+ {
+ brush_length_centimeters -= resolution;
+ }
+ }
+
+ prev_offset_cm = brush_offset_cm;
+
+ foreach (var liquidVolumes in brush.LiquidVolumes)
+ {
+ liquidQuantities[liquidVolumes.IdsPack.PackIndex] += liquidVolumes.NanoliterPerCentimeter * (brush_length_centimeters / solid_gradient_oeff);
+ }
+ }
+ total_length += segment_length_cm;
+ }
+
+ }
+
+ foreach (var liquidQuantity in liquidQuantities)
+ {
+ int index = liquidQuantity.Key;
+ var packLevel = MachineStatus.IDSPacksLevels.SingleOrDefault(x => x.Index == index);
+ var idsPack = configuration.NoneEmptyIdsPacks.SingleOrDefault(x => x.PackIndex == index);
+
+ if (packLevel != null)
+ {
+ _currentJobLiquidQuantities.Add(new BL.ValueObjects.JobRunLiquidQuantity()
+ {
+ LiquidType = idsPack.LiquidType.Type,
+ Quantity = (int)liquidQuantities[index],
+ });
+ }
+ }
+ }
+ }
+
private void ValidateJobLiquidQuantity(JobTicket ticket, ProcessParametersTable processParameters, Configuration configuration)
{
LogManager.Log("Validating job liquid quantity...");
@@ -2201,6 +2343,7 @@ namespace Tango.Integration.Operation
var result = await SendRequest<AbortJobRequest, AbortJobResponse>(new AbortJobRequest());
}
+ SaveLastJobLiquidQuantities(clonedJob, originalJob.Machine.Configuration, handler);
OnPrintingAborted(handler, clonedJob);
handler.RaiseCanceled();
}
@@ -2366,6 +2509,8 @@ namespace Tango.Integration.Operation
return;
}
+ _machineStatusBeforeJobStart = MachineStatus.Clone();
+
LogRequestSent(request);
bool responseLogged = false;
bool completed = false; //Use this in case Shlomo is sending progress after completion.
@@ -2431,6 +2576,7 @@ namespace Tango.Integration.Operation
if (!handler.IsCanceled)
{
+ SaveLastJobLiquidQuantities(originalJob, originalJob.Machine.Configuration, handler);
OnPrintingFailed(handler, originalJob, ex);
handler.RaiseFailed(ex);
LogRequestFailed(request, ex);
@@ -2453,6 +2599,7 @@ namespace Tango.Integration.Operation
UseKeepAlive = oldKeepAlive;
Status = MachineStatuses.ReadyToDye;
+ SaveLastJobLiquidQuantities(clonedJob, originalJob.Machine.Configuration, handler);
OnPrintingCompleted(handler, clonedJob);
handler.RaiseCompleted();
}
diff --git a/Software/Visual_Studio/Tango.Integration/Tango.Integration.csproj b/Software/Visual_Studio/Tango.Integration/Tango.Integration.csproj
index a3feac546..8ade1df4e 100644
--- a/Software/Visual_Studio/Tango.Integration/Tango.Integration.csproj
+++ b/Software/Visual_Studio/Tango.Integration/Tango.Integration.csproj
@@ -106,6 +106,7 @@
<Compile Include="Operation\IGradientGenerationConfiguration.cs" />
<Compile Include="Operation\InsufficientLiquidQuantityException.cs" />
<Compile Include="Operation\JobDescriptionFile.cs" />
+ <Compile Include="Operation\JobLiquidQuantityCalculationMode.cs" />
<Compile Include="Operation\JobUnitsMethods.cs" />
<Compile Include="Operation\PowerDownHandler.cs" />
<Compile Include="Operation\PowerDownStartedEventArgs.cs" />
@@ -199,7 +200,7 @@
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<ProjectExtensions>
<VisualStudio>
- <UserProperties BuildVersion_StartDate="2000/1/1" BuildVersion_UseGlobalSettings="False" BuildVersion_BuildVersioningStyle="None.None.Increment.TimeStamp" BuildVersion_UpdateAssemblyVersion="True" BuildVersion_AssemblyInfoFilename="Properties\AssemblyInfo.cs" />
+ <UserProperties BuildVersion_AssemblyInfoFilename="Properties\AssemblyInfo.cs" BuildVersion_UpdateAssemblyVersion="True" BuildVersion_BuildVersioningStyle="None.None.Increment.TimeStamp" BuildVersion_UseGlobalSettings="False" BuildVersion_StartDate="2000/1/1" />
</VisualStudio>
</ProjectExtensions>
</Project> \ No newline at end of file