ajustes na recepcao de dados dos sensores externos nos modulos

This commit is contained in:
Diego Freitas 2025-12-05 15:25:29 -03:00
parent d4baa3f0f8
commit 7b511861d7
14 changed files with 300 additions and 118 deletions

Binary file not shown.

View File

@ -36,6 +36,8 @@ namespace AgroBase.Forms.Direcional
this.lblTipoMovimento = new System.Windows.Forms.Label();
this.btnSalvarSentido = new System.Windows.Forms.Button();
this.gpbDF = new System.Windows.Forms.GroupBox();
this.label5 = new System.Windows.Forms.Label();
this.txtDFOffsetAngulo = new System.Windows.Forms.TextBox();
this.label2 = new System.Windows.Forms.Label();
this.txtDFEndereco = new System.Windows.Forms.TextBox();
this.nudDFOffset = new System.Windows.Forms.NumericUpDown();
@ -45,6 +47,8 @@ namespace AgroBase.Forms.Direcional
this.lblDFEsquerda = new System.Windows.Forms.Label();
this.lblDFDireita = new System.Windows.Forms.Label();
this.gpbEF = new System.Windows.Forms.GroupBox();
this.label6 = new System.Windows.Forms.Label();
this.txtEFOffsetAngulo = new System.Windows.Forms.TextBox();
this.label4 = new System.Windows.Forms.Label();
this.txtEFEndereco = new System.Windows.Forms.TextBox();
this.nudEFOffset = new System.Windows.Forms.NumericUpDown();
@ -54,6 +58,8 @@ namespace AgroBase.Forms.Direcional
this.lblEFEsquerda = new System.Windows.Forms.Label();
this.lblEFDireita = new System.Windows.Forms.Label();
this.gpbDT = new System.Windows.Forms.GroupBox();
this.label8 = new System.Windows.Forms.Label();
this.txtDTOffsetAngulo = new System.Windows.Forms.TextBox();
this.label3 = new System.Windows.Forms.Label();
this.txtDTEndereco = new System.Windows.Forms.TextBox();
this.nudDTOffset = new System.Windows.Forms.NumericUpDown();
@ -63,6 +69,8 @@ namespace AgroBase.Forms.Direcional
this.lblDTEsquerda = new System.Windows.Forms.Label();
this.lblDTDireita = new System.Windows.Forms.Label();
this.gpbET = new System.Windows.Forms.GroupBox();
this.label7 = new System.Windows.Forms.Label();
this.txtETOffsetAngulo = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
this.txtETEndereco = new System.Windows.Forms.TextBox();
this.nudETOffset = new System.Windows.Forms.NumericUpDown();
@ -71,14 +79,10 @@ namespace AgroBase.Forms.Direcional
this.cmbETEsquerda = new System.Windows.Forms.ComboBox();
this.lblETEsquerda = new System.Windows.Forms.Label();
this.lblETDireita = new System.Windows.Forms.Label();
this.label5 = new System.Windows.Forms.Label();
this.txtDFOffsetAngulo = new System.Windows.Forms.TextBox();
this.label6 = new System.Windows.Forms.Label();
this.txtEFOffsetAngulo = new System.Windows.Forms.TextBox();
this.label7 = new System.Windows.Forms.Label();
this.txtETOffsetAngulo = new System.Windows.Forms.TextBox();
this.label8 = new System.Windows.Forms.Label();
this.txtDTOffsetAngulo = new System.Windows.Forms.TextBox();
this.chbDFUsar = new System.Windows.Forms.CheckBox();
this.chbDTUsar = new System.Windows.Forms.CheckBox();
this.chbEFUsar = new System.Windows.Forms.CheckBox();
this.chbETUsar = new System.Windows.Forms.CheckBox();
this.gpbSentido.SuspendLayout();
this.gpbDF.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.nudDFOffset)).BeginInit();
@ -161,6 +165,7 @@ namespace AgroBase.Forms.Direcional
//
// gpbDF
//
this.gpbDF.Controls.Add(this.chbDFUsar);
this.gpbDF.Controls.Add(this.label5);
this.gpbDF.Controls.Add(this.txtDFOffsetAngulo);
this.gpbDF.Controls.Add(this.label2);
@ -180,6 +185,25 @@ namespace AgroBase.Forms.Direcional
this.gpbDF.TabStop = false;
this.gpbDF.Text = "M4 - Direito Frente (DF)";
//
// label5
//
this.label5.AutoSize = true;
this.label5.Location = new System.Drawing.Point(10, 125);
this.label5.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(51, 13);
this.label5.TabIndex = 18;
this.label5.Text = "Offset Ag";
//
// txtDFOffsetAngulo
//
this.txtDFOffsetAngulo.Location = new System.Drawing.Point(66, 122);
this.txtDFOffsetAngulo.Margin = new System.Windows.Forms.Padding(2);
this.txtDFOffsetAngulo.Name = "txtDFOffsetAngulo";
this.txtDFOffsetAngulo.Size = new System.Drawing.Size(56, 20);
this.txtDFOffsetAngulo.TabIndex = 17;
this.txtDFOffsetAngulo.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
//
// label2
//
this.label2.AutoSize = true;
@ -270,6 +294,7 @@ namespace AgroBase.Forms.Direcional
//
// gpbEF
//
this.gpbEF.Controls.Add(this.chbEFUsar);
this.gpbEF.Controls.Add(this.label6);
this.gpbEF.Controls.Add(this.txtEFOffsetAngulo);
this.gpbEF.Controls.Add(this.label4);
@ -289,6 +314,25 @@ namespace AgroBase.Forms.Direcional
this.gpbEF.TabStop = false;
this.gpbEF.Text = "M2 - Esquerdo Frente (EF)";
//
// label6
//
this.label6.AutoSize = true;
this.label6.Location = new System.Drawing.Point(10, 125);
this.label6.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
this.label6.Name = "label6";
this.label6.Size = new System.Drawing.Size(51, 13);
this.label6.TabIndex = 20;
this.label6.Text = "Offset Ag";
//
// txtEFOffsetAngulo
//
this.txtEFOffsetAngulo.Location = new System.Drawing.Point(66, 122);
this.txtEFOffsetAngulo.Margin = new System.Windows.Forms.Padding(2);
this.txtEFOffsetAngulo.Name = "txtEFOffsetAngulo";
this.txtEFOffsetAngulo.Size = new System.Drawing.Size(56, 20);
this.txtEFOffsetAngulo.TabIndex = 19;
this.txtEFOffsetAngulo.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
//
// label4
//
this.label4.AutoSize = true;
@ -379,6 +423,7 @@ namespace AgroBase.Forms.Direcional
//
// gpbDT
//
this.gpbDT.Controls.Add(this.chbDTUsar);
this.gpbDT.Controls.Add(this.label8);
this.gpbDT.Controls.Add(this.txtDTOffsetAngulo);
this.gpbDT.Controls.Add(this.label3);
@ -398,6 +443,25 @@ namespace AgroBase.Forms.Direcional
this.gpbDT.TabStop = false;
this.gpbDT.Text = "M3 - Direito Trás (DT)";
//
// label8
//
this.label8.AutoSize = true;
this.label8.Location = new System.Drawing.Point(9, 125);
this.label8.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
this.label8.Name = "label8";
this.label8.Size = new System.Drawing.Size(51, 13);
this.label8.TabIndex = 22;
this.label8.Text = "Offset Ag";
//
// txtDTOffsetAngulo
//
this.txtDTOffsetAngulo.Location = new System.Drawing.Point(65, 122);
this.txtDTOffsetAngulo.Margin = new System.Windows.Forms.Padding(2);
this.txtDTOffsetAngulo.Name = "txtDTOffsetAngulo";
this.txtDTOffsetAngulo.Size = new System.Drawing.Size(57, 20);
this.txtDTOffsetAngulo.TabIndex = 21;
this.txtDTOffsetAngulo.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
//
// label3
//
this.label3.AutoSize = true;
@ -488,6 +552,7 @@ namespace AgroBase.Forms.Direcional
//
// gpbET
//
this.gpbET.Controls.Add(this.chbETUsar);
this.gpbET.Controls.Add(this.label7);
this.gpbET.Controls.Add(this.txtETOffsetAngulo);
this.gpbET.Controls.Add(this.label1);
@ -507,6 +572,25 @@ namespace AgroBase.Forms.Direcional
this.gpbET.TabStop = false;
this.gpbET.Text = "M1 - Esquerdo Trás (ET)";
//
// label7
//
this.label7.AutoSize = true;
this.label7.Location = new System.Drawing.Point(9, 125);
this.label7.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
this.label7.Name = "label7";
this.label7.Size = new System.Drawing.Size(51, 13);
this.label7.TabIndex = 22;
this.label7.Text = "Offset Ag";
//
// txtETOffsetAngulo
//
this.txtETOffsetAngulo.Location = new System.Drawing.Point(65, 122);
this.txtETOffsetAngulo.Margin = new System.Windows.Forms.Padding(2);
this.txtETOffsetAngulo.Name = "txtETOffsetAngulo";
this.txtETOffsetAngulo.Size = new System.Drawing.Size(57, 20);
this.txtETOffsetAngulo.TabIndex = 21;
this.txtETOffsetAngulo.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
//
// label1
//
this.label1.AutoSize = true;
@ -595,81 +679,45 @@ namespace AgroBase.Forms.Direcional
this.lblETDireita.TabIndex = 2;
this.lblETDireita.Text = "Direita";
//
// label5
// chbDFUsar
//
this.label5.AutoSize = true;
this.label5.Location = new System.Drawing.Point(10, 125);
this.label5.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(51, 13);
this.label5.TabIndex = 18;
this.label5.Text = "Offset Ag";
this.chbDFUsar.AutoSize = true;
this.chbDFUsar.Location = new System.Drawing.Point(127, 124);
this.chbDFUsar.Name = "chbDFUsar";
this.chbDFUsar.Size = new System.Drawing.Size(32, 17);
this.chbDFUsar.TabIndex = 19;
this.chbDFUsar.Text = "L";
this.chbDFUsar.UseVisualStyleBackColor = true;
//
// txtDFOffsetAngulo
// chbDTUsar
//
this.txtDFOffsetAngulo.Location = new System.Drawing.Point(66, 122);
this.txtDFOffsetAngulo.Margin = new System.Windows.Forms.Padding(2);
this.txtDFOffsetAngulo.Name = "txtDFOffsetAngulo";
this.txtDFOffsetAngulo.Size = new System.Drawing.Size(92, 20);
this.txtDFOffsetAngulo.TabIndex = 17;
this.txtDFOffsetAngulo.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
this.chbDTUsar.AutoSize = true;
this.chbDTUsar.Location = new System.Drawing.Point(125, 124);
this.chbDTUsar.Name = "chbDTUsar";
this.chbDTUsar.Size = new System.Drawing.Size(32, 17);
this.chbDTUsar.TabIndex = 23;
this.chbDTUsar.Text = "L";
this.chbDTUsar.UseVisualStyleBackColor = true;
//
// label6
// chbEFUsar
//
this.label6.AutoSize = true;
this.label6.Location = new System.Drawing.Point(10, 125);
this.label6.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
this.label6.Name = "label6";
this.label6.Size = new System.Drawing.Size(51, 13);
this.label6.TabIndex = 20;
this.label6.Text = "Offset Ag";
this.chbEFUsar.AutoSize = true;
this.chbEFUsar.Location = new System.Drawing.Point(127, 124);
this.chbEFUsar.Name = "chbEFUsar";
this.chbEFUsar.Size = new System.Drawing.Size(32, 17);
this.chbEFUsar.TabIndex = 21;
this.chbEFUsar.Text = "L";
this.chbEFUsar.UseVisualStyleBackColor = true;
//
// txtEFOffsetAngulo
// chbETUsar
//
this.txtEFOffsetAngulo.Location = new System.Drawing.Point(66, 122);
this.txtEFOffsetAngulo.Margin = new System.Windows.Forms.Padding(2);
this.txtEFOffsetAngulo.Name = "txtEFOffsetAngulo";
this.txtEFOffsetAngulo.Size = new System.Drawing.Size(92, 20);
this.txtEFOffsetAngulo.TabIndex = 19;
this.txtEFOffsetAngulo.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
//
// label7
//
this.label7.AutoSize = true;
this.label7.Location = new System.Drawing.Point(9, 125);
this.label7.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
this.label7.Name = "label7";
this.label7.Size = new System.Drawing.Size(51, 13);
this.label7.TabIndex = 22;
this.label7.Text = "Offset Ag";
//
// txtETOffsetAngulo
//
this.txtETOffsetAngulo.Location = new System.Drawing.Point(65, 122);
this.txtETOffsetAngulo.Margin = new System.Windows.Forms.Padding(2);
this.txtETOffsetAngulo.Name = "txtETOffsetAngulo";
this.txtETOffsetAngulo.Size = new System.Drawing.Size(92, 20);
this.txtETOffsetAngulo.TabIndex = 21;
this.txtETOffsetAngulo.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
//
// label8
//
this.label8.AutoSize = true;
this.label8.Location = new System.Drawing.Point(9, 125);
this.label8.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
this.label8.Name = "label8";
this.label8.Size = new System.Drawing.Size(51, 13);
this.label8.TabIndex = 22;
this.label8.Text = "Offset Ag";
//
// txtDTOffsetAngulo
//
this.txtDTOffsetAngulo.Location = new System.Drawing.Point(65, 122);
this.txtDTOffsetAngulo.Margin = new System.Windows.Forms.Padding(2);
this.txtDTOffsetAngulo.Name = "txtDTOffsetAngulo";
this.txtDTOffsetAngulo.Size = new System.Drawing.Size(92, 20);
this.txtDTOffsetAngulo.TabIndex = 21;
this.txtDTOffsetAngulo.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
this.chbETUsar.AutoSize = true;
this.chbETUsar.Location = new System.Drawing.Point(127, 124);
this.chbETUsar.Name = "chbETUsar";
this.chbETUsar.Size = new System.Drawing.Size(32, 17);
this.chbETUsar.TabIndex = 23;
this.chbETUsar.Text = "L";
this.chbETUsar.UseVisualStyleBackColor = true;
//
// frmDirConfig
//
@ -753,5 +801,9 @@ namespace AgroBase.Forms.Direcional
private System.Windows.Forms.TextBox txtDTOffsetAngulo;
private System.Windows.Forms.Label label7;
private System.Windows.Forms.TextBox txtETOffsetAngulo;
private System.Windows.Forms.CheckBox chbDFUsar;
private System.Windows.Forms.CheckBox chbEFUsar;
private System.Windows.Forms.CheckBox chbDTUsar;
private System.Windows.Forms.CheckBox chbETUsar;
}
}

