2024-05-31 10:06:49 -03:00
|
|
|
|
|
2024-05-11 15:55:44 -03:00
|
|
|
|
using CtrEditor.Siemens;
|
2024-05-11 11:58:55 -03:00
|
|
|
|
using System.Windows;
|
|
|
|
|
using System.Windows.Controls;
|
|
|
|
|
using System.Windows.Media;
|
2024-05-18 05:53:04 -03:00
|
|
|
|
using Newtonsoft.Json;
|
2024-05-22 14:21:39 -03:00
|
|
|
|
using CommunityToolkit.Mvvm.ComponentModel;
|
2024-05-11 11:58:55 -03:00
|
|
|
|
|
|
|
|
|
namespace CtrEditor.ObjetosSim
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Interaction logic for ucVMmotorSim.xaml
|
|
|
|
|
/// </summary>
|
2024-05-14 07:04:22 -03:00
|
|
|
|
///
|
|
|
|
|
|
2024-05-22 14:21:39 -03:00
|
|
|
|
public partial class osVMmotorSim : osBase, IosBase
|
2024-05-11 11:58:55 -03:00
|
|
|
|
{
|
2024-05-14 07:04:22 -03:00
|
|
|
|
|
2024-05-11 11:58:55 -03:00
|
|
|
|
// Otros datos y métodos relevantes para la simulación
|
2024-05-22 14:21:39 -03:00
|
|
|
|
|
2024-05-18 05:53:04 -03:00
|
|
|
|
private VMSimMotor motState = new VMSimMotor();
|
2024-05-14 12:10:32 -03:00
|
|
|
|
|
2024-05-19 16:38:57 -03:00
|
|
|
|
public static string NombreClase()
|
|
|
|
|
{
|
|
|
|
|
return "VetroMeccanica Motor";
|
|
|
|
|
}
|
2024-05-22 14:21:39 -03:00
|
|
|
|
private string nombre = NombreClase();
|
|
|
|
|
public override string Nombre
|
2024-05-18 05:53:04 -03:00
|
|
|
|
{
|
2024-05-22 14:21:39 -03:00
|
|
|
|
get => nombre;
|
|
|
|
|
set => SetProperty(ref nombre, value);
|
2024-05-18 05:53:04 -03:00
|
|
|
|
}
|
2024-05-11 11:58:55 -03:00
|
|
|
|
|
2024-05-22 14:21:39 -03:00
|
|
|
|
[JsonIgnore]
|
|
|
|
|
[ObservableProperty]
|
|
|
|
|
public ImageSource imageSource_oculta;
|
2024-05-11 11:58:55 -03:00
|
|
|
|
|
2024-06-04 12:33:00 -03:00
|
|
|
|
[ObservableProperty]
|
|
|
|
|
public float angulo;
|
|
|
|
|
|
2024-05-22 14:21:39 -03:00
|
|
|
|
[ObservableProperty]
|
|
|
|
|
public float tamano;
|
|
|
|
|
[ObservableProperty]
|
2024-05-27 05:34:20 -03:00
|
|
|
|
public float proporcionalSpeed;
|
|
|
|
|
|
|
|
|
|
[ObservableProperty]
|
|
|
|
|
public float max_Speed_for_Ramp;
|
|
|
|
|
|
2024-05-14 12:10:32 -03:00
|
|
|
|
|
2024-05-22 14:21:39 -03:00
|
|
|
|
[ObservableProperty]
|
|
|
|
|
public float tiempoRampa;
|
2024-05-14 12:10:32 -03:00
|
|
|
|
|
2024-05-22 14:21:39 -03:00
|
|
|
|
partial void OnTiempoRampaChanged(float value)
|
2024-05-14 07:04:22 -03:00
|
|
|
|
{
|
2024-05-22 14:21:39 -03:00
|
|
|
|
if (value < 0.1f)
|
|
|
|
|
value = 0.1f;
|
|
|
|
|
tiempoRampa = value;
|
2024-05-14 07:04:22 -03:00
|
|
|
|
}
|
|
|
|
|
|
2024-05-22 14:21:39 -03:00
|
|
|
|
[ObservableProperty]
|
|
|
|
|
public bool encendido;
|
|
|
|
|
[ObservableProperty]
|
|
|
|
|
public int pLC_NumeroMotor;
|
|
|
|
|
[ObservableProperty]
|
|
|
|
|
public float ratio;
|
2024-05-11 11:58:55 -03:00
|
|
|
|
|
2024-05-22 14:21:39 -03:00
|
|
|
|
[ObservableProperty]
|
|
|
|
|
public float velocidad;
|
2024-05-11 11:58:55 -03:00
|
|
|
|
|
2024-05-22 14:21:39 -03:00
|
|
|
|
partial void OnVelocidadChanged(float value)
|
2024-05-11 11:58:55 -03:00
|
|
|
|
{
|
2024-05-22 14:21:39 -03:00
|
|
|
|
if (value > 0)
|
|
|
|
|
ImageSource_oculta = ImageFromPath("/imagenes/motorVerde.png");
|
|
|
|
|
else
|
|
|
|
|
ImageSource_oculta = ImageFromPath("/imagenes/motorNegro.png");
|
2024-05-14 07:04:22 -03:00
|
|
|
|
}
|
|
|
|
|
|
2024-05-11 11:58:55 -03:00
|
|
|
|
public osVMmotorSim()
|
|
|
|
|
{
|
|
|
|
|
Tamano = 0.30f;
|
2024-05-11 15:55:44 -03:00
|
|
|
|
PLC_NumeroMotor = 31;
|
2024-05-27 05:34:20 -03:00
|
|
|
|
ProporcionalSpeed = 100;
|
|
|
|
|
Max_Speed_for_Ramp = 100;
|
2024-05-14 12:10:32 -03:00
|
|
|
|
TiempoRampa = 3;
|
2024-05-22 14:21:39 -03:00
|
|
|
|
ImageSource_oculta = ImageFromPath("/imagenes/motor2.png");
|
2024-05-18 05:53:04 -03:00
|
|
|
|
}
|
2024-05-11 11:58:55 -03:00
|
|
|
|
|
2024-05-14 03:15:54 -03:00
|
|
|
|
public override void UpdateGeometryStart()
|
2024-05-11 11:58:55 -03:00
|
|
|
|
{
|
|
|
|
|
// Se llama antes de la simulacion
|
|
|
|
|
|
|
|
|
|
}
|
2024-05-14 12:10:32 -03:00
|
|
|
|
public override void UpdatePLC(PLCModel plc, int elapsedMilliseconds) {
|
|
|
|
|
|
2024-05-18 05:53:04 -03:00
|
|
|
|
motState.UpdatePLC(plc,PLC_NumeroMotor,Encendido, elapsedMilliseconds);
|
2024-05-27 05:34:20 -03:00
|
|
|
|
Velocidad = (ProporcionalSpeed / 100) * (motState.STATUS_VFD_ACT_Speed_Hz / 10);
|
2024-05-14 12:10:32 -03:00
|
|
|
|
}
|
|
|
|
|
|
2024-05-16 13:45:14 -03:00
|
|
|
|
public override void UpdateControl(int elapsedMilliseconds)
|
2024-05-11 11:58:55 -03:00
|
|
|
|
{
|
2024-05-18 05:53:04 -03:00
|
|
|
|
// Calculamos la velocidad
|
2024-05-27 05:34:20 -03:00
|
|
|
|
motState.UpdateSpeed(Max_Speed_for_Ramp, TiempoRampa, elapsedMilliseconds);
|
2024-05-11 15:55:44 -03:00
|
|
|
|
|
2024-05-11 11:58:55 -03:00
|
|
|
|
}
|
2024-05-18 05:53:04 -03:00
|
|
|
|
|
2024-05-14 03:15:54 -03:00
|
|
|
|
public override void ucLoaded()
|
|
|
|
|
{
|
|
|
|
|
// El UserControl ya se ha cargado y podemos obtener las coordenadas para
|
|
|
|
|
// crear el objeto de simulacion
|
2024-06-09 12:33:09 -03:00
|
|
|
|
base.ucLoaded();
|
2024-06-04 12:33:00 -03:00
|
|
|
|
OnVelocidadChanged(Velocidad);
|
2024-05-18 06:49:02 -03:00
|
|
|
|
|
2024-05-14 03:15:54 -03:00
|
|
|
|
}
|
2024-05-11 11:58:55 -03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public partial class ucVMmotorSim : UserControl, IDataContainer
|
|
|
|
|
{
|
|
|
|
|
public osBase? Datos { get; set; }
|
|
|
|
|
|
|
|
|
|
public ucVMmotorSim()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
2024-05-14 07:04:22 -03:00
|
|
|
|
this.Loaded += OnLoaded;
|
2024-05-18 09:58:41 -03:00
|
|
|
|
this.Unloaded += OnUnloaded;
|
2024-05-14 07:04:22 -03:00
|
|
|
|
}
|
|
|
|
|
private void OnLoaded(object sender, RoutedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
Datos?.ucLoaded();
|
2024-05-11 11:58:55 -03:00
|
|
|
|
}
|
2024-05-18 09:58:41 -03:00
|
|
|
|
private void OnUnloaded(object sender, RoutedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
Datos?.ucUnLoaded();
|
|
|
|
|
}
|
2024-05-11 11:58:55 -03:00
|
|
|
|
public void Resize(float width, float height) { }
|
|
|
|
|
public void Move(float LeftPixels, float TopPixels)
|
|
|
|
|
{
|
|
|
|
|
if (Datos != null)
|
|
|
|
|
{
|
|
|
|
|
Datos.Left = PixelToMeter.Instance.calc.PixelsToMeters(LeftPixels);
|
|
|
|
|
Datos.Top = PixelToMeter.Instance.calc.PixelsToMeters(TopPixels);
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-06-04 12:33:00 -03:00
|
|
|
|
public void Rotate(float Angle) {
|
|
|
|
|
if (Datos != null)
|
|
|
|
|
if (Datos is osVMmotorSim datos)
|
|
|
|
|
datos.Angulo = Angle;
|
|
|
|
|
}
|
2024-05-11 11:58:55 -03:00
|
|
|
|
public void Highlight(bool State) { }
|
|
|
|
|
public int ZIndex()
|
|
|
|
|
{
|
|
|
|
|
return 10;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-05-18 05:53:04 -03:00
|
|
|
|
|
|
|
|
|
public class VMSimMotor
|
|
|
|
|
{
|
|
|
|
|
public bool _STATUS_VFD_Ready;
|
|
|
|
|
public float STATUS_VFD_ACT_Speed_Hz;
|
|
|
|
|
public bool Motor_Running;
|
|
|
|
|
public bool STATUS_VFD_Trip;
|
|
|
|
|
public bool STATUS_VFD_Warning;
|
|
|
|
|
public bool STATUS_VFD_Coasting;
|
|
|
|
|
public bool OUT_Run;
|
|
|
|
|
public bool OUT_Stop;
|
|
|
|
|
public bool OUT_Reversal;
|
|
|
|
|
public float OUT_OUT_VFD_REQ_Speed_Hz;
|
|
|
|
|
|
|
|
|
|
public void UpdatePLC(PLCModel plc, int NumeroMotor, bool Encendido, int elapsedMilliseconds)
|
|
|
|
|
{
|
|
|
|
|
var index = 0;
|
|
|
|
|
switch (NumeroMotor)
|
|
|
|
|
{
|
|
|
|
|
case < 100:
|
|
|
|
|
index = (int)NumeroMotor - 30 + 300;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
OUT_Run = plc.LeerTagBool($"\"DB MotorSimulate\".Motors[{index}].OUT.Run");
|
|
|
|
|
OUT_Reversal = plc.LeerTagBool($"\"DB MotorSimulate\".Motors[{index}].OUT.\"Reversal Direction\"");
|
|
|
|
|
OUT_OUT_VFD_REQ_Speed_Hz = (float)plc.LeerTagInt16($"\"DB MotorSimulate\".Motors[{index}].OUT.OUT_VFD_REQ_Speed_Hz");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (Encendido)
|
|
|
|
|
{
|
|
|
|
|
_STATUS_VFD_Ready = true;
|
|
|
|
|
Motor_Running = true;
|
|
|
|
|
STATUS_VFD_Trip = false;
|
|
|
|
|
STATUS_VFD_Warning = false;
|
|
|
|
|
STATUS_VFD_Coasting = false;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_STATUS_VFD_Ready = false;
|
|
|
|
|
Motor_Running = false;
|
|
|
|
|
STATUS_VFD_Trip = true;
|
|
|
|
|
STATUS_VFD_Warning = false;
|
|
|
|
|
STATUS_VFD_Coasting = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
plc.EscribirTagBool($"\"DB MotorSimulate\".Motors[{index}].STATUS_VFD_Ready", _STATUS_VFD_Ready);
|
|
|
|
|
plc.EscribirTagBool($"\"DB MotorSimulate\".Motors[{index}].Motor_Running", Motor_Running);
|
|
|
|
|
plc.EscribirTagBool($"\"DB MotorSimulate\".Motors[{index}].STATUS_VFD_Trip", STATUS_VFD_Trip);
|
|
|
|
|
plc.EscribirTagBool($"\"DB MotorSimulate\".Motors[{index}].STATUS_VFD_Warning", STATUS_VFD_Warning);
|
|
|
|
|
plc.EscribirTagBool($"\"DB MotorSimulate\".Motors[{index}].STATUS_VFD_Coasting", STATUS_VFD_Coasting);
|
|
|
|
|
|
|
|
|
|
plc.EscribirTagInt16($"\"DB MotorSimulate\".Motors[{index}].STATUS_VFD_ACT_Speed_Hz", (int)STATUS_VFD_ACT_Speed_Hz);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-27 05:34:20 -03:00
|
|
|
|
private float CalcSpeedRamp(float max_Speed_for_Ramp, float TiempoRampa, float actual, float expected, int elapsedMilliseconds)
|
2024-05-18 05:53:04 -03:00
|
|
|
|
{
|
2024-05-27 05:34:20 -03:00
|
|
|
|
float hzIncrementsRamp = (max_Speed_for_Ramp * 10) / (TiempoRampa * (1000.0f / elapsedMilliseconds));
|
2024-05-18 05:53:04 -03:00
|
|
|
|
float delta = expected - actual;
|
|
|
|
|
// Conrtolar si la diferencia no es mayor de lo que falta
|
|
|
|
|
if (Math.Abs(hzIncrementsRamp) > Math.Abs(delta))
|
|
|
|
|
hzIncrementsRamp = Math.Abs(delta);
|
|
|
|
|
if (delta < 0)
|
|
|
|
|
return -hzIncrementsRamp;
|
|
|
|
|
else
|
|
|
|
|
return hzIncrementsRamp;
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-27 05:34:20 -03:00
|
|
|
|
public void UpdateSpeed(float max_Speed_for_Ramp, float TiempoRampa, int elapsedMilliseconds)
|
2024-05-18 05:53:04 -03:00
|
|
|
|
{
|
|
|
|
|
// Calculamos la velocidad
|
2024-05-27 05:34:20 -03:00
|
|
|
|
STATUS_VFD_ACT_Speed_Hz += CalcSpeedRamp(max_Speed_for_Ramp, TiempoRampa, STATUS_VFD_ACT_Speed_Hz, OUT_OUT_VFD_REQ_Speed_Hz, elapsedMilliseconds);
|
2024-05-18 05:53:04 -03:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-11 11:58:55 -03:00
|
|
|
|
}
|