From 69e87c3f207c4ba11e06e6afd4d10ab90a299efa Mon Sep 17 00:00:00 2001 From: Diego Freitas Date: Thu, 6 Aug 2026 14:30:53 -0300 Subject: [PATCH] correcao final eixos imu, incluido retries no envio de dados can --- .../frmResultadosOperacao.Designer.cs | 61 +++++++++++++++++++ .../Forms/Operacoes/frmResultadosOperacao.cs | 9 +++ .../Operacoes/OperacaoParametrosModel.cs | 4 +- AgroBase/AgroBase/Models/Variaveis.cs | 4 +- AgroBase/AgroBase/Services/CANService.cs | 1 + .../AgroBase/Services/CanServiceEthernet.cs | 16 +++++ .../camera_worker/camera_multispectral.py | 2 +- .../workers/health_worker/modulos/imu.py | 8 +-- 8 files changed, 96 insertions(+), 9 deletions(-) diff --git a/AgroBase/AgroBase/Forms/Operacoes/frmResultadosOperacao.Designer.cs b/AgroBase/AgroBase/Forms/Operacoes/frmResultadosOperacao.Designer.cs index bb211da08..f36dac0c9 100644 --- a/AgroBase/AgroBase/Forms/Operacoes/frmResultadosOperacao.Designer.cs +++ b/AgroBase/AgroBase/Forms/Operacoes/frmResultadosOperacao.Designer.cs @@ -531,6 +531,11 @@ this.label36 = new System.Windows.Forms.Label(); this.txtMomento = new System.Windows.Forms.TextBox(); this.btnPlay = new System.Windows.Forms.Button(); + this.pnlOrientacaoDados = new System.Windows.Forms.Panel(); + this.label146 = new System.Windows.Forms.Label(); + this.label147 = new System.Windows.Forms.Label(); + this.txtImuFrontal = new System.Windows.Forms.TextBox(); + this.txtImuLateral = new System.Windows.Forms.TextBox(); ((System.ComponentModel.ISupportInitialize)(this.trbMomento)).BeginInit(); this.panel1.SuspendLayout(); this.tabControl4.SuspendLayout(); @@ -584,6 +589,7 @@ this.pnlUltrassom.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.picRobo)).BeginInit(); this.tabOrientacao.SuspendLayout(); + this.pnl3D.SuspendLayout(); this.tabSonar.SuspendLayout(); this.tabControl3.SuspendLayout(); this.tabSonarRGB.SuspendLayout(); @@ -610,6 +616,7 @@ this.panel6.SuspendLayout(); this.pnlInformacoesOperacao.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.picCameraCaminho)).BeginInit(); + this.pnlOrientacaoDados.SuspendLayout(); this.SuspendLayout(); // // trbMomento @@ -4117,6 +4124,7 @@ // // pnl3D // + this.pnl3D.Controls.Add(this.pnlOrientacaoDados); this.pnl3D.Location = new System.Drawing.Point(5, 5); this.pnl3D.Margin = new System.Windows.Forms.Padding(2); this.pnl3D.Name = "pnl3D"; @@ -5908,6 +5916,51 @@ this.btnPlay.UseVisualStyleBackColor = true; this.btnPlay.Click += new System.EventHandler(this.btnPlay_Click); // + // pnlOrientacaoDados + // + this.pnlOrientacaoDados.Controls.Add(this.txtImuLateral); + this.pnlOrientacaoDados.Controls.Add(this.txtImuFrontal); + this.pnlOrientacaoDados.Controls.Add(this.label147); + this.pnlOrientacaoDados.Controls.Add(this.label146); + this.pnlOrientacaoDados.Location = new System.Drawing.Point(1, 362); + this.pnlOrientacaoDados.Name = "pnlOrientacaoDados"; + this.pnlOrientacaoDados.Size = new System.Drawing.Size(150, 150); + this.pnlOrientacaoDados.TabIndex = 0; + // + // label146 + // + this.label146.AutoSize = true; + this.label146.Location = new System.Drawing.Point(3, 16); + this.label146.Name = "label146"; + this.label146.Size = new System.Drawing.Size(39, 13); + this.label146.TabIndex = 1; + this.label146.Text = "Frontal"; + // + // label147 + // + this.label147.AutoSize = true; + this.label147.Location = new System.Drawing.Point(3, 71); + this.label147.Name = "label147"; + this.label147.Size = new System.Drawing.Size(39, 13); + this.label147.TabIndex = 2; + this.label147.Text = "Lateral"; + // + // txtImuFrontal + // + this.txtImuFrontal.Location = new System.Drawing.Point(6, 32); + this.txtImuFrontal.Name = "txtImuFrontal"; + this.txtImuFrontal.Size = new System.Drawing.Size(100, 20); + this.txtImuFrontal.TabIndex = 1; + this.txtImuFrontal.TextAlign = System.Windows.Forms.HorizontalAlignment.Right; + // + // txtImuLateral + // + this.txtImuLateral.Location = new System.Drawing.Point(6, 87); + this.txtImuLateral.Name = "txtImuLateral"; + this.txtImuLateral.Size = new System.Drawing.Size(100, 20); + this.txtImuLateral.TabIndex = 3; + this.txtImuLateral.TextAlign = System.Windows.Forms.HorizontalAlignment.Right; + // // frmResultadosOperacao // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); @@ -6007,6 +6060,7 @@ this.pnlUltrassom.ResumeLayout(false); ((System.ComponentModel.ISupportInitialize)(this.picRobo)).EndInit(); this.tabOrientacao.ResumeLayout(false); + this.pnl3D.ResumeLayout(false); this.tabSonar.ResumeLayout(false); this.tabSonar.PerformLayout(); this.tabControl3.ResumeLayout(false); @@ -6042,6 +6096,8 @@ this.pnlInformacoesOperacao.ResumeLayout(false); this.pnlInformacoesOperacao.PerformLayout(); ((System.ComponentModel.ISupportInitialize)(this.picCameraCaminho)).EndInit(); + this.pnlOrientacaoDados.ResumeLayout(false); + this.pnlOrientacaoDados.PerformLayout(); this.ResumeLayout(false); this.PerformLayout(); @@ -6527,5 +6583,10 @@ private System.Windows.Forms.Label lblVentilacaoRLOUT; private System.Windows.Forms.Label lblVentilacaoRLIN; private System.Windows.Forms.Label lblVentilacaoTemperatura; + private System.Windows.Forms.Panel pnlOrientacaoDados; + private System.Windows.Forms.TextBox txtImuLateral; + private System.Windows.Forms.TextBox txtImuFrontal; + private System.Windows.Forms.Label label147; + private System.Windows.Forms.Label label146; } } \ No newline at end of file diff --git a/AgroBase/AgroBase/Forms/Operacoes/frmResultadosOperacao.cs b/AgroBase/AgroBase/Forms/Operacoes/frmResultadosOperacao.cs index f4137f37b..c9bf6d357 100644 --- a/AgroBase/AgroBase/Forms/Operacoes/frmResultadosOperacao.cs +++ b/AgroBase/AgroBase/Forms/Operacoes/frmResultadosOperacao.cs @@ -1169,6 +1169,8 @@ namespace AgroBase.Forms.Operacoes AtualizarInformacoesSonar(); + AtualizarInformacoesIMU(); + AtualizarInformacoesCPU(); AtualizarInformacoesComandos(); @@ -1666,6 +1668,13 @@ namespace AgroBase.Forms.Operacoes } + private void AtualizarInformacoesIMU() + { + var imu = LogsIMU[idxMomentoAtual]; + txtImuFrontal.Text = imu.PitchSeguro.ToString("0.00"); + txtImuLateral.Text = imu.RollSeguro.ToString("0.00"); + } + private void AtualizarInformacoesCameraCaminho() { double? CalcularErroLateralPctImagem(int width, List centrosCorredor) diff --git a/AgroBase/AgroBase/Models/Operacoes/OperacaoParametrosModel.cs b/AgroBase/AgroBase/Models/Operacoes/OperacaoParametrosModel.cs index 421c964af..78b4197e1 100644 --- a/AgroBase/AgroBase/Models/Operacoes/OperacaoParametrosModel.cs +++ b/AgroBase/AgroBase/Models/Operacoes/OperacaoParametrosModel.cs @@ -819,8 +819,8 @@ namespace AgroBase.Models.Operacoes Imu = new OperacaoSensoriamentoLogImuModel { Iniciado = sen?.IMU?.Iniciado ?? false, - InclinacaoFrontal = sen?.IMU?.RollSeguro ?? 0, - InclinacaoLateral = sen?.IMU?.PitchSeguro ?? 0, + InclinacaoFrontal = sen?.IMU?.PitchSeguro ?? 0, + InclinacaoLateral = sen?.IMU?.RollSeguro ?? 0, Rotacao = sen?.IMU?.YawSeguro ?? 0 }; } diff --git a/AgroBase/AgroBase/Models/Variaveis.cs b/AgroBase/AgroBase/Models/Variaveis.cs index ff9451e6f..5f87ff5c6 100644 --- a/AgroBase/AgroBase/Models/Variaveis.cs +++ b/AgroBase/AgroBase/Models/Variaveis.cs @@ -926,8 +926,8 @@ namespace AgroBase.Models { TipoMovimentoDirecional.MovimentoLateral, 90 }, { TipoMovimentoDirecional.Diagnostico, 25 }, }; - public static double AnguloInclinacaoRollMax { get; set; } = 30.0; // Frontal 40 graus max - public static double AnguloInclinacaoPitchMax { get; set; } = 22.0; // Lateral + public static double AnguloInclinacaoRollMax { get; set; } = 22.0; // Lateral + public static double AnguloInclinacaoPitchMax { get; set; } = 30.0; // Frontal 40 graus max public static string VozAlerta { get; set; } = "Microsoft Maria Desktop"; public static bool Pronto => Variaveis.OperacaoEmAndamento?.Parametros?.Controle != null; diff --git a/AgroBase/AgroBase/Services/CANService.cs b/AgroBase/AgroBase/Services/CANService.cs index 0bda7889d..9480b1a9b 100644 --- a/AgroBase/AgroBase/Services/CANService.cs +++ b/AgroBase/AgroBase/Services/CANService.cs @@ -207,6 +207,7 @@ namespace AgroBase.Services public bool ContabilizarTimeoutHealth { get; set; } = true; public bool MensagemDescoberta { get; set; } = false; + public int TentativasEnvio { get; set; } = 0; } public class CanCommandFreqModel diff --git a/AgroBase/AgroBase/Services/CanServiceEthernet.cs b/AgroBase/AgroBase/Services/CanServiceEthernet.cs index 141f60516..7e6f163f1 100644 --- a/AgroBase/AgroBase/Services/CanServiceEthernet.cs +++ b/AgroBase/AgroBase/Services/CanServiceEthernet.cs @@ -90,6 +90,9 @@ namespace AgroBase.Services private readonly ConcurrentDictionary _timeoutsRespostaPorDispositivo = new ConcurrentDictionary(); private readonly ConcurrentDictionary _timeoutsRespostaPorChave = new ConcurrentDictionary(); + private readonly List DispositivosRetries = new List() { T_Code.Oid, T_Code.Bat }; + private const int MAX_TENTATIVAS_RETRIES = 2; + public Dictionary TimeoutsRespostaPorId => _timeoutsRespostaPorId.ToDictionary(x => x.Key, x => x.Value); public Dictionary TimeoutsRespostaPorDispositivo => _timeoutsRespostaPorDispositivo.ToDictionary(x => x.Key, x => x.Value); public Dictionary TimeoutsRespostaPorChave => _timeoutsRespostaPorChave.ToDictionary(x => x.Key, x => x.Value); @@ -575,6 +578,7 @@ namespace AgroBase.Services msg.Enviado = true; msg.EnviadoEm = DateTime.Now; + msg.TentativasEnvio++; _ultimoIdEnviado = msg.IdTx; _tokens -= 1; sent++; @@ -1076,6 +1080,18 @@ namespace AgroBase.Services foreach (var item in timeouts) { + if (DispositivosRetries.Contains(item.Dispositivo) && item.TentativasEnvio < MAX_TENTATIVAS_RETRIES) + { + // Rearma a MESMA transação para um retry. + item.Enviado = false; + item.EnviadoEm = DateTime.MinValue; + + MostrarLog($"Retry rápido OID | tentativa={item.TentativasEnvio + 1}/{MAX_TENTATIVAS_RETRIES} | {TimeoutChave(item)}", item.IdRx); + + continue; + } + + // Só chega aqui se realmente esgotou as tentativas. RegistrarTimeoutResposta(item); MensagensPendentes.Remove(item); } diff --git a/AgroBase/AgroBase/bin/x64/Debug/Python/Scripts/workers/camera_worker/camera_multispectral.py b/AgroBase/AgroBase/bin/x64/Debug/Python/Scripts/workers/camera_worker/camera_multispectral.py index e02b74f3e..c446bc514 100644 --- a/AgroBase/AgroBase/bin/x64/Debug/Python/Scripts/workers/camera_worker/camera_multispectral.py +++ b/AgroBase/AgroBase/bin/x64/Debug/Python/Scripts/workers/camera_worker/camera_multispectral.py @@ -179,7 +179,7 @@ class CameraMultispectral: nome_sensor=f"{self.modelo}_imu", modo=self.imu_modo, gyro_unidade="deg_s", - referencial_robo="p,-y,-r", + referencial_robo="r,p,y", ) else: self.tem_imu = False diff --git a/AgroBase/AgroBase/bin/x64/Debug/Python/Scripts/workers/health_worker/modulos/imu.py b/AgroBase/AgroBase/bin/x64/Debug/Python/Scripts/workers/health_worker/modulos/imu.py index f96b2bff1..633d1984d 100644 --- a/AgroBase/AgroBase/bin/x64/Debug/Python/Scripts/workers/health_worker/modulos/imu.py +++ b/AgroBase/AgroBase/bin/x64/Debug/Python/Scripts/workers/health_worker/modulos/imu.py @@ -39,10 +39,10 @@ class CameraIMU(ModuloDiagnosticoBase): # Limites principais vindos do equipamento. # No rover: - # roll = inclinação frontal - # pitch = inclinação lateral - roll_max_default_deg=45.0, - pitch_max_default_deg=25.0, + # roll = inclinação lateral + # pitch = inclinação frontal + roll_max_default_deg=25.0, + pitch_max_default_deg=45.0, # Níveis derivados do limite máximo configurado. angulo_attention_factor=0.50,