View File

@ -71,6 +71,9 @@ namespace AgroBase.Forms.Direcional
TextBox txtOffsetAngulo = FuncoesGlobais.FindControlRecursive<TextBox>(gpbSentido, "txt" + Modulo.Modulo_ID + "OffsetAngulo");
txtOffsetAngulo.Text = Modulo.DirMotor.OffsetAnguloReal.ToString();
CheckBox chbUsar = FuncoesGlobais.FindControlRecursive<CheckBox>(gpbSentido, "chb" + Modulo.Modulo_ID + "Usar");
chbUsar.Checked = Modulo.DirMotor.UsarAnguloSensor;
}
}
@ -117,6 +120,9 @@ namespace AgroBase.Forms.Direcional
TextBox txtOffsetAngulo = FuncoesGlobais.FindControlRecursive<TextBox>(gpbSentido, "txt" + Modulo.Modulo_ID + "OffsetAngulo");
Modulo.DirMotor.OffsetAnguloReal = Convert.ToDouble(txtOffsetAngulo.Text);
CheckBox chbUsar = FuncoesGlobais.FindControlRecursive<CheckBox>(gpbSentido, "chb" + Modulo.Modulo_ID + "Usar");
Modulo.DirMotor.UsarAnguloSensor = chbUsar.Checked;
}
}

