diff --git a/AutomaticControl/Simulator/MainWindow.xaml b/AutomaticControl/Simulator/MainWindow.xaml
index b70ccdd..b894f9c 100644
--- a/AutomaticControl/Simulator/MainWindow.xaml
+++ b/AutomaticControl/Simulator/MainWindow.xaml
@@ -9,6 +9,6 @@
Height="450"
mc:Ignorable="d">
+ Source="/Views/MovingSetpointPIDView.xaml">
diff --git a/AutomaticControl/Simulator/Models/MovingPIDSetpointModel.cs b/AutomaticControl/Simulator/Models/MovingPIDSetpointModel.cs
new file mode 100644
index 0000000..e43f653
--- /dev/null
+++ b/AutomaticControl/Simulator/Models/MovingPIDSetpointModel.cs
@@ -0,0 +1,16 @@
+using AutomaticController;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Simulator.Models
+{
+ internal class MovingPIDSetpointModel
+ {
+ public List Setpoints { get; set; }
+
+ public PIDController Controller { get; set; }
+ }
+}
diff --git a/AutomaticControl/Simulator/ViewModels/FixedSetpointPIDViewModel.cs b/AutomaticControl/Simulator/ViewModels/FixedSetpointPIDViewModel.cs
index 61dbd94..aacff0f 100644
--- a/AutomaticControl/Simulator/ViewModels/FixedSetpointPIDViewModel.cs
+++ b/AutomaticControl/Simulator/ViewModels/FixedSetpointPIDViewModel.cs
@@ -55,12 +55,14 @@ namespace Simulator.ViewModels
new LineSeries()
{
Title = "Actual",
- Values = new ChartValues()
+ Values = new ChartValues(),
+ PointGeometrySize = 5
},
new LineSeries()
{
Title = "Setpoint",
- Values = new ChartValues()
+ Values = new ChartValues(),
+ PointGeometrySize = 5
},
};
#if DEBUG
@@ -97,7 +99,7 @@ namespace Simulator.ViewModels
Series[1].Values.Add(setpoint);
Series[0].Values.Add(actual);
- SetpointHistory.Add(SetpointModel.Setpoint);
+ SetpointHistory.Add(setpoint);
ProcessHistory.Add(actual);
}
}
diff --git a/AutomaticControl/Simulator/ViewModels/MovingSetpointPIDViewModel.cs b/AutomaticControl/Simulator/ViewModels/MovingSetpointPIDViewModel.cs
new file mode 100644
index 0000000..3bf8ca1
--- /dev/null
+++ b/AutomaticControl/Simulator/ViewModels/MovingSetpointPIDViewModel.cs
@@ -0,0 +1,115 @@
+using AutomaticController;
+using CommunityToolkit.Mvvm.ComponentModel;
+using CommunityToolkit.Mvvm.Input;
+using LiveCharts;
+using LiveCharts.Wpf;
+using Simulator.Models;
+using System;
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using System.Linq;
+using System.Runtime.Intrinsics.X86;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Simulator.ViewModels
+{
+ internal partial class MovingSetpointPIDViewModel : ObservableObject
+ {
+ [ObservableProperty]
+ private MovingPIDSetpointModel _setpointModel;
+
+ [ObservableProperty]
+ private ObservableCollection _processHistory;
+ [ObservableProperty]
+ private ObservableCollection _setpointHistory;
+
+ [ObservableProperty]
+ private SeriesCollection _series;
+
+
+ [ObservableProperty]
+ private double _kp;
+ [ObservableProperty]
+ private double _ki;
+ [ObservableProperty]
+ private double _kd;
+
+ private readonly int SIMULATION_COUNT = 200;
+
+
+ public MovingSetpointPIDViewModel()
+ {
+ Kp = 0.5;
+ Ki = 0.1;
+ Kd = 0.2;
+
+ SetpointModel = new MovingPIDSetpointModel()
+ {
+ Controller = new PIDController(Kp, Kd, Ki),
+ Setpoints = new List()
+ };
+
+ // Generate setpoints
+ for (int i = 0; i < SIMULATION_COUNT; i++)
+ {
+ double cos = Math.Cos(0.5 / (2 * Math.PI) * i);
+ SetpointModel.Setpoints.Add(cos);
+ }
+
+ ProcessHistory = new ObservableCollection();
+ SetpointHistory = new ObservableCollection();
+ Series = new SeriesCollection()
+ {
+ new LineSeries()
+ {
+ Title = "Actual",
+ Values = new ChartValues(),
+ PointGeometrySize = 5
+ },
+ new LineSeries()
+ {
+ Title = "Setpoint",
+ Values = new ChartValues(),
+ PointGeometrySize = 5
+ },
+ };
+#if DEBUG
+ Simulate();
+#endif
+ }
+
+ [RelayCommand]
+ public void Simulate()
+ {
+ SetpointModel.Controller.Kp = Kp;
+ SetpointModel.Controller.Ki = Ki;
+ SetpointModel.Controller.Kd = Kd;
+
+ ProcessHistory.Clear();
+ SetpointHistory.Clear();
+ Series[0].Values.Clear();
+ Series[1].Values.Clear();
+
+ InsertData(SetpointModel.Setpoints[0], 0d);
+
+ for (int i = 1; i < SIMULATION_COUNT; i++)
+ {
+ double current = ProcessHistory.LastOrDefault();
+ double output = SetpointModel.Controller.Compute(SetpointModel.Setpoints[i], current);
+ double actual = current + output;
+
+ InsertData(SetpointModel.Setpoints[i], actual);
+ }
+ }
+
+ private void InsertData(double setpoint, double actual)
+ {
+ Series[1].Values.Add(setpoint);
+ Series[0].Values.Add(actual);
+
+ SetpointHistory.Add(setpoint);
+ ProcessHistory.Add(actual);
+ }
+ }
+}
diff --git a/AutomaticControl/Simulator/Views/MovingSetpointPIDView.xaml b/AutomaticControl/Simulator/Views/MovingSetpointPIDView.xaml
new file mode 100644
index 0000000..49ddd2a
--- /dev/null
+++ b/AutomaticControl/Simulator/Views/MovingSetpointPIDView.xaml
@@ -0,0 +1,43 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/AutomaticControl/Simulator/Views/MovingSetpointPIDView.xaml.cs b/AutomaticControl/Simulator/Views/MovingSetpointPIDView.xaml.cs
new file mode 100644
index 0000000..e4d8158
--- /dev/null
+++ b/AutomaticControl/Simulator/Views/MovingSetpointPIDView.xaml.cs
@@ -0,0 +1,28 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Data;
+using System.Windows.Documents;
+using System.Windows.Input;
+using System.Windows.Media;
+using System.Windows.Media.Imaging;
+using System.Windows.Navigation;
+using System.Windows.Shapes;
+
+namespace Simulator.Views
+{
+ ///
+ /// MovingSetpointPIDView.xaml에 대한 상호 작용 논리
+ ///
+ public partial class MovingSetpointPIDView : Page
+ {
+ public MovingSetpointPIDView()
+ {
+ InitializeComponent();
+ }
+ }
+}