Se añadieron nuevas propiedades relacionadas con el encoder en la clase ucVMmotorSim, permitiendo la lectura del valor actual de la posición del encoder y la habilitación de su uso. Se eliminaron instancias innecesarias de Stopwatch en las clases ucEncoderMotor y ucEncoderMotorLineal, optimizando el código. Además, se realizaron ajustes en la interfaz de usuario de ucBoolTag para incluir una opción de visualización de descripción.
This commit is contained in:
parent
fefc0a700d
commit
75c507be4e
|
@ -2,11 +2,13 @@
|
||||||
using CtrEditor.FuncionesBase;
|
using CtrEditor.FuncionesBase;
|
||||||
using LibS7Adv;
|
using LibS7Adv;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
using System.ComponentModel;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Controls;
|
using System.Windows.Controls;
|
||||||
using System.Windows.Media;
|
using System.Windows.Media;
|
||||||
|
|
||||||
|
|
||||||
namespace CtrEditor.ObjetosSim
|
namespace CtrEditor.ObjetosSim
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -59,6 +61,16 @@ namespace CtrEditor.ObjetosSim
|
||||||
[ObservableProperty]
|
[ObservableProperty]
|
||||||
public float tiempoRampa;
|
public float tiempoRampa;
|
||||||
|
|
||||||
|
[ObservableProperty]
|
||||||
|
[property: Description("Enable read of the Motor encoder simulated on PLC.")]
|
||||||
|
[property: Category("Encoder:")]
|
||||||
|
bool motor_With_Encoder;
|
||||||
|
|
||||||
|
[ObservableProperty]
|
||||||
|
[property: Description("Actual Value of the encoder position.")]
|
||||||
|
[property: Category("Encoder:")]
|
||||||
|
public float actual_Position;
|
||||||
|
|
||||||
partial void OnTiempoRampaChanged(float value)
|
partial void OnTiempoRampaChanged(float value)
|
||||||
{
|
{
|
||||||
if (value < 0.1f)
|
if (value < 0.1f)
|
||||||
|
@ -204,9 +216,14 @@ namespace CtrEditor.ObjetosSim
|
||||||
|
|
||||||
// Add timestamp to trace when the read occurs
|
// Add timestamp to trace when the read occurs
|
||||||
var timestamp = DateTime.Now;
|
var timestamp = DateTime.Now;
|
||||||
|
|
||||||
// Read ControlWord and track the raw response
|
if (Data.Motor_With_Encoder)
|
||||||
var rawResponse = plc.LeerTagDInt($"\"DB MotorSimulate\".Motors[{DB_Motor}].ControlWord");
|
Data.Actual_Position = (float)plc.LeerTagDInt($"\"DB MotorSimulate\".Motors[{DB_Motor}].ActualPosition");
|
||||||
|
else
|
||||||
|
Data.Actual_Position = 0;
|
||||||
|
|
||||||
|
// Read ControlWord and track the raw response
|
||||||
|
var rawResponse = plc.LeerTagDInt($"\"DB MotorSimulate\".Motors[{DB_Motor}].ControlWord");
|
||||||
int controlWord = rawResponse ?? 0;
|
int controlWord = rawResponse ?? 0;
|
||||||
var control = VMMotorBitPacker.UnpackControlWord(controlWord);
|
var control = VMMotorBitPacker.UnpackControlWord(controlWord);
|
||||||
|
|
||||||
|
|
|
@ -14,8 +14,6 @@ namespace CtrEditor.ObjetosSim
|
||||||
public partial class osEncoderMotor : osBase, IosBase
|
public partial class osEncoderMotor : osBase, IosBase
|
||||||
{
|
{
|
||||||
private osBase Motor = null;
|
private osBase Motor = null;
|
||||||
private Stopwatch Stopwatch = new Stopwatch();
|
|
||||||
private double stopwatch_last = 0;
|
|
||||||
|
|
||||||
public static string NombreClase()
|
public static string NombreClase()
|
||||||
{
|
{
|
||||||
|
@ -86,7 +84,6 @@ namespace CtrEditor.ObjetosSim
|
||||||
Pulsos_Por_Vuelta = 360; // Por defecto, un pulso por grado
|
Pulsos_Por_Vuelta = 360; // Por defecto, un pulso por grado
|
||||||
Ratio_Giros_50hz = 1; // Por defecto, 1 giro por cada 50Hz
|
Ratio_Giros_50hz = 1; // Por defecto, 1 giro por cada 50Hz
|
||||||
Color_oculto = Brushes.Gray;
|
Color_oculto = Brushes.Gray;
|
||||||
Stopwatch.Start();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void UpdatePLC(PLCViewModel plc, int elapsedMilliseconds)
|
public override void UpdatePLC(PLCViewModel plc, int elapsedMilliseconds)
|
||||||
|
|
|
@ -14,8 +14,6 @@ namespace CtrEditor.ObjetosSim
|
||||||
public partial class osEncoderMotorLineal : osBase, IosBase
|
public partial class osEncoderMotorLineal : osBase, IosBase
|
||||||
{
|
{
|
||||||
private osBase Motor = null;
|
private osBase Motor = null;
|
||||||
private Stopwatch Stopwatch = new Stopwatch();
|
|
||||||
private double stopwatch_last = 0;
|
|
||||||
|
|
||||||
public static string NombreClase()
|
public static string NombreClase()
|
||||||
{
|
{
|
||||||
|
@ -86,7 +84,6 @@ namespace CtrEditor.ObjetosSim
|
||||||
{
|
{
|
||||||
Pulsos_Por_Hz = 3000; // Por defecto, un pulso por grado
|
Pulsos_Por_Hz = 3000; // Por defecto, un pulso por grado
|
||||||
Color_oculto = Brushes.Gray;
|
Color_oculto = Brushes.Gray;
|
||||||
Stopwatch.Start();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void UpdatePLC(PLCViewModel plc, int elapsedMilliseconds)
|
public override void UpdatePLC(PLCViewModel plc, int elapsedMilliseconds)
|
||||||
|
@ -100,7 +97,8 @@ namespace CtrEditor.ObjetosSim
|
||||||
Valor_Actual = (int)value;
|
Valor_Actual = (int)value;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else if (Motor != null && Motor is osVMmotorSim motor)
|
}
|
||||||
|
else if (Motor != null && Motor is osVMmotorSim motor)
|
||||||
{
|
{
|
||||||
VelocidadActual = motor.Velocidad;
|
VelocidadActual = motor.Velocidad;
|
||||||
|
|
||||||
|
@ -116,7 +114,10 @@ namespace CtrEditor.ObjetosSim
|
||||||
float incrementoPulsos = pulsosPorHz * segundosTranscurridos;
|
float incrementoPulsos = pulsosPorHz * segundosTranscurridos;
|
||||||
|
|
||||||
// Actualizar valor del encoder
|
// Actualizar valor del encoder
|
||||||
Valor_Actual = (Valor_Actual + incrementoPulsos);
|
if (motor.Motor_With_Encoder)
|
||||||
|
Valor_Actual = motor.Actual_Position;
|
||||||
|
else
|
||||||
|
Valor_Actual = (Valor_Actual + incrementoPulsos);
|
||||||
|
|
||||||
// Actualizar color basado en si está girando
|
// Actualizar color basado en si está girando
|
||||||
Color_oculto = Math.Abs(pulsosPorHz) > 0.01f ? Brushes.LightGreen : Brushes.Gray;
|
Color_oculto = Math.Abs(pulsosPorHz) > 0.01f ? Brushes.LightGreen : Brushes.Gray;
|
||||||
|
|
|
@ -1,17 +1,14 @@
|
||||||
<UserControl x:Class="CtrEditor.ObjetosSim.ucBoolTag"
|
<UserControl x:Class="CtrEditor.ObjetosSim.ucBoolTag" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
xmlns:ei="http://schemas.microsoft.com/xaml/behaviors"
|
||||||
xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
xmlns:ei="http://schemas.microsoft.com/xaml/behaviors"
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:vm="clr-namespace:CtrEditor.ObjetosSim"
|
||||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
mc:Ignorable="d">
|
||||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
|
||||||
xmlns:vm="clr-namespace:CtrEditor.ObjetosSim"
|
|
||||||
mc:Ignorable="d">
|
|
||||||
|
|
||||||
<UserControl.DataContext>
|
<UserControl.DataContext>
|
||||||
<vm:osBoolTag/>
|
<vm:osBoolTag Show_Description="True" />
|
||||||
</UserControl.DataContext>
|
</UserControl.DataContext>
|
||||||
<Canvas RenderTransformOrigin="0.5,0.5">
|
<Canvas RenderTransformOrigin="0.5,0.5" ToolTip="{Binding Descripcion}">
|
||||||
<Canvas.RenderTransform>
|
<Canvas.RenderTransform>
|
||||||
<TransformGroup>
|
<TransformGroup>
|
||||||
<ScaleTransform />
|
<ScaleTransform />
|
||||||
|
@ -26,18 +23,14 @@
|
||||||
<ColumnDefinition Width="*" />
|
<ColumnDefinition Width="*" />
|
||||||
<ColumnDefinition Width="Auto" />
|
<ColumnDefinition Width="Auto" />
|
||||||
</Grid.ColumnDefinitions>
|
</Grid.ColumnDefinitions>
|
||||||
<Border x:Name="BackgroundRectangle"
|
<Border x:Name="BackgroundRectangle" BorderBrush="Black" BorderThickness="2" CornerRadius="10,0,0,10"
|
||||||
BorderBrush="Black"
|
Width="16" Height="25" VerticalAlignment="Center" HorizontalAlignment="Center"
|
||||||
BorderThickness="2"
|
Background="{Binding Color, Converter={StaticResource ColorToBrushConverter}}" />
|
||||||
CornerRadius="10,0,0,10"
|
<Label Content="{Binding Descripcion}" Grid.Column="1" VerticalAlignment="Center"
|
||||||
Width="30"
|
Background="{Binding Color}"
|
||||||
Height="40"
|
Visibility="{Binding Show_Description, Converter={StaticResource BooleanToVisibilityConverter}}" />
|
||||||
VerticalAlignment="Top"
|
|
||||||
HorizontalAlignment="Left"
|
|
||||||
Background="{Binding Color, Converter={StaticResource ColorToBrushConverter}}"/>
|
|
||||||
<Label Content="{Binding Descripcion}" Grid.Column="1" VerticalAlignment="Center" Background="{Binding Color}" />
|
|
||||||
<CheckBox Grid.Column="2" VerticalAlignment="Center" IsChecked="{Binding Estado}"
|
<CheckBox Grid.Column="2" VerticalAlignment="Center" IsChecked="{Binding Estado}"
|
||||||
Background="{Binding Color_oculto}" />
|
Background="{Binding Color_oculto}" />
|
||||||
</Grid>
|
</Grid>
|
||||||
</Canvas>
|
</Canvas>
|
||||||
</UserControl>
|
</UserControl>
|
||||||
|
|
|
@ -39,6 +39,9 @@ namespace CtrEditor.ObjetosSim
|
||||||
[ObservableProperty]
|
[ObservableProperty]
|
||||||
public bool estado;
|
public bool estado;
|
||||||
|
|
||||||
|
[ObservableProperty]
|
||||||
|
public bool show_Description;
|
||||||
|
|
||||||
partial void OnEstadoChanged(bool value)
|
partial void OnEstadoChanged(bool value)
|
||||||
{
|
{
|
||||||
EscribirBitTag(Tag, value);
|
EscribirBitTag(Tag, value);
|
||||||
|
@ -69,6 +72,7 @@ namespace CtrEditor.ObjetosSim
|
||||||
tag = "%M50.0";
|
tag = "%M50.0";
|
||||||
Descripcion = "Nombre del Tag";
|
Descripcion = "Nombre del Tag";
|
||||||
Color = Colors.LightBlue;
|
Color = Colors.LightBlue;
|
||||||
|
Show_Description = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void UpdatePLCPrimerCiclo()
|
public override void UpdatePLCPrimerCiclo()
|
||||||
|
|
|
@ -7,7 +7,7 @@ using LibS7Adv;
|
||||||
using nkast.Aether.Physics2D.Common;
|
using nkast.Aether.Physics2D.Common;
|
||||||
using PaddleOCRSharp;
|
using PaddleOCRSharp;
|
||||||
using Siemens.Simatic.Simulation.Runtime;
|
using Siemens.Simatic.Simulation.Runtime;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel; // Para poder usar [property: Category ...
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
|
|
Loading…
Reference in New Issue