View File

@ -49,6 +49,10 @@ namespace AgroBase.Models.Modules
}
public bool AtuPronto { get; set; } = false;
public double AnguloBarraEsquerda { get; set; }
public double AnguloBarraDireita { get; set; }
public double AnguloBarraAltura { get; set; }
public static PinoutDataModel Pinout { get; set; }
public static List<FuncoesPinout> Funcoes { get; set; } = new List<FuncoesPinout>()
{
@ -68,6 +72,31 @@ namespace AgroBase.Models.Modules
public AtuadorMensagemJsonModel DadosLeitura { get; set; } = new AtuadorMensagemJsonModel();
public AtuHandler _AtuHandler = new AtuHandler();
public SensorModel SensorAnguloBarraEsquerda
{
get
{
var sMAG = Sensores?.FirstOrDefault(x => x.Componente == S_Code.sMAG && x.ID.Contains("ESQ"));
return sMAG;
}
}
public SensorModel SensorAnguloBarraDireita
{
get
{
var sMAG = Sensores?.FirstOrDefault(x => x.Componente == S_Code.sMAG && x.ID.Contains("DIR"));
return sMAG;
}
}
public SensorModel SensorAnguloBarraAltura
{
get
{
var sMAG = Sensores?.FirstOrDefault(x => x.Componente == S_Code.sMAG && x.ID.Contains("ALT"));
return sMAG;
}
}
#region MASSA
public double _MassaRef { get; set; } = 0.8;
public double _MassaLeituraRef { get; set; } = 40876.37;
@ -1088,6 +1117,37 @@ namespace AgroBase.Models.Modules
return tasks;
}
public void RequisitarDadosSensoresExternos()
{
if (SensorAnguloBarraEsquerda != null)
RequisitarDadosModulo(SensorAnguloBarraEsquerda.ID_Num, CanMessagePosicaoDados.Dados1, CanMessagePosicaoDados.Dados1, true);
if (SensorAnguloBarraDireita != null)
RequisitarDadosModulo(SensorAnguloBarraDireita.ID_Num, CanMessagePosicaoDados.Dados1, CanMessagePosicaoDados.Dados1, true);
if (SensorAnguloBarraAltura != null)
RequisitarDadosModulo(SensorAnguloBarraAltura.ID_Num, CanMessagePosicaoDados.Dados1, CanMessagePosicaoDados.Dados1, true);
}
public void AtualizarDadosSensoresExternos(S_Code componente, int id_num)
{
switch (componente)
{
case S_Code.sMAG:
{
var sensor = Sensores.FirstOrDefault(x => x.ID_Num == id_num);
double angulo = sensor.ValoresLeituras?.FirstOrDefault(x => x.funcao == FuncoesPinout.LeituraAngulo)?.atual?.valor ?? double.NaN;
if (sensor.ID_Num == SensorAnguloBarraEsquerda.ID_Num)
AnguloBarraEsquerda = angulo;
else if (sensor.ID_Num == SensorAnguloBarraDireita.ID_Num)
AnguloBarraDireita = angulo;
else if (sensor.ID_Num == SensorAnguloBarraAltura.ID_Num)
AnguloBarraAltura = angulo;
}
break;
}
}
}
public class AtuadorBicoModel
@ -1762,6 +1822,8 @@ namespace AgroBase.Models.Modules
}
Dados.DadosLeitura.UltimoComandoRespondido = DateTime.Now;
Variaveis.OperacaoEmAndamento.DispAtu.Dados.AtualizarDadosSensoresExternos(componente, ID_Num);
}
}

