Se agregaron nuevas propiedades y métodos para gestionar el ángulo de rotación en la clase ucFramePlate, incluyendo la implementación de encoders para la rotación. Se mejoró la actualización de la posición en función del valor del encoder de rotación y se implementaron cambios en la gestión de eventos para reflejar adecuadamente las modificaciones en el ángulo.
This commit is contained in:
parent
e935efb0cb
commit
20467c88ae
|
@ -24,6 +24,8 @@ namespace CtrEditor.ObjetosSim
|
||||||
public float offsetY;
|
public float offsetY;
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
public float offsetX;
|
public float offsetX;
|
||||||
|
[JsonIgnore]
|
||||||
|
public float offsetAngulo;
|
||||||
|
|
||||||
public static string NombreClase()
|
public static string NombreClase()
|
||||||
{
|
{
|
||||||
|
@ -103,6 +105,29 @@ namespace CtrEditor.ObjetosSim
|
||||||
[property: Category("Encoders:")]
|
[property: Category("Encoders:")]
|
||||||
public float offset_encoder_Y;
|
public float offset_encoder_Y;
|
||||||
|
|
||||||
|
// Encoder Rotation
|
||||||
|
[ObservableProperty]
|
||||||
|
[property: Description("This is a link to a Encoder for Rotation.")]
|
||||||
|
[property: Category("Encoders:")]
|
||||||
|
[property: ItemsSource(typeof(osBaseItemsSource<osEncoderMotorLineal>))]
|
||||||
|
private string encoder_Rotation;
|
||||||
|
|
||||||
|
[ObservableProperty]
|
||||||
|
[property: Description("K Pulses per degree for Rotation")]
|
||||||
|
[property: Category("Encoders:")]
|
||||||
|
public float k_encoder_Rotation;
|
||||||
|
|
||||||
|
[ObservableProperty]
|
||||||
|
[property: ReadOnly(true)]
|
||||||
|
[property: Description("Actual Rotation Angle")]
|
||||||
|
[property: Category("Encoders:")]
|
||||||
|
public float encoder_Rotation_Angle;
|
||||||
|
|
||||||
|
[ObservableProperty]
|
||||||
|
[property: Description("Angle in degrees offset. Angle when the encoder is 0")]
|
||||||
|
[property: Category("Encoders:")]
|
||||||
|
public float offset_encoder_Rotation;
|
||||||
|
|
||||||
partial void OnK_encoder_YChanged(float value)
|
partial void OnK_encoder_YChanged(float value)
|
||||||
{
|
{
|
||||||
UpdatePosition();
|
UpdatePosition();
|
||||||
|
@ -123,18 +148,34 @@ namespace CtrEditor.ObjetosSim
|
||||||
UpdatePosition();
|
UpdatePosition();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
partial void OnK_encoder_RotationChanged(float value)
|
||||||
|
{
|
||||||
|
UpdatePosition();
|
||||||
|
}
|
||||||
|
|
||||||
|
partial void OnOffset_encoder_RotationChanged(float value)
|
||||||
|
{
|
||||||
|
UpdatePosition();
|
||||||
|
}
|
||||||
|
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
private osEncoderMotorLineal EncoderX;
|
private osEncoderMotorLineal EncoderX;
|
||||||
|
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
private osEncoderMotorLineal EncoderY;
|
private osEncoderMotorLineal EncoderY;
|
||||||
|
|
||||||
|
[JsonIgnore]
|
||||||
|
private osEncoderMotorLineal EncoderRotation;
|
||||||
|
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
private bool isUpdatingFromEncoderX = false;
|
private bool isUpdatingFromEncoderX = false;
|
||||||
|
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
private bool isUpdatingFromEncoderY = false;
|
private bool isUpdatingFromEncoderY = false;
|
||||||
|
|
||||||
|
[JsonIgnore]
|
||||||
|
private bool isUpdatingFromEncoderRotation = false;
|
||||||
|
|
||||||
partial void OnEncoder_XChanged(string value)
|
partial void OnEncoder_XChanged(string value)
|
||||||
{
|
{
|
||||||
if (EncoderX != null)
|
if (EncoderX != null)
|
||||||
|
@ -159,6 +200,18 @@ namespace CtrEditor.ObjetosSim
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
partial void OnEncoder_RotationChanged(string value)
|
||||||
|
{
|
||||||
|
if (EncoderRotation != null)
|
||||||
|
EncoderRotation.PropertyChanged -= OnEncoderRotationPropertyChanged;
|
||||||
|
if (_mainViewModel != null && value != null && value.Length > 0)
|
||||||
|
{
|
||||||
|
EncoderRotation = (osEncoderMotorLineal)_mainViewModel.ObjetosSimulables.FirstOrDefault(s => (s is osEncoderMotorLineal && s.Nombre == value), null);
|
||||||
|
if (EncoderRotation != null)
|
||||||
|
EncoderRotation.PropertyChanged += OnEncoderRotationPropertyChanged;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void OnEncoderXPropertyChanged(object sender, PropertyChangedEventArgs e)
|
private void OnEncoderXPropertyChanged(object sender, PropertyChangedEventArgs e)
|
||||||
{
|
{
|
||||||
if (!isUpdatingFromEncoderX)
|
if (!isUpdatingFromEncoderX)
|
||||||
|
@ -195,12 +248,30 @@ namespace CtrEditor.ObjetosSim
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void OnEncoderRotationPropertyChanged(object sender, PropertyChangedEventArgs e)
|
||||||
|
{
|
||||||
|
if (!isUpdatingFromEncoderRotation)
|
||||||
|
{
|
||||||
|
isUpdatingFromEncoderRotation = true;
|
||||||
|
// Actualizamos el nombre si este fue modificado
|
||||||
|
if (e.PropertyName == nameof(osEncoderMotorLineal.Nombre))
|
||||||
|
Encoder_Rotation = ((osEncoderMotorLineal)sender).Nombre;
|
||||||
|
|
||||||
|
if (e.PropertyName == nameof(osEncoderMotorLineal.Valor_Actual))
|
||||||
|
{
|
||||||
|
UpdatePosition();
|
||||||
|
}
|
||||||
|
|
||||||
|
isUpdatingFromEncoderRotation = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void UpdatePosition()
|
public void UpdatePosition()
|
||||||
{
|
{
|
||||||
// Update X position if encoder is available
|
// Update X position if encoder is available
|
||||||
if (EncoderX != null && K_encoder_X != 0)
|
if (EncoderX != null && K_encoder_X != 0)
|
||||||
{
|
{
|
||||||
Encoder_Y_Position = EncoderY.Valor_Actual;
|
Encoder_X_Position = EncoderX.Valor_Actual;
|
||||||
Left = (Encoder_X_Position / k_encoder_X) + offset_encoder_X;
|
Left = (Encoder_X_Position / k_encoder_X) + offset_encoder_X;
|
||||||
}
|
}
|
||||||
// Update Y position if encoder is available
|
// Update Y position if encoder is available
|
||||||
|
@ -209,6 +280,12 @@ namespace CtrEditor.ObjetosSim
|
||||||
Encoder_Y_Position = EncoderY.Valor_Actual;
|
Encoder_Y_Position = EncoderY.Valor_Actual;
|
||||||
Top = (Encoder_Y_Position / k_encoder_Y) + offset_encoder_Y;
|
Top = (Encoder_Y_Position / k_encoder_Y) + offset_encoder_Y;
|
||||||
}
|
}
|
||||||
|
// Update rotation angle if encoder is available
|
||||||
|
if (EncoderRotation != null && K_encoder_Rotation != 0)
|
||||||
|
{
|
||||||
|
Encoder_Rotation_Angle = EncoderRotation.Valor_Actual;
|
||||||
|
Angulo = (Encoder_Rotation_Angle / k_encoder_Rotation) + offset_encoder_Rotation;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void TopChanging(float oldValue, float newValue)
|
public override void TopChanging(float oldValue, float newValue)
|
||||||
|
@ -220,6 +297,11 @@ namespace CtrEditor.ObjetosSim
|
||||||
offsetX = newValue - oldValue;
|
offsetX = newValue - oldValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override void AnguloChanging(float oldValue, float newValue)
|
||||||
|
{
|
||||||
|
offsetAngulo = newValue - oldValue;
|
||||||
|
}
|
||||||
|
|
||||||
[ObservableProperty]
|
[ObservableProperty]
|
||||||
[property: Description("Show/Hide the plate background")]
|
[property: Description("Show/Hide the plate background")]
|
||||||
[property: Category("Appearance:")]
|
[property: Category("Appearance:")]
|
||||||
|
@ -242,6 +324,7 @@ namespace CtrEditor.ObjetosSim
|
||||||
// El UserControl se ha cargado
|
// El UserControl se ha cargado
|
||||||
OnEncoder_XChanged(Encoder_X);
|
OnEncoder_XChanged(Encoder_X);
|
||||||
OnEncoder_YChanged(Encoder_Y);
|
OnEncoder_YChanged(Encoder_Y);
|
||||||
|
OnEncoder_RotationChanged(Encoder_Rotation);
|
||||||
UpdateZIndex(Zindex_FramePlate);
|
UpdateZIndex(Zindex_FramePlate);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -160,7 +160,13 @@ namespace CtrEditor.ObjetosSim
|
||||||
{
|
{
|
||||||
AnguloChanged(value);
|
AnguloChanged(value);
|
||||||
}
|
}
|
||||||
|
partial void OnAnguloChanging(float oldValue, float newValue)
|
||||||
|
{
|
||||||
|
AnguloChanging(oldValue, newValue);
|
||||||
|
}
|
||||||
|
|
||||||
public virtual void AnguloChanged(float value) { }
|
public virtual void AnguloChanged(float value) { }
|
||||||
|
public virtual void AnguloChanging(float oldValue, float newValue) { }
|
||||||
|
|
||||||
|
|
||||||
public void Resize(double width, double height)
|
public void Resize(double width, double height)
|
||||||
|
@ -328,6 +334,12 @@ namespace CtrEditor.ObjetosSim
|
||||||
OnMoveResizeRotate();
|
OnMoveResizeRotate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (e.PropertyName == nameof(osFramePlate.Angulo))
|
||||||
|
{
|
||||||
|
Angulo += ((osFramePlate)sender).offsetAngulo;
|
||||||
|
OnMoveResizeRotate();
|
||||||
|
}
|
||||||
|
|
||||||
if (e.PropertyName == nameof(osFramePlate.Zindex_FramePlate))
|
if (e.PropertyName == nameof(osFramePlate.Zindex_FramePlate))
|
||||||
UpdateZIndex(((osFramePlate)sender).Zindex_FramePlate);
|
UpdateZIndex(((osFramePlate)sender).Zindex_FramePlate);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue