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 LibS7Adv;
|
||||
using Newtonsoft.Json;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Media;
|
||||
|
||||
|
||||
namespace CtrEditor.ObjetosSim
|
||||
{
|
||||
/// <summary>
|
||||
|
@ -59,6 +61,16 @@ namespace CtrEditor.ObjetosSim
|
|||
[ObservableProperty]
|
||||
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)
|
||||
{
|
||||
if (value < 0.1f)
|
||||
|
@ -204,9 +216,14 @@ namespace CtrEditor.ObjetosSim
|
|||
|
||||
// Add timestamp to trace when the read occurs
|
||||
var timestamp = DateTime.Now;
|
||||
|
||||
// Read ControlWord and track the raw response
|
||||
var rawResponse = plc.LeerTagDInt($"\"DB MotorSimulate\".Motors[{DB_Motor}].ControlWord");
|
||||
|
||||
if (Data.Motor_With_Encoder)
|
||||
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;
|
||||
var control = VMMotorBitPacker.UnpackControlWord(controlWord);
|
||||
|
||||
|
|
|
@ -14,8 +14,6 @@ namespace CtrEditor.ObjetosSim
|
|||
public partial class osEncoderMotor : osBase, IosBase
|
||||
{
|
||||
private osBase Motor = null;
|
||||
private Stopwatch Stopwatch = new Stopwatch();
|
||||
private double stopwatch_last = 0;
|
||||
|
||||
public static string NombreClase()
|
||||
{
|
||||
|
@ -86,7 +84,6 @@ namespace CtrEditor.ObjetosSim
|
|||
Pulsos_Por_Vuelta = 360; // Por defecto, un pulso por grado
|
||||
Ratio_Giros_50hz = 1; // Por defecto, 1 giro por cada 50Hz
|
||||
Color_oculto = Brushes.Gray;
|
||||
Stopwatch.Start();
|
||||
}
|
||||
|
||||
public override void UpdatePLC(PLCViewModel plc, int elapsedMilliseconds)
|
||||
|
|
|
@ -14,8 +14,6 @@ namespace CtrEditor.ObjetosSim
|
|||
public partial class osEncoderMotorLineal : osBase, IosBase
|
||||
{
|
||||
private osBase Motor = null;
|
||||
private Stopwatch Stopwatch = new Stopwatch();
|
||||
private double stopwatch_last = 0;
|
||||
|
||||
public static string NombreClase()
|
||||
{
|
||||
|
@ -86,7 +84,6 @@ namespace CtrEditor.ObjetosSim
|
|||
{
|
||||
Pulsos_Por_Hz = 3000; // Por defecto, un pulso por grado
|
||||
Color_oculto = Brushes.Gray;
|
||||
Stopwatch.Start();
|
||||
}
|
||||
|
||||
public override void UpdatePLC(PLCViewModel plc, int elapsedMilliseconds)
|
||||
|
@ -100,7 +97,8 @@ namespace CtrEditor.ObjetosSim
|
|||
Valor_Actual = (int)value;
|
||||
return;
|
||||
}
|
||||
} else if (Motor != null && Motor is osVMmotorSim motor)
|
||||
}
|
||||
else if (Motor != null && Motor is osVMmotorSim motor)
|
||||
{
|
||||
VelocidadActual = motor.Velocidad;
|
||||
|
||||
|
@ -116,7 +114,10 @@ namespace CtrEditor.ObjetosSim
|
|||
float incrementoPulsos = pulsosPorHz * segundosTranscurridos;
|
||||
|
||||
// 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
|
||||
Color_oculto = Math.Abs(pulsosPorHz) > 0.01f ? Brushes.LightGreen : Brushes.Gray;
|
||||
|
|
|
@ -1,17 +1,14 @@
|
|||
<UserControl x:Class="CtrEditor.ObjetosSim.ucBoolTag"
|
||||
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:ei="http://schemas.microsoft.com/xaml/behaviors"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:vm="clr-namespace:CtrEditor.ObjetosSim"
|
||||
mc:Ignorable="d">
|
||||
<UserControl x:Class="CtrEditor.ObjetosSim.ucBoolTag" 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:ei="http://schemas.microsoft.com/xaml/behaviors"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:vm="clr-namespace:CtrEditor.ObjetosSim"
|
||||
mc:Ignorable="d">
|
||||
|
||||
<UserControl.DataContext>
|
||||
<vm:osBoolTag/>
|
||||
<vm:osBoolTag Show_Description="True" />
|
||||
</UserControl.DataContext>
|
||||
<Canvas RenderTransformOrigin="0.5,0.5">
|
||||
<Canvas RenderTransformOrigin="0.5,0.5" ToolTip="{Binding Descripcion}">
|
||||
<Canvas.RenderTransform>
|
||||
<TransformGroup>
|
||||
<ScaleTransform />
|
||||
|
@ -26,18 +23,14 @@
|
|||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Border x:Name="BackgroundRectangle"
|
||||
BorderBrush="Black"
|
||||
BorderThickness="2"
|
||||
CornerRadius="10,0,0,10"
|
||||
Width="30"
|
||||
Height="40"
|
||||
VerticalAlignment="Top"
|
||||
HorizontalAlignment="Left"
|
||||
Background="{Binding Color, Converter={StaticResource ColorToBrushConverter}}"/>
|
||||
<Label Content="{Binding Descripcion}" Grid.Column="1" VerticalAlignment="Center" Background="{Binding Color}" />
|
||||
<Border x:Name="BackgroundRectangle" BorderBrush="Black" BorderThickness="2" CornerRadius="10,0,0,10"
|
||||
Width="16" Height="25" VerticalAlignment="Center" HorizontalAlignment="Center"
|
||||
Background="{Binding Color, Converter={StaticResource ColorToBrushConverter}}" />
|
||||
<Label Content="{Binding Descripcion}" Grid.Column="1" VerticalAlignment="Center"
|
||||
Background="{Binding Color}"
|
||||
Visibility="{Binding Show_Description, Converter={StaticResource BooleanToVisibilityConverter}}" />
|
||||
<CheckBox Grid.Column="2" VerticalAlignment="Center" IsChecked="{Binding Estado}"
|
||||
Background="{Binding Color_oculto}" />
|
||||
Background="{Binding Color_oculto}" />
|
||||
</Grid>
|
||||
</Canvas>
|
||||
</UserControl>
|
||||
|
|
|
@ -39,6 +39,9 @@ namespace CtrEditor.ObjetosSim
|
|||
[ObservableProperty]
|
||||
public bool estado;
|
||||
|
||||
[ObservableProperty]
|
||||
public bool show_Description;
|
||||
|
||||
partial void OnEstadoChanged(bool value)
|
||||
{
|
||||
EscribirBitTag(Tag, value);
|
||||
|
@ -69,6 +72,7 @@ namespace CtrEditor.ObjetosSim
|
|||
tag = "%M50.0";
|
||||
Descripcion = "Nombre del Tag";
|
||||
Color = Colors.LightBlue;
|
||||
Show_Description = true;
|
||||
}
|
||||
|
||||
public override void UpdatePLCPrimerCiclo()
|
||||
|
|
|
@ -7,7 +7,7 @@ using LibS7Adv;
|
|||
using nkast.Aether.Physics2D.Common;
|
||||
using PaddleOCRSharp;
|
||||
using Siemens.Simatic.Simulation.Runtime;
|
||||
using System.ComponentModel;
|
||||
using System.ComponentModel; // Para poder usar [property: Category ...
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Windows;
|
||||
|
|
Loading…
Reference in New Issue