View File

@ -66,24 +66,20 @@ namespace AgroBase.Models.Modules
}
}
public double AnguloReal { get; set; } = double.NaN;
public bool UsarAnguloSensor { get; set; }
public double AnguloLeitura
{
get
{
if (!UsarAnguloSensor)
return AnguloDriver;
if (double.IsNaN(AnguloReal)) return AnguloDriver;
var sMAG = Variaveis.OperacaoEmAndamento.DispSen?.Dados?.Sensores?.FirstOrDefault(x => x.Componente == S_Code.sMAG && x.ID.Contains(Mod_ID));
if ((sMAG?.Inicializado ?? false) && (sMAG?.Aferir ?? false)) return AnguloReal;
return AnguloDriver;
}
}
public double AnguloFolgaCompensar
{
get
{
double folga = AnguloDriver - AnguloLeitura;
return folga;
}
}
public double AnguloFolgaCompensar { get; set; }
public double OffsetAnguloReal { get; set; }
public double RPM
{
@ -110,6 +106,15 @@ namespace AgroBase.Models.Modules
public DateTime UltimoReferenciamento { get; set; }
public bool Referenciado { get; set; } = false;
public SensorModel SensorAnguloReal
{
get
{
var sMAG = Variaveis.OperacaoEmAndamento.DispSen?.Dados?.Sensores?.FirstOrDefault(x => x.Componente == S_Code.sMAG && x.ID.Contains(Mod_ID));
return sMAG;
}
}
public bool Comandar { get; set; } = false;
public bool Inicializado
{
@ -471,5 +476,41 @@ namespace AgroBase.Models.Modules
Console.WriteLine($"[DIR {Mod_ID}] - Comando Angulo Zero: {AnguloLeitura}");
}
public void RequisitarDadosSensoresExternos()
{
if (SensorAnguloReal != null)
{
Variaveis.OperacaoEmAndamento.DispSen.Dados.RequisitarDadosModulo(SensorAnguloReal.ID_Num, CanMessagePosicaoDados.Dados1, CanMessagePosicaoDados.Dados1, true);
}
}
public void AtualizarDadosSensoresExternos()
{
if (SensorAnguloReal != null)
{
double angulo = SensorAnguloReal.ValoresLeituras.FirstOrDefault(x => x.funcao == FuncoesPinout.LeituraAngulo)?.atual?.valor ?? double.NaN;
if (!double.IsNaN(angulo))
{
double bruto = angulo + OffsetAnguloReal;
// normaliza pra faixa [-180, 180]
double norm = bruto % 360.0;
if (norm > 180.0) norm -= 360.0;
if (norm < -180.0) norm += 360.0;
AnguloReal = Math.Round(-norm, 2);
double folga = AnguloDriver - AnguloLeitura;
AnguloFolgaCompensar = AtingiuAnguloSP ? folga : 0;
}
else
{
AnguloReal = angulo;
AnguloFolgaCompensar = 0;
}
}
}
}
}

