From e318068258baf07b4d1d70725a5c35232aee8547 Mon Sep 17 00:00:00 2001 From: Roy Ben Shabat Date: Thu, 10 Sep 2020 20:31:59 +0300 Subject: Improved accuracy of technician mode timer. --- .../PPC/Tango.PPC.UI/Views/LayoutView.xaml.cs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'Software') diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/LayoutView.xaml.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/LayoutView.xaml.cs index 883d3f893..b87f14b89 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/LayoutView.xaml.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/LayoutView.xaml.cs @@ -30,7 +30,7 @@ namespace Tango.PPC.UI.Views { public static LayoutView Instance { get; private set; } private LayoutViewVM _vm; - private DispatcherTimer _timer; + private System.Timers.Timer _timer; public LayoutView() { @@ -39,9 +39,9 @@ namespace Tango.PPC.UI.Views Loaded += (_, __) => _vm = DataContext as LayoutViewVM; techPressElement.RegisterForPreviewMouseOrTouchDown(OnMouseOrTouchDown); techPressElement.RegisterForPreviewMouseOrTouchUp(OnMouseOrTouchUp); - _timer = new DispatcherTimer(); - _timer.Interval = TimeSpan.FromSeconds(10); - _timer.Tick += _timer_Tick; + _timer = new System.Timers.Timer(); + _timer.Interval = TimeSpan.FromSeconds(10).TotalMilliseconds; + _timer.Elapsed += _timer_Elapsed; this.PreviewMouseUp += LayoutView_PreviewMouseUp; } @@ -51,10 +51,14 @@ namespace Tango.PPC.UI.Views _vm.ApplicationManager.ResetScreenLockTimer(); } - private void _timer_Tick(object sender, EventArgs e) + private void _timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) { _timer.Stop(); - _vm.ToggleTechnicianMode(); + + Dispatcher.BeginInvoke(new Action(() => + { + _vm.ToggleTechnicianMode(); + })); } private void OnMouseOrTouchDown(object sender, MouseOrTouchEventArgs e) -- cgit v1.3.1 From a133762c08f1bb5c413ae3baa553b7b8d99cd4f3 Mon Sep 17 00:00:00 2001 From: Roy Ben Shabat Date: Thu, 10 Sep 2020 20:53:53 +0300 Subject: Implemented Machine Studio TechBoard frames processing via concurrent queue to prevent thread collision. --- .../ViewModels/MachineTechViewVM.cs | 24 ++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) (limited to 'Software') diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/ViewModels/MachineTechViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/ViewModels/MachineTechViewVM.cs index 4205e5246..8f5c67f96 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/ViewModels/MachineTechViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Technician/ViewModels/MachineTechViewVM.cs @@ -41,6 +41,7 @@ using RealTimeGraphX.WPF; using Tango.Core.ExtensionMethods; using System.Diagnostics; using Tango.BL.Builders; +using Tango.Core; namespace Tango.MachineStudio.Technician.ViewModels { @@ -83,6 +84,9 @@ namespace Tango.MachineStudio.Technician.ViewModels private DateTime _diagnosticsStartTime; private DateTime _diagnosticsNowTime; + private ProducerConsumerQueue _framesQueue; + private Thread _populateFramesThread; + #region Properties private ObservableCollection _tabs; @@ -314,6 +318,8 @@ namespace Tango.MachineStudio.Technician.ViewModels /// The notification provider. public MachineTechViewVM(IStudioApplicationManager applicationManager, INotificationProvider notificationProvider, IDiagnosticsFrameProvider diagnosticsFrameProvider, IEventLogger eventLogger) { + _framesQueue = new ProducerConsumerQueue(); + Tabs = new ObservableCollection(); Tabs.Add(new MachineTechTabVM() { IsSelected = true, Name = "Untitled" }); SelectedTab = Tabs.First(); @@ -448,13 +454,22 @@ namespace Tango.MachineStudio.Technician.ViewModels /// The response. private void DiagnosticsFrameProvider_FrameReceived(object sender, StartDiagnosticsResponse response) { - PopulateDiagnosticsData(response); + _framesQueue.BlockEnqueue(response); } #endregion #region Populate Diagnostics Data + private void PopulateFramesThreadMethod() + { + while (!ApplicationManager.IsShuttingDown) + { + var frame = _framesQueue.BlockDequeue(); + PopulateDiagnosticsData(frame); + } + } + /// /// Populates the diagnostics data to the proper elements. /// @@ -2308,7 +2323,12 @@ namespace Tango.MachineStudio.Technician.ViewModels public override void OnApplicationReady() { - + if (_populateFramesThread == null) + { + _populateFramesThread = new Thread(PopulateFramesThreadMethod); + _populateFramesThread.IsBackground = true; + _populateFramesThread.Start(); + } } #endregion -- cgit v1.3.1 From 526019f244c1fc6f08361cd15cfce47927048823 Mon Sep 17 00:00:00 2001 From: Victoria Plitt Date: Sun, 13 Sep 2020 11:55:25 +0300 Subject: Dispenser Analyzer. A new analyzer was added - Process. Added additional level of Generic interfaces and implementation. --- Software/Visual_Studio/Tango.CSV/CsvFile.cs | 14 +- Software/Visual_Studio/Tango.CSV/CsvFileReader.cs | 3 + .../Analysis/AnalyserResultChartData.cs | 74 +++++++ .../Analysis/AnalysisService.cs | 27 ++- .../Analysis/AnalyzerResultBase.cs | 17 +- .../Analysis/DispenserReader.cs | 71 ++++++ .../Analysis/IAnalyzer.cs | 19 +- .../Analysis/IAnalyzerResult.cs | 53 +---- .../Tango.DispenserAnalyzer.UI/Analysis/IReader.cs | 17 ++ .../Analysis/ProcessReader.cs | 116 ++++++++++ .../Analyzers/DynamicSealingAnalyzer.cs | 23 +- .../Analyzers/FlowAnalyser.cs | 27 ++- .../Analyzers/PressureBuildUpAnalyser.cs | 22 +- .../Analyzers/PrimingAnalyzer.cs | 22 +- .../Analyzers/ProcessAnalyser.cs | 137 ++++++++++++ .../Analyzers/SealingAnalyzer.cs | 22 +- .../Tango.DispenserAnalyzer.UI/MainWindow.xaml | 69 ++++-- .../Tango.DispenserAnalyzer.UI/MainWindow.xaml.cs | 4 + .../Models/DispenserSample.cs | 2 +- .../Tango.DispenserAnalyzer.UI/Models/ISample.cs | 12 + .../Models/ProcessCsvRow.cs | 17 ++ .../Models/ProcessSample.cs | 25 +++ .../Tango.DispenserAnalyzer.UI/Settings.cs | 29 ++- .../Tango.DispenserAnalyzer.UI.csproj | 14 +- .../View/SettingsWnd.xaml | 245 +++++++++++---------- .../ViewModels/MainWindowVM.cs | 143 +++++------- .../ViewModels/SettingsVM.cs | 115 +++++++--- 27 files changed, 989 insertions(+), 350 deletions(-) create mode 100644 Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Analysis/AnalyserResultChartData.cs create mode 100644 Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Analysis/DispenserReader.cs create mode 100644 Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Analysis/IReader.cs create mode 100644 Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Analysis/ProcessReader.cs create mode 100644 Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Analyzers/ProcessAnalyser.cs create mode 100644 Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Models/ISample.cs create mode 100644 Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Models/ProcessCsvRow.cs create mode 100644 Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Models/ProcessSample.cs (limited to 'Software') diff --git a/Software/Visual_Studio/Tango.CSV/CsvFile.cs b/Software/Visual_Studio/Tango.CSV/CsvFile.cs index f925c0017..9b1d23bb3 100644 --- a/Software/Visual_Studio/Tango.CSV/CsvFile.cs +++ b/Software/Visual_Studio/Tango.CSV/CsvFile.cs @@ -72,6 +72,18 @@ namespace Tango.CSV return (IEnumerable)csvFileReader; } + /// + /// Gets the columns. + /// + /// + /// The CSV source. + /// + public static IEnumerable GetColumns(CsvSource csvSource) where T : new() + { + var csvFileReader = new CsvFileReader(csvSource); + return csvFileReader.Columns; + } + /// /// Gets the field separator. /// @@ -94,7 +106,7 @@ namespace Tango.CSV /// /// The columns. /// - public IEnumerable Columns { get; private set; } + public IEnumerable Columns { get; protected set; } /// /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. diff --git a/Software/Visual_Studio/Tango.CSV/CsvFileReader.cs b/Software/Visual_Studio/Tango.CSV/CsvFileReader.cs index ec5b07630..79f716aab 100644 --- a/Software/Visual_Studio/Tango.CSV/CsvFileReader.cs +++ b/Software/Visual_Studio/Tango.CSV/CsvFileReader.cs @@ -35,6 +35,8 @@ namespace Tango.CSV private readonly char textQualifier; private readonly StringBuilder parseFieldResult = new StringBuilder(); + + /// /// Initializes a new instance of the class. /// @@ -420,6 +422,7 @@ namespace Tango.CSV break; } this.columns = readColumns.ToArray(); + Columns = this.columns; } /// diff --git a/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Analysis/AnalyserResultChartData.cs b/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Analysis/AnalyserResultChartData.cs new file mode 100644 index 000000000..54431968f --- /dev/null +++ b/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Analysis/AnalyserResultChartData.cs @@ -0,0 +1,74 @@ +using OxyPlot; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.Core; + +namespace Tango.DispenserAnalyzer.UI.Analysis +{ + public class AnalyzerResultChartData : ExtendedObject + { + public ObservableCollection Points { get; set; } + + public string Title { get; set; } + + private int _step; + public int XStep + { + get { return _step; } + set { _step = value; RaisePropertyChangedAuto(); } + } + + private double _fromXAxis; + public double FromXAxis + { + get { return _fromXAxis; } + set { _fromXAxis = value; RaisePropertyChangedAuto(); } + } + + private double _toXAxis; + public double ToXAxis + { + get { return _toXAxis; } + set { _toXAxis = value; RaisePropertyChangedAuto(); } + } + + private double _fromYAxis; + public double FromYAxis + { + get { return _fromYAxis; } + set { _fromYAxis = value; RaisePropertyChangedAuto(); } + } + + private double _toYAxis; + public double ToYAxis + { + get { return _toYAxis; } + set { _toYAxis = value; RaisePropertyChangedAuto(); } + } + + public void UpdateData() + { + _toYAxis = Points.Max(x => x.Y) + 2; + _fromYAxis = Points.Min(x => x.Y) - 1; + _toXAxis = Points.Max(x => x.X); + _fromXAxis = Points.Min(x => x.X); + + RaisePropertyChanged("Title"); + RaisePropertyChanged("Points"); + } + + public AnalyzerResultChartData() + { + Points = new ObservableCollection(); + _fromYAxis = 0; + _fromXAxis = 0; + _toYAxis = 1; + _toXAxis = 1; + XStep = 1; + } + } +} diff --git a/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Analysis/AnalysisService.cs b/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Analysis/AnalysisService.cs index 0bebb4f11..0dbf9a83e 100644 --- a/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Analysis/AnalysisService.cs +++ b/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Analysis/AnalysisService.cs @@ -4,24 +4,37 @@ using System.Linq; using System.Reflection; using System.Text; using System.Threading.Tasks; +using Tango.CSV; +using Tango.DispenserAnalyzer.UI.Models; +using System.Windows.Controls; +using System.Windows.Media; +using System.IO; namespace Tango.DispenserAnalyzer.UI.Analysis { public class AnalysisService { - public static IAnalyzer GetAnalyzer(String fileName) + public static dynamic GetAnalyzer(String fileName) { - var analyzerTypes = typeof(AnalysisService).Assembly.GetTypes().Where(x => typeof(IAnalyzer).IsAssignableFrom(x)).ToList(); - // var words = fileName.Split().Select(x => x.Trim(' ')); - var analyzerType = analyzerTypes.FirstOrDefault(x => fileName.IndexOf(x.GetCustomAttribute().Name, StringComparison.OrdinalIgnoreCase) >= 0); - return (analyzerType != null) ? Activator.CreateInstance(analyzerType) as IAnalyzer : null; + string filename = Path.GetFileNameWithoutExtension(fileName); + + var analyzerTypes = typeof(AnalysisService).Assembly.GetTypes().Where(x => typeof(IBaseAnalyzer).IsAssignableFrom(x)).ToList(); + var analyzerType = analyzerTypes.FirstOrDefault(x => filename.StartsWith(x.GetCustomAttribute().Name, StringComparison.OrdinalIgnoreCase) ); + if(analyzerType == null) + {//in case name of test is not first word + analyzerType = analyzerTypes.FirstOrDefault(x => filename.IndexOf(x.GetCustomAttribute().Name, StringComparison.OrdinalIgnoreCase) >= 0); + } + + return (analyzerType != null) ? Activator.CreateInstance(analyzerType) : null; } public static string GetTestName(String fileName) { - var analyzerTypes = typeof(AnalysisService).Assembly.GetTypes().Where(x => typeof(IAnalyzer).IsAssignableFrom(x)).ToList(); - var analyzerType = analyzerTypes.SingleOrDefault(x => fileName.Contains(x.GetCustomAttribute().Name)); + var analyzerTypes = typeof(AnalysisService).Assembly.GetTypes().Where(x => typeof(IBaseAnalyzer).IsAssignableFrom(x)).ToList(); + var analyzerType = analyzerTypes.FirstOrDefault(x => fileName.IndexOf(x.GetCustomAttribute().Name, StringComparison.OrdinalIgnoreCase) >= 0); + return analyzerType.GetCustomAttribute().Name; } } + } diff --git a/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Analysis/AnalyzerResultBase.cs b/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Analysis/AnalyzerResultBase.cs index d3d217409..bc82d2215 100644 --- a/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Analysis/AnalyzerResultBase.cs +++ b/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Analysis/AnalyzerResultBase.cs @@ -15,7 +15,7 @@ namespace Tango.DispenserAnalyzer.UI.Analysis public class AnalyzerResultBase : ExtendedObject, IAnalyzerResult { public AnalyzerResultValue Result { get; set; } - public List PlotValues { get; set; } + // public List PlotValues { get; set; } //public ObservableCollection Points { get; set; } public List Properties @@ -53,17 +53,22 @@ namespace Tango.DispenserAnalyzer.UI.Analysis } public bool IsShowPlotResult { get; set; } - public AnalyzerResultPlotData RangeToCountChart { get; set; } - public AnalyzerResultPlotData RangeToTimeChart { get; set; } + public bool IsShowLineChartResult { get; set; } + public AnalyzerResultChartData RangeToCountChart { get; set; } + public AnalyzerResultChartData RangeToTimeChart { get; set; } + public AnalyzerResultChartData LineChart { get; set; } public bool BackgroundMode { get; set; } + public AnalyzerResultBase() { - PlotValues = new List(); + //PlotValues = new List(); Result = AnalyzerResultValue.Undetermined; IsShowPlotResult = false; - RangeToCountChart = new AnalyzerResultPlotData(); - RangeToTimeChart = new AnalyzerResultPlotData(); + IsShowLineChartResult = false; + RangeToCountChart = new AnalyzerResultChartData(); + RangeToTimeChart = new AnalyzerResultChartData(); + LineChart = new AnalyzerResultChartData(); BackgroundMode = false; } } diff --git a/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Analysis/DispenserReader.cs b/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Analysis/DispenserReader.cs new file mode 100644 index 000000000..8bb519425 --- /dev/null +++ b/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Analysis/DispenserReader.cs @@ -0,0 +1,71 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.CSV; +using Tango.DispenserAnalyzer.UI.Models; +using OxyPlot.Annotations; +using System.Windows.Media; +using System.Diagnostics; + +namespace Tango.DispenserAnalyzer.UI.Analysis +{ + public class DispenserReader: IReader + { + public List ReadScvFile(String filePath, List annotations) + { + List data = CsvFile.Read(new CsvSource(filePath)).ToList(); + List samples = new List(); + int index = 0; + int last_labelIndex = 0; + foreach (var item in data) + { + double pressure = 0; + if (item.Label == "Label") + { + item.Pressure = "0"; + item.Command = "Label"; + if (last_labelIndex == 0 || last_labelIndex < (index + 5)) + { + last_labelIndex = index; + + OxyPlot.Wpf.LineAnnotation _line = new OxyPlot.Wpf.LineAnnotation() + { + StrokeThickness = 1, + Color = Color.FromRgb(255, 5, 5), + Type = LineAnnotationType.Vertical, + Text = index.ToString(), + X = index, + }; + annotations.Add(_line); + + } + } + if (double.TryParse(item.Pressure, out pressure) || !String.IsNullOrWhiteSpace(item.Command)) + { + samples.Add(new DispenserSample() + { + Pressure = pressure, + Command = String.IsNullOrWhiteSpace(item.Command) ? null : item.Command, + Index = index + }); + index++; + } + } + return samples; + } + + public List GetTitles(String filePath) + { + string xAxistitle = "Time[msec]"; + string yAxistitle = "Pressure [mbar]"; + return new List() { xAxistitle, yAxistitle }; + } + + public bool PrintResultsToPDFFile() + { + return true ; + } + } +} diff --git a/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Analysis/IAnalyzer.cs b/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Analysis/IAnalyzer.cs index 6d522da82..fd3b3c267 100644 --- a/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Analysis/IAnalyzer.cs +++ b/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Analysis/IAnalyzer.cs @@ -7,9 +7,24 @@ using Tango.DispenserAnalyzer.UI.Models; namespace Tango.DispenserAnalyzer.UI.Analysis { + [Analyzer("BaseInterface")] + public interface IBaseAnalyzer + { + + } [Analyzer("INTERFACE")] - public interface IAnalyzer + public interface IAnalyzer: IBaseAnalyzer + { + IReader Reader { get; set; } + Task> Process(List csvRows, bool backgroundMode); + void GetPoints(List samples, IList points); + } + [Analyzer("DISPENSERINTERFACE")] + public interface IDispenserDispenserAnalyser : IAnalyzer + { + } + [Analyzer("PROCESSINTERFACE")] + public interface IProcessAnalyzer : IAnalyzer { - Task> Process(List csvRows, bool backgroundMode); } } diff --git a/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Analysis/IAnalyzerResult.cs b/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Analysis/IAnalyzerResult.cs index 60f7fcb36..5203828e5 100644 --- a/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Analysis/IAnalyzerResult.cs +++ b/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Analysis/IAnalyzerResult.cs @@ -5,62 +5,17 @@ using System.Collections.ObjectModel; using System.Linq; using System.Text; using System.Threading.Tasks; -using Tango.Core; namespace Tango.DispenserAnalyzer.UI.Analysis { - public class AnalyzerResultPlotData: ExtendedObject - { - public ObservableCollection Points { get; set; } - - public string Title { get; set; } - - private int _step; - public int XStep - { - get { return _step; } - set { _step = value; RaisePropertyChangedAuto(); } - } - - private double _from; - public double From - { - get { return _from; } - set { _from = value; RaisePropertyChangedAuto(); } - } - - private double _to; - public double To - { - get { return _to; } - set { _to = value; RaisePropertyChangedAuto(); } - } - - public void UpdateData() - { - _to = Points.Max(x => x.Y) + 2; - _from = Points.Min(x => x.Y)-1; - RaisePropertyChanged("Title"); - RaisePropertyChanged("Points"); - } - - public AnalyzerResultPlotData() - { - Points = new ObservableCollection(); - _from = 0; - _to = 1; - XStep = 1; - } - - } public interface IAnalyzerResult { AnalyzerResultValue Result { get; set; } bool BackgroundMode { get; set; } - List PlotValues { get; set; } - - AnalyzerResultPlotData RangeToCountChart { get; set; } - AnalyzerResultPlotData RangeToTimeChart { get; set; } + //List PlotValues { get; set; } + + //AnalyzerResultChartData RangeToCountChart { get; set; } + //AnalyzerResultChartData RangeToTimeChart { get; set; } } } diff --git a/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Analysis/IReader.cs b/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Analysis/IReader.cs new file mode 100644 index 000000000..35c7f8f76 --- /dev/null +++ b/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Analysis/IReader.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.DispenserAnalyzer.UI.Analysis +{ + public interface IReader + { + List ReadScvFile(String filePath, List annotations); + + List GetTitles(String filePath); + + bool PrintResultsToPDFFile(); + } +} diff --git a/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Analysis/ProcessReader.cs b/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Analysis/ProcessReader.cs new file mode 100644 index 000000000..b2e6f0388 --- /dev/null +++ b/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Analysis/ProcessReader.cs @@ -0,0 +1,116 @@ +using OxyPlot; +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.CSV; +using Tango.DispenserAnalyzer.UI.Models; +using OxyPlot.Annotations; +using System.Windows.Media; + + +namespace Tango.DispenserAnalyzer.UI.Analysis +{ + public class ProcessReader: IReader + { + public List ReadScvFile(String filePath, List annotations) + { + List samples = new List(); + try + { + List data = CsvFile.Read(new CsvSource(filePath)).ToList(); + + double index = 0; + double delta = 0; + if (data.Count > 2) + { + DateTime time1; + DateTime time2; + if (DateTime.TryParse(data[0].Time, out time1) && DateTime.TryParse(data[1].Time, out time2)) + { + int m1 = time1.Millisecond; + int m2 = time2.Millisecond; + delta = (time2 - time1).Milliseconds / 100; + } + } + delta = Settings.GetValueByName(AnalyzerSettingsEnum.TimeInterval); + if(delta == 0) + return samples; + + int endPoint = (int)(Settings.GetValueByName(AnalyzerSettingsEnum.EndCalculation) / delta); + foreach (var item in data) + { + double dValue = 0; + + if (double.TryParse(item.Value, out dValue)) + { + DateTime time; + DateTime.TryParse(item.Time, out time); + int mil = time.Millisecond; + samples.Add(new ProcessSample() + { + Time = time, + Value = dValue, + TimeIntervalSec = index, + }); + index += delta; + } + } + OxyPlot.Wpf.LineAnnotation _line1 = new OxyPlot.Wpf.LineAnnotation() + { + StrokeThickness = 1, + Color = Color.FromRgb(255, 5, 5), + Type = LineAnnotationType.Vertical, + Text = index.ToString(), + X = Settings.GetValueByName(AnalyzerSettingsEnum.StartCalculation) + }; + annotations.Add(_line1); + OxyPlot.Wpf.LineAnnotation _line2 = new OxyPlot.Wpf.LineAnnotation() + { + StrokeThickness = 1, + Color = Color.FromRgb(255, 5, 5), + Type = LineAnnotationType.Vertical, + Text = index.ToString(), + X = Settings.GetValueByName(AnalyzerSettingsEnum.EndCalculation) + }; + annotations.Add(_line2); + + + return samples; + } + catch (Exception ex) + { + Debug.Write("Exception in ProcessReader ReadScvFile" + ex.Message); + return samples; + } + } + + public List GetScvColumns(String filePath) + { + try + { + return CsvFile.GetColumns(new CsvSource(filePath)).ToList(); + } + catch (Exception ex) + { + Debug.Write("Exception in ProcessReader ReadScvFile" + ex.Message); + return null; + } + } + + public List GetTitles(String filePath) + { + List columns = GetScvColumns(filePath); + string xAxistitle = "Time [sec]"; + string yAxistitle = columns!= null && columns.Count > 1 ? columns[1] : "Values"; + return new List() { xAxistitle, yAxistitle }; + } + + public bool PrintResultsToPDFFile() + { + return false; + } + } +} diff --git a/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Analyzers/DynamicSealingAnalyzer.cs b/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Analyzers/DynamicSealingAnalyzer.cs index 8acd1651c..d440f42c3 100644 --- a/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Analyzers/DynamicSealingAnalyzer.cs +++ b/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Analyzers/DynamicSealingAnalyzer.cs @@ -10,8 +10,19 @@ using Tango.DispenserAnalyzer.UI.Models; namespace Tango.DispenserAnalyzer.UI.Analyzers { [Analyzer("dynamic")] - public class DynamicSealingAnalzyer : IAnalyzer + public class DynamicSealingAnalzyer : IDispenserDispenserAnalyser { + private IReader _reader; + public IReader Reader + { + get { return _reader; } + set { _reader = value; } + } + public DynamicSealingAnalzyer() + { + Reader = new DispenserReader(); + } + public Task> Process(List csvRows, bool backgroundMode) { return Task.Factory.StartNew>(() => @@ -61,6 +72,16 @@ namespace Tango.DispenserAnalyzer.UI.Analyzers return results; }); } + + public void GetPoints(List samples, IList points) + { + samples.ForEach(x => + { + if (x.Pressure != 0.0) + { points.Add(new OxyPlot.DataPoint(x.Index, x.Pressure)); } + }); + } + public class DynamicSealingAnalyzerResult : AnalyzerResultBase { [Description("Dynamic sealing result")] diff --git a/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Analyzers/FlowAnalyser.cs b/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Analyzers/FlowAnalyser.cs index 492fb3e6a..81c578e5c 100644 --- a/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Analyzers/FlowAnalyser.cs +++ b/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Analyzers/FlowAnalyser.cs @@ -19,15 +19,28 @@ namespace Tango.DispenserAnalyzer.UI.Analyzers { [Analyzer("flow")] - public class FlowAnalyser : IAnalyzer + public class FlowAnalyser : IDispenserDispenserAnalyser { + private IReader _reader; + public IReader Reader + { + get { return _reader; } + set { _reader = value; } + } + + + public FlowAnalyser() + { + Reader = new DispenserReader(); + } + public Task> Process(List csvRows, bool backgroundMode) { return Task.Factory.StartNew>(() => { List results = new List(); List commands = csvRows.Where(x => x.Command != null && x.Command.ToLower().Contains("label")).ToList(); - var pairs = commands.Select((x, i) => new { Index = i, Value = x }).GroupBy(x => x.Index / 2).Select(x => x.Select(v => v.Value).ToList()).ToList(); + var pairs = commands.Select((x, i) => new { Index = i, Value = x }).GroupBy(x => x.Index/2 ).Select(x => x.Select(v => v.Value).ToList()).ToList(); MovingAverageFilter filter = new MovingAverageFilter(); int flowtestNumber = 0; for (int index = 0; index < pairs.Count(); index++) @@ -101,6 +114,16 @@ namespace Tango.DispenserAnalyzer.UI.Analyzers return results; }); } + + public void GetPoints(List samples, IList points) + { + samples.ForEach(x => + { + if (x.Pressure != 0.0) + { points.Add(new OxyPlot.DataPoint(x.Index, x.Pressure)); } + }); + } + public class FlowAverageAnalyzerResult : AnalyzerResultBase { [Description("Average Value")] diff --git a/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Analyzers/PressureBuildUpAnalyser.cs b/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Analyzers/PressureBuildUpAnalyser.cs index 79b643294..9288eb2ad 100644 --- a/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Analyzers/PressureBuildUpAnalyser.cs +++ b/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Analyzers/PressureBuildUpAnalyser.cs @@ -9,8 +9,19 @@ using Tango.DispenserAnalyzer.UI.Models; namespace Tango.DispenserAnalyzer.UI.Analyzers { [Analyzer("pressure build up")] - public class PressureBuildUpAnalyser : IAnalyzer + public class PressureBuildUpAnalyser : IDispenserDispenserAnalyser { + private IReader _reader; + public IReader Reader + { + get { return _reader; } + set { _reader = value; } + } + + public PressureBuildUpAnalyser() + { + Reader = new DispenserReader(); + } public Task> Process(List csvRows, bool backgroundMode) { return Task.Factory.StartNew>(() => @@ -36,6 +47,15 @@ namespace Tango.DispenserAnalyzer.UI.Analyzers return results; }); } + + public void GetPoints(List samples, IList points) + { + samples.ForEach(x => + { + if (x.Pressure != 0.0) + { points.Add(new OxyPlot.DataPoint(x.Index, x.Pressure)); } + }); + } } } diff --git a/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Analyzers/PrimingAnalyzer.cs b/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Analyzers/PrimingAnalyzer.cs index cfd4a7b55..315c384d6 100644 --- a/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Analyzers/PrimingAnalyzer.cs +++ b/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Analyzers/PrimingAnalyzer.cs @@ -11,8 +11,19 @@ using Tango.DispenserAnalyzer.UI.Models; namespace Tango.DispenserAnalyzer.UI.Analyzers { [Analyzer("priming")] - public class PrimingAnalyzer : IAnalyzer + public class PrimingAnalyzer : IDispenserDispenserAnalyser { + private IReader _reader; + public IReader Reader + { + get { return _reader; } + set { _reader = value; } + } + + public PrimingAnalyzer() + { + Reader = new DispenserReader(); + } public Task> Process(List csvRows, bool backgroundMode) { return Task.Factory.StartNew>(() => @@ -35,6 +46,15 @@ namespace Tango.DispenserAnalyzer.UI.Analyzers return results; }); } + + public void GetPoints(List samples, IList points) + { + samples.ForEach(x => + { + if (x.Pressure != 0.0) + { points.Add(new OxyPlot.DataPoint(x.Index, x.Pressure)); } + }); + } } public class PrimingAnalyzerResult : AnalyzerResultBase { diff --git a/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Analyzers/ProcessAnalyser.cs b/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Analyzers/ProcessAnalyser.cs new file mode 100644 index 000000000..65fe9c85d --- /dev/null +++ b/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Analyzers/ProcessAnalyser.cs @@ -0,0 +1,137 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.CSV; +using Tango.DispenserAnalyzer.UI.Analysis; +using Tango.DispenserAnalyzer.UI.Models; + +namespace Tango.DispenserAnalyzer.UI.Analyzers +{ + [Analyzer("process")] + public class ProcessAnalyser : IProcessAnalyzer + { + private IReader _reader; + public IReader Reader { + get { return _reader; } + set { _reader = value; } + } + + public ProcessAnalyser() + { + Reader = new ProcessReader(); + } + + public Task> Process(List csvRows, bool backgroundMode) + { + return Task.Factory.StartNew>(() => + { + List results = new List(); + ProcessAnalyzerResult result = new ProcessAnalyzerResult(); + result.BackgroundMode = backgroundMode; + double delta = Settings.GetValueByName(AnalyzerSettingsEnum.TimeInterval); + int startPoint = delta == 0? 0 : (int)(Settings.GetValueByName(AnalyzerSettingsEnum.StartCalculation) / delta); + int endPoint = delta == 0 ? (csvRows.Count -1) : (int)(Settings.GetValueByName(AnalyzerSettingsEnum.EndCalculation) / delta); + List rangeValues = csvRows.Skip(startPoint).Take(endPoint).ToList(); + + result.MinValue = rangeValues.Min(x => x.Value); + result.MaxValue = rangeValues.Max(x => x.Value); + result.AverageValue = rangeValues.Average(x => x.Value); + result.StandardDeviation = ProcessAnalyser.StdDev(rangeValues.Select(x => x.Value)); + + result.Result = AnalyzerResultValue.Passed; + + //Move Average data + List tasks = new List(); + int calc_count = (int)csvRows.Count() / 4; + int start_index = 0; + while (start_index < csvRows.Count()) + { + int calc_amount = (start_index + calc_count) >= (csvRows.Count() - 4) ? csvRows.Count() - start_index : calc_count; + var source_filter = csvRows.Skip(start_index).Take(calc_amount).ToList(); + tasks.Add(Task.Run(() => + { + ProcessAnalyser.Filtering(source_filter); + })); + start_index += calc_amount; + } + Task.WaitAll(tasks.ToArray()); + + result.CreateMovingAvgGraph(csvRows); + results.Add(result); + return results; + }); + } + + public static double StdDev(IEnumerable values) + { + double avg = values.Average(); + double sum = values.Sum(v => (v - avg) * (v - avg)); + double denominator = values.Count() - 1; + return denominator > 0.0 ? Math.Sqrt(sum / denominator) : -1; + } + public static void Filtering(List source) + { + int periodAverage = (int)Settings.GetValueByName(AnalyzerSettingsEnum.MovingAvg); + int count = (source.Count < periodAverage) ? source.Count : source.Count - periodAverage; + for (int i = 0; i < count; i++) + { + source[i].Value = source.Skip(i).Take(periodAverage).Average(x => x.Value); + } + } + + public void GetPoints(List samples, IList points) + { + samples.ForEach(x => + { + points.Add(new OxyPlot.DataPoint(x.TimeIntervalSec, x.Value)); + }); + } + + } + + public class ProcessAnalyzerResult : AnalyzerResultBase + { + [Description("Selected Area")] + public string Header { get; set; } + + [Description("Average Value")] + public double AverageValue { get; set; } + [Description("Max value")] + public double MaxValue { get; set; } + [Description("Min value")] + public double MinValue { get; set; } + [Description("Standard deviation value")] + public double StandardDeviation { get; set; } + + + public ProcessAnalyzerResult() + { + double from = Settings.GetValueByName(AnalyzerSettingsEnum.StartCalculation); + double to = Settings.GetValueByName(AnalyzerSettingsEnum.EndCalculation); + Header = $"from {from} to {to} seconds"; + AverageValue = MaxValue = MinValue = 0.0; + Result = AnalyzerResultValue.Undetermined; + IsShowLineChartResult = true; + } + + public void CreateMovingAvgGraph(List avgValues) + { + if (!BackgroundMode) + { + var points = LineChart.Points; + points.Clear(); + avgValues.ForEach(x => + { + points.Add(new OxyPlot.DataPoint(x.TimeIntervalSec, x.Value)); + }); + + LineChart.Title = $"Moving Average Values"; + LineChart.UpdateData(); + } + } + + } +} diff --git a/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Analyzers/SealingAnalyzer.cs b/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Analyzers/SealingAnalyzer.cs index e1fe232c3..841101b10 100644 --- a/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Analyzers/SealingAnalyzer.cs +++ b/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Analyzers/SealingAnalyzer.cs @@ -10,8 +10,19 @@ using Tango.DispenserAnalyzer.UI.Models; namespace Tango.DispenserAnalyzer.UI.Analyzers { [Analyzer("sealtest")] - public class SealingAnalyzer : IAnalyzer + public class SealingAnalyzer : IDispenserDispenserAnalyser { + private IReader _reader; + public IReader Reader + { + get { return _reader; } + set { _reader = value; } + } + + public SealingAnalyzer() + { + Reader = new DispenserReader(); + } public Task> Process(List csvRows, bool backgroundMode) { return Task.Factory.StartNew>(() => @@ -38,6 +49,15 @@ namespace Tango.DispenserAnalyzer.UI.Analyzers return results; }); } + + public void GetPoints(List samples, IList points) + { + samples.ForEach(x => + { + if (x.Pressure != 0.0) + { points.Add(new OxyPlot.DataPoint(x.Index, x.Pressure)); } + }); + } } public class SealingAnalyzerResult : AnalyzerResultBase diff --git a/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/MainWindow.xaml b/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/MainWindow.xaml index e56ae6639..595d74e3d 100644 --- a/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/MainWindow.xaml +++ b/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/MainWindow.xaml @@ -48,33 +48,34 @@ - - - + + + + + + + + + + + + + + + + + + + + + + - - + + @@ -130,7 +131,27 @@ - + + + + + + + + + + + + + + + + diff --git a/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/MainWindow.xaml.cs b/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/MainWindow.xaml.cs index d328ea8a5..e7d263a1c 100644 --- a/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/MainWindow.xaml.cs +++ b/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/MainWindow.xaml.cs @@ -43,6 +43,10 @@ namespace Tango.DispenserAnalyzer.UI for (int index = 0; index < filePathArr.Length; index++) { await _vm.GenerateInBackground(filePathArr[index]); + if(index < filePathArr.Length) + { + await Task.Delay(500); + } } } await Task.Delay(500); diff --git a/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Models/DispenserSample.cs b/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Models/DispenserSample.cs index d1d37955d..899aaa600 100644 --- a/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Models/DispenserSample.cs +++ b/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Models/DispenserSample.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace Tango.DispenserAnalyzer.UI.Models { - public class DispenserSample + public class DispenserSample: ISample { public double Pressure { get; set; } public String Command { get; set; } diff --git a/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Models/ISample.cs b/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Models/ISample.cs new file mode 100644 index 000000000..ea374a846 --- /dev/null +++ b/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Models/ISample.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.DispenserAnalyzer.UI.Models +{ + public interface ISample + { + } +} diff --git a/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Models/ProcessCsvRow.cs b/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Models/ProcessCsvRow.cs new file mode 100644 index 000000000..33e85d5b5 --- /dev/null +++ b/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Models/ProcessCsvRow.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.CSV; + +namespace Tango.DispenserAnalyzer.UI.Models +{ + public class ProcessCsvRow + { + [CsvOrder(0)] + public String Time { get; set; } + [CsvOrder(1)] + public String Value { get; set; } + } +} \ No newline at end of file diff --git a/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Models/ProcessSample.cs b/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Models/ProcessSample.cs new file mode 100644 index 000000000..3f02ea35d --- /dev/null +++ b/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Models/ProcessSample.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.DispenserAnalyzer.UI.Models +{ + public class ProcessSample : ISample + { + public double TimeIntervalSec { get; set; } + public DateTime Time { get; set; } + public double Value { get; set; } + + public ProcessSample() + { + Value = 0.0; + } + + public override string ToString() + { + return $"{TimeIntervalSec}, {Value}"; + } + } +} diff --git a/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Settings.cs b/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Settings.cs index 9a1f10aed..b8084b2d3 100644 --- a/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Settings.cs +++ b/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Settings.cs @@ -9,7 +9,8 @@ namespace Tango.DispenserAnalyzer.UI { public enum AnalyzerSettingsEnum { - //Undetermined + [Description("Print Results to PDF file")] + PrintResultsToPDF, [Description("PBU Pass fail")] PBUPassFail, [Description("PBU Pass fail")] @@ -28,6 +29,15 @@ namespace Tango.DispenserAnalyzer.UI MaxError, [Description("Take off 'Max-min' values(out of highest results)")] TakeOffMaxMin, + [Description("Time gap between data point [sec]")] + TimeInterval, + [Description("Time point to start calculation [sec]")] + StartCalculation, + [Description("Time point to end calculation [sec]")] + EndCalculation, + [Description("How many points to use for moving average")] + MovingAvg + } @@ -39,7 +49,6 @@ namespace Tango.DispenserAnalyzer.UI static Settings() { DefaultValues = new Dictionary(); - DefaultValues[AnalyzerSettingsEnum.PBUPassFail] = 4.5; DefaultValues[AnalyzerSettingsEnum.FlowPBUPassFail] = 4.5; DefaultValues[AnalyzerSettingsEnum.ExcludeAnalysis] = 1800; @@ -49,17 +58,13 @@ namespace Tango.DispenserAnalyzer.UI DefaultValues[AnalyzerSettingsEnum.MaxMinIntervals] = 300; DefaultValues[AnalyzerSettingsEnum.MaxError] = 1.5; DefaultValues[AnalyzerSettingsEnum.TakeOffMaxMin] = 3; + DefaultValues[AnalyzerSettingsEnum.TimeInterval] = 0.1; + DefaultValues[AnalyzerSettingsEnum.StartCalculation] = 600; + DefaultValues[AnalyzerSettingsEnum.EndCalculation] = 900; + DefaultValues[AnalyzerSettingsEnum.MovingAvg] = 50; - CurrentValues = new Dictionary(); - CurrentValues[AnalyzerSettingsEnum.PBUPassFail] = 4.5; - CurrentValues[AnalyzerSettingsEnum.FlowPBUPassFail] = 4.5; - CurrentValues[AnalyzerSettingsEnum.ExcludeAnalysis] = 1800; - CurrentValues[AnalyzerSettingsEnum.AvgMinValue] = 1400; - CurrentValues[AnalyzerSettingsEnum.AvgMaxValue] = 1850; - CurrentValues[AnalyzerSettingsEnum.MaxMinRange] = 500; - CurrentValues[AnalyzerSettingsEnum.MaxMinIntervals] = 300; - CurrentValues[AnalyzerSettingsEnum.MaxError] = 1.5; - CurrentValues[AnalyzerSettingsEnum.TakeOffMaxMin] = 3; + CurrentValues = new Dictionary(DefaultValues); + } public static double GetValueByName(AnalyzerSettingsEnum name) { diff --git a/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Tango.DispenserAnalyzer.UI.csproj b/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Tango.DispenserAnalyzer.UI.csproj index b7db85ef8..5a261fb85 100644 --- a/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Tango.DispenserAnalyzer.UI.csproj +++ b/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Tango.DispenserAnalyzer.UI.csproj @@ -15,7 +15,7 @@ true true false - P:\Users - Public\Ori\Dispenser Analyzer\ + P:\Dispenser Analyzer Installer\ true Disk false @@ -29,8 +29,8 @@ Dispenser Analyser Twine false - 4 - 2.1.1.%2a + 2 + 3.1.1.%2a true true true @@ -126,17 +126,22 @@ MSBuild:Compile Designer + + + + + @@ -144,6 +149,9 @@ + + + diff --git a/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/View/SettingsWnd.xaml b/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/View/SettingsWnd.xaml index 2bfa2bba1..d8d4594b8 100644 --- a/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/View/SettingsWnd.xaml +++ b/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/View/SettingsWnd.xaml @@ -6,7 +6,7 @@ xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes" xmlns:local="clr-namespace:Tango.DispenserAnalyzer.UI.View" mc:Ignorable="d" - Title="Settings" Height="630" Width="800" FontSize="22" ResizeMode="NoResize" WindowStyle="ToolWindow" Closing="Window_Closing"> + Title="Settings" Height="690" Width="800" FontSize="22" ResizeMode="NoResize" WindowStyle="ToolWindow" Closing="Window_Closing"> @@ -64,138 +64,149 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + - - + - + - - - - - - - - - - - - - - Pressure build up test - - - - - - - - - - - - - - - - - - - Flow test - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + diff --git a/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/ViewModels/MainWindowVM.cs b/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/ViewModels/MainWindowVM.cs index 38f8dee81..48d426d23 100644 --- a/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/ViewModels/MainWindowVM.cs +++ b/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/ViewModels/MainWindowVM.cs @@ -126,7 +126,24 @@ namespace Tango.DispenserAnalyzer.UI.ViewModels } } - + private string _titleAxisBottom; + + public string TitleAxisBottom + { + get { return _titleAxisBottom; } + set { _titleAxisBottom = value; RaisePropertyChangedAuto(); } + } + + private string _titleAxisLeft; + + public string TitleAxisLeft + { + get { return _titleAxisLeft; } + set { _titleAxisLeft = value; RaisePropertyChangedAuto(); } + } + + + private bool _isRunning; /// /// Gets or sets a value indicating whether this instance is running. @@ -162,7 +179,8 @@ namespace Tango.DispenserAnalyzer.UI.ViewModels XStep = 1; AnalyzerResults = new ObservableCollection(); _isRunning = false; - + TitleAxisBottom = ""; + TitleAxisLeft = ""; this.Points = new List(); } @@ -251,69 +269,38 @@ namespace Tango.DispenserAnalyzer.UI.ViewModels return; ResetSettings(); - IAnalyzer analyzer = AnalysisService.GetAnalyzer(OpenFilePath); + var analyzer = AnalysisService.GetAnalyzer(OpenFilePath); if (analyzer == null) return; IsRunning = true; - AnalyzerAttribute attribute = (AnalyzerAttribute)analyzer.GetType().GetCustomAttributes(typeof(AnalyzerAttribute), true).FirstOrDefault(); - - TestName = attribute.Name; - List data = CsvFile.Read(new CsvSource(OpenFilePath)).ToList(); - List samples = new List(); - - To = 0; - From = 0; - int index = 0; - int last_labelIndex = 0; - - - foreach (var item in data) + AnalyzerAttribute[] attr = analyzer.GetType().GetCustomAttributes(typeof(AnalyzerAttribute), true); + if (attr != null && attr.Count() > 0) { - double pressure = 0; - if(item.Label == "Label") - { - item.Pressure = "0"; - item.Command = "Label"; - if (last_labelIndex == 0 || last_labelIndex < (index + 5)) - { - last_labelIndex = index; - - OxyPlot.Wpf.LineAnnotation _line = new OxyPlot.Wpf.LineAnnotation() - { - StrokeThickness = 1, - Color = Color.FromRgb(255, 5, 5), - Type = LineAnnotationType.Vertical, - Text = index.ToString(), - X = index, - }; - PlotControl.Annotations.Add(_line); - - } - } - if (double.TryParse(item.Pressure, out pressure) || !String.IsNullOrWhiteSpace(item.Command)) - { - samples.Add(new DispenserSample() - { - Pressure = pressure, - Command = String.IsNullOrWhiteSpace(item.Command) ? null : item.Command, - Index = index - }); - index++; - } + TestName = attr[0].Name; + } + List annotations = new List(); + var samples = analyzer.Reader.ReadScvFile(OpenFilePath, annotations); + analyzer.GetPoints(samples, Points); + if (Points.Count == 0) + { + IsRunning = false; + return; } + annotations.ForEach(x => PlotControl.Annotations.Add(x)); + To = 0; + From = 0; + List res = await analyzer.Process(samples, false); AnalyzerResults = new ObservableCollection(res); - samples.ForEach(x => - { - if (x.Pressure != 0.0) - { Points.Add(new DataPoint(x.Index, x.Pressure)); } - }); _to = Points.Max(x => x.Y); _from = TestName.Contains("sealtest") ? Points.FirstOrDefault(x => x.X == 0).Y : Points.Min(x => x.Y); + List titles = analyzer.Reader.GetTitles(OpenFilePath); + TitleAxisBottom = titles[0]; + TitleAxisLeft = titles[1]; - data.Clear(); + // data.Clear(); _to += 100; RaisePropertyChanged("To"); if (_from != 0) @@ -324,8 +311,10 @@ namespace Tango.DispenserAnalyzer.UI.ViewModels IsRunning = false; PlotControl.InvalidatePlot(true); - await PrintToXpsFile(); - + if(analyzer.Reader.PrintResultsToPDFFile()) + { + await PrintToXpsFile(); + } } /// @@ -338,44 +327,24 @@ namespace Tango.DispenserAnalyzer.UI.ViewModels if (false == File.Exists(OpenFilePath) || IsFileLocked(OpenFilePath)) return; - IAnalyzer analyzer = AnalysisService.GetAnalyzer(OpenFilePath); + var analyzer = AnalysisService.GetAnalyzer(OpenFilePath); if (analyzer == null) return; - - AnalyzerAttribute attribute = (AnalyzerAttribute)analyzer.GetType().GetCustomAttributes(typeof(AnalyzerAttribute), true).FirstOrDefault(); - - TestName = attribute.Name; - List data = CsvFile.Read(new CsvSource(OpenFilePath)).ToList(); - List samples = new List(); - - int index = 0; - int last_labelIndex = 0; + AnalyzerAttribute[] attr = analyzer.GetType().GetCustomAttributes(typeof(AnalyzerAttribute), true); + if (attr != null && attr.Count() > 0) + { + TestName = attr[0].Name; + } - foreach (var item in data) + List annotations = new List(); + var samples = analyzer.Reader.ReadScvFile(OpenFilePath, annotations); + analyzer.GetPoints(samples, Points); + if (Points.Count == 0) { - double pressure = 0; - if (item.Label == "Label") - { - item.Pressure = "0"; - item.Command = "Label"; - if (last_labelIndex == 0 || last_labelIndex < (index + 5)) - { - last_labelIndex = index; - } - } - if (double.TryParse(item.Pressure, out pressure) || !String.IsNullOrWhiteSpace(item.Command)) - { - samples.Add(new DispenserSample() - { - Pressure = pressure, - Command = String.IsNullOrWhiteSpace(item.Command) ? null : item.Command, - Index = index - }); - index++; - } + return; } - + List res = await analyzer.Process(samples, true); AnalyzerResults = new ObservableCollection(res); diff --git a/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/ViewModels/SettingsVM.cs b/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/ViewModels/SettingsVM.cs index d5c54ab08..0f2b5a457 100644 --- a/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/ViewModels/SettingsVM.cs +++ b/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/ViewModels/SettingsVM.cs @@ -9,79 +9,124 @@ using Tango.SharedUI; namespace Tango.DispenserAnalyzer.UI.ViewModels { - public class SettingsVM : ViewModel, IDisposable + public class SettingVM: ViewModel { - private ObservableCollection _PBUSettings; + private string _name; - public ObservableCollection PBUTestSettings + public string Name { - get { return _PBUSettings; } - set { _PBUSettings = value; RaisePropertyChangedAuto(); } + get { return _name; } + set { _name = value; } } - private ObservableCollection _flowTestSettings; + private ObservableCollection _settings; + + public ObservableCollection Settings + { + get { return _settings; } + set { _settings = value; RaisePropertyChangedAuto(); } + } - public ObservableCollection FlowTestSettings + public SettingVM(string name) { - get { return _flowTestSettings; } - set { _flowTestSettings = value; RaisePropertyChangedAuto(); } + _settings = new ObservableCollection(); + Name = name; } - private Dictionary changedValues; + public void AddSettings(List settings) + { + settings.ForEach(x => Settings.Add(x)); + } + + + } + public class SettingsVM : ViewModel, IDisposable + { + public Dictionary ChangedValues { get; set; } + + private ObservableCollection _settings; + public ObservableCollection Settings + { + get { return _settings; } + set { _settings = value; RaisePropertyChangedAuto(); } + } + public SettingsVM() { - _PBUSettings = new ObservableCollection(); + _settings = new ObservableCollection(); + ChangedValues = new Dictionary(); InitPBUTestSettings(); - _flowTestSettings = new ObservableCollection(); - changedValues = new Dictionary(); + InitProcessSettings(); InitFlowTestSettings(); + } private void InitPBUTestSettings() { - var setting = new SettingsModel(AnalyzerSettingsEnum.PBUPassFail, "4.5 sec"); - setting.SettingValueEvent += new EventHandler(OnSettingValueChanged); - _PBUSettings.Add(setting); + SettingVM model = new SettingVM("Pressure build up"); + List list = new List(); + list.Add(new SettingsModel(AnalyzerSettingsEnum.PBUPassFail, "4.5 sec")); + model.AddSettings(list); + list.ForEach(x => x.SettingValueEvent += new EventHandler(OnSettingValueChanged)); + Settings.Add(model); } private void InitFlowTestSettings() { - _flowTestSettings.Add(new SettingsModel(AnalyzerSettingsEnum.FlowPBUPassFail, "4.5 sec")); - _flowTestSettings.Add(new SettingsModel(AnalyzerSettingsEnum.ExcludeAnalysis, "1800 reads")); - _flowTestSettings.Add(new SettingsModel(AnalyzerSettingsEnum.AvgMinValue, "1400-1850 [mbar]", true)); - _flowTestSettings.Add(new SettingsModel(AnalyzerSettingsEnum.MaxMinRange, "500 reads")); - _flowTestSettings.Add(new SettingsModel(AnalyzerSettingsEnum.MaxMinIntervals, "300 reads")); - _flowTestSettings.Add(new SettingsModel(AnalyzerSettingsEnum.MaxError, "1.5%")); - _flowTestSettings.Add(new SettingsModel(AnalyzerSettingsEnum.TakeOffMaxMin, "3")); - - _flowTestSettings.ToList().ForEach(x => x.SettingValueEvent += new EventHandler(OnSettingValueChanged)); + SettingVM model = new SettingVM("Flow test"); + List list = new List(); + + list.Add(new SettingsModel(AnalyzerSettingsEnum.FlowPBUPassFail, "4.5 sec")); + list.Add(new SettingsModel(AnalyzerSettingsEnum.ExcludeAnalysis, "1800 reads")); + list.Add(new SettingsModel(AnalyzerSettingsEnum.AvgMinValue, "1400-1850 [mbar]", true)); + list.Add(new SettingsModel(AnalyzerSettingsEnum.MaxMinRange, "500 reads")); + list.Add(new SettingsModel(AnalyzerSettingsEnum.MaxMinIntervals, "300 reads")); + list.Add(new SettingsModel(AnalyzerSettingsEnum.MaxError, "1.5%")); + list.Add(new SettingsModel(AnalyzerSettingsEnum.TakeOffMaxMin, "3")); + list.ForEach(x => x.SettingValueEvent += new EventHandler(OnSettingValueChanged)); + model.AddSettings(list); + Settings.Add(model); + } + + private void InitProcessSettings() + { + SettingVM model = new SettingVM("Process"); + List list = new List(); + list.Add(new SettingsModel(AnalyzerSettingsEnum.TimeInterval, "0.1 sec")); + list.Add(new SettingsModel(AnalyzerSettingsEnum.StartCalculation, "600 sec")); + list.Add(new SettingsModel(AnalyzerSettingsEnum.EndCalculation, "900 sec")); + list.Add(new SettingsModel(AnalyzerSettingsEnum.MovingAvg, "50 points")); + list.ForEach(x => x.SettingValueEvent += new EventHandler(OnSettingValueChanged)); + model.AddSettings(list); + Settings.Add(model); } private void OnSettingValueChanged(object sender, EventArgs e) { - if(sender is SettingsModel) + if (sender is SettingsModel) { SettingsModel settingModel = sender as SettingsModel; - if(settingModel.IsRangeVisible) + if (settingModel.IsRangeVisible) { - changedValues[AnalyzerSettingsEnum.AvgMinValue] = settingModel.MinRangeValue; - changedValues[AnalyzerSettingsEnum.AvgMaxValue] = settingModel.MaxRangeValue; + ChangedValues[AnalyzerSettingsEnum.AvgMinValue] = settingModel.MinRangeValue; + ChangedValues[AnalyzerSettingsEnum.AvgMaxValue] = settingModel.MaxRangeValue; } else - changedValues[settingModel._enumName] = settingModel.PropertyValue; + ChangedValues[settingModel._enumName] = settingModel.PropertyValue; } } - + public Dictionary GetChanges() { - return changedValues; + return ChangedValues; } - + public void Dispose() { - _PBUSettings.ToList().ForEach(x => x.SettingValueEvent -= OnSettingValueChanged); - _flowTestSettings.ToList().ForEach(x => x.SettingValueEvent -= OnSettingValueChanged); + Settings.ToList().ForEach(x => { + x.Settings.ToList().ForEach(k => k.SettingValueEvent -= OnSettingValueChanged); + }); } } } -- cgit v1.3.1 From 1ad6cf1498affb02a86f9901b5e95f0ec34abc58 Mon Sep 17 00:00:00 2001 From: Shlomo Hecht Date: Sun, 13 Sep 2020 16:04:22 +0300 Subject: Version 1.5.0.1: Thread load changes, 4 winders, RFID, ARC head --- .../Embedded_SW/Embedded/Common/SW_Info/SW_Info.c | 2 +- .../Embedded_SW/Embedded/Drivers/Motors/Motor.h | 8 +- .../Embedded/Drivers/Motors/MotorActions.c | 424 ++++++++++++++++----- .../Modules/Diagnostics/DiagnosticsHoming.c | 112 +++--- .../Embedded_SW/Embedded/Modules/General/buttons.c | 5 +- .../Embedded/Modules/Stubs_Handler/Progress.c | 37 ++ .../Embedded/Modules/Thread/ThreadLoad.c | 220 +++++------ .../Embedded/Modules/Thread/Thread_print.c | 16 +- 8 files changed, 556 insertions(+), 268 deletions(-) (limited to 'Software') diff --git a/Software/Embedded_SW/Embedded/Common/SW_Info/SW_Info.c b/Software/Embedded_SW/Embedded/Common/SW_Info/SW_Info.c index bf2c4e98d..a607fedcb 100644 --- a/Software/Embedded_SW/Embedded/Common/SW_Info/SW_Info.c +++ b/Software/Embedded_SW/Embedded/Common/SW_Info/SW_Info.c @@ -20,7 +20,7 @@ typedef struct } TangoVersion_t; -TangoVersion_t _gTangoVersion = {1,4,6,44}; +TangoVersion_t _gTangoVersion = {1,5,0,1}; #define BUILD_DATE __DATE__ char Dat[50] = BUILD_DATE; char _gTangoName [MAX_STRING_LEN] = "Tango01 ";//e diff --git a/Software/Embedded_SW/Embedded/Drivers/Motors/Motor.h b/Software/Embedded_SW/Embedded/Drivers/Motors/Motor.h index e6947a8d4..00cada255 100644 --- a/Software/Embedded_SW/Embedded/Drivers/Motors/Motor.h +++ b/Software/Embedded_SW/Embedded/Drivers/Motors/Motor.h @@ -312,6 +312,7 @@ uint32_t MotorStop(TimerMotors_t _motorId, STOP_TYPE_ENUM StopType); uint32_t MotorMove(TimerMotors_t _motorId,bool direction, uint32_t Steps); uint32_t MotorMoveWithCallback (TimerMotors_t _motorId,bool direction, uint32_t Steps, callback_fptr callback,uint32_t timeout); +uint32_t MotorRunWithCallback (TimerMotors_t MotorId,bool direction, uint32_t Freq, callback_fptr callback,uint32_t timeout); uint32_t MotorGotoWithCallback (TimerMotors_t MotorId, uint32_t Steps, uint32_t LimitSwitchId,callback_fptr callback,uint32_t timeout); //TODO uint32_t MotorGotoWithBusyCallback (TimerMotors_t MotorId,bool direction, uint32_t Steps, callback_fptr callback,uint32_t timeout); //TODO @@ -352,7 +353,12 @@ uint32_t MotorMovetoBreakSensor (TimerMotors_t _motorId,bool direction, uint32_t uint32_t MotorMovetoDancerPosition (TimerMotors_t _motorId,bool direction, uint32_t Freq,uint32_t DancerId,bool dancervaluedirection, callback_fptr callback,uint32_t timeout); uint32_t MotorAbortMovetoLimitSwitch (TimerMotors_t _motorId); uint32_t MotorMoveToStopper (TimerMotors_t _motorId,bool direction, uint32_t Speed, callback_fptr callback,uint32_t backlash,uint32_t timeout); -uint32_t MotorMovetoEncoderPosition (TimerMotors_t MotorId, callback_fptr callback,uint32_t timeout, bool direction); +uint32_t MotorMovetoEncoderPosition (TimerMotors_t MotorId, callback_fptr callback,uint32_t timeout, bool direction,uint32_t speed); +uint32_t LoadingArmReset (callback_fptr callback,uint32_t timeout); +uint32_t LoadingStopArmReset (void); + +float Calculate_Arm_Angle(uint32_t Drier_Center,uint32_t Current_Angle); +int Calculate_Arm_Distance(uint32_t Drier_Center,uint32_t Current_Angle); uint32_t MotorStopAction (TimerMotors_t MotorId); //Stop the controlled action of a motor diff --git a/Software/Embedded_SW/Embedded/Drivers/Motors/MotorActions.c b/Software/Embedded_SW/Embedded/Drivers/Motors/MotorActions.c index f33edee50..be0475b28 100644 --- a/Software/Embedded_SW/Embedded/Drivers/Motors/MotorActions.c +++ b/Software/Embedded_SW/Embedded/Drivers/Motors/MotorActions.c @@ -39,11 +39,26 @@ //callback_fptr MotorMovetoLimitSwitchCallback[NUM_OF_MOTORS]; callback_fptr MotorCallback[NUM_OF_MOTORS]; ControlCBFunction MotorControlCallback[NUM_OF_MOTORS]; +uint32_t DrierZeroPosition = 0; +//uint32_t DryerBackLash = 0; +//bool DrierBackLashDirection = false; +uint32_t Arm_Drier_Center = 0; +callback_fptr UnloadingReset = NULL; +/*int CallbackCalls=0; +int FirstCall = 0; +#define MAX_CONTROL_SAMPLES 10*/ +int32_t ArmSamples[MAX_CONTROL_SAMPLES] = {0}; +int ArmSamplePointer = {0}; +int StoredavreageSampleValue = 0; +uint32_t CallbackCalls = 0; +int32_t Initialcurrentposition =0; +int cycles = 0; uint32_t MotorMoveCallBackFunction(uint32_t deviceId, uint32_t BusyFlag); uint32_t MotorSetSpeedCallBackFunction(uint32_t deviceId, uint32_t BusyFlag); uint32_t MotorVerifiedCallBackFunction(uint32_t IfIndex, uint32_t BusyFlag); uint32_t MotorMoveToLimitSwitchCallBackFunction(uint32_t IfIndex, uint32_t LimitSwitch); +uint32_t MotorRunCallBackFunction(uint32_t IfIndex, uint32_t BusyFlag); //uint32_t MotorMoveControlId[NUM_OF_MOTORS]; //uint32_t MotorSetSpeedControlId[NUM_OF_MOTORS]; //uint32_t MotorMovetoLimitSwitchControlId[NUM_OF_MOTORS]; @@ -206,6 +221,173 @@ uint32_t MotorGotoWithBusyCallback (TimerMotors_t MotorId,bool direction, uint32 int32_t AccumulatedArmMovement = 0; int32_t InitialArmLocation = 0; bool ArmDirection = true; +int failCounter = 0; +uint32_t MotorRunWithCallback (TimerMotors_t MotorId,bool direction, uint32_t Freq, callback_fptr callback,uint32_t timeout) //TODO +{ + ReportWithPackageFilter(GeneralFilter,"MotorRunWithCallback",__FILE__,direction,MotorId,RpMessage,Freq,0); + + //call driver action to device id with the parameter + //SetMotorSpeed (deviceId, parameter); + MotorCallback[MotorId] = callback; + MotorTimeout[MotorId] = 0; + MotorTimeLag[MotorId] = 20; + MotorTimeLimit[MotorId] = timeout; + if (MotorId ==HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM) + { + InitialArmLocation = Read_Dryer_ENC_Position(0,0); + AccumulatedArmMovement = 0; + ArmDirection = direction; + MCU_E2PromRead(EEPROM_STORAGE_DRYER_CENTER,&DrierZeroPosition); + failCounter = 0; + MotorSetDirection(HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM,direction); + MotorSetSpeed(HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM,Freq); + } + else + { + return ERROR; + } + MotorControlId[MotorId] = AddControlCallback(NULL, MotorRunCallBackFunction, /*eTenMillisecond*/20, MotorControlGetnBusyState,(IfTypeMotors*0x100+MotorId), MotorId, 0 ); + MotorControlCallback[MotorId] = MotorMoveCallBackFunction; + return MotorControlId[MotorId]; +} +uint32_t MotorRunCallBackFunction(uint32_t IfIndex, uint32_t BusyFlag) //TODO +{ + uint32_t MotorId,encoder,temp = 0,tt; + uint32_t Busy = BusyFlag; + int angle; + + if (IfIndex>>8 != IfTypeMotors) + { + LOG_ERROR (IfIndex, "Wrong Interface type"); + return 0xFFFFFFFF; + } + MotorId = IfIndex&0xFF; + CallbackCalls++; + + if (MotorId ==HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM) + { + encoder = Read_Dryer_ENC_Position(0,0); + tt=InitialArmLocation; + if (ArmDirection == 1-MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM].directionthreadwize) //unloading - numbers going down + { + //previous number is bigger than current + if (InitialArmLocation>encoder) + { + temp = InitialArmLocation-encoder; + if ((temp>25)&&(temp<1000)) + { + AccumulatedArmMovement+=temp; + InitialArmLocation=encoder; + } + } + else if (InitialArmLocation25)&&(temp<1000)) + { + AccumulatedArmMovement+=temp; + InitialArmLocation=encoder; + InitialArmLocation=encoder; + } + } + } + else //loading - going up + { + //previous number is smaller than current + if (InitialArmLocation25)&&(temp<1000)) + { + AccumulatedArmMovement+=temp; + InitialArmLocation=encoder; + } + } + else if (InitialArmLocation>encoder)//rollover + { + temp = 0x3FFF + encoder -InitialArmLocation; + if ((temp>25)&&(temp<1000)) + { + AccumulatedArmMovement+=temp; + InitialArmLocation=encoder; + } + } + } + if (((temp>1000)||(temp<20))&&(CallbackCalls>10)) + { + Report("MotorRunCallBackFunctionMotorRunCallBackFunction temp curr prev small",__FILE__,encoder,tt,RpWarning,temp,0); + failCounter++; + if (failCounter>=10) + { + Report("arm stopped",__FILE__,failCounter,encoder,RpWarning,temp,0); + MotorStop(HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM,Hard_Hiz); + BusyFlag = NOTBUSY; + } + } + else + { + failCounter = 0; + BusyFlag = BUSY; + } + if (CallbackCalls%50 == 0) + { + //encoder = Read_Dryer_ENC_Position(0,0); + Report("MotorRunCallBackFunctionMotorRunCallBackFunction periodic curr prev total",__FILE__,encoder,temp,RpWarning,AccumulatedArmMovement,0); + } + if (CallbackCalls%200 == 0) + { + //encoder = Read_Dryer_ENC_Position(0,0); + Report("MotorRunCallBackFunctionMotorRunCallBackFunction",__FILE__,__LINE__,encoder,RpWarning,CallbackCalls,0); + } + } + else + { + if (CallbackCalls%100 == 1) + { + Report("MotorRunCallBackFunction wrong motor",__FILE__,MotorId,MotorTimeout[MotorId],RpWarning,MotorTimeLimit[MotorId],0); + return ERROR; + } + } + MotorTimeout[MotorId]+=MotorTimeLag[MotorId]; + + if ((BusyFlag == NOTBUSY)||((MotorTimeout[MotorId]>=MotorTimeLimit[MotorId])&&(MotorTimeLimit[MotorId]>0))) + { + if (MotorId == HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM) + { + angle = Calculate_Arm_Distance(Arm_Drier_Center,temp); + + if ((angle<400)||(angle>16000)) + { + BusyFlag = NOTBUSY; + } + else + { + BusyFlag = BUSY; + } + Report("arm stopped call",__FILE__,failCounter,encoder,RpWarning,abs(DrierZeroPosition-encoder),0); + } + //stop this control loop + Report("MotorControlGetnBusyState stop",__FILE__,MotorId,BusyFlag,RpMessage,MotorCallback[MotorId],0); + SafeRemoveControlCallback(MotorControlId[MotorId], MotorRunCallBackFunction ); + MotorControlCallback[MotorId] = 0; + MotorControlId[MotorId] = 0xFF; + //possibly: start regular control (speed etc) + //uint32_t ControlId = AddControlCallback(NULL,ControlCBFunction Callback, eOneMillisecond, (IfTypeMotors*0x100+MotorId), deviceId, Parameter ); + if ((MotorTimeout[MotorId]>=MotorTimeLimit[MotorId])&&(MotorTimeLimit[MotorId]>0)) + { + Report("motor timeout",__FILE__,__LINE__,MotorId,RpMessage,MotorTimeout[MotorId],0); + Busy = BUSY; + } + Report("MotorRunCallBackFunctionMotorRunCallBackFunction curr prev return",__FILE__,encoder,temp,RpWarning,AccumulatedArmMovement,0); + //call the module callback + if (MotorCallback[MotorId]) + { + MotorCallback[MotorId](MotorId,Busy); + } + + } + return OK; +} uint32_t MotorMoveWithCallback (TimerMotors_t MotorId,bool direction, uint32_t Steps, callback_fptr callback,uint32_t timeout) //TODO { @@ -224,31 +406,28 @@ uint32_t MotorMoveWithCallback (TimerMotors_t MotorId,bool direction, uint32_t S MotorTimeout[MotorId] = 0; MotorTimeLag[MotorId] = 20; MotorTimeLimit[MotorId] = timeout; - if (MotorId ==HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM) + /*if (MotorId ==HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM) { InitialArmLocation = Read_Dryer_ENC_Position(0,0); AccumulatedArmMovement = 0; ArmDirection = direction; + MCU_E2PromRead(EEPROM_STORAGE_DRYER_CENTER,&DrierZeroPosition); + failCounter = 0; + MotorSetSpeed(HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM,MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM].maxfrequency); + } + else*/ + { + //MotorStop(MotorId,Hard_Hiz ); + MotorMove(MotorId,direction,Steps ); + } + if (MotorId ==HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM) + { + Task_sleep (100); } - - //MotorStop(MotorId,Hard_Hiz ); - MotorMove(MotorId,direction,Steps ); MotorControlId[MotorId] = AddControlCallback(NULL, MotorMoveCallBackFunction, /*eTenMillisecond*/20, MotorControlGetnBusyState,(IfTypeMotors*0x100+MotorId), MotorId, 0 ); MotorControlCallback[MotorId] = MotorMoveCallBackFunction; return MotorControlId[MotorId]; } -uint32_t DryerBackLash = 0; -uint32_t DrierZeroPosition = 0; -bool DrierBackLashDirection = false; -int CallbackCalls=0; -int FirstCall = 0; -#define MAX_CONTROL_SAMPLES 10 -int32_t ArmSamples[MAX_CONTROL_SAMPLES] = {0}; -int ArmSamplePointer = {0}; -int StoredavreageSampleValue = 0; - -int32_t Initialcurrentposition =0; -int cycles = 0; uint32_t MotorVerifiedCallBackFunction(uint32_t IfIndex, uint32_t ArmPosition) //TODO { uint32_t MotorId; @@ -262,6 +441,7 @@ uint32_t MotorVerifiedCallBackFunction(uint32_t IfIndex, uint32_t ArmPosition) / MotorId = IfIndex&0xFF; MotorPosition = ArmPosition; CallbackCalls++; + if (CallbackCalls%20 == 0) { // REPORT_MSG(MotorPosition,"MotorVerifiedCallBackFunction"); @@ -276,11 +456,6 @@ uint32_t MotorVerifiedCallBackFunction(uint32_t IfIndex, uint32_t ArmPosition) / Read_Dryer_ENC_Position(); //trigger the next call ArmSamples[ArmSamplePointer] = MotorPosition;//(-1 * TranslatedReadValue); - if (FirstCall<5) - { - FirstCall++; - return OK; - } ArmSamples[ArmSamplePointer] = MotorPosition;//(-1 * TranslatedReadValue); ArmSamplePointer++; if (ArmSamplePointer >= MAX_CONTROL_SAMPLES) @@ -320,13 +495,13 @@ uint32_t MotorVerifiedCallBackFunction(uint32_t IfIndex, uint32_t ArmPosition) / Task_sleep(5);*/ // MCU_E2PromProgram(EEPROM_STORAGE_DRYER_CENTER,DrierZeroPosition); - Report("MotorVerifiedCallBackFunction",__FILE__,__LINE__,DrierZeroPosition,RpWarning,DryerBackLash,0); + Report("MotorVerifiedCallBackFunction",__FILE__,__LINE__,DrierZeroPosition,RpWarning,avreageSampleValue,0); //call the module callback if (MotorCallback[MotorId]) MotorCallback[MotorId](MotorId,ArmPosition); MotorSetDirection(HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM,MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM].directionthreadwize); - MotorMovetoEncoderPosition(HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM,NULL,1000,MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM].directionthreadwize); + MotorMovetoEncoderPosition(HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM,NULL,1000,MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM].directionthreadwize,40); DrierZeroPosition = Read_Dryer_ENC_Position(); //trigger the next call } @@ -359,12 +534,8 @@ uint32_t MotorMoveToStopper (TimerMotors_t MotorId,bool direction, uint32_t Spee MotorStop(MotorId,Hard_Hiz ); Task_sleep(5); - DryerBackLash = backlash; - DrierBackLashDirection = 1-direction; MotorSetDirection( MotorId, direction); - CallbackCalls = 0; - FirstCall = 0; MotorGetPositionFromFPGA(MotorId); memset(ArmSamples,0,sizeof(ArmSamples)); ArmSamplePointer = 0; @@ -422,11 +593,14 @@ uint32_t MotorMoveToDrierPositionCallBackFunction(uint32_t IfIndex, uint32_t Rea //call the module callback if (MotorCallback[MotorId]) + { + Report("MotorMoveToDrierPosition callback",__FILE__,__LINE__,MotorCallback[MotorId],RpWarning,ReadValue,0); MotorCallback[MotorId](MotorId,ReadValue); + } } return OK; } -uint32_t MotorMovetoEncoderPosition (TimerMotors_t MotorId, callback_fptr callback,uint32_t timeout, bool direction) +uint32_t MotorMovetoEncoderPosition (TimerMotors_t MotorId, callback_fptr callback,uint32_t timeout, bool direction,uint32_t speed) { //assert (callback); uint32_t currentposition = 0; @@ -446,6 +620,7 @@ uint32_t MotorMovetoEncoderPosition (TimerMotors_t MotorId, callback_fptr callb currentposition = Control_Read_Dryer_Position(0,0); MCU_E2PromRead(EEPROM_STORAGE_DRYER_CENTER,&DrierZeroPosition); Report("MotorMovetoEncoderPosition",__FILE__,__LINE__,DrierZeroPosition,RpWarning,currentposition,0); + Report("MotorMovetoEncoderPosition callback",__FILE__,__LINE__,callback,RpWarning,speed,0); if (abs(currentposition - DrierZeroPosition)<5) { if (callback) @@ -456,7 +631,7 @@ uint32_t MotorMovetoEncoderPosition (TimerMotors_t MotorId, callback_fptr callb //MotorSetDirection( MotorId, direction); MotorSetDirection(MotorId,direction); - MotorSetSpeed (MotorId, 30); + MotorSetSpeed (MotorId, speed); MotorControlId[MotorId] = AddControlCallback(NULL, MotorMoveToDrierPositionCallBackFunction, 2,Control_Read_Dryer_Position,(IfTypeMotors*0x100+MotorId), MotorId, 0 ); MotorControlCallback[MotorId] = MotorMoveToDrierPositionCallBackFunction; MotorTimeout[MotorId] = 0; @@ -480,78 +655,22 @@ uint32_t MotorSetSpeedWithCallback (TimerMotors_t MotorId, uint32_t _freq, callb } uint32_t MotorMoveCallBackFunction(uint32_t IfIndex, uint32_t BusyFlag) //TODO { - uint32_t MotorId,encoder,temp = 0,tt; + uint32_t MotorId; uint32_t Busy = BusyFlag; + if (IfIndex>>8 != IfTypeMotors) { LOG_ERROR (IfIndex, "Wrong Interface type"); return 0xFFFFFFFF; } MotorId = IfIndex&0xFF; - CallbackCalls++; + if (MotorId ==HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM) { - encoder = Read_Dryer_ENC_Position(0,0); - tt=InitialArmLocation; - if (ArmDirection == 1-MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM].directionthreadwize) //unloading - numbers going down - { - //previous number is bigger than current - if (InitialArmLocation>encoder) - { - temp = InitialArmLocation-encoder; - if ((temp>25)&&(temp<1000)) - { - AccumulatedArmMovement+=temp; - InitialArmLocation=encoder; - } - } - else if (InitialArmLocation25)&&(temp<1000)) - { - AccumulatedArmMovement+=temp; - InitialArmLocation=encoder; - InitialArmLocation=encoder; - } - } - } - else //loading - going up - { - //previous number is smaller than current - if (InitialArmLocation25)&&(temp<1000)) - { - AccumulatedArmMovement+=temp; - InitialArmLocation=encoder; - } - } - else if (InitialArmLocation>encoder)//rollover - { - temp = 0x3FFF + encoder -InitialArmLocation; - if ((temp>25)&&(temp<1000)) - { - AccumulatedArmMovement+=temp; - InitialArmLocation=encoder; - } - } - } - /*if (temp>1000) - { - Report("MotorMoveCallBackFunction temp curr prev total",__FILE__,encoder,tt,RpWarning,temp,0); - }*/ - if (CallbackCalls%50 == 0) - { - //encoder = Read_Dryer_ENC_Position(0,0); - Report("MotorMoveCallBackFunction periodic curr prev total",__FILE__,encoder,temp,RpWarning,AccumulatedArmMovement,0); - } if (CallbackCalls%200 == 0) { - //encoder = Read_Dryer_ENC_Position(0,0); - Report("MotorMoveCallBackFunction",__FILE__,__LINE__,encoder,RpWarning,CallbackCalls,0); + Report("MotorMoveCallBackFunction",__FILE__,__LINE__,MotorId,RpWarning,Read_Dryer_ENC_Position(0,0),0); } } else @@ -565,10 +684,6 @@ uint32_t MotorMoveCallBackFunction(uint32_t IfIndex, uint32_t BusyFlag) //TODO if ((BusyFlag == NOTBUSY)||((MotorTimeout[MotorId]>=MotorTimeLimit[MotorId])&&(MotorTimeLimit[MotorId]>0))) { - /*if (MotorId == HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM) - { - printBusy = false; - }*/ //stop this control loop Report("MotorControlGetnBusyState stop",__FILE__,MotorId,BusyFlag,RpMessage,MotorTimeout[MotorId],0); SafeRemoveControlCallback(MotorControlId[MotorId], MotorMoveCallBackFunction ); @@ -581,7 +696,6 @@ uint32_t MotorMoveCallBackFunction(uint32_t IfIndex, uint32_t BusyFlag) //TODO Report("motor timeout",__FILE__,__LINE__,MotorId,RpMessage,MotorTimeout[MotorId],0); Busy = BUSY; } - Report("MotorMoveCallBackFunction curr prev total",__FILE__,encoder,temp,RpWarning,AccumulatedArmMovement,0); //call the module callback if (MotorCallback[MotorId]) { @@ -977,6 +1091,14 @@ uint32_t MotorAbortMovetoLimitSwitch (TimerMotors_t MotorId) } //call driver action to device id with the parameter //SetMotorSpeed (deviceId, parameter); + if (MotorId == HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM) + { + if (UnloadingReset) + { + UnloadingReset(MotorId, BUSY); + UnloadingReset = NULL; + } + } MotorStop(MotorId,Hard_Hiz); MotorCallback[MotorId] = NULL; @@ -984,7 +1106,121 @@ uint32_t MotorAbortMovetoLimitSwitch (TimerMotors_t MotorId) return OK; } +float Calculate_Arm_Angle(uint32_t Drier_Center,uint32_t Current_Angle) +{ + float angle; + float Calc_angle; + if (Current_Angle >= Drier_Center) + angle = Current_Angle - Drier_Center; + else + angle = Current_Angle + 0x3FFF - Drier_Center; + Calc_angle = (float)(angle/0x3FFF); + MCU_E2PromProgram(EEPROM_DRIER_LOADING_ARM_ANGLE,Calc_angle); + ReportWithPackageFilter(DiagnosticsFilter,"Calculate_Arm_Angle",__FILE__,(int)(Calc_angle*1000),Current_Angle,RpMessage,Drier_Center,0); + return Calc_angle; +} +int Calculate_Arm_Distance(uint32_t Drier_Center,uint32_t Current_Angle) +{ + int angle; + if (Current_Angle >= Drier_Center) + angle = Current_Angle - Drier_Center; + else + angle = Current_Angle + 0x3FFF - Drier_Center; + ReportWithPackageFilter(DiagnosticsFilter,"Calculate_Arm_Distance",__FILE__,angle,Current_Angle,RpMessage,Drier_Center,0); + return angle; +} + +uint32_t LoadingArmReset_Callback_Stopper_Callback(uint32_t deviceID, uint32_t BusyFlag) +{ + ReportWithPackageFilter(DiagnosticsFilter,"LoadingArmReset_Callback_Stopper_Callback time",__FILE__,__LINE__,msec_millisecondCounter,RpMessage,0,0); + + if (UnloadingReset) + { + UnloadingReset(deviceID, BusyFlag); + UnloadingReset = NULL; + } + + return OK; +} +uint32_t LoadingArmReset_Callback(uint32_t MotorId, uint32_t ReadValue) +{ + bool direction; + int angle = 0; + + uint32_t temp = Read_Dryer_ENC_Position(); + angle = Calculate_Arm_Distance(Arm_Drier_Center,temp); + ReportWithPackageFilter(DiagnosticsFilter,"LoadingArmReset_Callback",__FILE__,angle,temp,RpMessage,Arm_Drier_Center,0); + //ReportWithPackageFilter(DiagnosticsFilter,"Diagnostics_Dryer_UnLoading_Callback details",__FILE__,(int)(TotalLoadedLen),D_numberOfCycles,RpMessage,CallbackCounter,0); + //if ((AccumulatedArmMovement>8000 )&&(ReadValue == NOTBUSY)) // OK - take another round + if (ReadValue == NOTBUSY) // OK - take another round + { + ReportWithPackageFilter(DiagnosticsFilter,"LoadingArmReset_Callback OK",__FILE__,__LINE__,Arm_Drier_Center,RpMessage,ReadValue,0); + MCU_E2PromProgram(EEPROM_STORAGE_DRYER_CYCLES,0); + if ((angle<400)||(angle>16000)) + //if (fabs(angle)<0.2) + { + ReportWithPackageFilter(DiagnosticsFilter,"drier center proximity",__FILE__,temp,Arm_Drier_Center,RpMessage,angle,0); + if (angle<400) + direction = 1-MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM].directionthreadwize; + else + direction = MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM].directionthreadwize; + MotorMovetoEncoderPosition(HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM,LoadingArmReset_Callback_Stopper_Callback,6000,direction,10); + + } + else + { + ReportWithPackageFilter(DiagnosticsFilter,"LoadingArmReset_Callback Fail",__FILE__,__LINE__,Arm_Drier_Center,RpMessage,ReadValue,0); + MotorStop(HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM,Hard_Stop); + if (UnloadingReset) + { + UnloadingReset(MotorId, ReadValue); + UnloadingReset = NULL; + } + } + + } + else //timeout or no movement + { + ReportWithPackageFilter(DiagnosticsFilter,"Unloading drier - halted",__FILE__,__LINE__,Arm_Drier_Center,RpMessage,0,0); + //MCU_E2PromProgram(EEPROM_STORAGE_DRYER_CYCLES,LoadArmRounds-(D_numberOfCycles-2));//it takes two cycles to identify a stop of the arm + + ReportWithPackageFilter(DiagnosticsFilter,"Drier unloading timeout(1) or no movement",__FILE__,temp,Arm_Drier_Center,RpWarning,ReadValue,0); + if (UnloadingReset) + { + UnloadingReset(MotorId, ReadValue); + UnloadingReset = NULL; + } + } + return OK; +} + +uint32_t LoadingArmReset (callback_fptr callback,uint32_t timeout) //TODO +{ + uint32_t temp; + + if (UnloadingReset == NULL) + UnloadingReset = callback; + else + { + ReportWithPackageFilter(DiagnosticsFilter,"LoadingArmReset is active",__FILE__,__LINE__,timeout,RpMessage, 0,0); + return ERROR; + } + MCU_E2PromRead(EEPROM_STORAGE_DRYER_CENTER,&temp); + Arm_Drier_Center = temp; + ReportWithPackageFilter(DiagnosticsFilter,"LoadingArmReset",__FILE__,__LINE__,timeout,RpMessage, 0,0); + + MotorRunWithCallback (HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM, 1-MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM].directionthreadwize, + MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM].pulseperround/6*MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM].pulleyradius, LoadingArmReset_Callback, 300000); + + return OK; + +} +uint32_t LoadingStopArmReset(void) +{ + return MotorAbortMovetoLimitSwitch(HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM); + +} void MotorActionsInit(void) { int i; diff --git a/Software/Embedded_SW/Embedded/Modules/Diagnostics/DiagnosticsHoming.c b/Software/Embedded_SW/Embedded/Modules/Diagnostics/DiagnosticsHoming.c index b40bbe4c7..9eba08678 100644 --- a/Software/Embedded_SW/Embedded/Modules/Diagnostics/DiagnosticsHoming.c +++ b/Software/Embedded_SW/Embedded/Modules/Diagnostics/DiagnosticsHoming.c @@ -133,7 +133,7 @@ uint32_t LoadArmRounds; uint32_t D_numberOfSteps = 0; float D_numberOfCycles = 0; -double D_DrierPrevLocation = 0; +uint32_t D_DrierPrevLocation = 0; uint32_t MotorHomingRequestFunc(MessageContainer* requestContainer) @@ -465,30 +465,33 @@ return OK; /******************************************************************************** * Drier Loading Arm Homing ********************************************************************************/ -uint32_t Drier_Center = 0; -float Calculate_Arm_Angle(uint32_t Current_Angle) -{ - uint32_t angle; - float Calc_angle; - if (Current_Angle >= Drier_Center) - angle = Current_Angle - Drier_Center; - else - angle = Current_Angle + 0x3FFF - Drier_Center; - Calc_angle = angle/0x3FFF; - MCU_E2PromProgram(EEPROM_DRIER_LOADING_ARM_ANGLE,Calc_angle); - ReportWithPackageFilter(DiagnosticsFilter,"Calculate_Arm_Angle",__FILE__,(int)(Calc_angle*1000),Current_Angle,RpMessage,Drier_Center,0); - return Calc_angle; -} +uint32_t Drier_Center_read = 0; uint32_t Diagnostics_Set_Load_Arm_To_Stopper_Callback(uint32_t deviceID, uint32_t BusyFlag) { MessageContainer responseContainer; MotorHomingResponse response = MOTOR_HOMING_RESPONSE__INIT; + uint32_t angle, temp = Read_Dryer_ENC_Position(); + angle = Calculate_Arm_Distance(D_DrierPrevLocation,temp); + + if ((angle<14000 )||(ReadValue == BUSY)) // OK - take another round + { + responseContainer.has_error = true; + responseContainer.error = ERROR_CODE__GENERAL_ERROR; + + } ReportWithPackageFilter(DiagnosticsFilter,"Diagnostics_Set_Load_Arm_To_Stopper time",__FILE__,__LINE__,msec_millisecondCounter,RpMessage,0,0); + if (HomingControlId[deviceID] != 0xff) + { + ReportWithPackageFilter(DiagnosticsFilter,"MotorHomingProgressReport stopped",__FILE__,__LINE__,deviceID,RpMessage,HomingCounter[deviceID],0); + RemoveControlCallback(HomingControlId[deviceID],MotorHomingProgressReport); + HomingControlId[deviceID] = 0xff; + } //NumberOfDrierLoaderCycles=0; //storeLoadArmParameters(); - SetMotHome(HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM); //set this point as the spool home + //SetMotHome(HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM); //set this point as the spool home + ThreadLoadingRestartReport(); responseContainer = createContainer(MESSAGE_TYPE__MotorHomingResponse, HomingToken[deviceID], true, &response, &motor_homing_response__pack, &motor_homing_response__get_packed_size); responseContainer.has_continuous = true; responseContainer.continuous = true; @@ -501,45 +504,50 @@ uint32_t Diagnostics_Set_Load_Arm_To_Stopper_Callback(uint32_t deviceID, uint32_ return OK; } -uint32_t Diagnostics_Dryer_UnLoading_Callback(uint32_t MotorId, uint32_t ReadValue) +/*uint32_t Diagnostics_Dryer_UnLoading_Callback(uint32_t MotorId, uint32_t ReadValue) { + bool direction; + D_numberOfCycles++; uint32_t temp = Read_Dryer_ENC_Position(); ReportWithPackageFilter(DiagnosticsFilter,"Diagnostics_Dryer_UnLoading_Callback",__FILE__,ReadValue,temp,RpMessage,D_DrierPrevLocation,0); //ReportWithPackageFilter(DiagnosticsFilter,"Diagnostics_Dryer_UnLoading_Callback details",__FILE__,(int)(TotalLoadedLen),D_numberOfCycles,RpMessage,CallbackCounter,0); - if ((AccumulatedArmMovement>8000 )&&(ReadValue == NOTBUSY)) // OK - take another round -// if (ReadValue == NOTBUSY) // OK - take another round + //if ((AccumulatedArmMovement>8000 )&&(ReadValue == NOTBUSY)) // OK - take another round + if (ReadValue == NOTBUSY) // OK - take another round { - D_DrierPrevLocation = temp; ReportWithPackageFilter(DiagnosticsFilter,"Diagnostics_Dryer_UnLoading cycles",__FILE__,D_numberOfCycles,LoadArmRounds,RpMessage,0,0); - if (D_numberOfCycles14000 )&&(ReadValue == NOTBUSY)) // OK - take another round { + D_DrierPrevLocation = temp; //ReportWithPackageFilter(DiagnosticsFilter,"Diagnostics_Dryer_Loading_Callback",__FILE__,__LINE__,LoadStages,RpMessage,NumberOfDrierLoaderCycles,0); //ReportWithPackageFilter(DiagnosticsFilter,"Diagnostics_Dryer_Loading_Callback details",__FILE__,(int)(TotalLoadedLen),numberOfCycles,RpMessage,CallbackCounter,0); if (D_numberOfCyclesamount == 0xB11) //fast refresh for pressure + { + temp1 = Read_Dryer_ENC_Position(); + temp2 = MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM].pulseperround*MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM].microstep*MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM].pulleyradius/4; + + MotorStop(HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM,Hard_Hiz); + MotorSetMaxSpeed (HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM,200); + //6 seconds per round + Report("Arm movement test",__FILE__,request->delay,request->delay/2*2,RpWarning,(int)request->delay%2,0); + + //SetMotHome(ThreadMotorIdToMotorId[Motor_i]); + MotorMoveWithCallback (HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM, request->delay%2,request->delay/2*2, NULL, 12000); + + response.progress = temp2; + response.has_progress = true; + } + else + if(request->amount == 0xB12) //fast refresh for pressure + { + + temp2 = Calculate_Arm_Distance(temp1,Read_Dryer_ENC_Position()); + Report("Arm movement test calc",__FILE__,temp2,temp1,RpWarning,Read_Dryer_ENC_Position(),0); + + response.progress = temp2; + response.has_progress = true; + } + else + if(request->amount == 0xB13) //TryThreadLoadingRequest + { + TryThreadLoadingFunc(NULL); + Report("TryThreadLoadingFunc",__FILE__,temp2,temp1,RpWarning,Read_Dryer_ENC_Position(),0); + + response.progress = 0xB13; + response.has_progress = true; + } + else if(request->amount == 0xC3) //suspend I2C task { if (request->delay == 0) diff --git a/Software/Embedded_SW/Embedded/Modules/Thread/ThreadLoad.c b/Software/Embedded_SW/Embedded/Modules/Thread/ThreadLoad.c index cd7c146fe..d16683967 100644 --- a/Software/Embedded_SW/Embedded/Modules/Thread/ThreadLoad.c +++ b/Software/Embedded_SW/Embedded/Modules/Thread/ThreadLoad.c @@ -126,6 +126,7 @@ uint32_t Thread_Load_Dryer_UnLoading(void); uint32_t ThreadLoadingReport(void); + uint32_t ThreadLoadingRestartReport(void); //sending after a failure in the finalizing stage bool ThreadLoaded(void); bool ThreadLoadingActive(void) { @@ -245,38 +246,41 @@ } uint32_t Thread_Load_Set_Load_Arm_To_Stopper_Callback(uint32_t deviceID, uint32_t BusyFlag) { + uint32_t angle, temp = Read_Dryer_ENC_Position(); - /*if(PullerControlId != 0xFF) - { - MotorStop(ThreadMotorIdToMotorId[POOLER_MOTOR],Hard_Hiz); - RemoveControlCallback(PullerControlId, ThreadLoadControlCBFunction ); - PullerControlId = 0xFF; - }*/ - if(WinderControlId != 0xFF) + ReportWithPackageFilter(DiagnosticsFilter,"Thread_Load_Set_Load_Arm_To_Stopper_Callback",__FILE__,(int)numberOfCycles,(int)DrierPrevLocation,RpMessage,temp,0); + + angle = Calculate_Arm_Distance(DrierPrevLocation,temp); + + DrierPrevLocation = temp; + if (CallbackCounter) { - MotorStop(ThreadMotorIdToMotorId[WINDER_MOTOR],Hard_Hiz); - RemoveControlCallback(WinderControlId, ThreadLoadControlCBFunction ); - WinderControlId = 0xFF; + CallbackCounter--; } + if ((angle>14000 )&&(BusyFlag == NOTBUSY)) // OK - take another round + { + Report("Thread_Load_Set_Load_Arm_To_Stopper time",__FILE__,msec_millisecondCounter - UnloadingStart,msec_millisecondCounter,RpMessage,UnloadingStart,0); - MotorAbortMovetoLimitSwitch(HARDWARE_MOTOR_TYPE__MOTO_SCREW); - /*Task_sleep(5) - MotorStop(ThreadMotorIdToMotorId[FEEDER_MOTOR],Hard_Hiz); - MotorStop(ThreadMotorIdToMotorId[FEEDER_MOTOR],Hard_Hiz);*/ + Report("Thread_Load_Set_Load_Arm_To_Stopper_Callback",__FILE__,__LINE__,LoadStages,RpMessage,CallbackCounter,0); + NumberOfDrierLoaderCycles=0; + //storeLoadArmParameters(); + LoadStages++; + + ThreadLoadStateMachine(LoadStages); + } + else + { + load.color = fastBILNK; + usnprintf(LoadErrorMsg, 100, "Stage %s - %s timeout",LoadStagesStr[LoadStages], MotorStr[HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM]); + Report(LoadErrorMsg,__FILE__,__LINE__,LoadStages,RpWarning,TimeoutsCounter,0); - MotorStop(HARDWARE_MOTOR_TYPE__MOTO_DRYER_DRIVING,Hard_Hiz); + LoadStatus = ERROR; + ThreadLoadingReport(); + TryAgain = true; + //ThreadLoadButton(LoadStages); + } //move to exact location? // Report("Thread Load State Machine Callback.",__FILE__,__LINE__,LoadStages,RpMessage,NumberOfDrierLoaderCycles,0); - CallbackCounter = 0; - Report("Thread_Load_Set_Load_Arm_To_Stopper time",__FILE__,msec_millisecondCounter - UnloadingStart,msec_millisecondCounter,RpMessage,UnloadingStart,0); - - Report("Thread_Load_Set_Load_Arm_To_Stopper_Callback",__FILE__,__LINE__,LoadStages,RpMessage,CallbackCounter,0); - NumberOfDrierLoaderCycles=0; - //storeLoadArmParameters(); - LoadStages++; - SetMotHome(HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM); //set this point as the spool home - - ThreadLoadStateMachine(LoadStages); return OK; } uint32_t Thread_Load_HomingCallback(uint32_t MotorId, uint32_t ReadValue) @@ -484,6 +488,8 @@ CallbackCounter++; MotorMovetoLimitSwitch (HARDWARE_MOTOR_TYPE__MOTO_RDANCER,MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_RDANCER].directionthreadwize, 15, Motor_Id_to_LS_IdDown[HARDWARE_MOTOR_TYPE__MOTO_RDANCER], Thread_Load_HomingCallback,10000); + Report("Thread_Load_Close dancers tension",__FILE__,__LINE__,(int)windertension,RpMessage,(int)pullertension,0); + // MotorMovetoLimitSwitch (HARDWARE_MOTOR_TYPE__MOTO_LDANCER1,MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_LDANCER1].directionthreadwize, 500, Motor_Id_to_LS_IdDown[HARDWARE_MOTOR_TYPE__MOTO_LDANCER1], Thread_Load_HomingCallback,25000); status |= MCU_E2PromRead(EEPROM_WINDER_TENSION_POSITION,¤t); @@ -666,7 +672,7 @@ } else { - MotorMovetoEncoderPosition(HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM,Thread_Load_Dryer_MovetoEncoderPosition_Callback,30000,MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM].directionthreadwize); + MotorMovetoEncoderPosition(HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM,Thread_Load_Dryer_MovetoEncoderPosition_Callback,30000,MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM].directionthreadwize,40); Report("Store Number of cycles in drier",__FILE__,__LINE__,numberOfCycles,RpMessage,LoadArmRounds,0); } } @@ -826,6 +832,7 @@ ThreadLoadControlId = 0xFF; } + LoadingStopArmReset(); MotorStopAction(HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM); MotorStopAction(HARDWARE_MOTOR_TYPE__MOTO_RLOADING); MotorStopAction(HARDWARE_MOTOR_TYPE__MOTO_LLOADING); @@ -860,7 +867,7 @@ return OK; } - uint32_t Thread_Load_Dryer_UnLoading_Callback(uint32_t MotorId, uint32_t ReadValue) + /*uint32_t Thread_Load_Dryer_UnLoading_Callback(uint32_t MotorId, uint32_t ReadValue) { bool direction; numberOfCycles++; @@ -884,7 +891,7 @@ } else //done enough cycles, go to the center point { - MotorMovetoEncoderPosition(HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM,Thread_Load_Set_Load_Arm_To_Stopper_Callback,30000,1-MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM].directionthreadwize); + MotorMovetoEncoderPosition(HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM,Thread_Load_Set_Load_Arm_To_Stopper_Callback,30000,1-MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM].directionthreadwize,40); MCU_E2PromProgram(EEPROM_STORAGE_DRYER_CYCLES,0); Report("Store Number of cycles in drier",__FILE__,__LINE__,numberOfCycles,RpMessage,LoadArmRounds,0); } @@ -902,7 +909,7 @@ direction = 1-MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM].directionthreadwize; else direction = MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM].directionthreadwize; - MotorMovetoEncoderPosition(HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM,Thread_Load_Set_Load_Arm_To_Stopper_OnError_Callback,3000,direction); + MotorMovetoEncoderPosition(HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM,Thread_Load_Set_Load_Arm_To_Stopper_OnError_Callback,3000,direction,10); } else @@ -911,12 +918,6 @@ TimeoutsCounter = 0; CallbackCounter = 0; - /*if(PullerControlId != 0xFF) - { - MotorStop(ThreadMotorIdToMotorId[POOLER_MOTOR],Hard_Hiz); - RemoveControlCallback(PullerControlId, ThreadLoadControlCBFunction ); - PullerControlId = 0xFF; - }*/ if(WinderControlId != 0xFF) { MotorStop(ThreadMotorIdToMotorId[WINDER_MOTOR],Hard_Hiz); @@ -925,9 +926,6 @@ } MotorAbortMovetoLimitSwitch(HARDWARE_MOTOR_TYPE__MOTO_SCREW); - /*Task_sleep(5) - MotorStop(ThreadMotorIdToMotorId[FEEDER_MOTOR],Hard_Hiz); - MotorStop(ThreadMotorIdToMotorId[FEEDER_MOTOR],Hard_Hiz);*/ MotorStop(HARDWARE_MOTOR_TYPE__MOTO_DRYER_DRIVING,Hard_Hiz); load.color = fastBILNK; @@ -940,79 +938,24 @@ //ThreadLoadButton(LoadStages); } return OK; - } + }*/ uint32_t Thread_Load_Dryer_UnLoading(void) { uint32_t temp; REPORT_MSG(LoadStages, "Thread Load State Machine step Dryer Unloading"); //LoadArmRounds = 0; //uint32_t numberOfSteps = 0; - //Start Feeder Pid, Rotate Loading Arm Counter Thread Direction X Circles According To Rml. Feeder Speed Is 40 - SetOriginMotorSpeed(22); -// OriginalMotorSpd_2PPS[FEEDER_MOTOR] = 1000; -// CurrentControlledSpeed[FEEDER_MOTOR] = 1000; - -// Rockers are up already, so puller handling is not needed - //numberOfSteps = MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM].pulseperround*LoadArmRounds*MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM].microstep*MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM].pulleyradius; - /*MotorControlConfig[POOLER_MOTOR].m_params.MAX = 1; - MotorControlConfig[POOLER_MOTOR].m_params.MIN = MotorsControl[POOLER_MOTOR].outputproportionalpowerlimit*-1; - MotorControlConfig[POOLER_MOTOR].m_params.Kd = MotorsControl[POOLER_MOTOR].derivativetime; - MotorControlConfig[POOLER_MOTOR].m_params.Kp = MotorsControl[POOLER_MOTOR].proportionalgain; - MotorControlConfig[POOLER_MOTOR].m_params.Ki = 0;//MotorsControl[POOLER_MOTOR].integraltime; - MotorControlConfig[POOLER_MOTOR].m_params.IntegralErrorMultiplier = MotorsControl[POOLER_MOTOR].setpointramprateorsoftstartramp; - MotorControlConfig[POOLER_MOTOR].m_params.ProportionalErrorMultiplier = MotorsControl[POOLER_MOTOR].outputonoffhysteresisvalue; - MotorControlConfig[POOLER_MOTOR].m_params.epsilon = MotorsControl[POOLER_MOTOR].epsilon; - MotorControlConfig[POOLER_MOTOR].m_params.dt = MotorsControl[POOLER_MOTOR].controloutputtype; - MotorControlConfig[POOLER_MOTOR].m_ingnoreValue = MotorsControl[POOLER_MOTOR].sensorcorrectionadjustment; // the minimal change required to change the motor speed in pulses - MotorControlConfig[POOLER_MOTOR].m_calculatedError = 0; - MotorControlConfig[POOLER_MOTOR].m_integral = 0; - MotorControlConfig[POOLER_MOTOR].m_isEnabled = true; - MotorControlConfig[POOLER_MOTOR].m_isReady = true; - MotorControlConfig[POOLER_MOTOR].m_mesuredParam = 0; - MotorControlConfig[POOLER_MOTOR].m_preError = 0; - MotorControlConfig[POOLER_MOTOR].m_SetParam = 0;//need to update SetParams on presegment stage - MotorSetDirection(HARDWARE_MOTOR_TYPE__MOTO_LDRIVING,MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_LDRIVING].directionthreadwize); - - PullerControlId = AddControlCallback(ThreadLoadControlCBFunction, eOneMillisecond,Control_Read_Dancer_Position,(IfTypeThread*0x100+POOLER_MOTOR),POOLER_DANCER,POOLER_MOTOR); - Report("AddControlCallback Puller",__FILE__,__LINE__,PullerControlId,RpMessage,IfTypeThread*0x100+POOLER_MOTOR,0);*/ -//////////////////////// - MotorControlConfig[WINDER_MOTOR].m_params.MAX = 1; - MotorControlConfig[WINDER_MOTOR].m_params.MIN = MotorsControl[WINDER_MOTOR].outputproportionalpowerlimit*-1; - MotorControlConfig[WINDER_MOTOR].m_params.Kd = MotorsControl[WINDER_MOTOR].derivativetime; - MotorControlConfig[WINDER_MOTOR].m_params.Kp = MotorsControl[WINDER_MOTOR].proportionalgain; - MotorControlConfig[WINDER_MOTOR].m_params.Ki = 0;//MotorsControl[WINDER_MOTOR].integraltime; - MotorControlConfig[WINDER_MOTOR].m_params.IntegralErrorMultiplier = MotorsControl[WINDER_MOTOR].setpointramprateorsoftstartramp; - MotorControlConfig[WINDER_MOTOR].m_params.ProportionalErrorMultiplier = MotorsControl[WINDER_MOTOR].outputonoffhysteresisvalue; - MotorControlConfig[WINDER_MOTOR].m_params.epsilon = MotorsControl[WINDER_MOTOR].epsilon; - MotorControlConfig[WINDER_MOTOR].m_params.dt = MotorsControl[WINDER_MOTOR].controloutputtype; - MotorControlConfig[WINDER_MOTOR].m_ingnoreValue = MotorsControl[WINDER_MOTOR].sensorcorrectionadjustment; // the minimal change required to change the motor speed in pulses - MotorControlConfig[WINDER_MOTOR].m_calculatedError = 0; - MotorControlConfig[WINDER_MOTOR].m_integral = 0; - MotorControlConfig[WINDER_MOTOR].m_isEnabled = true; - MotorControlConfig[WINDER_MOTOR].m_isReady = true; - MotorControlConfig[WINDER_MOTOR].m_mesuredParam = 0; - MotorControlConfig[WINDER_MOTOR].m_preError = 0; - MotorControlConfig[WINDER_MOTOR].m_SetParam = 0;//need to update SetParams on presegment stage - MotorSetDirection(HARDWARE_MOTOR_TYPE__MOTO_WINDER,MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_WINDER].directionthreadwize); - - WinderControlId = AddControlCallback(NULL,ThreadLoadControlCBFunction, eOneMillisecond,Control_Read_Dancer_Position,(IfTypeThread*0x100+WINDER_MOTOR),WINDER_DANCER,WINDER_MOTOR); - Report("AddControlCallback Winder",__FILE__,__LINE__,WinderControlId,RpMessage,IfTypeThread*0x100+WINDER_MOTOR,0); - -//////////////////////// - MotorSetDirection(HARDWARE_MOTOR_TYPE__MOTO_DRYER_DRIVING,MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_DRYER_DRIVING].directionthreadwize); - MotorSetSpeed(HARDWARE_MOTOR_TYPE__MOTO_DRYER_DRIVING, OriginalMotorSpd_2PPS[DRYER_MOTOR]); CallbackCounter++; - //MotorMoveWithCallback (HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM, MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM].directionthreadwize, - // numberOfSteps, Thread_Load_Dryer_Loading_Callback, 100000); - //Report("Store Number of cycles in drier - halted",__FILE__,__LINE__,numberOfCycles,RpMessage,LoadArmRounds,0); - //MCU_E2PromProgram(EEPROM_STORAGE_DRYER_CYCLES,numberOfCycles); -//shlomo - UnloadingStart = msec_millisecondCounter; - numberOfSteps = MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM].pulseperround/**LoadArmRounds*/*MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM].microstep*MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM].pulleyradius; - numberOfCycles = 0; - if (SecondTry == true) + MCU_E2PromRead(EEPROM_STORAGE_DRYER_CENTER,&temp); + DrierCenterLocation = DrierPrevLocation; + DrierPrevLocation = temp; + UnloadingStart = msec_millisecondCounter; + //numberOfSteps = MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM].pulseperround/**LoadArmRounds*/*MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM].microstep*MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM].pulleyradius; + //numberOfCycles = 0; + LoadingArmReset(Thread_Load_Set_Load_Arm_To_Stopper_Callback,300000); + /*if (SecondTry == true) { MCU_E2PromRead(EEPROM_STORAGE_DRYER_CYCLES,&LoadArmRounds); if (LoadArmRounds == 0) //prev trial stopped @@ -1028,8 +971,8 @@ { LoadArmRounds = (int)dryerbufferlength; } - } - MCU_E2PromRead(EEPROM_STORAGE_DRYER_CENTER,&temp); + }*/ + /*MCU_E2PromRead(EEPROM_STORAGE_DRYER_CENTER,&temp); DrierCenterLocation = DrierPrevLocation; DrierPrevLocation = temp; Report("Thread_Load_Set_Load_Arm_To_Start_Position",__FILE__,UnloadingStart,DrierPrevLocation,RpMessage, LoadArmRounds,0); @@ -1046,6 +989,8 @@ //Keep Notation How Many Rotations In The Dryer //LoadArmRounds = (int)dryerbufferlength; + * + */ load.color = BLINK; return OK; } @@ -1172,6 +1117,8 @@ uint32_t ThreadLoadButton(THREAD_LOAD_STAGES_ENUM ReadValue) LoadStatus = OK; SecondTry = true; load.color = BLINK; + if (LoadStages > THREAD_LOAD_INITIAL_TENSION) + ThreadLoadingRestartReport(); Report("Calling State machine retry",__FILE__,LoadStages,LoadStatus,RpMessage,SecondTry,0); ThreadLoadStateMachine(LoadStages); } @@ -1180,6 +1127,8 @@ uint32_t ThreadLoadButton(THREAD_LOAD_STAGES_ENUM ReadValue) SecondTry = false; Report("Calling State machine 2nd try",__FILE__,LoadStages,LoadStatus,RpMessage,SecondTry,0); load.color = BLINK; + if (LoadStages > THREAD_LOAD_INITIAL_TENSION) + ThreadLoadingRestartReport(); ThreadLoadStateMachine(LoadStages+1); } else //((SecondTry == false)&&(TryAgain == false))??????? @@ -1191,6 +1140,8 @@ uint32_t ThreadLoadButton(THREAD_LOAD_STAGES_ENUM ReadValue) else { Report("Calling State machine status OK",__FILE__,ReadValue,LoadStatus,RpMessage,SecondTry,0); + if (LoadStages > THREAD_LOAD_INITIAL_TENSION) + ThreadLoadingRestartReport(); ThreadLoadStateMachine(LoadStages); SecondTry = false; } @@ -1520,23 +1471,54 @@ uint32_t ThreadLoadingReport(void) return OK; +} +bool ThreadLoadingRestartFlag = false; +uint32_t ThreadLoadingRestartReport(void) //sending after a failure in the finalizing stage +{ + MessageContainer responseContainer; + StartThreadLoadingResponse response = START_THREAD_LOADING_RESPONSE__INIT; + + if (ThreadLoadingToken[0] == 0) + return OK; + ThreadLoadingRestartFlag = true; + + response.has_state = true; + response.state = THREAD_LOADING_STATE__ReadyForLoading; + response.errorreason = DefaultErrSrt; + Report("ThreadLoadingReport",__FILE__,MessageState,response.state,RpWarning,(int)LoadStages,0); + //------------------------------------------------------------------------------------------- + responseContainer = createContainer(MESSAGE_TYPE__StartThreadLoadingResponse, ThreadLoadingToken, false, &response, &start_thread_loading_response__pack, &start_thread_loading_response__get_packed_size); + responseContainer.has_continuous = true; + responseContainer.continuous = true; + uint8_t* container_buffer = my_malloc(message_container__get_packed_size(&responseContainer)); + size_t container_size = message_container__pack(&responseContainer, container_buffer); + my_free(responseContainer.data.data); + SendChars((char*)container_buffer, container_size); + + return OK; + } uint32_t TryThreadLoadingFunc(MessageContainer* requestContainer) { - TryThreadLoadingRequest *request = try_thread_loading_request__unpack(NULL, requestContainer->data.len, requestContainer->data.data); + TryThreadLoadingRequest *request; TryThreadLoadingResponse Cresponse = TRY_THREAD_LOADING_RESPONSE__INIT; MessageContainer responseContainer; - MessageState = 2; + //MessageState = 2; + if (requestContainer) + request = try_thread_loading_request__unpack(NULL, requestContainer->data.len, requestContainer->data.data); ThreadLoadingReport(); Report("TryThreadLoadingFunc",__FILE__,__LINE__,MESSAGE_TYPE__TryThreadLoadingResponse,RpWarning,(int)LoadStages,0); - responseContainer = createContainer(MESSAGE_TYPE__TryThreadLoadingResponse, requestContainer->token, true, &Cresponse, &try_thread_loading_response__pack, &try_thread_loading_response__get_packed_size); - responseContainer.continuous = false; - uint8_t* container_buffer = my_malloc(message_container__get_packed_size(&responseContainer)); - size_t container_size = message_container__pack(&responseContainer, container_buffer); - my_free(responseContainer.data.data); - SendChars((char*)container_buffer, container_size); + if (requestContainer) + { + responseContainer = createContainer(MESSAGE_TYPE__TryThreadLoadingResponse, requestContainer->token, true, &Cresponse, &try_thread_loading_response__pack, &try_thread_loading_response__get_packed_size); + responseContainer.continuous = false; + uint8_t* container_buffer = my_malloc(message_container__get_packed_size(&responseContainer)); + size_t container_size = message_container__pack(&responseContainer, container_buffer); + my_free(responseContainer.data.data); + SendChars((char*)container_buffer, container_size); + } ThreadLoadButton(LoadStages); return OK; @@ -1544,7 +1526,8 @@ uint32_t TryThreadLoadingFunc(MessageContainer* requestContainer) uint32_t ThreadUpdateCallBackFunction(uint32_t IfIndex, uint32_t BusyFlag) { - ThreadLoadingReport(); + if(ThreadLoadingActive()) + ThreadLoadingReport(); return OK; } @@ -1567,13 +1550,16 @@ uint32_t ContinueThreadLoadingFunc(MessageContainer* requestContainer) MessageContainer responseContainer; MessageState = 2; ThreadLoadingReport(); - if (request->processparameters) + if (ThreadLoadingRestartFlag == false) { - dryerbufferlength = request->processparameters->dryerbufferlength; - LoadArmRounds = (int)(request->processparameters->dryerbufferlength); + if (request->processparameters) + { + dryerbufferlength = request->processparameters->dryerbufferlength; + LoadArmRounds = (int)(request->processparameters->dryerbufferlength); + } + Report("ContinueThreadLoadingFunc",__FILE__,__LINE__,(int)(request->processparameters->dryerbufferlength),RpWarning,(int)LoadStages,0); } - Report("ContinueThreadLoadingFunc",__FILE__,__LINE__,(int)(request->processparameters->dryerbufferlength),RpWarning,(int)LoadStages,0); responseContainer = createContainer(MESSAGE_TYPE__ContinueThreadLoadingResponse, requestContainer->token, true, &Cresponse, &continue_thread_loading_response__pack, &continue_thread_loading_response__get_packed_size); responseContainer.continuous = false; diff --git a/Software/Embedded_SW/Embedded/Modules/Thread/Thread_print.c b/Software/Embedded_SW/Embedded/Modules/Thread/Thread_print.c index 275e7e5b7..d7bfb1b6e 100644 --- a/Software/Embedded_SW/Embedded/Modules/Thread/Thread_print.c +++ b/Software/Embedded_SW/Embedded/Modules/Thread/Thread_print.c @@ -162,7 +162,7 @@ int FeederSpeedIndex = 0,Speed_i; void ThreadUpdateProcessLength (double length, void *Funcptr) { - REPORT_MSG(length,"ThreadUpdateProcessLength"); + ReportWithPackageFilter(ThreadFilter,"ThreadUpdateProcessLength.",__FILE__,__LINE__,(int)length,RpMessage,(int)dyeingspeed,0); CurrentRequestedLength = length*100;//Centimetres CurrentProcessedLength = 0; ProcessedLengthFuncPtr = (ProcessedLengthFunc)Funcptr; @@ -337,7 +337,10 @@ uint32_t PoolerThreadLengthCBFunction(uint32_t IfIndex, uint32_t ReadValue) }**/ //} - +#ifdef FOUR_WINDERS + if (CurrentControlledSpeed[WINDER_MOTOR]>100) + length = dyeingspeed/10; +#endif PoolerTotalProcessedLength+= (length/100); TempPoolerTotalProcessedLength = PoolerTotalProcessedLength; #ifndef FEEDER_LENGTH_CALCULATION @@ -642,11 +645,12 @@ uint32_t ThreadControlCBFunction(uint32_t IfIndex, uint32_t ReadValue) { c++; } - if ((index == WINDER_2_MOTOR)||(index == WINDER_3_MOTOR)) + //if ((index == WINDER_2_MOTOR)||(index == WINDER_3_MOTOR)||(index == WINDER_4_MOTOR)) + /*if (index >= WINDER_MOTOR) { //pooler dancer is right sided: data is opposite TranslatedReadValue = (-1*TranslatedReadValue); - } + }*/ #endif if (index == POOLER_MOTOR) { @@ -738,12 +742,12 @@ uint32_t ThreadControlCBFunction(uint32_t IfIndex, uint32_t ReadValue) //calculated_speed = (1-MotorControlConfig[index].m_calculatedError)*CurrentControlledSpeed[index]; //if (0)//(JobCounter % 1000 == 0) #ifdef FOUR_WINDERS - if (JobCounter % 500 < 4)//(FirstCalcInJob == true) + if (0)//(JobCounter % 500 < 7)//(FirstCalcInJob == true) { if (index >= WINDER_MOTOR) { // FirstCalcInJob = false; - len = usnprintf(ATMessage[index], 150, "index %d read %d avg %d error(6) %d integral(9) %d,delta(9) %d, calc(3) %d speed %d %d",index, + len = usnprintf(ATMessage[index], 150, "index %d read %d avg %d error(6) %d integral(9) %d,delta(9) %d, calc(3) %d speed %d %d",index-WINDER_MOTOR+1, TranslatedReadValue,avreageSampleValue,(int)(MotorControlConfig[index].m_mesuredParam*1000000), (int)(MotorControlConfig[index].m_integral*1000000000),(int)((MotorControlConfig[index].m_mesuredParam*MotorControlConfig[index].m_params.dt)*1000000000), (int)(MotorControlConfig[index].m_calculatedError*1000),(int)calculated_speed, (int)(InitialDryerSpeed*100/OriginalMotorSpd_2PPS[DRYER_MOTOR])); -- cgit v1.3.1 From 57800c7c60ca335463a54abf148049615fc51c59 Mon Sep 17 00:00:00 2001 From: Shlomo Hecht Date: Mon, 14 Sep 2020 09:59:20 +0300 Subject: Version 1.5.0.1 --- .../Embedded_SW/Embedded/Common/SW_Info/SW_Info.c | 2 +- .../Communication/PMR/Stubs/ProgressRequest.pb-c.c | 45 ++- .../Communication/PMR/Stubs/ProgressRequest.pb-c.h | 8 +- .../PMR/Stubs/ProgressResponse.pb-c.c | 19 +- .../PMR/Stubs/ProgressResponse.pb-c.h | 4 +- .../Embedded_SW/Embedded/Drivers/Motors/Motor.h | 8 +- .../Embedded/Drivers/Motors/MotorActions.c | 419 ++++++++++++++++----- .../Modules/Diagnostics/DiagnosticsHoming.c | 112 +++--- .../Embedded_SW/Embedded/Modules/General/buttons.c | 5 +- .../Embedded/Modules/Stubs_Handler/Progress.c | 37 ++ .../Embedded/Modules/Thread/ThreadLoad.c | 220 +++++------ .../Embedded/Modules/Thread/Thread_print.c | 16 +- 12 files changed, 619 insertions(+), 276 deletions(-) (limited to 'Software') diff --git a/Software/Embedded_SW/Embedded/Common/SW_Info/SW_Info.c b/Software/Embedded_SW/Embedded/Common/SW_Info/SW_Info.c index bf2c4e98d..a607fedcb 100644 --- a/Software/Embedded_SW/Embedded/Common/SW_Info/SW_Info.c +++ b/Software/Embedded_SW/Embedded/Common/SW_Info/SW_Info.c @@ -20,7 +20,7 @@ typedef struct } TangoVersion_t; -TangoVersion_t _gTangoVersion = {1,4,6,44}; +TangoVersion_t _gTangoVersion = {1,5,0,1}; #define BUILD_DATE __DATE__ char Dat[50] = BUILD_DATE; char _gTangoName [MAX_STRING_LEN] = "Tango01 ";//e diff --git a/Software/Embedded_SW/Embedded/Communication/PMR/Stubs/ProgressRequest.pb-c.c b/Software/Embedded_SW/Embedded/Communication/PMR/Stubs/ProgressRequest.pb-c.c index b151bea09..3a3aadd3b 100644 --- a/Software/Embedded_SW/Embedded/Communication/PMR/Stubs/ProgressRequest.pb-c.c +++ b/Software/Embedded_SW/Embedded/Communication/PMR/Stubs/ProgressRequest.pb-c.c @@ -52,7 +52,7 @@ void progress_request__free_unpacked assert(message->base.descriptor == &progress_request__descriptor); protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator); } -static const ProtobufCFieldDescriptor progress_request__field_descriptors[2] = +static const ProtobufCFieldDescriptor progress_request__field_descriptors[5] = { { "", @@ -78,15 +78,54 @@ static const ProtobufCFieldDescriptor progress_request__field_descriptors[2] = 0, /* flags */ 0,NULL,NULL /* reserved1,reserved2, etc */ }, + { + "", + 3, + PROTOBUF_C_LABEL_OPTIONAL, + PROTOBUF_C_TYPE_UINT32, + offsetof(ProgressRequest, has_param1), + offsetof(ProgressRequest, param1), + NULL, + NULL, + 0, /* flags */ + 0,NULL,NULL /* reserved1,reserved2, etc */ + }, + { + "", + 4, + PROTOBUF_C_LABEL_OPTIONAL, + PROTOBUF_C_TYPE_UINT32, + offsetof(ProgressRequest, has_param2), + offsetof(ProgressRequest, param2), + NULL, + NULL, + 0, /* flags */ + 0,NULL,NULL /* reserved1,reserved2, etc */ + }, + { + "", + 5, + PROTOBUF_C_LABEL_OPTIONAL, + PROTOBUF_C_TYPE_UINT32, + offsetof(ProgressRequest, has_param3), + offsetof(ProgressRequest, param3), + NULL, + NULL, + 0, /* flags */ + 0,NULL,NULL /* reserved1,reserved2, etc */ + }, }; static const unsigned progress_request__field_indices_by_name[] = { 0, /* field[0] = Amount */ 1, /* field[1] = Delay */ + 2, /* field[2] = Param1 */ + 3, /* field[3] = Param2 */ + 4, /* field[4] = Param3 */ }; static const ProtobufCIntRange progress_request__number_ranges[1 + 1] = { { 1, 0 }, - { 0, 2 } + { 0, 5 } }; const ProtobufCMessageDescriptor progress_request__descriptor = { @@ -96,7 +135,7 @@ const ProtobufCMessageDescriptor progress_request__descriptor = "", "", sizeof(ProgressRequest), - 2, + 5, progress_request__field_descriptors, progress_request__field_indices_by_name, 1, progress_request__number_ranges, diff --git a/Software/Embedded_SW/Embedded/Communication/PMR/Stubs/ProgressRequest.pb-c.h b/Software/Embedded_SW/Embedded/Communication/PMR/Stubs/ProgressRequest.pb-c.h index 1ce2b6d6b..da8eac4f1 100644 --- a/Software/Embedded_SW/Embedded/Communication/PMR/Stubs/ProgressRequest.pb-c.h +++ b/Software/Embedded_SW/Embedded/Communication/PMR/Stubs/ProgressRequest.pb-c.h @@ -30,10 +30,16 @@ struct _ProgressRequest int32_t amount; protobuf_c_boolean has_delay; int32_t delay; + protobuf_c_boolean has_param1; + uint32_t param1; + protobuf_c_boolean has_param2; + uint32_t param2; + protobuf_c_boolean has_param3; + uint32_t param3; }; #define PROGRESS_REQUEST__INIT \ { PROTOBUF_C_MESSAGE_INIT (&progress_request__descriptor) \ - , 0, 0, 0, 0 } + , 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } /* ProgressRequest methods */ diff --git a/Software/Embedded_SW/Embedded/Communication/PMR/Stubs/ProgressResponse.pb-c.c b/Software/Embedded_SW/Embedded/Communication/PMR/Stubs/ProgressResponse.pb-c.c index 537f8e763..ff0667e61 100644 --- a/Software/Embedded_SW/Embedded/Communication/PMR/Stubs/ProgressResponse.pb-c.c +++ b/Software/Embedded_SW/Embedded/Communication/PMR/Stubs/ProgressResponse.pb-c.c @@ -52,7 +52,7 @@ void progress_response__free_unpacked assert(message->base.descriptor == &progress_response__descriptor); protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator); } -static const ProtobufCFieldDescriptor progress_response__field_descriptors[1] = +static const ProtobufCFieldDescriptor progress_response__field_descriptors[2] = { { "", @@ -66,14 +66,27 @@ static const ProtobufCFieldDescriptor progress_response__field_descriptors[1] = 0, /* flags */ 0,NULL,NULL /* reserved1,reserved2, etc */ }, + { + "", + 2, + PROTOBUF_C_LABEL_OPTIONAL, + PROTOBUF_C_TYPE_UINT32, + offsetof(ProgressResponse, has_info), + offsetof(ProgressResponse, info), + NULL, + NULL, + 0, /* flags */ + 0,NULL,NULL /* reserved1,reserved2, etc */ + }, }; static const unsigned progress_response__field_indices_by_name[] = { + 1, /* field[1] = Info */ 0, /* field[0] = Progress */ }; static const ProtobufCIntRange progress_response__number_ranges[1 + 1] = { { 1, 0 }, - { 0, 1 } + { 0, 2 } }; const ProtobufCMessageDescriptor progress_response__descriptor = { @@ -83,7 +96,7 @@ const ProtobufCMessageDescriptor progress_response__descriptor = "", "", sizeof(ProgressResponse), - 1, + 2, progress_response__field_descriptors, progress_response__field_indices_by_name, 1, progress_response__number_ranges, diff --git a/Software/Embedded_SW/Embedded/Communication/PMR/Stubs/ProgressResponse.pb-c.h b/Software/Embedded_SW/Embedded/Communication/PMR/Stubs/ProgressResponse.pb-c.h index de5201ee5..bd1a3141a 100644 --- a/Software/Embedded_SW/Embedded/Communication/PMR/Stubs/ProgressResponse.pb-c.h +++ b/Software/Embedded_SW/Embedded/Communication/PMR/Stubs/ProgressResponse.pb-c.h @@ -28,10 +28,12 @@ struct _ProgressResponse ProtobufCMessage base; protobuf_c_boolean has_progress; double progress; + protobuf_c_boolean has_info; + uint32_t info; }; #define PROGRESS_RESPONSE__INIT \ { PROTOBUF_C_MESSAGE_INIT (&progress_response__descriptor) \ - , 0, 0 } + , 0, 0, 0, 0 } /* ProgressResponse methods */ diff --git a/Software/Embedded_SW/Embedded/Drivers/Motors/Motor.h b/Software/Embedded_SW/Embedded/Drivers/Motors/Motor.h index e6947a8d4..00cada255 100644 --- a/Software/Embedded_SW/Embedded/Drivers/Motors/Motor.h +++ b/Software/Embedded_SW/Embedded/Drivers/Motors/Motor.h @@ -312,6 +312,7 @@ uint32_t MotorStop(TimerMotors_t _motorId, STOP_TYPE_ENUM StopType); uint32_t MotorMove(TimerMotors_t _motorId,bool direction, uint32_t Steps); uint32_t MotorMoveWithCallback (TimerMotors_t _motorId,bool direction, uint32_t Steps, callback_fptr callback,uint32_t timeout); +uint32_t MotorRunWithCallback (TimerMotors_t MotorId,bool direction, uint32_t Freq, callback_fptr callback,uint32_t timeout); uint32_t MotorGotoWithCallback (TimerMotors_t MotorId, uint32_t Steps, uint32_t LimitSwitchId,callback_fptr callback,uint32_t timeout); //TODO uint32_t MotorGotoWithBusyCallback (TimerMotors_t MotorId,bool direction, uint32_t Steps, callback_fptr callback,uint32_t timeout); //TODO @@ -352,7 +353,12 @@ uint32_t MotorMovetoBreakSensor (TimerMotors_t _motorId,bool direction, uint32_t uint32_t MotorMovetoDancerPosition (TimerMotors_t _motorId,bool direction, uint32_t Freq,uint32_t DancerId,bool dancervaluedirection, callback_fptr callback,uint32_t timeout); uint32_t MotorAbortMovetoLimitSwitch (TimerMotors_t _motorId); uint32_t MotorMoveToStopper (TimerMotors_t _motorId,bool direction, uint32_t Speed, callback_fptr callback,uint32_t backlash,uint32_t timeout); -uint32_t MotorMovetoEncoderPosition (TimerMotors_t MotorId, callback_fptr callback,uint32_t timeout, bool direction); +uint32_t MotorMovetoEncoderPosition (TimerMotors_t MotorId, callback_fptr callback,uint32_t timeout, bool direction,uint32_t speed); +uint32_t LoadingArmReset (callback_fptr callback,uint32_t timeout); +uint32_t LoadingStopArmReset (void); + +float Calculate_Arm_Angle(uint32_t Drier_Center,uint32_t Current_Angle); +int Calculate_Arm_Distance(uint32_t Drier_Center,uint32_t Current_Angle); uint32_t MotorStopAction (TimerMotors_t MotorId); //Stop the controlled action of a motor diff --git a/Software/Embedded_SW/Embedded/Drivers/Motors/MotorActions.c b/Software/Embedded_SW/Embedded/Drivers/Motors/MotorActions.c index f33edee50..f7604b37c 100644 --- a/Software/Embedded_SW/Embedded/Drivers/Motors/MotorActions.c +++ b/Software/Embedded_SW/Embedded/Drivers/Motors/MotorActions.c @@ -39,11 +39,26 @@ //callback_fptr MotorMovetoLimitSwitchCallback[NUM_OF_MOTORS]; callback_fptr MotorCallback[NUM_OF_MOTORS]; ControlCBFunction MotorControlCallback[NUM_OF_MOTORS]; +uint32_t DrierZeroPosition = 0; +//uint32_t DryerBackLash = 0; +//bool DrierBackLashDirection = false; +uint32_t Arm_Drier_Center = 0; +callback_fptr UnloadingReset = NULL; +/*int CallbackCalls=0; +int FirstCall = 0; +#define MAX_CONTROL_SAMPLES 10*/ +int32_t ArmSamples[MAX_CONTROL_SAMPLES] = {0}; +int ArmSamplePointer = {0}; +int StoredavreageSampleValue = 0; +uint32_t CallbackCalls = 0; +int32_t Initialcurrentposition =0; +int cycles = 0; uint32_t MotorMoveCallBackFunction(uint32_t deviceId, uint32_t BusyFlag); uint32_t MotorSetSpeedCallBackFunction(uint32_t deviceId, uint32_t BusyFlag); uint32_t MotorVerifiedCallBackFunction(uint32_t IfIndex, uint32_t BusyFlag); uint32_t MotorMoveToLimitSwitchCallBackFunction(uint32_t IfIndex, uint32_t LimitSwitch); +uint32_t MotorRunCallBackFunction(uint32_t IfIndex, uint32_t BusyFlag); //uint32_t MotorMoveControlId[NUM_OF_MOTORS]; //uint32_t MotorSetSpeedControlId[NUM_OF_MOTORS]; //uint32_t MotorMovetoLimitSwitchControlId[NUM_OF_MOTORS]; @@ -206,6 +221,7 @@ uint32_t MotorGotoWithBusyCallback (TimerMotors_t MotorId,bool direction, uint32 int32_t AccumulatedArmMovement = 0; int32_t InitialArmLocation = 0; bool ArmDirection = true; +int failCounter = 0; uint32_t MotorMoveWithCallback (TimerMotors_t MotorId,bool direction, uint32_t Steps, callback_fptr callback,uint32_t timeout) //TODO { @@ -224,31 +240,24 @@ uint32_t MotorMoveWithCallback (TimerMotors_t MotorId,bool direction, uint32_t S MotorTimeout[MotorId] = 0; MotorTimeLag[MotorId] = 20; MotorTimeLimit[MotorId] = timeout; - if (MotorId ==HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM) + /*if (MotorId ==HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM) { InitialArmLocation = Read_Dryer_ENC_Position(0,0); AccumulatedArmMovement = 0; ArmDirection = direction; + MCU_E2PromRead(EEPROM_STORAGE_DRYER_CENTER,&DrierZeroPosition); + failCounter = 0; + MotorSetSpeed(HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM,MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM].maxfrequency); + } + else*/ + { + //MotorStop(MotorId,Hard_Hiz ); + MotorMove(MotorId,direction,Steps ); } - - //MotorStop(MotorId,Hard_Hiz ); - MotorMove(MotorId,direction,Steps ); MotorControlId[MotorId] = AddControlCallback(NULL, MotorMoveCallBackFunction, /*eTenMillisecond*/20, MotorControlGetnBusyState,(IfTypeMotors*0x100+MotorId), MotorId, 0 ); MotorControlCallback[MotorId] = MotorMoveCallBackFunction; return MotorControlId[MotorId]; } -uint32_t DryerBackLash = 0; -uint32_t DrierZeroPosition = 0; -bool DrierBackLashDirection = false; -int CallbackCalls=0; -int FirstCall = 0; -#define MAX_CONTROL_SAMPLES 10 -int32_t ArmSamples[MAX_CONTROL_SAMPLES] = {0}; -int ArmSamplePointer = {0}; -int StoredavreageSampleValue = 0; - -int32_t Initialcurrentposition =0; -int cycles = 0; uint32_t MotorVerifiedCallBackFunction(uint32_t IfIndex, uint32_t ArmPosition) //TODO { uint32_t MotorId; @@ -262,6 +271,7 @@ uint32_t MotorVerifiedCallBackFunction(uint32_t IfIndex, uint32_t ArmPosition) / MotorId = IfIndex&0xFF; MotorPosition = ArmPosition; CallbackCalls++; + if (CallbackCalls%20 == 0) { // REPORT_MSG(MotorPosition,"MotorVerifiedCallBackFunction"); @@ -276,11 +286,6 @@ uint32_t MotorVerifiedCallBackFunction(uint32_t IfIndex, uint32_t ArmPosition) / Read_Dryer_ENC_Position(); //trigger the next call ArmSamples[ArmSamplePointer] = MotorPosition;//(-1 * TranslatedReadValue); - if (FirstCall<5) - { - FirstCall++; - return OK; - } ArmSamples[ArmSamplePointer] = MotorPosition;//(-1 * TranslatedReadValue); ArmSamplePointer++; if (ArmSamplePointer >= MAX_CONTROL_SAMPLES) @@ -320,13 +325,13 @@ uint32_t MotorVerifiedCallBackFunction(uint32_t IfIndex, uint32_t ArmPosition) / Task_sleep(5);*/ // MCU_E2PromProgram(EEPROM_STORAGE_DRYER_CENTER,DrierZeroPosition); - Report("MotorVerifiedCallBackFunction",__FILE__,__LINE__,DrierZeroPosition,RpWarning,DryerBackLash,0); + Report("MotorVerifiedCallBackFunction",__FILE__,__LINE__,DrierZeroPosition,RpWarning,avreageSampleValue,0); //call the module callback if (MotorCallback[MotorId]) MotorCallback[MotorId](MotorId,ArmPosition); MotorSetDirection(HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM,MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM].directionthreadwize); - MotorMovetoEncoderPosition(HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM,NULL,1000,MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM].directionthreadwize); + MotorMovetoEncoderPosition(HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM,NULL,1000,MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM].directionthreadwize,40); DrierZeroPosition = Read_Dryer_ENC_Position(); //trigger the next call } @@ -359,12 +364,8 @@ uint32_t MotorMoveToStopper (TimerMotors_t MotorId,bool direction, uint32_t Spee MotorStop(MotorId,Hard_Hiz ); Task_sleep(5); - DryerBackLash = backlash; - DrierBackLashDirection = 1-direction; MotorSetDirection( MotorId, direction); - CallbackCalls = 0; - FirstCall = 0; MotorGetPositionFromFPGA(MotorId); memset(ArmSamples,0,sizeof(ArmSamples)); ArmSamplePointer = 0; @@ -422,11 +423,14 @@ uint32_t MotorMoveToDrierPositionCallBackFunction(uint32_t IfIndex, uint32_t Rea //call the module callback if (MotorCallback[MotorId]) + { + Report("MotorMoveToDrierPosition callback",__FILE__,__LINE__,MotorCallback[MotorId],RpWarning,ReadValue,0); MotorCallback[MotorId](MotorId,ReadValue); + } } return OK; } -uint32_t MotorMovetoEncoderPosition (TimerMotors_t MotorId, callback_fptr callback,uint32_t timeout, bool direction) +uint32_t MotorMovetoEncoderPosition (TimerMotors_t MotorId, callback_fptr callback,uint32_t timeout, bool direction,uint32_t speed) { //assert (callback); uint32_t currentposition = 0; @@ -446,6 +450,7 @@ uint32_t MotorMovetoEncoderPosition (TimerMotors_t MotorId, callback_fptr callb currentposition = Control_Read_Dryer_Position(0,0); MCU_E2PromRead(EEPROM_STORAGE_DRYER_CENTER,&DrierZeroPosition); Report("MotorMovetoEncoderPosition",__FILE__,__LINE__,DrierZeroPosition,RpWarning,currentposition,0); + Report("MotorMovetoEncoderPosition callback",__FILE__,__LINE__,callback,RpWarning,speed,0); if (abs(currentposition - DrierZeroPosition)<5) { if (callback) @@ -456,7 +461,7 @@ uint32_t MotorMovetoEncoderPosition (TimerMotors_t MotorId, callback_fptr callb //MotorSetDirection( MotorId, direction); MotorSetDirection(MotorId,direction); - MotorSetSpeed (MotorId, 30); + MotorSetSpeed (MotorId, speed); MotorControlId[MotorId] = AddControlCallback(NULL, MotorMoveToDrierPositionCallBackFunction, 2,Control_Read_Dryer_Position,(IfTypeMotors*0x100+MotorId), MotorId, 0 ); MotorControlCallback[MotorId] = MotorMoveToDrierPositionCallBackFunction; MotorTimeout[MotorId] = 0; @@ -480,78 +485,22 @@ uint32_t MotorSetSpeedWithCallback (TimerMotors_t MotorId, uint32_t _freq, callb } uint32_t MotorMoveCallBackFunction(uint32_t IfIndex, uint32_t BusyFlag) //TODO { - uint32_t MotorId,encoder,temp = 0,tt; + uint32_t MotorId; uint32_t Busy = BusyFlag; + if (IfIndex>>8 != IfTypeMotors) { LOG_ERROR (IfIndex, "Wrong Interface type"); return 0xFFFFFFFF; } MotorId = IfIndex&0xFF; - CallbackCalls++; + if (MotorId ==HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM) { - encoder = Read_Dryer_ENC_Position(0,0); - tt=InitialArmLocation; - if (ArmDirection == 1-MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM].directionthreadwize) //unloading - numbers going down - { - //previous number is bigger than current - if (InitialArmLocation>encoder) - { - temp = InitialArmLocation-encoder; - if ((temp>25)&&(temp<1000)) - { - AccumulatedArmMovement+=temp; - InitialArmLocation=encoder; - } - } - else if (InitialArmLocation25)&&(temp<1000)) - { - AccumulatedArmMovement+=temp; - InitialArmLocation=encoder; - InitialArmLocation=encoder; - } - } - } - else //loading - going up - { - //previous number is smaller than current - if (InitialArmLocation25)&&(temp<1000)) - { - AccumulatedArmMovement+=temp; - InitialArmLocation=encoder; - } - } - else if (InitialArmLocation>encoder)//rollover - { - temp = 0x3FFF + encoder -InitialArmLocation; - if ((temp>25)&&(temp<1000)) - { - AccumulatedArmMovement+=temp; - InitialArmLocation=encoder; - } - } - } - /*if (temp>1000) - { - Report("MotorMoveCallBackFunction temp curr prev total",__FILE__,encoder,tt,RpWarning,temp,0); - }*/ - if (CallbackCalls%50 == 0) - { - //encoder = Read_Dryer_ENC_Position(0,0); - Report("MotorMoveCallBackFunction periodic curr prev total",__FILE__,encoder,temp,RpWarning,AccumulatedArmMovement,0); - } if (CallbackCalls%200 == 0) { - //encoder = Read_Dryer_ENC_Position(0,0); - Report("MotorMoveCallBackFunction",__FILE__,__LINE__,encoder,RpWarning,CallbackCalls,0); + Report("MotorMoveCallBackFunction",__FILE__,__LINE__,MotorId,RpWarning,Read_Dryer_ENC_Position(0,0),0); } } else @@ -565,10 +514,6 @@ uint32_t MotorMoveCallBackFunction(uint32_t IfIndex, uint32_t BusyFlag) //TODO if ((BusyFlag == NOTBUSY)||((MotorTimeout[MotorId]>=MotorTimeLimit[MotorId])&&(MotorTimeLimit[MotorId]>0))) { - /*if (MotorId == HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM) - { - printBusy = false; - }*/ //stop this control loop Report("MotorControlGetnBusyState stop",__FILE__,MotorId,BusyFlag,RpMessage,MotorTimeout[MotorId],0); SafeRemoveControlCallback(MotorControlId[MotorId], MotorMoveCallBackFunction ); @@ -581,7 +526,6 @@ uint32_t MotorMoveCallBackFunction(uint32_t IfIndex, uint32_t BusyFlag) //TODO Report("motor timeout",__FILE__,__LINE__,MotorId,RpMessage,MotorTimeout[MotorId],0); Busy = BUSY; } - Report("MotorMoveCallBackFunction curr prev total",__FILE__,encoder,temp,RpWarning,AccumulatedArmMovement,0); //call the module callback if (MotorCallback[MotorId]) { @@ -977,6 +921,14 @@ uint32_t MotorAbortMovetoLimitSwitch (TimerMotors_t MotorId) } //call driver action to device id with the parameter //SetMotorSpeed (deviceId, parameter); + if (MotorId == HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM) + { + if (UnloadingReset) + { + UnloadingReset(MotorId, BUSY); + UnloadingReset = NULL; + } + } MotorStop(MotorId,Hard_Hiz); MotorCallback[MotorId] = NULL; @@ -984,7 +936,286 @@ uint32_t MotorAbortMovetoLimitSwitch (TimerMotors_t MotorId) return OK; } +uint32_t MotorRunWithCallback (TimerMotors_t MotorId,bool direction, uint32_t Freq, callback_fptr callback,uint32_t timeout) //TODO +{ + ReportWithPackageFilter(GeneralFilter,"MotorRunWithCallback",__FILE__,direction,MotorId,RpMessage,Freq,0); + + //call driver action to device id with the parameter + //SetMotorSpeed (deviceId, parameter); + MotorCallback[MotorId] = callback; + MotorTimeout[MotorId] = 0; + MotorTimeLag[MotorId] = 20; + MotorTimeLimit[MotorId] = timeout; + if (MotorId ==HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM) + { + InitialArmLocation = Read_Dryer_ENC_Position(0,0); + AccumulatedArmMovement = 0; + ArmDirection = direction; + MCU_E2PromRead(EEPROM_STORAGE_DRYER_CENTER,&DrierZeroPosition); + failCounter = 0; + MotorSetDirection(HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM,direction); + MotorSetSpeed(HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM,Freq); + } + else + { + return ERROR; + } + MotorControlId[MotorId] = AddControlCallback(NULL, MotorRunCallBackFunction, /*eTenMillisecond*/20, MotorControlGetnBusyState,(IfTypeMotors*0x100+MotorId), MotorId, 0 ); + MotorControlCallback[MotorId] = MotorMoveCallBackFunction; + return MotorControlId[MotorId]; +} +uint32_t MotorRunCallBackFunction(uint32_t IfIndex, uint32_t BusyFlag) //TODO +{ + uint32_t MotorId,encoder,temp = 0; + uint32_t Busy = BusyFlag; + int angle; + + if (IfIndex>>8 != IfTypeMotors) + { + LOG_ERROR (IfIndex, "Wrong Interface type"); + return 0xFFFFFFFF; + } + MotorId = IfIndex&0xFF; + CallbackCalls++; + if (MotorId ==HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM) + { + encoder = Read_Dryer_ENC_Position(0,0); + if (ArmDirection == 1-MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM].directionthreadwize) //unloading - numbers going down + { + //previous number is bigger than current + if (InitialArmLocation>encoder) + { + temp = InitialArmLocation-encoder; + if ((temp>25)&&(temp<1000)) + { + AccumulatedArmMovement+=temp; + InitialArmLocation=encoder; + } + } + else if (InitialArmLocation25)&&(temp<1000)) + { + AccumulatedArmMovement+=temp; + InitialArmLocation=encoder; + } + } + } + else //loading - going up + { + //previous number is smaller than current + if (InitialArmLocation25)&&(temp<1000)) + { + AccumulatedArmMovement+=temp; + InitialArmLocation=encoder; + } + } + else if (InitialArmLocation>encoder)//rollover + { + temp = 0x3FFF + encoder -InitialArmLocation; + if ((temp>25)&&(temp<1000)) + { + AccumulatedArmMovement+=temp; + InitialArmLocation=encoder; + } + } + } + if (((temp>1000)||(temp<20))&&(CallbackCalls>10)) + { + Report("MotorRunCallBackFunctionMotorRunCallBackFunction temp curr prev small",__FILE__,encoder,InitialArmLocation,RpWarning,temp,0); + failCounter++; + if (failCounter>=20) + { + Report("arm stopped",__FILE__,failCounter,encoder,RpWarning,temp,0); + MotorStop(HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM,Hard_Hiz); + BusyFlag = NOTBUSY; + } + } + else + { + failCounter = 0; + BusyFlag = BUSY; + } + if (CallbackCalls%50 == 0) + { + //encoder = Read_Dryer_ENC_Position(0,0); + Report("MotorRunCallBackFunctionMotorRunCallBackFunction periodic curr prev total",__FILE__,encoder,temp,RpWarning,AccumulatedArmMovement,0); + } + if (CallbackCalls%200 == 0) + { + //encoder = Read_Dryer_ENC_Position(0,0); + Report("MotorRunCallBackFunctionMotorRunCallBackFunction",__FILE__,__LINE__,encoder,RpWarning,CallbackCalls,0); + } + } + else + { + if (CallbackCalls%100 == 1) + { + Report("MotorRunCallBackFunction wrong motor",__FILE__,MotorId,MotorTimeout[MotorId],RpWarning,MotorTimeLimit[MotorId],0); + return ERROR; + } + } + MotorTimeout[MotorId]+=MotorTimeLag[MotorId]; + + if ((BusyFlag == NOTBUSY)||((MotorTimeout[MotorId]>=MotorTimeLimit[MotorId])&&(MotorTimeLimit[MotorId]>0))) + { + if (MotorId == HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM) + { + angle = Calculate_Arm_Distance(Arm_Drier_Center,temp); + + if ((angle<400)||(angle>16000)) + { + BusyFlag = NOTBUSY; + } + else + { + BusyFlag = BUSY; + } + Report("arm stopped call",__FILE__,failCounter,encoder,RpWarning,abs(DrierZeroPosition-encoder),0); + } + //stop this control loop + Report("MotorControlGetnBusyState stop",__FILE__,MotorId,BusyFlag,RpMessage,MotorCallback[MotorId],0); + SafeRemoveControlCallback(MotorControlId[MotorId], MotorRunCallBackFunction ); + MotorControlCallback[MotorId] = 0; + MotorControlId[MotorId] = 0xFF; + //possibly: start regular control (speed etc) + //uint32_t ControlId = AddControlCallback(NULL,ControlCBFunction Callback, eOneMillisecond, (IfTypeMotors*0x100+MotorId), deviceId, Parameter ); + if ((MotorTimeout[MotorId]>=MotorTimeLimit[MotorId])&&(MotorTimeLimit[MotorId]>0)) + { + Report("motor timeout",__FILE__,__LINE__,MotorId,RpMessage,MotorTimeout[MotorId],0); + Busy = BUSY; + } + Report("MotorRunCallBackFunctionMotorRunCallBackFunction curr prev return",__FILE__,encoder,temp,RpWarning,AccumulatedArmMovement,0); + //call the module callback + if (MotorCallback[MotorId]) + { + MotorCallback[MotorId](MotorId,Busy); + } + + } + return OK; +} + +float Calculate_Arm_Angle(uint32_t Drier_Center,uint32_t Current_Angle) +{ + float angle; + float Calc_angle; + if (Current_Angle >= Drier_Center) + angle = Current_Angle - Drier_Center; + else + angle = Current_Angle + 0x3FFF - Drier_Center; + Calc_angle = (float)(angle/0x3FFF); + MCU_E2PromProgram(EEPROM_DRIER_LOADING_ARM_ANGLE,Calc_angle); + ReportWithPackageFilter(DiagnosticsFilter,"Calculate_Arm_Angle",__FILE__,(int)(Calc_angle*1000),Current_Angle,RpMessage,Drier_Center,0); + return Calc_angle; +} +int Calculate_Arm_Distance(uint32_t Drier_Center,uint32_t Current_Angle) +{ + int angle; + if (Current_Angle >= Drier_Center) + angle = Current_Angle - Drier_Center; + else + angle = Current_Angle + 0x3FFF - Drier_Center; + ReportWithPackageFilter(DiagnosticsFilter,"Calculate_Arm_Distance",__FILE__,angle,Current_Angle,RpMessage,Drier_Center,0); + return angle; +} + +uint32_t LoadingArmReset_Callback_Stopper_Callback(uint32_t deviceID, uint32_t BusyFlag) +{ + ReportWithPackageFilter(DiagnosticsFilter,"LoadingArmReset_Callback_Stopper_Callback time",__FILE__,__LINE__,msec_millisecondCounter,RpMessage,0,0); + + if (UnloadingReset) + { + UnloadingReset(deviceID, BusyFlag); + UnloadingReset = NULL; + } + + return OK; +} + +uint32_t LoadingArmReset_Callback(uint32_t MotorId, uint32_t ReadValue) +{ + bool direction; + int angle = 0; + + uint32_t temp = Read_Dryer_ENC_Position(); + angle = Calculate_Arm_Distance(Arm_Drier_Center,temp); + ReportWithPackageFilter(DiagnosticsFilter,"LoadingArmReset_Callback",__FILE__,ReadValue,temp,RpMessage,ReadValue,0); + //ReportWithPackageFilter(DiagnosticsFilter,"Diagnostics_Dryer_UnLoading_Callback details",__FILE__,(int)(TotalLoadedLen),D_numberOfCycles,RpMessage,CallbackCounter,0); + //if ((AccumulatedArmMovement>8000 )&&(ReadValue == NOTBUSY)) // OK - take another round + if (ReadValue == NOTBUSY) // OK - take another round + { + ReportWithPackageFilter(DiagnosticsFilter,"LoadingArmReset_Callback OK",__FILE__,__LINE__,Arm_Drier_Center,RpMessage,ReadValue,0); + MCU_E2PromProgram(EEPROM_STORAGE_DRYER_CYCLES,0); + if ((angle<400)||(angle>16000)) + //if (fabs(angle)<0.2) + { + ReportWithPackageFilter(DiagnosticsFilter,"drier center proximity",__FILE__,temp,Arm_Drier_Center,RpMessage,angle,0); + if (angle<400) + direction = 1-MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM].directionthreadwize; + else + direction = MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM].directionthreadwize; + MotorMovetoEncoderPosition(HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM,LoadingArmReset_Callback_Stopper_Callback,/*3000*/16000,direction,10); + + } + else + { + ReportWithPackageFilter(DiagnosticsFilter,"LoadingArmReset_Callback Fail",__FILE__,__LINE__,Arm_Drier_Center,RpMessage,ReadValue,0); + MotorStop(HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM,Hard_Stop); + if (UnloadingReset) + { + UnloadingReset(MotorId, ReadValue); + UnloadingReset = NULL; + } + } + + } + else //timeout or no movement + { + ReportWithPackageFilter(DiagnosticsFilter,"Unloading drier - halted",__FILE__,__LINE__,Arm_Drier_Center,RpMessage,0,0); + //MCU_E2PromProgram(EEPROM_STORAGE_DRYER_CYCLES,LoadArmRounds-(D_numberOfCycles-2));//it takes two cycles to identify a stop of the arm + + ReportWithPackageFilter(DiagnosticsFilter,"Drier unloading timeout(1) or no movement",__FILE__,temp,Arm_Drier_Center,RpWarning,ReadValue,0); + if (UnloadingReset) + { + UnloadingReset(MotorId, ReadValue); + UnloadingReset = NULL; + } + } + return OK; +} + +uint32_t LoadingArmReset (callback_fptr callback,uint32_t timeout) //TODO +{ + uint32_t temp; + + if (UnloadingReset == NULL) + UnloadingReset = callback; + else + { + ReportWithPackageFilter(DiagnosticsFilter,"LoadingArmReset is active",__FILE__,__LINE__,timeout,RpMessage, 0,0); + return ERROR; + } + MCU_E2PromRead(EEPROM_STORAGE_DRYER_CENTER,&temp); + Arm_Drier_Center = temp; + ReportWithPackageFilter(DiagnosticsFilter,"LoadingArmReset",__FILE__,__LINE__,timeout,RpMessage, 0,0); + + MotorRunWithCallback (HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM, 1-MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM].directionthreadwize, + MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM].pulseperround/4*MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM].pulleyradius, LoadingArmReset_Callback, 300000); + + return OK; + +} +uint32_t LoadingStopArmReset(void) +{ + return MotorAbortMovetoLimitSwitch(HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM); + +} void MotorActionsInit(void) { int i; diff --git a/Software/Embedded_SW/Embedded/Modules/Diagnostics/DiagnosticsHoming.c b/Software/Embedded_SW/Embedded/Modules/Diagnostics/DiagnosticsHoming.c index b40bbe4c7..9eba08678 100644 --- a/Software/Embedded_SW/Embedded/Modules/Diagnostics/DiagnosticsHoming.c +++ b/Software/Embedded_SW/Embedded/Modules/Diagnostics/DiagnosticsHoming.c @@ -133,7 +133,7 @@ uint32_t LoadArmRounds; uint32_t D_numberOfSteps = 0; float D_numberOfCycles = 0; -double D_DrierPrevLocation = 0; +uint32_t D_DrierPrevLocation = 0; uint32_t MotorHomingRequestFunc(MessageContainer* requestContainer) @@ -465,30 +465,33 @@ return OK; /******************************************************************************** * Drier Loading Arm Homing ********************************************************************************/ -uint32_t Drier_Center = 0; -float Calculate_Arm_Angle(uint32_t Current_Angle) -{ - uint32_t angle; - float Calc_angle; - if (Current_Angle >= Drier_Center) - angle = Current_Angle - Drier_Center; - else - angle = Current_Angle + 0x3FFF - Drier_Center; - Calc_angle = angle/0x3FFF; - MCU_E2PromProgram(EEPROM_DRIER_LOADING_ARM_ANGLE,Calc_angle); - ReportWithPackageFilter(DiagnosticsFilter,"Calculate_Arm_Angle",__FILE__,(int)(Calc_angle*1000),Current_Angle,RpMessage,Drier_Center,0); - return Calc_angle; -} +uint32_t Drier_Center_read = 0; uint32_t Diagnostics_Set_Load_Arm_To_Stopper_Callback(uint32_t deviceID, uint32_t BusyFlag) { MessageContainer responseContainer; MotorHomingResponse response = MOTOR_HOMING_RESPONSE__INIT; + uint32_t angle, temp = Read_Dryer_ENC_Position(); + angle = Calculate_Arm_Distance(D_DrierPrevLocation,temp); + + if ((angle<14000 )||(ReadValue == BUSY)) // OK - take another round + { + responseContainer.has_error = true; + responseContainer.error = ERROR_CODE__GENERAL_ERROR; + + } ReportWithPackageFilter(DiagnosticsFilter,"Diagnostics_Set_Load_Arm_To_Stopper time",__FILE__,__LINE__,msec_millisecondCounter,RpMessage,0,0); + if (HomingControlId[deviceID] != 0xff) + { + ReportWithPackageFilter(DiagnosticsFilter,"MotorHomingProgressReport stopped",__FILE__,__LINE__,deviceID,RpMessage,HomingCounter[deviceID],0); + RemoveControlCallback(HomingControlId[deviceID],MotorHomingProgressReport); + HomingControlId[deviceID] = 0xff; + } //NumberOfDrierLoaderCycles=0; //storeLoadArmParameters(); - SetMotHome(HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM); //set this point as the spool home + //SetMotHome(HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM); //set this point as the spool home + ThreadLoadingRestartReport(); responseContainer = createContainer(MESSAGE_TYPE__MotorHomingResponse, HomingToken[deviceID], true, &response, &motor_homing_response__pack, &motor_homing_response__get_packed_size); responseContainer.has_continuous = true; responseContainer.continuous = true; @@ -501,45 +504,50 @@ uint32_t Diagnostics_Set_Load_Arm_To_Stopper_Callback(uint32_t deviceID, uint32_ return OK; } -uint32_t Diagnostics_Dryer_UnLoading_Callback(uint32_t MotorId, uint32_t ReadValue) +/*uint32_t Diagnostics_Dryer_UnLoading_Callback(uint32_t MotorId, uint32_t ReadValue) { + bool direction; + D_numberOfCycles++; uint32_t temp = Read_Dryer_ENC_Position(); ReportWithPackageFilter(DiagnosticsFilter,"Diagnostics_Dryer_UnLoading_Callback",__FILE__,ReadValue,temp,RpMessage,D_DrierPrevLocation,0); //ReportWithPackageFilter(DiagnosticsFilter,"Diagnostics_Dryer_UnLoading_Callback details",__FILE__,(int)(TotalLoadedLen),D_numberOfCycles,RpMessage,CallbackCounter,0); - if ((AccumulatedArmMovement>8000 )&&(ReadValue == NOTBUSY)) // OK - take another round -// if (ReadValue == NOTBUSY) // OK - take another round + //if ((AccumulatedArmMovement>8000 )&&(ReadValue == NOTBUSY)) // OK - take another round + if (ReadValue == NOTBUSY) // OK - take another round { - D_DrierPrevLocation = temp; ReportWithPackageFilter(DiagnosticsFilter,"Diagnostics_Dryer_UnLoading cycles",__FILE__,D_numberOfCycles,LoadArmRounds,RpMessage,0,0); - if (D_numberOfCycles14000 )&&(ReadValue == NOTBUSY)) // OK - take another round { + D_DrierPrevLocation = temp; //ReportWithPackageFilter(DiagnosticsFilter,"Diagnostics_Dryer_Loading_Callback",__FILE__,__LINE__,LoadStages,RpMessage,NumberOfDrierLoaderCycles,0); //ReportWithPackageFilter(DiagnosticsFilter,"Diagnostics_Dryer_Loading_Callback details",__FILE__,(int)(TotalLoadedLen),numberOfCycles,RpMessage,CallbackCounter,0); if (D_numberOfCyclesamount == 0xB11) //fast refresh for pressure + { + temp1 = Read_Dryer_ENC_Position(); + temp2 = MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM].pulseperround*MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM].microstep*MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM].pulleyradius/4; + + MotorStop(HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM,Hard_Hiz); + MotorSetMaxSpeed (HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM,200); + //6 seconds per round + Report("Arm movement test",__FILE__,request->delay,request->delay/2*2,RpWarning,(int)request->delay%2,0); + + //SetMotHome(ThreadMotorIdToMotorId[Motor_i]); + MotorMoveWithCallback (HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM, request->delay%2,request->delay/2*2, NULL, 12000); + + response.progress = temp2; + response.has_progress = true; + } + else + if(request->amount == 0xB12) //fast refresh for pressure + { + + temp2 = Calculate_Arm_Distance(temp1,Read_Dryer_ENC_Position()); + Report("Arm movement test calc",__FILE__,temp2,temp1,RpWarning,Read_Dryer_ENC_Position(),0); + + response.progress = temp2; + response.has_progress = true; + } + else + if(request->amount == 0xB13) //TryThreadLoadingRequest + { + TryThreadLoadingFunc(NULL); + Report("TryThreadLoadingFunc",__FILE__,temp2,temp1,RpWarning,Read_Dryer_ENC_Position(),0); + + response.progress = 0xB13; + response.has_progress = true; + } + else if(request->amount == 0xC3) //suspend I2C task { if (request->delay == 0) diff --git a/Software/Embedded_SW/Embedded/Modules/Thread/ThreadLoad.c b/Software/Embedded_SW/Embedded/Modules/Thread/ThreadLoad.c index cd7c146fe..d16683967 100644 --- a/Software/Embedded_SW/Embedded/Modules/Thread/ThreadLoad.c +++ b/Software/Embedded_SW/Embedded/Modules/Thread/ThreadLoad.c @@ -126,6 +126,7 @@ uint32_t Thread_Load_Dryer_UnLoading(void); uint32_t ThreadLoadingReport(void); + uint32_t ThreadLoadingRestartReport(void); //sending after a failure in the finalizing stage bool ThreadLoaded(void); bool ThreadLoadingActive(void) { @@ -245,38 +246,41 @@ } uint32_t Thread_Load_Set_Load_Arm_To_Stopper_Callback(uint32_t deviceID, uint32_t BusyFlag) { + uint32_t angle, temp = Read_Dryer_ENC_Position(); - /*if(PullerControlId != 0xFF) - { - MotorStop(ThreadMotorIdToMotorId[POOLER_MOTOR],Hard_Hiz); - RemoveControlCallback(PullerControlId, ThreadLoadControlCBFunction ); - PullerControlId = 0xFF; - }*/ - if(WinderControlId != 0xFF) + ReportWithPackageFilter(DiagnosticsFilter,"Thread_Load_Set_Load_Arm_To_Stopper_Callback",__FILE__,(int)numberOfCycles,(int)DrierPrevLocation,RpMessage,temp,0); + + angle = Calculate_Arm_Distance(DrierPrevLocation,temp); + + DrierPrevLocation = temp; + if (CallbackCounter) { - MotorStop(ThreadMotorIdToMotorId[WINDER_MOTOR],Hard_Hiz); - RemoveControlCallback(WinderControlId, ThreadLoadControlCBFunction ); - WinderControlId = 0xFF; + CallbackCounter--; } + if ((angle>14000 )&&(BusyFlag == NOTBUSY)) // OK - take another round + { + Report("Thread_Load_Set_Load_Arm_To_Stopper time",__FILE__,msec_millisecondCounter - UnloadingStart,msec_millisecondCounter,RpMessage,UnloadingStart,0); - MotorAbortMovetoLimitSwitch(HARDWARE_MOTOR_TYPE__MOTO_SCREW); - /*Task_sleep(5) - MotorStop(ThreadMotorIdToMotorId[FEEDER_MOTOR],Hard_Hiz); - MotorStop(ThreadMotorIdToMotorId[FEEDER_MOTOR],Hard_Hiz);*/ + Report("Thread_Load_Set_Load_Arm_To_Stopper_Callback",__FILE__,__LINE__,LoadStages,RpMessage,CallbackCounter,0); + NumberOfDrierLoaderCycles=0; + //storeLoadArmParameters(); + LoadStages++; + + ThreadLoadStateMachine(LoadStages); + } + else + { + load.color = fastBILNK; + usnprintf(LoadErrorMsg, 100, "Stage %s - %s timeout",LoadStagesStr[LoadStages], MotorStr[HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM]); + Report(LoadErrorMsg,__FILE__,__LINE__,LoadStages,RpWarning,TimeoutsCounter,0); - MotorStop(HARDWARE_MOTOR_TYPE__MOTO_DRYER_DRIVING,Hard_Hiz); + LoadStatus = ERROR; + ThreadLoadingReport(); + TryAgain = true; + //ThreadLoadButton(LoadStages); + } //move to exact location? // Report("Thread Load State Machine Callback.",__FILE__,__LINE__,LoadStages,RpMessage,NumberOfDrierLoaderCycles,0); - CallbackCounter = 0; - Report("Thread_Load_Set_Load_Arm_To_Stopper time",__FILE__,msec_millisecondCounter - UnloadingStart,msec_millisecondCounter,RpMessage,UnloadingStart,0); - - Report("Thread_Load_Set_Load_Arm_To_Stopper_Callback",__FILE__,__LINE__,LoadStages,RpMessage,CallbackCounter,0); - NumberOfDrierLoaderCycles=0; - //storeLoadArmParameters(); - LoadStages++; - SetMotHome(HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM); //set this point as the spool home - - ThreadLoadStateMachine(LoadStages); return OK; } uint32_t Thread_Load_HomingCallback(uint32_t MotorId, uint32_t ReadValue) @@ -484,6 +488,8 @@ CallbackCounter++; MotorMovetoLimitSwitch (HARDWARE_MOTOR_TYPE__MOTO_RDANCER,MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_RDANCER].directionthreadwize, 15, Motor_Id_to_LS_IdDown[HARDWARE_MOTOR_TYPE__MOTO_RDANCER], Thread_Load_HomingCallback,10000); + Report("Thread_Load_Close dancers tension",__FILE__,__LINE__,(int)windertension,RpMessage,(int)pullertension,0); + // MotorMovetoLimitSwitch (HARDWARE_MOTOR_TYPE__MOTO_LDANCER1,MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_LDANCER1].directionthreadwize, 500, Motor_Id_to_LS_IdDown[HARDWARE_MOTOR_TYPE__MOTO_LDANCER1], Thread_Load_HomingCallback,25000); status |= MCU_E2PromRead(EEPROM_WINDER_TENSION_POSITION,¤t); @@ -666,7 +672,7 @@ } else { - MotorMovetoEncoderPosition(HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM,Thread_Load_Dryer_MovetoEncoderPosition_Callback,30000,MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM].directionthreadwize); + MotorMovetoEncoderPosition(HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM,Thread_Load_Dryer_MovetoEncoderPosition_Callback,30000,MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM].directionthreadwize,40); Report("Store Number of cycles in drier",__FILE__,__LINE__,numberOfCycles,RpMessage,LoadArmRounds,0); } } @@ -826,6 +832,7 @@ ThreadLoadControlId = 0xFF; } + LoadingStopArmReset(); MotorStopAction(HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM); MotorStopAction(HARDWARE_MOTOR_TYPE__MOTO_RLOADING); MotorStopAction(HARDWARE_MOTOR_TYPE__MOTO_LLOADING); @@ -860,7 +867,7 @@ return OK; } - uint32_t Thread_Load_Dryer_UnLoading_Callback(uint32_t MotorId, uint32_t ReadValue) + /*uint32_t Thread_Load_Dryer_UnLoading_Callback(uint32_t MotorId, uint32_t ReadValue) { bool direction; numberOfCycles++; @@ -884,7 +891,7 @@ } else //done enough cycles, go to the center point { - MotorMovetoEncoderPosition(HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM,Thread_Load_Set_Load_Arm_To_Stopper_Callback,30000,1-MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM].directionthreadwize); + MotorMovetoEncoderPosition(HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM,Thread_Load_Set_Load_Arm_To_Stopper_Callback,30000,1-MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM].directionthreadwize,40); MCU_E2PromProgram(EEPROM_STORAGE_DRYER_CYCLES,0); Report("Store Number of cycles in drier",__FILE__,__LINE__,numberOfCycles,RpMessage,LoadArmRounds,0); } @@ -902,7 +909,7 @@ direction = 1-MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM].directionthreadwize; else direction = MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM].directionthreadwize; - MotorMovetoEncoderPosition(HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM,Thread_Load_Set_Load_Arm_To_Stopper_OnError_Callback,3000,direction); + MotorMovetoEncoderPosition(HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM,Thread_Load_Set_Load_Arm_To_Stopper_OnError_Callback,3000,direction,10); } else @@ -911,12 +918,6 @@ TimeoutsCounter = 0; CallbackCounter = 0; - /*if(PullerControlId != 0xFF) - { - MotorStop(ThreadMotorIdToMotorId[POOLER_MOTOR],Hard_Hiz); - RemoveControlCallback(PullerControlId, ThreadLoadControlCBFunction ); - PullerControlId = 0xFF; - }*/ if(WinderControlId != 0xFF) { MotorStop(ThreadMotorIdToMotorId[WINDER_MOTOR],Hard_Hiz); @@ -925,9 +926,6 @@ } MotorAbortMovetoLimitSwitch(HARDWARE_MOTOR_TYPE__MOTO_SCREW); - /*Task_sleep(5) - MotorStop(ThreadMotorIdToMotorId[FEEDER_MOTOR],Hard_Hiz); - MotorStop(ThreadMotorIdToMotorId[FEEDER_MOTOR],Hard_Hiz);*/ MotorStop(HARDWARE_MOTOR_TYPE__MOTO_DRYER_DRIVING,Hard_Hiz); load.color = fastBILNK; @@ -940,79 +938,24 @@ //ThreadLoadButton(LoadStages); } return OK; - } + }*/ uint32_t Thread_Load_Dryer_UnLoading(void) { uint32_t temp; REPORT_MSG(LoadStages, "Thread Load State Machine step Dryer Unloading"); //LoadArmRounds = 0; //uint32_t numberOfSteps = 0; - //Start Feeder Pid, Rotate Loading Arm Counter Thread Direction X Circles According To Rml. Feeder Speed Is 40 - SetOriginMotorSpeed(22); -// OriginalMotorSpd_2PPS[FEEDER_MOTOR] = 1000; -// CurrentControlledSpeed[FEEDER_MOTOR] = 1000; - -// Rockers are up already, so puller handling is not needed - //numberOfSteps = MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM].pulseperround*LoadArmRounds*MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM].microstep*MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM].pulleyradius; - /*MotorControlConfig[POOLER_MOTOR].m_params.MAX = 1; - MotorControlConfig[POOLER_MOTOR].m_params.MIN = MotorsControl[POOLER_MOTOR].outputproportionalpowerlimit*-1; - MotorControlConfig[POOLER_MOTOR].m_params.Kd = MotorsControl[POOLER_MOTOR].derivativetime; - MotorControlConfig[POOLER_MOTOR].m_params.Kp = MotorsControl[POOLER_MOTOR].proportionalgain; - MotorControlConfig[POOLER_MOTOR].m_params.Ki = 0;//MotorsControl[POOLER_MOTOR].integraltime; - MotorControlConfig[POOLER_MOTOR].m_params.IntegralErrorMultiplier = MotorsControl[POOLER_MOTOR].setpointramprateorsoftstartramp; - MotorControlConfig[POOLER_MOTOR].m_params.ProportionalErrorMultiplier = MotorsControl[POOLER_MOTOR].outputonoffhysteresisvalue; - MotorControlConfig[POOLER_MOTOR].m_params.epsilon = MotorsControl[POOLER_MOTOR].epsilon; - MotorControlConfig[POOLER_MOTOR].m_params.dt = MotorsControl[POOLER_MOTOR].controloutputtype; - MotorControlConfig[POOLER_MOTOR].m_ingnoreValue = MotorsControl[POOLER_MOTOR].sensorcorrectionadjustment; // the minimal change required to change the motor speed in pulses - MotorControlConfig[POOLER_MOTOR].m_calculatedError = 0; - MotorControlConfig[POOLER_MOTOR].m_integral = 0; - MotorControlConfig[POOLER_MOTOR].m_isEnabled = true; - MotorControlConfig[POOLER_MOTOR].m_isReady = true; - MotorControlConfig[POOLER_MOTOR].m_mesuredParam = 0; - MotorControlConfig[POOLER_MOTOR].m_preError = 0; - MotorControlConfig[POOLER_MOTOR].m_SetParam = 0;//need to update SetParams on presegment stage - MotorSetDirection(HARDWARE_MOTOR_TYPE__MOTO_LDRIVING,MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_LDRIVING].directionthreadwize); - - PullerControlId = AddControlCallback(ThreadLoadControlCBFunction, eOneMillisecond,Control_Read_Dancer_Position,(IfTypeThread*0x100+POOLER_MOTOR),POOLER_DANCER,POOLER_MOTOR); - Report("AddControlCallback Puller",__FILE__,__LINE__,PullerControlId,RpMessage,IfTypeThread*0x100+POOLER_MOTOR,0);*/ -//////////////////////// - MotorControlConfig[WINDER_MOTOR].m_params.MAX = 1; - MotorControlConfig[WINDER_MOTOR].m_params.MIN = MotorsControl[WINDER_MOTOR].outputproportionalpowerlimit*-1; - MotorControlConfig[WINDER_MOTOR].m_params.Kd = MotorsControl[WINDER_MOTOR].derivativetime; - MotorControlConfig[WINDER_MOTOR].m_params.Kp = MotorsControl[WINDER_MOTOR].proportionalgain; - MotorControlConfig[WINDER_MOTOR].m_params.Ki = 0;//MotorsControl[WINDER_MOTOR].integraltime; - MotorControlConfig[WINDER_MOTOR].m_params.IntegralErrorMultiplier = MotorsControl[WINDER_MOTOR].setpointramprateorsoftstartramp; - MotorControlConfig[WINDER_MOTOR].m_params.ProportionalErrorMultiplier = MotorsControl[WINDER_MOTOR].outputonoffhysteresisvalue; - MotorControlConfig[WINDER_MOTOR].m_params.epsilon = MotorsControl[WINDER_MOTOR].epsilon; - MotorControlConfig[WINDER_MOTOR].m_params.dt = MotorsControl[WINDER_MOTOR].controloutputtype; - MotorControlConfig[WINDER_MOTOR].m_ingnoreValue = MotorsControl[WINDER_MOTOR].sensorcorrectionadjustment; // the minimal change required to change the motor speed in pulses - MotorControlConfig[WINDER_MOTOR].m_calculatedError = 0; - MotorControlConfig[WINDER_MOTOR].m_integral = 0; - MotorControlConfig[WINDER_MOTOR].m_isEnabled = true; - MotorControlConfig[WINDER_MOTOR].m_isReady = true; - MotorControlConfig[WINDER_MOTOR].m_mesuredParam = 0; - MotorControlConfig[WINDER_MOTOR].m_preError = 0; - MotorControlConfig[WINDER_MOTOR].m_SetParam = 0;//need to update SetParams on presegment stage - MotorSetDirection(HARDWARE_MOTOR_TYPE__MOTO_WINDER,MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_WINDER].directionthreadwize); - - WinderControlId = AddControlCallback(NULL,ThreadLoadControlCBFunction, eOneMillisecond,Control_Read_Dancer_Position,(IfTypeThread*0x100+WINDER_MOTOR),WINDER_DANCER,WINDER_MOTOR); - Report("AddControlCallback Winder",__FILE__,__LINE__,WinderControlId,RpMessage,IfTypeThread*0x100+WINDER_MOTOR,0); - -//////////////////////// - MotorSetDirection(HARDWARE_MOTOR_TYPE__MOTO_DRYER_DRIVING,MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_DRYER_DRIVING].directionthreadwize); - MotorSetSpeed(HARDWARE_MOTOR_TYPE__MOTO_DRYER_DRIVING, OriginalMotorSpd_2PPS[DRYER_MOTOR]); CallbackCounter++; - //MotorMoveWithCallback (HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM, MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM].directionthreadwize, - // numberOfSteps, Thread_Load_Dryer_Loading_Callback, 100000); - //Report("Store Number of cycles in drier - halted",__FILE__,__LINE__,numberOfCycles,RpMessage,LoadArmRounds,0); - //MCU_E2PromProgram(EEPROM_STORAGE_DRYER_CYCLES,numberOfCycles); -//shlomo - UnloadingStart = msec_millisecondCounter; - numberOfSteps = MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM].pulseperround/**LoadArmRounds*/*MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM].microstep*MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM].pulleyradius; - numberOfCycles = 0; - if (SecondTry == true) + MCU_E2PromRead(EEPROM_STORAGE_DRYER_CENTER,&temp); + DrierCenterLocation = DrierPrevLocation; + DrierPrevLocation = temp; + UnloadingStart = msec_millisecondCounter; + //numberOfSteps = MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM].pulseperround/**LoadArmRounds*/*MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM].microstep*MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM].pulleyradius; + //numberOfCycles = 0; + LoadingArmReset(Thread_Load_Set_Load_Arm_To_Stopper_Callback,300000); + /*if (SecondTry == true) { MCU_E2PromRead(EEPROM_STORAGE_DRYER_CYCLES,&LoadArmRounds); if (LoadArmRounds == 0) //prev trial stopped @@ -1028,8 +971,8 @@ { LoadArmRounds = (int)dryerbufferlength; } - } - MCU_E2PromRead(EEPROM_STORAGE_DRYER_CENTER,&temp); + }*/ + /*MCU_E2PromRead(EEPROM_STORAGE_DRYER_CENTER,&temp); DrierCenterLocation = DrierPrevLocation; DrierPrevLocation = temp; Report("Thread_Load_Set_Load_Arm_To_Start_Position",__FILE__,UnloadingStart,DrierPrevLocation,RpMessage, LoadArmRounds,0); @@ -1046,6 +989,8 @@ //Keep Notation How Many Rotations In The Dryer //LoadArmRounds = (int)dryerbufferlength; + * + */ load.color = BLINK; return OK; } @@ -1172,6 +1117,8 @@ uint32_t ThreadLoadButton(THREAD_LOAD_STAGES_ENUM ReadValue) LoadStatus = OK; SecondTry = true; load.color = BLINK; + if (LoadStages > THREAD_LOAD_INITIAL_TENSION) + ThreadLoadingRestartReport(); Report("Calling State machine retry",__FILE__,LoadStages,LoadStatus,RpMessage,SecondTry,0); ThreadLoadStateMachine(LoadStages); } @@ -1180,6 +1127,8 @@ uint32_t ThreadLoadButton(THREAD_LOAD_STAGES_ENUM ReadValue) SecondTry = false; Report("Calling State machine 2nd try",__FILE__,LoadStages,LoadStatus,RpMessage,SecondTry,0); load.color = BLINK; + if (LoadStages > THREAD_LOAD_INITIAL_TENSION) + ThreadLoadingRestartReport(); ThreadLoadStateMachine(LoadStages+1); } else //((SecondTry == false)&&(TryAgain == false))??????? @@ -1191,6 +1140,8 @@ uint32_t ThreadLoadButton(THREAD_LOAD_STAGES_ENUM ReadValue) else { Report("Calling State machine status OK",__FILE__,ReadValue,LoadStatus,RpMessage,SecondTry,0); + if (LoadStages > THREAD_LOAD_INITIAL_TENSION) + ThreadLoadingRestartReport(); ThreadLoadStateMachine(LoadStages); SecondTry = false; } @@ -1520,23 +1471,54 @@ uint32_t ThreadLoadingReport(void) return OK; +} +bool ThreadLoadingRestartFlag = false; +uint32_t ThreadLoadingRestartReport(void) //sending after a failure in the finalizing stage +{ + MessageContainer responseContainer; + StartThreadLoadingResponse response = START_THREAD_LOADING_RESPONSE__INIT; + + if (ThreadLoadingToken[0] == 0) + return OK; + ThreadLoadingRestartFlag = true; + + response.has_state = true; + response.state = THREAD_LOADING_STATE__ReadyForLoading; + response.errorreason = DefaultErrSrt; + Report("ThreadLoadingReport",__FILE__,MessageState,response.state,RpWarning,(int)LoadStages,0); + //------------------------------------------------------------------------------------------- + responseContainer = createContainer(MESSAGE_TYPE__StartThreadLoadingResponse, ThreadLoadingToken, false, &response, &start_thread_loading_response__pack, &start_thread_loading_response__get_packed_size); + responseContainer.has_continuous = true; + responseContainer.continuous = true; + uint8_t* container_buffer = my_malloc(message_container__get_packed_size(&responseContainer)); + size_t container_size = message_container__pack(&responseContainer, container_buffer); + my_free(responseContainer.data.data); + SendChars((char*)container_buffer, container_size); + + return OK; + } uint32_t TryThreadLoadingFunc(MessageContainer* requestContainer) { - TryThreadLoadingRequest *request = try_thread_loading_request__unpack(NULL, requestContainer->data.len, requestContainer->data.data); + TryThreadLoadingRequest *request; TryThreadLoadingResponse Cresponse = TRY_THREAD_LOADING_RESPONSE__INIT; MessageContainer responseContainer; - MessageState = 2; + //MessageState = 2; + if (requestContainer) + request = try_thread_loading_request__unpack(NULL, requestContainer->data.len, requestContainer->data.data); ThreadLoadingReport(); Report("TryThreadLoadingFunc",__FILE__,__LINE__,MESSAGE_TYPE__TryThreadLoadingResponse,RpWarning,(int)LoadStages,0); - responseContainer = createContainer(MESSAGE_TYPE__TryThreadLoadingResponse, requestContainer->token, true, &Cresponse, &try_thread_loading_response__pack, &try_thread_loading_response__get_packed_size); - responseContainer.continuous = false; - uint8_t* container_buffer = my_malloc(message_container__get_packed_size(&responseContainer)); - size_t container_size = message_container__pack(&responseContainer, container_buffer); - my_free(responseContainer.data.data); - SendChars((char*)container_buffer, container_size); + if (requestContainer) + { + responseContainer = createContainer(MESSAGE_TYPE__TryThreadLoadingResponse, requestContainer->token, true, &Cresponse, &try_thread_loading_response__pack, &try_thread_loading_response__get_packed_size); + responseContainer.continuous = false; + uint8_t* container_buffer = my_malloc(message_container__get_packed_size(&responseContainer)); + size_t container_size = message_container__pack(&responseContainer, container_buffer); + my_free(responseContainer.data.data); + SendChars((char*)container_buffer, container_size); + } ThreadLoadButton(LoadStages); return OK; @@ -1544,7 +1526,8 @@ uint32_t TryThreadLoadingFunc(MessageContainer* requestContainer) uint32_t ThreadUpdateCallBackFunction(uint32_t IfIndex, uint32_t BusyFlag) { - ThreadLoadingReport(); + if(ThreadLoadingActive()) + ThreadLoadingReport(); return OK; } @@ -1567,13 +1550,16 @@ uint32_t ContinueThreadLoadingFunc(MessageContainer* requestContainer) MessageContainer responseContainer; MessageState = 2; ThreadLoadingReport(); - if (request->processparameters) + if (ThreadLoadingRestartFlag == false) { - dryerbufferlength = request->processparameters->dryerbufferlength; - LoadArmRounds = (int)(request->processparameters->dryerbufferlength); + if (request->processparameters) + { + dryerbufferlength = request->processparameters->dryerbufferlength; + LoadArmRounds = (int)(request->processparameters->dryerbufferlength); + } + Report("ContinueThreadLoadingFunc",__FILE__,__LINE__,(int)(request->processparameters->dryerbufferlength),RpWarning,(int)LoadStages,0); } - Report("ContinueThreadLoadingFunc",__FILE__,__LINE__,(int)(request->processparameters->dryerbufferlength),RpWarning,(int)LoadStages,0); responseContainer = createContainer(MESSAGE_TYPE__ContinueThreadLoadingResponse, requestContainer->token, true, &Cresponse, &continue_thread_loading_response__pack, &continue_thread_loading_response__get_packed_size); responseContainer.continuous = false; diff --git a/Software/Embedded_SW/Embedded/Modules/Thread/Thread_print.c b/Software/Embedded_SW/Embedded/Modules/Thread/Thread_print.c index 275e7e5b7..d7bfb1b6e 100644 --- a/Software/Embedded_SW/Embedded/Modules/Thread/Thread_print.c +++ b/Software/Embedded_SW/Embedded/Modules/Thread/Thread_print.c @@ -162,7 +162,7 @@ int FeederSpeedIndex = 0,Speed_i; void ThreadUpdateProcessLength (double length, void *Funcptr) { - REPORT_MSG(length,"ThreadUpdateProcessLength"); + ReportWithPackageFilter(ThreadFilter,"ThreadUpdateProcessLength.",__FILE__,__LINE__,(int)length,RpMessage,(int)dyeingspeed,0); CurrentRequestedLength = length*100;//Centimetres CurrentProcessedLength = 0; ProcessedLengthFuncPtr = (ProcessedLengthFunc)Funcptr; @@ -337,7 +337,10 @@ uint32_t PoolerThreadLengthCBFunction(uint32_t IfIndex, uint32_t ReadValue) }**/ //} - +#ifdef FOUR_WINDERS + if (CurrentControlledSpeed[WINDER_MOTOR]>100) + length = dyeingspeed/10; +#endif PoolerTotalProcessedLength+= (length/100); TempPoolerTotalProcessedLength = PoolerTotalProcessedLength; #ifndef FEEDER_LENGTH_CALCULATION @@ -642,11 +645,12 @@ uint32_t ThreadControlCBFunction(uint32_t IfIndex, uint32_t ReadValue) { c++; } - if ((index == WINDER_2_MOTOR)||(index == WINDER_3_MOTOR)) + //if ((index == WINDER_2_MOTOR)||(index == WINDER_3_MOTOR)||(index == WINDER_4_MOTOR)) + /*if (index >= WINDER_MOTOR) { //pooler dancer is right sided: data is opposite TranslatedReadValue = (-1*TranslatedReadValue); - } + }*/ #endif if (index == POOLER_MOTOR) { @@ -738,12 +742,12 @@ uint32_t ThreadControlCBFunction(uint32_t IfIndex, uint32_t ReadValue) //calculated_speed = (1-MotorControlConfig[index].m_calculatedError)*CurrentControlledSpeed[index]; //if (0)//(JobCounter % 1000 == 0) #ifdef FOUR_WINDERS - if (JobCounter % 500 < 4)//(FirstCalcInJob == true) + if (0)//(JobCounter % 500 < 7)//(FirstCalcInJob == true) { if (index >= WINDER_MOTOR) { // FirstCalcInJob = false; - len = usnprintf(ATMessage[index], 150, "index %d read %d avg %d error(6) %d integral(9) %d,delta(9) %d, calc(3) %d speed %d %d",index, + len = usnprintf(ATMessage[index], 150, "index %d read %d avg %d error(6) %d integral(9) %d,delta(9) %d, calc(3) %d speed %d %d",index-WINDER_MOTOR+1, TranslatedReadValue,avreageSampleValue,(int)(MotorControlConfig[index].m_mesuredParam*1000000), (int)(MotorControlConfig[index].m_integral*1000000000),(int)((MotorControlConfig[index].m_mesuredParam*MotorControlConfig[index].m_params.dt)*1000000000), (int)(MotorControlConfig[index].m_calculatedError*1000),(int)calculated_speed, (int)(InitialDryerSpeed*100/OriginalMotorSpd_2PPS[DRYER_MOTOR])); -- cgit v1.3.1 From b5bab54ffb6d1af775f44e82c14257c349a411d9 Mon Sep 17 00:00:00 2001 From: Shlomo Hecht Date: Mon, 14 Sep 2020 10:04:34 +0300 Subject: motor action changes --- Software/Embedded_SW/Embedded/Drivers/Motors/MotorActions.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'Software') diff --git a/Software/Embedded_SW/Embedded/Drivers/Motors/MotorActions.c b/Software/Embedded_SW/Embedded/Drivers/Motors/MotorActions.c index be0475b28..63e21e85a 100644 --- a/Software/Embedded_SW/Embedded/Drivers/Motors/MotorActions.c +++ b/Software/Embedded_SW/Embedded/Drivers/Motors/MotorActions.c @@ -252,7 +252,7 @@ uint32_t MotorRunWithCallback (TimerMotors_t MotorId,bool direction, uint32_t Fr } uint32_t MotorRunCallBackFunction(uint32_t IfIndex, uint32_t BusyFlag) //TODO { - uint32_t MotorId,encoder,temp = 0,tt; + uint32_t MotorId,encoder,temp = 0; uint32_t Busy = BusyFlag; int angle; @@ -267,7 +267,6 @@ uint32_t MotorRunCallBackFunction(uint32_t IfIndex, uint32_t BusyFlag) //TODO if (MotorId ==HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM) { encoder = Read_Dryer_ENC_Position(0,0); - tt=InitialArmLocation; if (ArmDirection == 1-MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM].directionthreadwize) //unloading - numbers going down { //previous number is bigger than current @@ -287,7 +286,6 @@ uint32_t MotorRunCallBackFunction(uint32_t IfIndex, uint32_t BusyFlag) //TODO { AccumulatedArmMovement+=temp; InitialArmLocation=encoder; - InitialArmLocation=encoder; } } } @@ -315,9 +313,9 @@ uint32_t MotorRunCallBackFunction(uint32_t IfIndex, uint32_t BusyFlag) //TODO } if (((temp>1000)||(temp<20))&&(CallbackCalls>10)) { - Report("MotorRunCallBackFunctionMotorRunCallBackFunction temp curr prev small",__FILE__,encoder,tt,RpWarning,temp,0); + Report("MotorRunCallBackFunctionMotorRunCallBackFunction temp curr prev small",__FILE__,encoder,InitialArmLocation,RpWarning,temp,0); failCounter++; - if (failCounter>=10) + if (failCounter>=20) { Report("arm stopped",__FILE__,failCounter,encoder,RpWarning,temp,0); MotorStop(HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM,Hard_Hiz); @@ -389,6 +387,7 @@ uint32_t MotorRunCallBackFunction(uint32_t IfIndex, uint32_t BusyFlag) //TODO return OK; } + uint32_t MotorMoveWithCallback (TimerMotors_t MotorId,bool direction, uint32_t Steps, callback_fptr callback,uint32_t timeout) //TODO { //assert (callback); @@ -1165,7 +1164,7 @@ uint32_t LoadingArmReset_Callback(uint32_t MotorId, uint32_t ReadValue) direction = 1-MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM].directionthreadwize; else direction = MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM].directionthreadwize; - MotorMovetoEncoderPosition(HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM,LoadingArmReset_Callback_Stopper_Callback,6000,direction,10); + MotorMovetoEncoderPosition(HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM,LoadingArmReset_Callback_Stopper_Callback,/*3000*/16000,direction,10); } else @@ -1211,7 +1210,7 @@ uint32_t LoadingArmReset (callback_fptr callback,uint32_t timeout) //TODO ReportWithPackageFilter(DiagnosticsFilter,"LoadingArmReset",__FILE__,__LINE__,timeout,RpMessage, 0,0); MotorRunWithCallback (HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM, 1-MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM].directionthreadwize, - MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM].pulseperround/6*MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM].pulleyradius, LoadingArmReset_Callback, 300000); + MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM].pulseperround/4*MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM].pulleyradius, LoadingArmReset_Callback, 300000); return OK; -- cgit v1.3.1 From fedfddddd682dc369f8ad410e6e72f6477747810 Mon Sep 17 00:00:00 2001 From: Ronen Sberlo Date: Mon, 14 Sep 2020 11:58:38 +0300 Subject: change polarity of arc actuator limit switch --- .../Embedded/Drivers/FPGA/FPGA_GPIO/FPGA_GPIO.c | 1 + .../Embedded_SW/Embedded/Drivers/Motors/MotorActions.c | 4 +++- .../Embedded/Modules/Heaters/Heaters_print.c | 18 ++++++++---------- 3 files changed, 12 insertions(+), 11 deletions(-) (limited to 'Software') diff --git a/Software/Embedded_SW/Embedded/Drivers/FPGA/FPGA_GPIO/FPGA_GPIO.c b/Software/Embedded_SW/Embedded/Drivers/FPGA/FPGA_GPIO/FPGA_GPIO.c index f8e8d7b9e..6e38cc68a 100644 --- a/Software/Embedded_SW/Embedded/Drivers/FPGA/FPGA_GPIO/FPGA_GPIO.c +++ b/Software/Embedded_SW/Embedded/Drivers/FPGA/FPGA_GPIO/FPGA_GPIO.c @@ -443,6 +443,7 @@ bool FPGA_Read_limit_Switches(FPGA_GPI_ENUM Limit_Switch) case I2C_HEADCARD_COVER_LS_FRONT: case I2C_HEADCARD_ARC_LS_ACTUATOR: LM_Status = !(Head_I2C_EXP4_0x46.bits.INPUT_LS_FRONT_ARC_ACT); + LM_Status -= 1; break; case I2C_HEADCARD_COVER_LS_REAR: case I2C_HEADCARD_COVER_LS_ARC: diff --git a/Software/Embedded_SW/Embedded/Drivers/Motors/MotorActions.c b/Software/Embedded_SW/Embedded/Drivers/Motors/MotorActions.c index be0475b28..f76c345ce 100644 --- a/Software/Embedded_SW/Embedded/Drivers/Motors/MotorActions.c +++ b/Software/Embedded_SW/Embedded/Drivers/Motors/MotorActions.c @@ -894,7 +894,9 @@ uint32_t MotorMovetoLimitSwitch (TimerMotors_t MotorId,bool direction, uint32_t ReportWithPackageFilter(GeneralFilter,"calling DeActivateHeadMagnet",__FILE__,timeout,direction,RpMessage,Freq,0); if (direction == MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_DH_LID].directionthreadwize) { - CloseMagnet = true; + if (Head_Type != HEAD_TYPE_ARC) { + CloseMagnet = true; + } /*if (Head_Type == HEAD_TYPE_FLAT) { Report("Close_actuators",__FILE__,__LINE__,LOW,RpMessage,true,0); diff --git a/Software/Embedded_SW/Embedded/Modules/Heaters/Heaters_print.c b/Software/Embedded_SW/Embedded/Modules/Heaters/Heaters_print.c index 3c7248204..a6b7bff86 100644 --- a/Software/Embedded_SW/Embedded/Modules/Heaters/Heaters_print.c +++ b/Software/Embedded_SW/Embedded/Modules/Heaters/Heaters_print.c @@ -218,13 +218,12 @@ void initializeArrays(void) HeaterId2PT100Id[HEATER_TYPE__HeaterZone1] = HEAD_PT100_ZONE_1_0X80_0; HeaterId2PT100Id[HEATER_TYPE__HeaterZone2] = HEAD_PT100_ZONE_2_0X80_1; HeaterId2PT100Id[HEATER_TYPE__HeaterZone3] = HEAD_PT100_ZONE_3_0X82_0; - /* - HeaterId2PT100Id[HEATER_TYPE__HeaterZone4] = HEAD_PT100_ZONE_4_0X82_1; + //HeaterId2PT100Id[HEATER_TYPE__HeaterZone4] = HEAD_PT100_ZONE_4_0X82_1; HeaterId2PT100Id[HEATER_TYPE__HeaterZone5] = HEAD_PT100_ZONE_5_0X84_0; - HeaterId2PT100Id[HEATER_TYPE__HeaterZone6] = HEAD_PT100_ZONE_6_0X84_1;*/ + //HeaterId2PT100Id[HEATER_TYPE__HeaterZone6] = HEAD_PT100_ZONE_6_0X84_1;*/ HeaterId2PT100Id[HEATER_TYPE__MixerHeater] = HEAD_PT100_MIXER_0X8E_0; - /*HeaterId2PT100Id[HEATER_TYPE__HeaterZone7] = HEAD_PT100_ZONE_7_0X86_0; - HeaterId2PT100Id[HEATER_TYPE__HeaterZone8] = HEAD_PT100_ZONE_8_0X86_1; + HeaterId2PT100Id[HEATER_TYPE__HeaterZone7] = HEAD_PT100_ZONE_7_0X86_0; + /*HeaterId2PT100Id[HEATER_TYPE__HeaterZone8] = HEAD_PT100_ZONE_8_0X86_1; HeaterId2PT100Id[HEATER_TYPE__HeaterZone9] = HEAD_PT100_ZONE_9_0X88_0; HeaterId2PT100Id[HEATER_TYPE__HeaterZone10] = HEAD_PT100_ZONE_10_0X88_1; HeaterId2PT100Id[HEATER_TYPE__HeaterZone11] = HEAD_PT100_ZONE_11_0X8A_0; @@ -239,13 +238,12 @@ void initializeArrays(void) HeaterId2CurrentId[HEATER_TYPE__HeaterZone1] = HEAD_CURRENT_ZONE_1; HeaterId2CurrentId[HEATER_TYPE__HeaterZone2] = HEAD_CURRENT_ZONE_2; HeaterId2CurrentId[HEATER_TYPE__HeaterZone3] = HEAD_CURRENT_ZONE_3; - /* - HeaterId2CurrentId[HEATER_TYPE__HeaterZone4] = HEAD_CURRENT_ZONE_4; + //HeaterId2CurrentId[HEATER_TYPE__HeaterZone4] = HEAD_CURRENT_ZONE_4; HeaterId2CurrentId[HEATER_TYPE__HeaterZone5] = HEAD_CURRENT_ZONE_5; - HeaterId2CurrentId[HEATER_TYPE__HeaterZone6] = HEAD_CURRENT_ZONE_6;*/ + //HeaterId2CurrentId[HEATER_TYPE__HeaterZone6] = HEAD_CURRENT_ZONE_6; HeaterId2CurrentId[HEATER_TYPE__MixerHeater] = HEAD_CURRENT_MIXER; - /*HeaterId2CurrentId[HEATER_TYPE__HeaterZone7] = HEAD_CURRENT_ZONE_7; - HeaterId2CurrentId[HEATER_TYPE__HeaterZone8] = HEAD_CURRENT_ZONE_8; + HeaterId2CurrentId[HEATER_TYPE__HeaterZone7] = HEAD_CURRENT_ZONE_7; + /*HeaterId2CurrentId[HEATER_TYPE__HeaterZone8] = HEAD_CURRENT_ZONE_8; HeaterId2CurrentId[HEATER_TYPE__HeaterZone9] = HEAD_CURRENT_ZONE_9; HeaterId2CurrentId[HEATER_TYPE__HeaterZone10] = HEAD_CURRENT_ZONE_10; HeaterId2CurrentId[HEATER_TYPE__HeaterZone11] = HEAD_CURRENT_ZONE_11; -- cgit v1.3.1