123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- using IModel;
- using Shaker.Models;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ShakerService.ViewModel
- {
- internal sealed class BalancingControlViewModel:ViewModelBase<BalancingControlModel>
- {
- /// <summary>
- /// 启用静支撑积分
- /// </summary>
- public bool EnabledIntegration =>CurrentModel.EnabledIntegration;
- /// <summary>
- /// 静支撑积分
- /// </summary>
- public double BalancingIntegration =>CurrentModel.BalancingIntegration;
- /// <summary>
- /// 静支撑增益
- /// </summary>
- public double StaticSupportGain =>CurrentModel.StaticSupportGain;
- /// <summary>
- /// 静支撑闭环
- /// </summary>
- public bool StaticSupportCloseLoop =>CurrentModel.StaticSupportCloseLoop;
- /// <summary>
- /// 静支撑开环驱动(V)
- /// </summary>
- public double[] StaticSupportOpenLoopDrvier =>CurrentModel.StaticSupportOpenLoopDrvier;
- /// <summary>
- /// 预加载质量(kg)
- /// </summary>
- public double[] PreloadingQuality =>CurrentModel.PreloadingQuality;
- /// <summary>
- /// 支撑缸面积(mm^2)
- /// </summary>
- public double Area =>CurrentModel.Area;
- private BalancingControlViewModel():base()
- {
- }
- static BalancingControlViewModel()
- {
- }
- public override void SetFpga()
- {
- base.SetFpga();
- ShakerFpga.ShakerFpga.Instance.静支撑增益.Value = CurrentModel.StaticSupportGain;
- ShakerFpga.ShakerFpga.Instance.空台面压力.Value = [.. PreloadingQuality.Select(x => x * ShakerConfigViewModel.Instance.G / Area)];
- ShakerFpga.ShakerFpga.Instance.静支撑开环驱动.Value = StaticSupportOpenLoopDrvier;
- ShakerFpga.ShakerFpga.Instance.静支撑积分.Value = EnabledIntegration;
- ShakerFpga.ShakerFpga.Instance.静支撑闭环.Value = StaticSupportCloseLoop;
- ShakerFpga.ShakerFpga.Instance.支撑缸积分.Value = BalancingIntegration;
- }
- private protected override void ReadModel()
- {
- Communication.Instance.DbConnection.CreateTable<BalancingControlModel>(tableName: nameof(BalancingControlModel));
- var model = Communication.Instance.DbConnection.Query<BalancingControlModel>($"select * from {nameof(BalancingControlModel)} limit 1")?.FirstOrDefault() ?? new BalancingControlModel();
- Communication.Instance.DbConnection.Execute($"CREATE TABLE IF NOT EXISTS {nameof(BalancingControlModel.PreloadingQuality)} ({nameof(BaseModel.Id)} INTEGER PRIMARY KEY AUTOINCREMENT, Value REAL);");
- model.PreloadingQuality = Communication.Instance.DbConnection.Query<double>($"select Value from {nameof(BalancingControlModel.PreloadingQuality)} limit 4")?.ToArray() ?? new double[4];
- if(model.PreloadingQuality == null|| model.PreloadingQuality.Length!=4)
- {
- model.PreloadingQuality = new double[4];
- }
- Communication.Instance.DbConnection.Execute($"CREATE TABLE IF NOT EXISTS {nameof(BalancingControlModel.StaticSupportOpenLoopDrvier)} ({nameof(BaseModel.Id)} INTEGER PRIMARY KEY AUTOINCREMENT, Value REAL);");
- model.StaticSupportOpenLoopDrvier = Communication.Instance.DbConnection.Query<double>($"select Value from {nameof(BalancingControlModel.StaticSupportOpenLoopDrvier)} limit 4")?.ToArray() ?? new double[4];
- if(model.StaticSupportOpenLoopDrvier ==null || model.StaticSupportOpenLoopDrvier.Length!=4)
- {
- model.StaticSupportOpenLoopDrvier = new double[4];
- }
- CurrentModel = model;
- SaveModel();
- base.ReadModel();
- }
- private protected override void UpModel(BalancingControlModel model)
- {
- if(model.PreloadingQuality==null || model.PreloadingQuality.Length!=4)
- {
- model.PreloadingQuality = new double[4];
- }
- if(model.StaticSupportOpenLoopDrvier==null || model.StaticSupportOpenLoopDrvier.Length!=4)
- {
- model.StaticSupportOpenLoopDrvier = new double[4];
- }
- base.UpModel(model);
- }
- private protected override void SaveModel()
- {
- base.SaveModel();
- Communication.Instance.DbConnection.DeleteAll<BalancingControlModel>(tableName: nameof(BalancingControlModel));
- Communication.Instance.DbConnection.Insert(CurrentModel, nameof(BalancingControlModel));
- Communication.Instance.DbConnection.DeleteAll<double>(tableName: nameof(BalancingControlModel.PreloadingQuality));
- for(int i=0;i<CurrentModel.PreloadingQuality.Length;i++)
- {
- Communication.Instance.DbConnection.Execute($"INSERT INTO {nameof(BalancingControlModel.PreloadingQuality)} (Value) VALUES ({CurrentModel.PreloadingQuality[i]});");
- }
- Communication.Instance.DbConnection.DeleteAll<double>(tableName: nameof(BalancingControlModel.StaticSupportOpenLoopDrvier));
- for (int i = 0; i < CurrentModel.StaticSupportOpenLoopDrvier.Length; i++)
- {
- Communication.Instance.DbConnection.Execute($"INSERT INTO {nameof(BalancingControlModel.StaticSupportOpenLoopDrvier)} (Value) VALUES ({CurrentModel.StaticSupportOpenLoopDrvier[i]});");
- }
- }
- public static BalancingControlViewModel Instance { get; } = new BalancingControlViewModel();
- }
- }
|