View File

@ -173,6 +173,14 @@ namespace AgroBase.Models.Modules
}
}
public SensorModel SensorTemperaturaMotor
{
get
{
var sNTC = Variaveis.OperacaoEmAndamento.DispSen?.Dados?.Sensores?.FirstOrDefault(x => x.Componente == S_Code.sNTC && x.ID.Contains(Mod_ID));
return sNTC;
}
}
public bool Comandar { get; set; } = false;
public bool AlarmeSensores { get; set; } = false;
@ -446,9 +454,24 @@ namespace AgroBase.Models.Modules
public void RequisitarDadosSensoresExternos()
{
if (SensorTemperaturaMotor != null)
{
Variaveis.OperacaoEmAndamento.DispSen.Dados.RequisitarDadosModulo(SensorTemperaturaMotor.ID_Num, CanMessagePosicaoDados.Dados1, CanMessagePosicaoDados.Dados1, true);
}
}
public void AtualizarDadosSensoresExternos()
{
if (SensorTemperaturaMotor != null)
{
Temperatura = SensorTemperaturaMotor.ValoresLeituras.FirstOrDefault(x => x.funcao == FuncoesPinout.Temperatura)?.atual?.valor ?? double.NaN;
}
}
}
public class MvdServoFreioModel

View File

@ -262,6 +262,7 @@ namespace AgroBase.Models.Modules
OIDCanService.RequisitarDado(addrTx, addrRx, OIDCanService.OidHandler.OidParametros.CorrenteBarramento);
OIDCanService.RequisitarDado(addrTx, addrRx, OIDCanService.OidHandler.OidParametros.CorrenteMotor);
OIDCanService.RequisitarDado(addrTx, addrRx, OIDCanService.OidHandler.OidParametros.Tensao);
Modulo.MovMotor.RequisitarDadosSensoresExternos();
var Controle = Variaveis.OperacaoEmAndamento.Controle.TiposControle?.FirstOrDefault(x => x.Tipo == T_Code.Mov);
if (Controle != null)
@ -273,12 +274,6 @@ namespace AgroBase.Models.Modules
Variaveis.OperacaoEmAndamento.DispMvd.Dados.RegistrarLogMov(Modulo);
}
var sTMP = Variaveis.OperacaoEmAndamento.DispSen?.Dados?.Sensores?.FirstOrDefault(x => x.Componente == S_Code.sNTC && x.ID.Contains(Modulo.Modulo_ID));
if (sTMP != null)
{
Modulo.MovMotor.Temperatura = sTMP.ValoresLeituras.FirstOrDefault(x => x.funcao == FuncoesPinout.Temperatura)?.atual?.valor ?? -1;
}
}
tmrRegistradorMOV.SetInterval(OIDCanService.TaxaAmostragem);
@ -310,6 +305,7 @@ namespace AgroBase.Models.Modules
byte addrRx = Modulo.DirMotor._EnderecoCAN_Rx;
MKS057DCanService.RequisitarDado(addrTx, addrRx, MKS057DCanService.MksHandler.MksFuncCode.PulsosRecebidos);
MKS057DCanService.RequisitarDado(addrTx, addrRx, MKS057DCanService.MksHandler.MksFuncCode.IO);
Modulo.DirMotor.RequisitarDadosSensoresExternos();
// Verifica se o angulo de set point do motor em questao e diferente do angulo atual, e se for, reenvia o comando para garantir que o motor esteja coerente com o set point
if (!MKS057DCanService.Referenciando && (Modulo.DirMotor.UltimoComandoEnviado.AddMilliseconds(MKS057DCanService.TaxaAmostragem) < DateTime.Now) && !Modulo.DirMotor.AtingiuAnguloSP)
@ -321,32 +317,32 @@ namespace AgroBase.Models.Modules
}
}
}
var sMAG = Variaveis.OperacaoEmAndamento.DispSen?.Dados?.Sensores?.FirstOrDefault(x => x.Componente == S_Code.sMAG && x.ID.Contains(Modulo.Modulo_ID));
if (sMAG != null)
{
Variaveis.OperacaoEmAndamento.DispSen.Dados.RequisitarDadosModulo(sMAG.ID_Num, CanMessagePosicaoDados.Dados1, CanMessagePosicaoDados.Dados1, true);
double angulo = sMAG.ValoresLeituras.FirstOrDefault(x => x.funcao == FuncoesPinout.LeituraAngulo)?.atual?.valor ?? -1;
if (angulo >= 0)
{
double bruto = angulo + Modulo.DirMotor.OffsetAnguloReal;
// normaliza pra faixa [-180, 180]
double norm = bruto % 360.0;
if (norm > 180.0) norm -= 360.0;
if (norm < -180.0) norm += 360.0;
Modulo.DirMotor.AnguloReal = Math.Round(-norm, 2);
}
else
{
Modulo.DirMotor.AnguloReal = double.NaN;
}
}
}
tmrRegistradorDIR.SetInterval(MKS057DCanService.TaxaAmostragem);
}
public void AtualizarDadosSensoresExternos(S_Code componente, int id_num)
{
switch (componente)
{
case S_Code.sNTC:
{
var mod = Modulos.FirstOrDefault(x => x.MovMotor.SensorTemperaturaMotor?.ID_Num == id_num);
if (mod != null)
mod.MovMotor.AtualizarDadosSensoresExternos();
break;
}
case S_Code.sMAG:
{
var mod = Modulos.FirstOrDefault(x => x.DirMotor.SensorAnguloReal?.ID_Num == id_num);
if (mod != null)
mod.DirMotor.AtualizarDadosSensoresExternos();
}
break;
}
}
public async Task ExecutarMovimentoDirecionalCombinado(Direcao DirecaoAtual)

View File

@ -3562,7 +3562,7 @@ namespace AgroBase.Models.Modules
ushort raw = Converter2BytesU16(data, 2);
double angle = ConverterAngle100(data, 4);
AtualizarDados(ID_Num, posicao, componente, new List<dynamic>() { raw, angle });
Console.WriteLine($"[sMAG] {ID_Num}, Raw: {raw}, Angulo: {angle}");
//Console.WriteLine($"[sMAG] {ID_Num}, Raw: {raw}, Angulo: {angle}");
break;
}
}
@ -3574,6 +3574,8 @@ namespace AgroBase.Models.Modules
Dados.DadosLeitura.UltimoComandoRespondido = DateTime.Now;
//Console.WriteLine("Ultimo comando respondido: " + Dados.DadosLeitura.UltimoComandoRespondido.ToString("HH:mm:ss.fff") + ", Conectado: " + Dados.Conectado);
Variaveis.OperacaoEmAndamento.DispMvd.Dados.AtualizarDadosSensoresExternos(componente, ID_Num);
}
}

View File

@ -2312,9 +2312,9 @@ namespace AgroBase.Models
LeituraPotenciaBomba = FuncoesMatematicas.Clamp(_DispAtu.Dados.BombasPressurizadoras.FirstOrDefault().ValoresLeituras.FirstOrDefault(x => x.funcao == FuncoesPinout.Potencia)?.atual?.valor ?? 0, 0, 100),
VolumeVazaoMl = _DispAtu.Dados.VolumeVazaoML,
Iniciados = _DispAtu.Dados.Sensores.Select(s => new { s.ID, s.Inicializado }).Union(_DispAtu.Dados.BicosPulverizadores.Select(b => new { b.ID, b.Inicializado })).Union(_DispAtu.Dados.BombasPressurizadoras.Select(b => new { b.ID, b.Inicializado })).ToDictionary(x => x.ID, x => x.Inicializado),
AnguloBarraEsquerda = _DispAtu.Dados.Sensores.FirstOrDefault(x => x.Componente == S_Code.sMAG && x.ID.Contains("ESQ"))?.ValoresLeituras?.FirstOrDefault(x => x.funcao == FuncoesPinout.LeituraAngulo)?.atual?.valor ?? -1,
AnguloBarraDireita = _DispAtu.Dados.Sensores.FirstOrDefault(x => x.Componente == S_Code.sMAG && x.ID.Contains("DIR"))?.ValoresLeituras?.FirstOrDefault(x => x.funcao == FuncoesPinout.LeituraAngulo)?.atual?.valor ?? -1,
AnguloBarraAltura = _DispAtu.Dados.Sensores.FirstOrDefault(x => x.Componente == S_Code.sMAG && x.ID.Contains("ALT"))?.ValoresLeituras?.FirstOrDefault(x => x.funcao == FuncoesPinout.LeituraAngulo)?.atual?.valor ?? -1,
AnguloBarraEsquerda = _DispAtu.Dados.AnguloBarraEsquerda,
AnguloBarraDireita = _DispAtu.Dados.AnguloBarraDireita,
AnguloBarraAltura = _DispAtu.Dados.AnguloBarraAltura,
} : new OperacaoSensoriamentoLogAtuModel();
var dadosMovimentacao = _DispMvd != null ? new OperacaoSensoriamentoLogMovModel()

View File

@ -34,7 +34,7 @@ namespace AgroBase.Services
{
get
{
return Referenciando ? 250 : 1000;
return Referenciando ? 250 : 500;
}
}

File diff suppressed because one or more lines are too long