adicionado controle do servo freio

This commit is contained in:
Diego Freitas 2024-07-24 17:04:55 -03:00
parent 04ca18acc2
commit d7ec074071
107 changed files with 6057 additions and 1533 deletions

Binary file not shown.

View File

@ -32,8 +32,6 @@ namespace AgroBase.Forms.Direcional
this.gpbSentido = new System.Windows.Forms.GroupBox();
this.btnSalvarSentido = new System.Windows.Forms.Button();
this.gpbDF = new System.Windows.Forms.GroupBox();
this.chbDFLivre = new System.Windows.Forms.CheckBox();
this.chbDFEstabilizar = new System.Windows.Forms.CheckBox();
this.chbDFControlar = new System.Windows.Forms.CheckBox();
this.nudDFOffset = new System.Windows.Forms.NumericUpDown();
this.lblDFOffset = new System.Windows.Forms.Label();
@ -42,8 +40,6 @@ 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.chbEFLivre = new System.Windows.Forms.CheckBox();
this.chbEFEstabilizar = new System.Windows.Forms.CheckBox();
this.chbEFControlar = new System.Windows.Forms.CheckBox();
this.nudEFOffset = new System.Windows.Forms.NumericUpDown();
this.lblEFOffset = new System.Windows.Forms.Label();
@ -52,8 +48,6 @@ 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.hbDTLivre = new System.Windows.Forms.CheckBox();
this.chbDTEstabilizar = new System.Windows.Forms.CheckBox();
this.chbDTControlar = new System.Windows.Forms.CheckBox();
this.nudDTOffset = new System.Windows.Forms.NumericUpDown();
this.lblDTOffset = new System.Windows.Forms.Label();
@ -62,8 +56,6 @@ 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.chbETLivre = new System.Windows.Forms.CheckBox();
this.chbETEstabilizar = new System.Windows.Forms.CheckBox();
this.chbETControlar = new System.Windows.Forms.CheckBox();
this.nudETOffset = new System.Windows.Forms.NumericUpDown();
this.lblETOffset = new System.Windows.Forms.Label();
@ -71,6 +63,14 @@ 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.label3 = new System.Windows.Forms.Label();
this.txtDTEndereco = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
this.txtETEndereco = new System.Windows.Forms.TextBox();
this.label2 = new System.Windows.Forms.Label();
this.txtDFEndereco = new System.Windows.Forms.TextBox();
this.label4 = new System.Windows.Forms.Label();
this.txtEFEndereco = new System.Windows.Forms.TextBox();
this.gpbSentido.SuspendLayout();
this.gpbDF.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.nudDFOffset)).BeginInit();
@ -111,8 +111,8 @@ namespace AgroBase.Forms.Direcional
//
// gpbDF
//
this.gpbDF.Controls.Add(this.chbDFLivre);
this.gpbDF.Controls.Add(this.chbDFEstabilizar);
this.gpbDF.Controls.Add(this.label2);
this.gpbDF.Controls.Add(this.txtDFEndereco);
this.gpbDF.Controls.Add(this.chbDFControlar);
this.gpbDF.Controls.Add(this.nudDFOffset);
this.gpbDF.Controls.Add(this.lblDFOffset);
@ -129,32 +129,10 @@ namespace AgroBase.Forms.Direcional
this.gpbDF.TabStop = false;
this.gpbDF.Text = "M4 - Direito Frente (DF)";
//
// chbDFLivre
//
this.chbDFLivre.AutoSize = true;
this.chbDFLivre.Location = new System.Drawing.Point(92, 123);
this.chbDFLivre.Margin = new System.Windows.Forms.Padding(2);
this.chbDFLivre.Name = "chbDFLivre";
this.chbDFLivre.Size = new System.Drawing.Size(49, 17);
this.chbDFLivre.TabIndex = 19;
this.chbDFLivre.Text = "Livre";
this.chbDFLivre.UseVisualStyleBackColor = true;
//
// chbDFEstabilizar
//
this.chbDFEstabilizar.AutoSize = true;
this.chbDFEstabilizar.Location = new System.Drawing.Point(92, 101);
this.chbDFEstabilizar.Margin = new System.Windows.Forms.Padding(2);
this.chbDFEstabilizar.Name = "chbDFEstabilizar";
this.chbDFEstabilizar.Size = new System.Drawing.Size(73, 17);
this.chbDFEstabilizar.TabIndex = 15;
this.chbDFEstabilizar.Text = "Estabilizar";
this.chbDFEstabilizar.UseVisualStyleBackColor = true;
//
// chbDFControlar
//
this.chbDFControlar.AutoSize = true;
this.chbDFControlar.Location = new System.Drawing.Point(12, 101);
this.chbDFControlar.Location = new System.Drawing.Point(12, 127);
this.chbDFControlar.Margin = new System.Windows.Forms.Padding(2);
this.chbDFControlar.Name = "chbDFControlar";
this.chbDFControlar.Size = new System.Drawing.Size(68, 17);
@ -231,8 +209,8 @@ namespace AgroBase.Forms.Direcional
//
// gpbEF
//
this.gpbEF.Controls.Add(this.chbEFLivre);
this.gpbEF.Controls.Add(this.chbEFEstabilizar);
this.gpbEF.Controls.Add(this.label4);
this.gpbEF.Controls.Add(this.txtEFEndereco);
this.gpbEF.Controls.Add(this.chbEFControlar);
this.gpbEF.Controls.Add(this.nudEFOffset);
this.gpbEF.Controls.Add(this.lblEFOffset);
@ -249,32 +227,10 @@ namespace AgroBase.Forms.Direcional
this.gpbEF.TabStop = false;
this.gpbEF.Text = "M2 - Esquerdo Frente (EF)";
//
// chbEFLivre
//
this.chbEFLivre.AutoSize = true;
this.chbEFLivre.Location = new System.Drawing.Point(92, 123);
this.chbEFLivre.Margin = new System.Windows.Forms.Padding(2);
this.chbEFLivre.Name = "chbEFLivre";
this.chbEFLivre.Size = new System.Drawing.Size(49, 17);
this.chbEFLivre.TabIndex = 17;
this.chbEFLivre.Text = "Livre";
this.chbEFLivre.UseVisualStyleBackColor = true;
//
// chbEFEstabilizar
//
this.chbEFEstabilizar.AutoSize = true;
this.chbEFEstabilizar.Location = new System.Drawing.Point(92, 101);
this.chbEFEstabilizar.Margin = new System.Windows.Forms.Padding(2);
this.chbEFEstabilizar.Name = "chbEFEstabilizar";
this.chbEFEstabilizar.Size = new System.Drawing.Size(73, 17);
this.chbEFEstabilizar.TabIndex = 15;
this.chbEFEstabilizar.Text = "Estabilizar";
this.chbEFEstabilizar.UseVisualStyleBackColor = true;
//
// chbEFControlar
//
this.chbEFControlar.AutoSize = true;
this.chbEFControlar.Location = new System.Drawing.Point(12, 101);
this.chbEFControlar.Location = new System.Drawing.Point(12, 127);
this.chbEFControlar.Margin = new System.Windows.Forms.Padding(2);
this.chbEFControlar.Name = "chbEFControlar";
this.chbEFControlar.Size = new System.Drawing.Size(68, 17);
@ -351,8 +307,8 @@ namespace AgroBase.Forms.Direcional
//
// gpbDT
//
this.gpbDT.Controls.Add(this.hbDTLivre);
this.gpbDT.Controls.Add(this.chbDTEstabilizar);
this.gpbDT.Controls.Add(this.label3);
this.gpbDT.Controls.Add(this.txtDTEndereco);
this.gpbDT.Controls.Add(this.chbDTControlar);
this.gpbDT.Controls.Add(this.nudDTOffset);
this.gpbDT.Controls.Add(this.lblDTOffset);
@ -369,32 +325,10 @@ namespace AgroBase.Forms.Direcional
this.gpbDT.TabStop = false;
this.gpbDT.Text = "M3 - Direito Trás (DT)";
//
// hbDTLivre
//
this.hbDTLivre.AutoSize = true;
this.hbDTLivre.Location = new System.Drawing.Point(92, 122);
this.hbDTLivre.Margin = new System.Windows.Forms.Padding(2);
this.hbDTLivre.Name = "hbDTLivre";
this.hbDTLivre.Size = new System.Drawing.Size(49, 17);
this.hbDTLivre.TabIndex = 19;
this.hbDTLivre.Text = "Livre";
this.hbDTLivre.UseVisualStyleBackColor = true;
//
// chbDTEstabilizar
//
this.chbDTEstabilizar.AutoSize = true;
this.chbDTEstabilizar.Location = new System.Drawing.Point(92, 100);
this.chbDTEstabilizar.Margin = new System.Windows.Forms.Padding(2);
this.chbDTEstabilizar.Name = "chbDTEstabilizar";
this.chbDTEstabilizar.Size = new System.Drawing.Size(73, 17);
this.chbDTEstabilizar.TabIndex = 13;
this.chbDTEstabilizar.Text = "Estabilizar";
this.chbDTEstabilizar.UseVisualStyleBackColor = true;
//
// chbDTControlar
//
this.chbDTControlar.AutoSize = true;
this.chbDTControlar.Location = new System.Drawing.Point(12, 100);
this.chbDTControlar.Location = new System.Drawing.Point(12, 127);
this.chbDTControlar.Margin = new System.Windows.Forms.Padding(2);
this.chbDTControlar.Name = "chbDTControlar";
this.chbDTControlar.Size = new System.Drawing.Size(68, 17);
@ -471,8 +405,8 @@ namespace AgroBase.Forms.Direcional
//
// gpbET
//
this.gpbET.Controls.Add(this.chbETLivre);
this.gpbET.Controls.Add(this.chbETEstabilizar);
this.gpbET.Controls.Add(this.label1);
this.gpbET.Controls.Add(this.txtETEndereco);
this.gpbET.Controls.Add(this.chbETControlar);
this.gpbET.Controls.Add(this.nudETOffset);
this.gpbET.Controls.Add(this.lblETOffset);
@ -489,32 +423,10 @@ namespace AgroBase.Forms.Direcional
this.gpbET.TabStop = false;
this.gpbET.Text = "M1 - Esquerdo Trás (ET)";
//
// chbETLivre
//
this.chbETLivre.AutoSize = true;
this.chbETLivre.Location = new System.Drawing.Point(92, 123);
this.chbETLivre.Margin = new System.Windows.Forms.Padding(2);
this.chbETLivre.Name = "chbETLivre";
this.chbETLivre.Size = new System.Drawing.Size(49, 17);
this.chbETLivre.TabIndex = 19;
this.chbETLivre.Text = "Livre";
this.chbETLivre.UseVisualStyleBackColor = true;
//
// chbETEstabilizar
//
this.chbETEstabilizar.AutoSize = true;
this.chbETEstabilizar.Location = new System.Drawing.Point(92, 101);
this.chbETEstabilizar.Margin = new System.Windows.Forms.Padding(2);
this.chbETEstabilizar.Name = "chbETEstabilizar";
this.chbETEstabilizar.Size = new System.Drawing.Size(73, 17);
this.chbETEstabilizar.TabIndex = 15;
this.chbETEstabilizar.Text = "Estabilizar";
this.chbETEstabilizar.UseVisualStyleBackColor = true;
//
// chbETControlar
//
this.chbETControlar.AutoSize = true;
this.chbETControlar.Location = new System.Drawing.Point(12, 101);
this.chbETControlar.Location = new System.Drawing.Point(12, 127);
this.chbETControlar.Margin = new System.Windows.Forms.Padding(2);
this.chbETControlar.Name = "chbETControlar";
this.chbETControlar.Size = new System.Drawing.Size(68, 17);
@ -589,6 +501,82 @@ namespace AgroBase.Forms.Direcional
this.lblETDireita.TabIndex = 2;
this.lblETDireita.Text = "Direita";
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(10, 101);
this.label3.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(53, 13);
this.label3.TabIndex = 14;
this.label3.Text = "Endereço";
//
// txtDTEndereco
//
this.txtDTEndereco.Location = new System.Drawing.Point(66, 98);
this.txtDTEndereco.Margin = new System.Windows.Forms.Padding(2);
this.txtDTEndereco.Name = "txtDTEndereco";
this.txtDTEndereco.Size = new System.Drawing.Size(92, 20);
this.txtDTEndereco.TabIndex = 13;
this.txtDTEndereco.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(10, 101);
this.label1.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(53, 13);
this.label1.TabIndex = 16;
this.label1.Text = "Endereço";
//
// txtETEndereco
//
this.txtETEndereco.Location = new System.Drawing.Point(66, 98);
this.txtETEndereco.Margin = new System.Windows.Forms.Padding(2);
this.txtETEndereco.Name = "txtETEndereco";
this.txtETEndereco.Size = new System.Drawing.Size(92, 20);
this.txtETEndereco.TabIndex = 15;
this.txtETEndereco.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(10, 101);
this.label2.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(53, 13);
this.label2.TabIndex = 16;
this.label2.Text = "Endereço";
//
// txtDFEndereco
//
this.txtDFEndereco.Location = new System.Drawing.Point(66, 98);
this.txtDFEndereco.Margin = new System.Windows.Forms.Padding(2);
this.txtDFEndereco.Name = "txtDFEndereco";
this.txtDFEndereco.Size = new System.Drawing.Size(92, 20);
this.txtDFEndereco.TabIndex = 15;
this.txtDFEndereco.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
//
// label4
//
this.label4.AutoSize = true;
this.label4.Location = new System.Drawing.Point(10, 101);
this.label4.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(53, 13);
this.label4.TabIndex = 18;
this.label4.Text = "Endereço";
//
// txtEFEndereco
//
this.txtEFEndereco.Location = new System.Drawing.Point(66, 98);
this.txtEFEndereco.Margin = new System.Windows.Forms.Padding(2);
this.txtEFEndereco.Name = "txtEFEndereco";
this.txtEFEndereco.Size = new System.Drawing.Size(92, 20);
this.txtEFEndereco.TabIndex = 17;
this.txtEFEndereco.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
//
// frmDirConfig
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
@ -650,17 +638,17 @@ namespace AgroBase.Forms.Direcional
private System.Windows.Forms.Label lblDTOffset;
private System.Windows.Forms.NumericUpDown nudETOffset;
private System.Windows.Forms.Label lblETOffset;
private System.Windows.Forms.CheckBox chbDFEstabilizar;
private System.Windows.Forms.CheckBox chbDFControlar;
private System.Windows.Forms.CheckBox chbEFEstabilizar;
private System.Windows.Forms.CheckBox chbEFControlar;
private System.Windows.Forms.CheckBox chbDTEstabilizar;
private System.Windows.Forms.CheckBox chbDTControlar;
private System.Windows.Forms.CheckBox chbETEstabilizar;
private System.Windows.Forms.CheckBox chbETControlar;
private System.Windows.Forms.CheckBox chbDFLivre;
private System.Windows.Forms.CheckBox chbEFLivre;
private System.Windows.Forms.CheckBox hbDTLivre;
private System.Windows.Forms.CheckBox chbETLivre;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.TextBox txtDTEndereco;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.TextBox txtDFEndereco;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.TextBox txtEFEndereco;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.TextBox txtETEndereco;
}
}

View File

@ -1,6 +1,7 @@
using AgroBase.Comum;
using AgroBase.Models;
using AgroBase.Models.Modules;
using OpenTK.Graphics.ES11;
using System;
using System.Collections.Generic;
using System.ComponentModel;
@ -59,35 +60,18 @@ namespace AgroBase.Forms.Direcional
}
cmb.SelectedItem = Enum.GetName(typeof(Sentido), sentido);
TextBox txtEndereco = FuncoesGlobais.FindControlRecursive<TextBox>(gpbSentido, "txt" + Modulo.Modulo_ID + "Endereco");
txtEndereco.Text = Modulo.DirMotor.Endereco;
NumericUpDown nudOffset = FuncoesGlobais.FindControlRecursive<NumericUpDown>(gpbSentido, "nud" + Modulo.Modulo_ID + "Offset");
nudOffset.Value = Convert.ToInt32(Modulo.DirMotor.Angulo_Offset);
CheckBox chbComandar = FuncoesGlobais.FindControlRecursive<CheckBox>(gpbSentido, "chb" + Modulo.Modulo_ID + "Controlar");
chbComandar.Checked = Modulo.DirMotor.Comandar;
}
}
var nudsOffsets = gpbET.Controls.OfType<NumericUpDown>().ToList().Union(gpbEF.Controls.OfType<NumericUpDown>().ToList()).Union(gpbDT.Controls.OfType<NumericUpDown>().ToList()).Union(gpbDF.Controls.OfType<NumericUpDown>().ToList()).ToList();
foreach (var nud in nudsOffsets)
{
var Modulo = Disp.Dados.Modulos.FirstOrDefault(x => x.Modulo_ID == nud.Name.Substring(3, 2));
if (Modulo != null)
{
nud.Value = Convert.ToInt32(Modulo.DirMotor.Angulo_Offset);
}
}
var chbs = gpbET.Controls.OfType<CheckBox>().ToList().Union(gpbEF.Controls.OfType<CheckBox>().ToList()).Union(gpbDT.Controls.OfType<CheckBox>().ToList()).Union(gpbDF.Controls.OfType<CheckBox>().ToList()).ToList();
foreach (var chb in chbs)
{
var Modulo = Disp.Dados.Modulos.FirstOrDefault(x => x.Modulo_ID == chb.Name.Substring(3, 2));
if (Modulo != null)
{
var chbEstabilizar = chbs.FirstOrDefault(x => x.Name.Contains(Modulo.Modulo_ID + "Estabilizar"));
chbEstabilizar.Checked = Modulo.DirMotor.Estabilizar;
var chbControlar = chbs.FirstOrDefault(x => x.Name.Contains(Modulo.Modulo_ID + "Controlar"));
chbControlar.Checked = Modulo.DirMotor.Controlar;
var chbLivre = chbs.FirstOrDefault(x => x.Name.Contains(Modulo.Modulo_ID + "Livre"));
chbDFLivre.Checked = Modulo.DirMotor.Livre;
}
}
}
private void frmDirConfig_FormClosing(object sender, FormClosingEventArgs e)
@ -121,31 +105,15 @@ namespace AgroBase.Forms.Direcional
{
Modulo.DirMotor.ConfigSentidos.Direita = sentido;
}
}
}
var nudsOffsets = gpbET.Controls.OfType<NumericUpDown>().ToList().Union(gpbEF.Controls.OfType<NumericUpDown>().ToList()).Union(gpbDT.Controls.OfType<NumericUpDown>().ToList()).Union(gpbDF.Controls.OfType<NumericUpDown>().ToList()).ToList();
foreach (var nud in nudsOffsets)
{
var Modulo = Disp.Dados.Modulos.FirstOrDefault(x => x.Modulo_ID == nud.Name.Substring(3, 2));
if (Modulo != null)
{
Modulo.DirMotor.Angulo_Offset = Convert.ToDouble(nud.Value);
}
}
TextBox txtEndereco = FuncoesGlobais.FindControlRecursive<TextBox>(gpbSentido, "txt" + Modulo.Modulo_ID + "Endereco");
Modulo.DirMotor.Endereco = txtEndereco.Text;
var chbs = gpbET.Controls.OfType<CheckBox>().ToList().Union(gpbEF.Controls.OfType<CheckBox>().ToList()).Union(gpbDT.Controls.OfType<CheckBox>().ToList()).Union(gpbDF.Controls.OfType<CheckBox>().ToList()).ToList();
foreach (var chb in chbs)
{
var Modulo = Disp.Dados.Modulos.FirstOrDefault(x => x.Modulo_ID == chb.Name.Substring(3, 2));
if (Modulo != null)
{
var chbEstabilizar = chbs.FirstOrDefault(x => x.Name.Contains(Modulo.Modulo_ID + "Estabilizar"));
Modulo.DirMotor.Estabilizar = chbEstabilizar.Checked;
var chbControlar = chbs.FirstOrDefault(x => x.Name.Contains(Modulo.Modulo_ID + "Controlar"));
Modulo.DirMotor.Controlar = chbControlar.Checked;
var chbLivre = chbs.FirstOrDefault(x => x.Name.Contains(Modulo.Modulo_ID + "Livre"));
Modulo.DirMotor.Livre = chbLivre.Checked;
NumericUpDown nudOffset = FuncoesGlobais.FindControlRecursive<NumericUpDown>(gpbSentido, "nud" + Modulo.Modulo_ID + "Offset");
Modulo.DirMotor.Angulo_Offset = Convert.ToDouble(nudOffset.Value);
CheckBox chbComandar = FuncoesGlobais.FindControlRecursive<CheckBox>(gpbSentido, "chb" + Modulo.Modulo_ID + "Controlar");
Modulo.DirMotor.Comandar = chbComandar.Checked;
}
}

View File

@ -395,17 +395,17 @@ namespace AgroBase.Forms.IHM
await EnviarComandoBomba(Dispositivo, Bomba, true, 5000);
double Pressao = PressaoInicializado ? Dispositivo.Dados.PressaoLinha : 0;
double Pressao = PressaoInicializado ? Dispositivo.Dados.PressaoLinha : -1;
idx = PreencheDadosLinha(grid, Testes, idx, Pressao);
double Massa = MassaInicializado ? Dispositivo.Dados.VolumeReservatorio : 0;
double Massa = MassaInicializado ? Dispositivo.Dados.VolumeReservatorio : -1;
idx = PreencheDadosLinha(grid, Testes, idx, Massa);
idx = PreencheDadosLinha(grid, Testes, idx, Pressao);
await EnviarComandoBico(Dispositivo, B01, true, 1000);
double Fluxo = FluxoInicializado ? Dispositivo.Dados.VazaoFluxoMLpS : 0;
double Fluxo = FluxoInicializado ? Dispositivo.Dados.VazaoFluxoMLpS : -1;
idx = PreencheDadosLinha(grid, Testes, idx, Fluxo);
bool statusB01_1 = B01 != null && B01.StatusBico;
@ -476,6 +476,23 @@ namespace AgroBase.Forms.IHM
private void PreencherDadosDiagnosticoMovimentacao(DiagnosticoModel Diagnostico)
{
var Testes = new List<ColunasDiagnosticoModel>();
Testes.AddRange(new List<ColunasDiagnosticoModel>()
{
new ColunasDiagnosticoModel()
{
Componente = "Módulo SEN",
Teste = "Conectado",
ValorPadrao = 1,
ComplementoValorPadrao = ComplementosPadrao[1]
},
new ColunasDiagnosticoModel()
{
Componente = "Módulo SEN",
Teste = "Inicializado",
ValorPadrao = 1,
ComplementoValorPadrao = ComplementosPadrao[1]
},
});
Testes.AddRange(Variaveis.OperacaoEmAndamento.DispMvd.Dados.Modulos.SelectMany(x => new List<ColunasDiagnosticoModel>()
{
new ColunasDiagnosticoModel()
@ -493,6 +510,19 @@ namespace AgroBase.Forms.IHM
ComplementoValorPadrao = ComplementosPadrao[1]
},
new ColunasDiagnosticoModel()
{
Componente = "S_TMP_" + x.Modulo_ID,
Teste = "Inicializado",
ValorPadrao = 1,
},
new ColunasDiagnosticoModel()
{
Componente = x.Modulo_ID,
Teste = "Temperatura",
ValorPadrao = 85,
ComplementoValorPadrao = "<"
},
new ColunasDiagnosticoModel()
{
Componente = x.Modulo_ID,
Teste = "Tensão",
@ -502,8 +532,8 @@ namespace AgroBase.Forms.IHM
new ColunasDiagnosticoModel()
{
Componente = x.Modulo_ID,
Teste = "Temperatura",
ValorPadrao = 85,
Teste = "Temperatura Driver",
ValorPadrao = 65,
ComplementoValorPadrao = "<"
},
new ColunasDiagnosticoModel()
@ -516,7 +546,7 @@ namespace AgroBase.Forms.IHM
{
Componente = x.Modulo_ID,
Teste = "Para Frente",
ValorPadrao = 0,
ValorPadrao = 2,
ComplementoValorPadrao = ">"
},
new ColunasDiagnosticoModel()
@ -529,7 +559,7 @@ namespace AgroBase.Forms.IHM
{
Componente = x.Modulo_ID,
Teste = "Para Trás",
ValorPadrao = 0,
ValorPadrao = 2,
ComplementoValorPadrao = ">"
},
new ColunasDiagnosticoModel()
@ -558,34 +588,51 @@ namespace AgroBase.Forms.IHM
return false;
}
bool SenConectado = SerialService.DispositivosMapeados.Any(x => x.Dispositivo == T_Code.Sen);
idx = PreencheDadosLinha(grid, Testes, idx, SenConectado ? 1 : 0);
var Modulo_Sen = Variaveis.OperacaoEmAndamento.DispSen.Dados;
bool SenIniciado = Modulo_Sen.Conectado;
idx = PreencheDadosLinha(grid, Testes, idx, SenIniciado ? 1 : 0);
foreach (var Modulo in Dispositivo.Dados.Modulos)
{
bool Conectado = SerialService.DispositivosMapeados.Any(x => x.Dispositivo == Enuns.T_Code.Mvd && x.Mod_ID == Modulo.Modulo_ID);
bool Conectado = SerialService.DispositivosMapeados.Any(x => x.Dispositivo == Enuns.T_Code.Bld && x.Mod_ID == Modulo.Modulo_ID);
idx = PreencheDadosLinha(grid, Testes, idx, Conectado ? 1 : 0);
bool Inicializado = Modulo.Conectado;
bool Inicializado = Modulo.MovMotor.BLD_Inicializado;
idx = PreencheDadosLinha(grid, Testes, idx, Inicializado ? 1 : 0);
double Tensao = Modulo.MovMotor.Tensao;
idx = PreencheDadosLinha(grid, Testes, idx, Tensao);
var SensorTmp = Modulo_Sen.Sensores.FirstOrDefault(x => x.Componente == S_Code.sTMP && x.ID.Contains(Modulo.Modulo_ID));
double Temperatura = Modulo.MovMotor.Temperatura;
bool TempIniciado = SensorTmp != null && SensorTmp.Inicializado;
idx = PreencheDadosLinha(grid, Testes, idx, TempIniciado ? 1 : 0);
double Temperatura = TempIniciado ? Modulo.MovMotor.Temperatura : -1;
idx = PreencheDadosLinha(grid, Testes, idx, Temperatura);
double CodigoErro = Modulo.MovMotor.CodigoAlarme;
double Tensao = Inicializado ? Modulo.MovMotor.Tensao : -1;
idx = PreencheDadosLinha(grid, Testes, idx, Tensao);
double TemperaturaDriver = Inicializado ? Modulo.MovMotor.TemperaturaDriver : -1;
idx = PreencheDadosLinha(grid, Testes, idx, TemperaturaDriver);
double CodigoErro = Inicializado ? Modulo.MovMotor.CodigoAlarme : -1;
idx = PreencheDadosLinha(grid, Testes, idx, CodigoErro);
bool ParaFrente = await EnviarComandoMov(Dispositivo, Modulo, Enuns.Direcao.Frente, Testes[idx], 5000);
idx = PreencheDadosLinha(grid, Testes, idx, ParaFrente ? 1 : 0);
bool ParaFrente = Inicializado ? await EnviarComandoMov(Dispositivo, Modulo, Enuns.Direcao.Frente, Testes[idx], 5000) : false;
idx = PreencheDadosLinha(grid, Testes, idx, Inicializado ? Testes[idx].ValorAferido : -1);
bool Parado = await EnviarComandoMov(Dispositivo, Modulo, Enuns.Direcao.Parado, Testes[idx], 5000);
idx = PreencheDadosLinha(grid, Testes, idx, Parado ? 0 : 1);
bool Parado = Inicializado ? await EnviarComandoMov(Dispositivo, Modulo, Enuns.Direcao.Parado, Testes[idx], 5000) : false;
idx = PreencheDadosLinha(grid, Testes, idx, Inicializado ? Testes[idx].ValorAferido : -1);
bool ParaTras = await EnviarComandoMov(Dispositivo, Modulo, Enuns.Direcao.Tras, Testes[idx], 5000);
idx = PreencheDadosLinha(grid, Testes, idx, ParaTras ? 1 : 0);
bool ParaTras = Inicializado ? await EnviarComandoMov(Dispositivo, Modulo, Enuns.Direcao.Tras, Testes[idx], 5000) : false;
idx = PreencheDadosLinha(grid, Testes, idx, Inicializado ? Testes[idx].ValorAferido : -1);
Parado = await EnviarComandoMov(Dispositivo, Modulo, Enuns.Direcao.Parado, Testes[idx], 5000);
idx = PreencheDadosLinha(grid, Testes, idx, Parado ? 0 : 1);
Parado = Inicializado ? await EnviarComandoMov(Dispositivo, Modulo, Enuns.Direcao.Parado, Testes[idx], 5000) : false;
idx = PreencheDadosLinha(grid, Testes, idx, Inicializado ? Testes[idx].ValorAferido : -1);
}
@ -594,7 +641,7 @@ namespace AgroBase.Forms.IHM
private async Task<bool> EnviarComandoMov(DispositivosService<MovimentacaoUnificadaModel> Dispositivo, ModuloMvdModel Modulo, Enuns.Direcao Sentido, ColunasDiagnosticoModel Teste, int Timeout)
{
Variaveis.OperacaoEmAndamento.Controle.RPM = 20;
Variaveis.OperacaoEmAndamento.Controle.RPM_SP = 20;
bool oldCmd = Modulo.MovMotor.Comandar;
Modulo.MovMotor.Comandar = true;
@ -605,21 +652,24 @@ namespace AgroBase.Forms.IHM
bool Sucesso = false;
while (!Sucesso && Inicio.AddMilliseconds(Timeout) > DateTime.Now)
{
await Task.Delay(200);
await Task.Delay(500);
bool sentidoCorreto = Modulo.MovMotor.Sentido ==
bool sentidoCorreto = Sentido == Direcao.Parado ? true :
Modulo.MovMotor.Sentido ==
(Sentido == Enuns.Direcao.Frente ? Modulo.MovMotor.ConfigSentidos.Frente :
Sentido == Enuns.Direcao.Tras ? Modulo.MovMotor.ConfigSentidos.Tras :
Enuns.Sentido.Parado);
bool rpmCorreto =
Teste.ComplementoValorPadrao == "<" ? Modulo.MovMotor.RPM < Teste.ValorPadrao :
Teste.ComplementoValorPadrao == ">" ? Modulo.MovMotor.RPM > Teste.ValorPadrao :
Modulo.MovMotor.RPM == Teste.ValorPadrao;
Teste.ComplementoValorPadrao == "<" ? Modulo.MovMotor.RPM_Roda < Teste.ValorPadrao :
Teste.ComplementoValorPadrao == ">" ? Modulo.MovMotor.RPM_Roda > Teste.ValorPadrao :
Modulo.MovMotor.RPM_Roda == Teste.ValorPadrao;
Sucesso = sentidoCorreto && rpmCorreto;
}
Teste.ValorAferido = Modulo.MovMotor.RPM_Roda;
Modulo.MovMotor.Comandar = oldCmd;
return Sucesso;
@ -706,15 +756,15 @@ namespace AgroBase.Forms.IHM
idx = PreencheDadosLinha(grid, Testes, idx, Inicializado ? 1 : 0);
int.TryParse(Leitura?.Mensagem ?? "", out int CodigoErro);
idx = PreencheDadosLinha(grid, Testes, idx, CodigoErro);
idx = PreencheDadosLinha(grid, Testes, idx, Inicializado ? CodigoErro : -1);
bool ParaEsquerda = await EnviarComandoDir(Dispositivo, Modulo, Enuns.Direcao.Esquerda, Testes[idx], 5000);
bool ParaEsquerda = Inicializado ? await EnviarComandoDir(Dispositivo, Modulo, Enuns.Direcao.Esquerda, Testes[idx], 5000) : false;
idx = PreencheDadosLinha(grid, Testes, idx, ParaEsquerda ? 1 : 0);
bool ParaDireita = await EnviarComandoDir(Dispositivo, Modulo, Enuns.Direcao.Direita, Testes[idx], 5000);
bool ParaDireita = Inicializado ? await EnviarComandoDir(Dispositivo, Modulo, Enuns.Direcao.Direita, Testes[idx], 5000) : false;
idx = PreencheDadosLinha(grid, Testes, idx, ParaDireita ? 1 : 0);
bool Parado = await EnviarComandoDir(Dispositivo, Modulo, Enuns.Direcao.Parado, Testes[idx], 5000);
bool Parado = Inicializado ? await EnviarComandoDir(Dispositivo, Modulo, Enuns.Direcao.Parado, Testes[idx], 5000) : true;
idx = PreencheDadosLinha(grid, Testes, idx, Parado ? 0 : 1);
}
@ -794,6 +844,48 @@ namespace AgroBase.Forms.IHM
ComplementoValorPadrao = ">"
},
new ColunasDiagnosticoModel()
{
Componente = "Módulo Sen",
Teste = "Conectado",
ValorPadrao = 1,
ComplementoValorPadrao = ComplementosPadrao[1]
},
new ColunasDiagnosticoModel()
{
Componente = "Módulo Sen",
Teste = "Inicializado",
ValorPadrao = 1,
ComplementoValorPadrao = ComplementosPadrao[1]
},
new ColunasDiagnosticoModel()
{
Componente = "Módulo Sen",
Teste = "Tensão Barramento 5V",
ValorPadrao = 4.95,
ComplementoValorPadrao = ">"
},
new ColunasDiagnosticoModel()
{
Componente = "Módulo Sen",
Teste = "Corrente Barramento 5V",
ValorPadrao = 1,
ComplementoValorPadrao = ">"
},
new ColunasDiagnosticoModel()
{
Componente = "Módulo Sen",
Teste = "Tensão Barramento 12V",
ValorPadrao = 11.5,
ComplementoValorPadrao = ">"
},
new ColunasDiagnosticoModel()
{
Componente = "Módulo Sen",
Teste = "Corrente Barramento 12V",
ValorPadrao = 1,
ComplementoValorPadrao = ">"
},
new ColunasDiagnosticoModel()
{
Componente = "WIT MOTION",
Teste = "Conectado",
@ -854,19 +946,41 @@ namespace AgroBase.Forms.IHM
bool PzmInicializado = PZEMService.Iniciado;
idx = PreencheDadosLinha(grid, Testes, idx, PzmInicializado ? 1 : 0);
double Tensao = PzmInicializado ? PZEMService.UltimaLeitura.Tensao : 0;
double Tensao = PzmInicializado ? PZEMService.UltimaLeitura.Tensao : -1;
idx = PreencheDadosLinha(grid, Testes, idx, Tensao);
double Corrente = PzmInicializado ? PZEMService.UltimaLeitura.Corrente : 0;
double Corrente = PzmInicializado ? PZEMService.UltimaLeitura.Corrente : -1;
idx = PreencheDadosLinha(grid, Testes, idx, Corrente);
bool SenConectado = SerialService.DispositivosMapeados.Any(x => x.Dispositivo == T_Code.Sen);
idx = PreencheDadosLinha(grid, Testes, idx, SenConectado ? 1 : 0);
var Modulo_Sen = Variaveis.OperacaoEmAndamento.DispSen.Dados;
bool SenIniciado = Modulo_Sen.Conectado;
idx = PreencheDadosLinha(grid, Testes, idx, SenIniciado ? 1 : 0);
var S5V = Modulo_Sen.Sensores.FirstOrDefault(x => x.ID == "AB5V");
double Tensao5V = S5V != null && S5V.Leituras.Count() > 1 ? S5V.Leituras[1] : -1;
idx = PreencheDadosLinha(grid, Testes, idx, Tensao5V);
double Corrente5V = S5V != null && S5V.Leituras.Count() > 0 ? S5V.Leituras[0] : -1;
idx = PreencheDadosLinha(grid, Testes, idx, Corrente5V);
var S12V = Modulo_Sen.Sensores.FirstOrDefault(x => x.ID == "AB12V");
double Tensao12V = S12V != null && S12V.Leituras.Count() > 1 ? S12V.Leituras[1] : -1;
idx = PreencheDadosLinha(grid, Testes, idx, Tensao12V);
double Corrente12V = S12V != null && S12V.Leituras.Count() > 0 ? S12V.Leituras[0] : -1;
idx = PreencheDadosLinha(grid, Testes, idx, Corrente12V);
bool WitConectado = SerialService.DispositivosMapeados.Any(x => x.Dispositivo == Enuns.T_Code.Wit);
idx = PreencheDadosLinha(grid, Testes, idx, WitConectado ? 1 : 0);
bool WitInicializado = WT901CService.Iniciado;
idx = PreencheDadosLinha(grid, Testes, idx, WitInicializado ? 1 : 0);
double Orientacao = WitInicializado ? WT901CService.DadosLeitura.AngleZ : 0;
double Orientacao = WitInicializado ? WT901CService.DadosLeitura.AngleZ : -1;
idx = PreencheDadosLinha(grid, Testes, idx, Orientacao);
bool GpsConectado = SerialService.DispositivosMapeados.Any(x => x.Dispositivo == Enuns.T_Code.Gps);
@ -875,7 +989,7 @@ namespace AgroBase.Forms.IHM
bool GpsInicializado = GPSService.Iniciado;
idx = PreencheDadosLinha(grid, Testes, idx, GpsInicializado ? 1 : 0);
double Precisao = GpsInicializado ? GPSService.UltimaLeitura.PrecisaoHorizontal : 0;
double Precisao = GpsInicializado ? GPSService.UltimaLeitura.PrecisaoHorizontal : -1;
idx = PreencheDadosLinha(grid, Testes, idx, Precisao);
return true;
@ -1282,15 +1396,21 @@ namespace AgroBase.Forms.IHM
bool Iniciado = Sinaleiro.Inicializado;
idx = PreencheDadosLinha(grid, Testes, idx, Inicializado ? 1 : 0);
await EnviarComandoSinaleiro(Dispositivo, Sinaleiro, true, 1000);
if (Iniciado)
{
await EnviarComandoSinaleiro(Dispositivo, Sinaleiro, true, 1000);
}
StatusLED Status = Sinaleiro.StatusLED;
idx = PreencheDadosLinha(grid, Testes, idx, Status == StatusLED.Aceso ? 1 : 0);
idx = PreencheDadosLinha(grid, Testes, idx, Iniciado && Status == StatusLED.Aceso ? 1 : 0);
await EnviarComandoSinaleiro(Dispositivo, Sinaleiro, false, 1000);
if (Iniciado)
{
await EnviarComandoSinaleiro(Dispositivo, Sinaleiro, false, 1000);
}
Status = Sinaleiro.StatusLED;
idx = PreencheDadosLinha(grid, Testes, idx, Status == StatusLED.Apagado ? 0 : 1);
idx = PreencheDadosLinha(grid, Testes, idx, Iniciado && Status == StatusLED.Apagado ? 0 : 1);
}

View File

@ -28,7 +28,7 @@
/// </summary>
private void InitializeComponent()
{
this.lblD_Mvd_DF = new System.Windows.Forms.Label();
this.lblD_Bld_DF = new System.Windows.Forms.Label();
this.lblD_Atu = new System.Windows.Forms.Label();
this.lblD_Sen = new System.Windows.Forms.Label();
this.lblD_Gps = new System.Windows.Forms.Label();
@ -36,13 +36,13 @@
this.lblD_Pzm = new System.Windows.Forms.Label();
this.lblD_Lra = new System.Windows.Forms.Label();
this.lblD_Wit = new System.Windows.Forms.Label();
this.lblD_Mvd_DT = new System.Windows.Forms.Label();
this.lblD_Bld_DT = new System.Windows.Forms.Label();
this.lblD_Mks_DF = new System.Windows.Forms.Label();
this.lblD_Mks_EF = new System.Windows.Forms.Label();
this.lblD_Mvd_EF = new System.Windows.Forms.Label();
this.lblD_Bld_EF = new System.Windows.Forms.Label();
this.lblD_Mks_DT = new System.Windows.Forms.Label();
this.lblD_Mks_ET = new System.Windows.Forms.Label();
this.lblD_Mvd_ET = new System.Windows.Forms.Label();
this.lblD_Bld_ET = new System.Windows.Forms.Label();
this.lblD_Cam_S0 = new System.Windows.Forms.Label();
this.lblD_Cam_S1 = new System.Windows.Forms.Label();
this.lblD_Cam_C = new System.Windows.Forms.Label();
@ -62,17 +62,17 @@
((System.ComponentModel.ISupportInitialize)(this.picRobo)).BeginInit();
this.SuspendLayout();
//
// lblD_Mvd_DF
// lblD_Bld_DF
//
this.lblD_Mvd_DF.AutoSize = true;
this.lblD_Mvd_DF.BackColor = System.Drawing.Color.Transparent;
this.lblD_Mvd_DF.Cursor = System.Windows.Forms.Cursors.Hand;
this.lblD_Mvd_DF.Location = new System.Drawing.Point(264, 66);
this.lblD_Mvd_DF.Name = "lblD_Mvd_DF";
this.lblD_Mvd_DF.Size = new System.Drawing.Size(52, 24);
this.lblD_Mvd_DF.TabIndex = 2;
this.lblD_Mvd_DF.Text = "MVD";
this.lblD_Mvd_DF.Click += new System.EventHandler(this.lblModulo_Click);
this.lblD_Bld_DF.AutoSize = true;
this.lblD_Bld_DF.BackColor = System.Drawing.Color.Transparent;
this.lblD_Bld_DF.Cursor = System.Windows.Forms.Cursors.Hand;
this.lblD_Bld_DF.Location = new System.Drawing.Point(264, 66);
this.lblD_Bld_DF.Name = "lblD_Bld_DF";
this.lblD_Bld_DF.Size = new System.Drawing.Size(45, 24);
this.lblD_Bld_DF.TabIndex = 2;
this.lblD_Bld_DF.Text = "BLD";
this.lblD_Bld_DF.Click += new System.EventHandler(this.lblModulo_Click);
//
// lblD_Atu
//
@ -155,17 +155,17 @@
this.lblD_Wit.Text = "WIT";
this.lblD_Wit.Click += new System.EventHandler(this.lblModulo_Click);
//
// lblD_Mvd_DT
// lblD_Bld_DT
//
this.lblD_Mvd_DT.AutoSize = true;
this.lblD_Mvd_DT.BackColor = System.Drawing.Color.Lavender;
this.lblD_Mvd_DT.Cursor = System.Windows.Forms.Cursors.Hand;
this.lblD_Mvd_DT.Location = new System.Drawing.Point(264, 255);
this.lblD_Mvd_DT.Name = "lblD_Mvd_DT";
this.lblD_Mvd_DT.Size = new System.Drawing.Size(52, 24);
this.lblD_Mvd_DT.TabIndex = 18;
this.lblD_Mvd_DT.Text = "MVD";
this.lblD_Mvd_DT.Click += new System.EventHandler(this.lblModulo_Click);
this.lblD_Bld_DT.AutoSize = true;
this.lblD_Bld_DT.BackColor = System.Drawing.Color.Lavender;
this.lblD_Bld_DT.Cursor = System.Windows.Forms.Cursors.Hand;
this.lblD_Bld_DT.Location = new System.Drawing.Point(264, 255);
this.lblD_Bld_DT.Name = "lblD_Bld_DT";
this.lblD_Bld_DT.Size = new System.Drawing.Size(45, 24);
this.lblD_Bld_DT.TabIndex = 18;
this.lblD_Bld_DT.Text = "BLD";
this.lblD_Bld_DT.Click += new System.EventHandler(this.lblModulo_Click);
//
// lblD_Mks_DF
//
@ -191,17 +191,17 @@
this.lblD_Mks_EF.Text = "MKS";
this.lblD_Mks_EF.Click += new System.EventHandler(this.lblModulo_Click);
//
// lblD_Mvd_EF
// lblD_Bld_EF
//
this.lblD_Mvd_EF.AutoSize = true;
this.lblD_Mvd_EF.BackColor = System.Drawing.Color.Transparent;
this.lblD_Mvd_EF.Cursor = System.Windows.Forms.Cursors.Hand;
this.lblD_Mvd_EF.Location = new System.Drawing.Point(35, 66);
this.lblD_Mvd_EF.Name = "lblD_Mvd_EF";
this.lblD_Mvd_EF.Size = new System.Drawing.Size(52, 24);
this.lblD_Mvd_EF.TabIndex = 20;
this.lblD_Mvd_EF.Text = "MVD";
this.lblD_Mvd_EF.Click += new System.EventHandler(this.lblModulo_Click);
this.lblD_Bld_EF.AutoSize = true;
this.lblD_Bld_EF.BackColor = System.Drawing.Color.Transparent;
this.lblD_Bld_EF.Cursor = System.Windows.Forms.Cursors.Hand;
this.lblD_Bld_EF.Location = new System.Drawing.Point(35, 66);
this.lblD_Bld_EF.Name = "lblD_Bld_EF";
this.lblD_Bld_EF.Size = new System.Drawing.Size(45, 24);
this.lblD_Bld_EF.TabIndex = 20;
this.lblD_Bld_EF.Text = "BLD";
this.lblD_Bld_EF.Click += new System.EventHandler(this.lblModulo_Click);
//
// lblD_Mks_DT
//
@ -227,17 +227,17 @@
this.lblD_Mks_ET.Text = "MKS";
this.lblD_Mks_ET.Click += new System.EventHandler(this.lblModulo_Click);
//
// lblD_Mvd_ET
// lblD_Bld_ET
//
this.lblD_Mvd_ET.AutoSize = true;
this.lblD_Mvd_ET.BackColor = System.Drawing.Color.Lavender;
this.lblD_Mvd_ET.Cursor = System.Windows.Forms.Cursors.Hand;
this.lblD_Mvd_ET.Location = new System.Drawing.Point(35, 255);
this.lblD_Mvd_ET.Name = "lblD_Mvd_ET";
this.lblD_Mvd_ET.Size = new System.Drawing.Size(52, 24);
this.lblD_Mvd_ET.TabIndex = 23;
this.lblD_Mvd_ET.Text = "MVD";
this.lblD_Mvd_ET.Click += new System.EventHandler(this.lblModulo_Click);
this.lblD_Bld_ET.AutoSize = true;
this.lblD_Bld_ET.BackColor = System.Drawing.Color.Lavender;
this.lblD_Bld_ET.Cursor = System.Windows.Forms.Cursors.Hand;
this.lblD_Bld_ET.Location = new System.Drawing.Point(35, 255);
this.lblD_Bld_ET.Name = "lblD_Bld_ET";
this.lblD_Bld_ET.Size = new System.Drawing.Size(45, 24);
this.lblD_Bld_ET.TabIndex = 23;
this.lblD_Bld_ET.Text = "BLD";
this.lblD_Bld_ET.Click += new System.EventHandler(this.lblModulo_Click);
//
// lblD_Cam_S0
//
@ -389,12 +389,12 @@
this.Controls.Add(this.lblD_Cam_S0);
this.Controls.Add(this.picDesligar);
this.Controls.Add(this.lblD_Mks_ET);
this.Controls.Add(this.lblD_Mvd_ET);
this.Controls.Add(this.lblD_Bld_ET);
this.Controls.Add(this.lblD_Mks_DT);
this.Controls.Add(this.lblD_Mks_EF);
this.Controls.Add(this.lblD_Mvd_EF);
this.Controls.Add(this.lblD_Bld_EF);
this.Controls.Add(this.lblD_Mks_DF);
this.Controls.Add(this.lblD_Mvd_DT);
this.Controls.Add(this.lblD_Bld_DT);
this.Controls.Add(this.lblD_Wit);
this.Controls.Add(this.lblD_Lra);
this.Controls.Add(this.lblD_Pzm);
@ -402,7 +402,7 @@
this.Controls.Add(this.lblD_Gps);
this.Controls.Add(this.lblD_Sen);
this.Controls.Add(this.lblD_Atu);
this.Controls.Add(this.lblD_Mvd_DF);
this.Controls.Add(this.lblD_Bld_DF);
this.Controls.Add(this.picRobo);
this.Font = new System.Drawing.Font("Microsoft Sans Serif", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
@ -424,7 +424,7 @@
#endregion
private System.Windows.Forms.PictureBox picRobo;
private System.Windows.Forms.Label lblD_Mvd_DF;
private System.Windows.Forms.Label lblD_Bld_DF;
private System.Windows.Forms.Label lblD_Atu;
private System.Windows.Forms.Label lblD_Sen;
private System.Windows.Forms.Label lblD_Gps;
@ -432,13 +432,13 @@
private System.Windows.Forms.Label lblD_Pzm;
private System.Windows.Forms.Label lblD_Lra;
private System.Windows.Forms.Label lblD_Wit;
private System.Windows.Forms.Label lblD_Mvd_DT;
private System.Windows.Forms.Label lblD_Bld_DT;
private System.Windows.Forms.Label lblD_Mks_DF;
private System.Windows.Forms.Label lblD_Mks_EF;
private System.Windows.Forms.Label lblD_Mvd_EF;
private System.Windows.Forms.Label lblD_Bld_EF;
private System.Windows.Forms.Label lblD_Mks_DT;
private System.Windows.Forms.Label lblD_Mks_ET;
private System.Windows.Forms.Label lblD_Mvd_ET;
private System.Windows.Forms.Label lblD_Bld_ET;
private System.Windows.Forms.PictureBox picDiagnosticos;
private System.Windows.Forms.PictureBox picOperacao;
private System.Windows.Forms.PictureBox picDesligar;

View File

@ -80,10 +80,12 @@ namespace AgroBase.Forms.Movimentacao
this.lblRPMMax = new System.Windows.Forms.Label();
this.nudRPMMax = new System.Windows.Forms.NumericUpDown();
this.lblNumPolos = new System.Windows.Forms.Label();
this.nudNumPolos = new System.Windows.Forms.NumericUpDown();
this.lblRampa = new System.Windows.Forms.Label();
this.nudRampa = new System.Windows.Forms.NumericUpDown();
this.btnSalvar = new System.Windows.Forms.Button();
this.nudNumPolos = new System.Windows.Forms.NumericUpDown();
this.lblReducao = new System.Windows.Forms.Label();
this.nudReducao = new System.Windows.Forms.NumericUpDown();
this.gpbSentido.SuspendLayout();
this.gpbDF.SuspendLayout();
this.gpbEF.SuspendLayout();
@ -92,8 +94,9 @@ namespace AgroBase.Forms.Movimentacao
this.groupBox1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.nudDiametroRoda)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.nudRPMMax)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.nudNumPolos)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.nudRampa)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.nudNumPolos)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.nudReducao)).BeginInit();
this.SuspendLayout();
//
// gpbSentido
@ -577,6 +580,9 @@ namespace AgroBase.Forms.Movimentacao
//
// groupBox1
//
this.groupBox1.Controls.Add(this.lblReducao);
this.groupBox1.Controls.Add(this.nudReducao);
this.groupBox1.Controls.Add(this.btnSalvar);
this.groupBox1.Controls.Add(this.lblDiametroRoda);
this.groupBox1.Controls.Add(this.nudDiametroRoda);
this.groupBox1.Controls.Add(this.lblRPMMax);
@ -589,7 +595,7 @@ namespace AgroBase.Forms.Movimentacao
this.groupBox1.Margin = new System.Windows.Forms.Padding(2);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Padding = new System.Windows.Forms.Padding(2);
this.groupBox1.Size = new System.Drawing.Size(376, 66);
this.groupBox1.Size = new System.Drawing.Size(376, 113);
this.groupBox1.TabIndex = 135;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "Ajustes";
@ -663,25 +669,6 @@ namespace AgroBase.Forms.Movimentacao
this.lblNumPolos.TabIndex = 36;
this.lblNumPolos.Text = "Número de Polos";
//
// nudNumPolos
//
this.nudNumPolos.Location = new System.Drawing.Point(100, 37);
this.nudNumPolos.Margin = new System.Windows.Forms.Padding(2);
this.nudNumPolos.Maximum = new decimal(new int[] {
999,
0,
0,
0});
this.nudNumPolos.Name = "nudNumPolos";
this.nudNumPolos.Size = new System.Drawing.Size(85, 20);
this.nudNumPolos.TabIndex = 35;
this.nudNumPolos.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
this.nudNumPolos.Value = new decimal(new int[] {
2,
0,
0,
0});
//
// lblRampa
//
this.lblRampa.AutoSize = true;
@ -708,22 +695,69 @@ namespace AgroBase.Forms.Movimentacao
//
// btnSalvar
//
this.btnSalvar.Location = new System.Drawing.Point(272, 432);
this.btnSalvar.Location = new System.Drawing.Point(283, 67);
this.btnSalvar.Margin = new System.Windows.Forms.Padding(2);
this.btnSalvar.Name = "btnSalvar";
this.btnSalvar.Size = new System.Drawing.Size(115, 24);
this.btnSalvar.Size = new System.Drawing.Size(85, 41);
this.btnSalvar.TabIndex = 136;
this.btnSalvar.Text = "Salvar";
this.btnSalvar.UseVisualStyleBackColor = true;
this.btnSalvar.Click += new System.EventHandler(this.btnSalvar_Click);
//
// nudNumPolos
//
this.nudNumPolos.Location = new System.Drawing.Point(100, 37);
this.nudNumPolos.Margin = new System.Windows.Forms.Padding(2);
this.nudNumPolos.Maximum = new decimal(new int[] {
999,
0,
0,
0});
this.nudNumPolos.Name = "nudNumPolos";
this.nudNumPolos.Size = new System.Drawing.Size(85, 20);
this.nudNumPolos.TabIndex = 35;
this.nudNumPolos.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
this.nudNumPolos.Value = new decimal(new int[] {
2,
0,
0,
0});
//
// lblReducao
//
this.lblReducao.AutoSize = true;
this.lblReducao.Location = new System.Drawing.Point(5, 67);
this.lblReducao.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
this.lblReducao.Name = "lblReducao";
this.lblReducao.Size = new System.Drawing.Size(51, 13);
this.lblReducao.TabIndex = 138;
this.lblReducao.Text = "Redução";
//
// nudReducao
//
this.nudReducao.Location = new System.Drawing.Point(8, 84);
this.nudReducao.Margin = new System.Windows.Forms.Padding(2);
this.nudReducao.Minimum = new decimal(new int[] {
1,
0,
0,
0});
this.nudReducao.Name = "nudReducao";
this.nudReducao.Size = new System.Drawing.Size(85, 20);
this.nudReducao.TabIndex = 137;
this.nudReducao.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
this.nudReducao.Value = new decimal(new int[] {
1,
0,
0,
0});
//
// frmMovConfig
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackColor = System.Drawing.Color.White;
this.ClientSize = new System.Drawing.Size(398, 469);
this.Controls.Add(this.btnSalvar);
this.ClientSize = new System.Drawing.Size(398, 482);
this.Controls.Add(this.groupBox1);
this.Controls.Add(this.gpbSentido);
this.Margin = new System.Windows.Forms.Padding(2);
@ -746,8 +780,9 @@ namespace AgroBase.Forms.Movimentacao
this.groupBox1.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.nudDiametroRoda)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.nudRPMMax)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.nudNumPolos)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.nudRampa)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.nudNumPolos)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.nudReducao)).EndInit();
this.ResumeLayout(false);
}
@ -792,7 +827,6 @@ namespace AgroBase.Forms.Movimentacao
private System.Windows.Forms.Label lblETFrente;
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.Label lblNumPolos;
private System.Windows.Forms.NumericUpDown nudNumPolos;
private System.Windows.Forms.Label lblRampa;
private System.Windows.Forms.NumericUpDown nudRampa;
private System.Windows.Forms.Label lblRPMMax;
@ -808,5 +842,8 @@ namespace AgroBase.Forms.Movimentacao
private System.Windows.Forms.TextBox txtDTEndereco;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.TextBox txtETEndereco;
private System.Windows.Forms.Label lblReducao;
private System.Windows.Forms.NumericUpDown nudReducao;
private System.Windows.Forms.NumericUpDown nudNumPolos;
}
}

View File

@ -61,6 +61,8 @@ namespace AgroBase.Forms.Movimentacao
nudNumPolos.Value = Modulo.MovMotor.NumeroPolos;
nudRampa.Value = Modulo.MovMotor.Rampa;
nudRPMMax.Value = Modulo.MovMotor.RPM_Max;
nudReducao.Value = Modulo.MovMotor.Reducao;
nudDiametroRoda.Value = Convert.ToInt32(VariaveisEquipamento.DiametroRoda * 1000);
TextBox txtEndereco = FuncoesGlobais.FindControlRecursive<TextBox>(gpbSentido, "txt" + Modulo.Modulo_ID + "Endereco");
@ -105,10 +107,12 @@ namespace AgroBase.Forms.Movimentacao
Modulo.MovMotor.NumeroPolos = Convert.ToInt32(nudNumPolos.Value);
Modulo.MovMotor.Rampa = Convert.ToInt32(nudRampa.Value);
Modulo.MovMotor.RPM_Max = Convert.ToInt32(nudRPMMax.Value);
Modulo.MovMotor.Reducao = Convert.ToInt32(nudReducao.Value);
VariaveisEquipamento.DiametroRoda = Convert.ToDouble(nudDiametroRoda.Value / 1000);
TextBox txtEndereco = FuncoesGlobais.FindControlRecursive<TextBox>(gpbSentido, "txt" + Modulo.Modulo_ID + "Endereco");
Modulo.MovMotor.Endereco = txtEndereco.Text;
Modulo.DirMotor.Endereco = txtEndereco.Text;
}
}

View File

@ -23,7 +23,6 @@ namespace AgroBase.Forms.Operacoes
{
Timer tmrLeitura;
DateTime UltimoComandoDir = DateTime.Now;
GraficoInterativoModel graficoMovGeral;
public frmOperacaoManual()
{
@ -52,7 +51,7 @@ namespace AgroBase.Forms.Operacoes
PopularInformacoesGerais();
InicializarMapa();
PopularBicos();
//InicializarGraficos();
Variaveis.OperacaoEmAndamento.chartGraficos = chartGraficos;
tmrLeitura = new Timer() { Interval = 500 };
tmrLeitura.Tick += tmrLeitura_Tick;
@ -104,7 +103,6 @@ namespace AgroBase.Forms.Operacoes
pnlAnguloGPS.Invalidate();
pnlAnguloMagnetometro.Invalidate();
AtualizarGrafico();
AtualizarInformacoesGerais();
lblDistanciaEsquerda.Text = "Distancia Esq: " + Variaveis.OperacaoEmAndamento.Sensoriamento.DistanciaEsquerda.ToString("0.00") + " cm";
@ -116,7 +114,7 @@ namespace AgroBase.Forms.Operacoes
lblTensao.Text = PZEMService.UltimaLeitura.Tensao.ToString("0.00") + " v";
lblCorrente.Text = PZEMService.UltimaLeitura.Corrente.ToString("0.00") + " A";
lblRPM.Text = Variaveis.OperacaoEmAndamento.DispMvd.Dados.Modulos.Average(x => x.MovMotor.RPM).ToString("0") + " rpm";
lblRPM.Text = Variaveis.OperacaoEmAndamento.DispMvd.Dados.Modulos.Average(x => x.MovMotor.RPM_Motor).ToString("0") + " rpm";
lblVelocidade.Text = Variaveis.OperacaoEmAndamento.DispMvd.Dados.Modulos.Average(x => x.MovMotor.VelocidadeInstantanea).ToString("0.00");
chbSonar.Enabled = Variaveis.OperacaoEmAndamento.DispSen.Dados.Sensores.Any(x => x.Componente == S_Code.sSNR && x.Inicializado);
@ -128,15 +126,16 @@ namespace AgroBase.Forms.Operacoes
if (chbSonar.Checked && Sonar.DesvioNecessario && UltimoComandoDir.AddSeconds(1) < DateTime.Now)
{
Variaveis.OperacaoEmAndamento.Controle.Angulo = Sonar.AnguloDesvio;
Direcao direcaoDesvio = Direcao.Direita;
Keys TeclaDirecao = Keys.Right;
if (Variaveis.OperacaoEmAndamento.Controle.Angulo < 0)
{
Variaveis.OperacaoEmAndamento.Controle.Angulo *= -1;
direcaoDesvio = Direcao.Esquerda;
TeclaDirecao = Keys.Left;
}
Variaveis.OperacaoEmAndamento.DispMvd.Dados.Modulos.ForEach(Modulo =>
{
Variaveis.OperacaoEmAndamento.DispMvd.AdicionarMensagemFila(Modulo.Modulo_ID, Modulo.DirMotor.ProtocoloComando(direcaoDesvio), true, false);
//Variaveis.OperacaoEmAndamento.DispMvd.AdicionarMensagemFila(Modulo.Modulo_ID, Modulo.DirMotor.ProtocoloComando(direcaoDesvio), true, false);
GeneralJoystick.EnviaComandoMotor(TeclaDirecao, T_Code.Dir);
});
UltimoComandoDir = DateTime.Now;
}
@ -177,8 +176,8 @@ namespace AgroBase.Forms.Operacoes
{
string ID = chbCmd.Name.Split('_')[1];
var Modulo = Variaveis.OperacaoEmAndamento.DispMvd.Dados.Modulos.FirstOrDefault(x => x.Modulo_ID == ID);
chbCmd.Checked = Modulo.DirMotor.Controlar;
chbLivre.Checked = Modulo.DirMotor.Livre;
chbCmd.Checked = Modulo.DirMotor.Comandar;
//chbLivre.Checked = Modulo.DirMotor.Livre;
}
private void pnlDir_Paint(object sender, PaintEventArgs e)
@ -336,8 +335,8 @@ namespace AgroBase.Forms.Operacoes
string ID = ((Button)sender).Name.Replace("btnRef_", "");
var Dispositivo = Variaveis.OperacaoEmAndamento.DispMvd;
var Modulo = Dispositivo.Dados.Modulos.FirstOrDefault(x => x.Modulo_ID == ID);
var Comando = Modulo.DirMotor.ProtocoloComando(Direcao.Parado);
Dispositivo.AdicionarMensagemFila(Modulo.Modulo_ID, Comando, true, false);
//var Comando = Modulo.DirMotor.ProtocoloComando(Direcao.Parado);
//Dispositivo.AdicionarMensagemFila(Modulo.Modulo_ID, Comando, true, false);
}
private void chbCmd_CheckedChanged(object sender, EventArgs e)
@ -345,7 +344,7 @@ namespace AgroBase.Forms.Operacoes
string ID = ((CheckBox)sender).Name.Replace("chbCmd_", "");
var Dispositivo = Variaveis.OperacaoEmAndamento.DispMvd;
var Modulo = Dispositivo.Dados.Modulos.FirstOrDefault(x => x.Modulo_ID == ID);
Modulo.DirMotor.Controlar = ((CheckBox)sender).Checked;
Modulo.DirMotor.Comandar = ((CheckBox)sender).Checked;
}
private void chbLivre_CheckedChanged(object sender, EventArgs e)
@ -353,7 +352,7 @@ namespace AgroBase.Forms.Operacoes
string ID = ((CheckBox)sender).Name.Replace("chbLivre_", "");
var Dispositivo = Variaveis.OperacaoEmAndamento.DispMvd;
var Modulo = Dispositivo.Dados.Modulos.FirstOrDefault(x => x.Modulo_ID == ID);
Modulo.DirMotor.Livre = ((CheckBox)sender).Checked;
//Modulo.DirMotor.Livre = ((CheckBox)sender).Checked;
}
#endregion
@ -381,162 +380,6 @@ namespace AgroBase.Forms.Operacoes
}
#endregion
#region Graficos
private void InicializarGraficos()
{
//var Logs = Variaveis.OperacaoEmAndamento.DispMvd.Dados.Modulos.SelectMany(x => x.MovMotor.LogGrafico).ToList();
var Logs = Variaveis.OperacaoEmAndamento.DispMvd.Dados.Modulos.FirstOrDefault(x => x.Modulo_ID == "ET").MovMotor.LogGrafico.ToList();
var Momentos = Logs.Select(x => x.Momento.ToString("mm:ss:fff")).ToList();
graficoMovGeral = new GraficoInterativoModel(chartGraficos, Momentos, new List<GraficoInterativoSerieModel>()
{
new GraficoInterativoSerieModel()
{
Titulo = "RPM SP",
Valores = Logs.Select(x => Convert.ToDouble(x.RPM_SP)).ToList(),
Visivel = true,
MostrarValor = true
},
new GraficoInterativoSerieModel()
{
Titulo = "RPM",
Valores = Logs.Select(x => x.RPM).ToList(),
Visivel = true,
MostrarValor = true
},
new GraficoInterativoSerieModel()
{
Titulo = "Temperatura",
Valores = Logs.Select(x => x.Temperatura).ToList(),
Visivel = true,
MostrarValor = true
},
/*new GraficoInterativoSerieModel()
{
Titulo = "EF",
Valores = Logs.Where(x => x.Modulo_ID == "EF").Select(x => x.RPM).ToList(),
Visivel = true,
MostrarValor = true
},
new GraficoInterativoSerieModel()
{
Titulo = "DT",
Valores = Logs.Where(x => x.Modulo_ID == "DT").Select(x => x.RPM).ToList(),
Visivel = true,
MostrarValor = true
},
new GraficoInterativoSerieModel()
{
Titulo = "DF",
Valores = Logs.Where(x => x.Modulo_ID == "DF").Select(x => x.RPM).ToList(),
Visivel = true,
MostrarValor = true
},*/
}, 60);
}
private void AtualizarGrafico()
{
/*var Logs = Variaveis.OperacaoEmAndamento.DispMvd.Dados.Modulos.FirstOrDefault(x => x.Modulo_ID == "ET").MovMotor.LogGrafico.OrderBy(x => x.Momento).ToList();
var Momentos = Logs.Select(x => x.Momento.ToString("mm:ss:fff")).ToList();
int idx = Logs.Count() - 1;
var series = new List<GraficoInterativoSerieModel>()
{
new GraficoInterativoSerieModel()
{
Titulo = "RPM SP",
Valores = Logs.Select(x => Convert.ToDouble(x.RPM_SP)).ToList(),
Visivel = true,
MostrarValor = true
},
new GraficoInterativoSerieModel()
{
Titulo = "RPM",
Valores = Logs.Select(x => x.RPM).ToList(),
Visivel = true,
MostrarValor = true
},
new GraficoInterativoSerieModel()
{
Titulo = "Temperatura",
Valores = Logs.Select(x => x.Temperatura).ToList(),
Visivel = true,
MostrarValor = true
}
};
graficoMovGeral.AtualizarDados(idx, Momentos, series);*/
MvdMotorMOVSensorimanetoGrafico Log = null;
// Primeiro, coletar todos os logs alinhados por índice em uma lista de tuplas (index, moduloLog)
var Logs = Variaveis.OperacaoEmAndamento.DispMvd.Dados.Modulos
.SelectMany(m => m.MovMotor.LogGrafico.Select((log, index) => new { Index = index, Log = log }))
.GroupBy(x => x.Index) // Agrupa por índice
.OrderBy(g => g.Key) // Ordena pelos índices (opcional, mas ajuda na leitura)
.Select(g => new MvdMotorMOVSensorimanetoGrafico()
{
// Calcula a média de cada propriedade no grupo
Momento = new DateTime((long)g.Average(x => x.Log.Momento.Ticks)),
Velocidade = g.Average(x => x.Log.Velocidade),
RPM = Convert.ToInt32(g.Average(x => x.Log.RPM)),
RPM_SP = Convert.ToInt32(g.Average(x => x.Log.RPM_SP)),
Temperatura = g.Average(x => x.Log.Temperatura),
Tensao = g.Average(x => x.Log.Tensao),
})
.ToList();
double Minimo = 0;
double Maximo = 0;
Chart chart = chartGraficos;
chart.Titles.Clear();
//chart.Titles.Add("Acompanhamento");
//var Logs = (Modulo.MovMotor.LogGrafico.Count > MovimentacaoModel.LogsManter ? Modulo.MovMotor.LogGrafico.Skip(Math.Max(0, Modulo.MovMotor.LogGrafico.Count - MovimentacaoModel.LogsManter)).Take(MovimentacaoModel.LogsManter).ToList() : Modulo.MovMotor.LogGrafico).Where(log => log.Modulo_ID == Modulo.Modulo_ID).ToList();
chart.Series.Clear();
List<string> Momentos = Logs.Select(x => x.Momento.ToString("mm:ss:fff")).ToList();
var serieVelocidade = new Series("Velocidade: " + (Log != null ? Log.Velocidade : 0));
serieVelocidade.Points.DataBindXY(Momentos, Logs.Select(x => x.Velocidade).ToList());
serieVelocidade.ChartType = SeriesChartType.Line;
chart.Series.Add(serieVelocidade);
Minimo = Logs.Min(x => x.Velocidade) < Minimo ? Logs.Min(x => x.Velocidade) : Minimo;
Maximo = Logs.Min(x => x.Velocidade) > Maximo ? Logs.Min(x => x.Velocidade) : Maximo;
var serieRPMsp = new Series("RPM SP: " + (Log != null ? Log.RPM_SP : 0));
serieRPMsp.Points.DataBindXY(Momentos, Logs.Select(x => x.RPM_SP).ToList());
serieRPMsp.ChartType = SeriesChartType.Spline;
chart.Series.Add(serieRPMsp);
Minimo = Logs.Min(x => x.RPM_SP) < Minimo ? Logs.Min(x => x.RPM_SP) : Minimo;
Maximo = Logs.Max(x => x.RPM_SP) > Maximo ? Logs.Max(x => x.RPM_SP) : Maximo;
var serieRPM = new Series("RPM: " + (Log != null ? Log.RPM : 0));
serieRPM.Points.DataBindXY(Momentos, Logs.Select(x => x.RPM).ToList());
serieRPM.ChartType = SeriesChartType.Spline;
chart.Series.Add(serieRPM);
Minimo = Logs.Min(x => x.RPM) < Minimo ? Logs.Min(x => x.RPM) : Minimo;
Maximo = Logs.Max(x => x.RPM) > Maximo ? Logs.Max(x => x.RPM) : Maximo;
var serieTemperatura = new Series("Temperatura: " + (Log != null ? Log.Temperatura : 0));
serieTemperatura.Points.DataBindXY(Momentos, Logs.Select(x => x.Temperatura).ToList());
serieTemperatura.ChartType = SeriesChartType.Line;
chart.Series.Add(serieTemperatura);
Minimo = Logs.Min(x => x.Temperatura) < Minimo ? Logs.Min(x => x.Temperatura) : Minimo;
Maximo = Logs.Max(x => x.Temperatura) > Maximo ? Logs.Max(x => x.Temperatura) : Maximo;
foreach (var legend in chart.Legends)
{
legend.Docking = Docking.Bottom;
}
chart.ChartAreas[0].AxisY.Minimum = Minimo - 5;
chart.ChartAreas[0].AxisY.Maximum = Maximo + 5;
}
#endregion
#region Informacoes gerais
@ -574,6 +417,11 @@ namespace AgroBase.Forms.Operacoes
private void AtualizarInformacoesGerais()
{
var AB3V = Variaveis.OperacaoEmAndamento.DispSen.Dados.Sensores.FirstOrDefault(x => x.ID == "AB3V");
var AB5V = Variaveis.OperacaoEmAndamento.DispSen.Dados.Sensores.FirstOrDefault(x => x.ID == "AB5V");
var AB7V2 = Variaveis.OperacaoEmAndamento.DispSen.Dados.Sensores.FirstOrDefault(x => x.ID == "AB7V2");
var AB12V = Variaveis.OperacaoEmAndamento.DispSen.Dados.Sensores.FirstOrDefault(x => x.ID == "AB12V");
gridDados.Rows[0].Cells[1].Value = Variaveis.OperacaoEmAndamento.Tempo.Hours.ToString("00") + ":" + Variaveis.OperacaoEmAndamento.Tempo.Minutes.ToString("00") + ":" + Variaveis.OperacaoEmAndamento.Tempo.Seconds.ToString("00");
gridDados.Rows[1].Cells[1].Value = TimeSpan.FromSeconds(Variaveis.OperacaoEmAndamento.DispMvd.Dados.TempoEmAtividade).ToString(@"hh\:mm\:ss");
gridDados.Rows[2].Cells[1].Value = Variaveis.OperacaoEmAndamento.Sensoriamento.VelocidadeMedia.ToString("0.00");
@ -581,14 +429,14 @@ namespace AgroBase.Forms.Operacoes
gridDados.Rows[4].Cells[1].Value = (PZEMService.Iniciado && PZEMService.UltimaLeitura != null ? Variaveis.OperacaoEmAndamento.Sensoriamento.PorcentagemBateria.ToString("00.00") : "");
gridDados.Rows[5].Cells[1].Value = (PZEMService.Iniciado && PZEMService.UltimaLeitura != null ? PZEMService.UltimaLeitura.Tensao.ToString("0.00") : "");
gridDados.Rows[6].Cells[1].Value = (PZEMService.Iniciado && PZEMService.UltimaLeitura != null ? PZEMService.UltimaLeitura.Corrente.ToString("0.00") : "");
gridDados.Rows[7].Cells[1].Value = Variaveis.OperacaoEmAndamento.DispSen.Dados.Sensores.FirstOrDefault(x => x.ID == "AB3V").Leituras?[1].ToString("0.00");
gridDados.Rows[8].Cells[1].Value = Variaveis.OperacaoEmAndamento.DispSen.Dados.Sensores.FirstOrDefault(x => x.ID == "AB3V").Leituras?[0].ToString("0.00");
gridDados.Rows[9].Cells[1].Value = Variaveis.OperacaoEmAndamento.DispSen.Dados.Sensores.FirstOrDefault(x => x.ID == "AB5V").Leituras?[1].ToString("0.00");
gridDados.Rows[10].Cells[1].Value = Variaveis.OperacaoEmAndamento.DispSen.Dados.Sensores.FirstOrDefault(x => x.ID == "AB5V").Leituras?[0].ToString("0.00");
gridDados.Rows[11].Cells[1].Value = Variaveis.OperacaoEmAndamento.DispSen.Dados.Sensores.FirstOrDefault(x => x.ID == "AB7V2").Leituras?[1].ToString("0.00");
gridDados.Rows[12].Cells[1].Value = Variaveis.OperacaoEmAndamento.DispSen.Dados.Sensores.FirstOrDefault(x => x.ID == "AB7V2").Leituras?[0].ToString("0.00");
gridDados.Rows[13].Cells[1].Value = Variaveis.OperacaoEmAndamento.DispSen.Dados.Sensores.FirstOrDefault(x => x.ID == "AB12V").Leituras?[1].ToString("0.00");
gridDados.Rows[14].Cells[1].Value = Variaveis.OperacaoEmAndamento.DispSen.Dados.Sensores.FirstOrDefault(x => x.ID == "AB12V").Leituras?[0].ToString("0.00");
gridDados.Rows[7].Cells[1].Value = (AB3V != null && AB3V.Leituras != null && AB3V.Leituras.Count() > 0 ? AB3V.Leituras[0] : 0).ToString("0.00");
gridDados.Rows[8].Cells[1].Value = (AB3V != null && AB3V.Leituras != null && AB3V.Leituras.Count() > 1 ? AB3V.Leituras[1] : 0).ToString("0.00");
gridDados.Rows[9].Cells[1].Value = (AB5V != null && AB5V.Leituras != null && AB5V.Leituras.Count() > 0 ? AB5V.Leituras[0] : 0).ToString("0.00");
gridDados.Rows[10].Cells[1].Value = (AB5V != null && AB5V.Leituras != null && AB5V.Leituras.Count() > 1 ? AB5V.Leituras[1] : 0).ToString("0.00");
gridDados.Rows[11].Cells[1].Value = (AB7V2 != null && AB7V2.Leituras != null && AB7V2.Leituras.Count() > 0 ? AB7V2.Leituras[0] : 0).ToString("0.00");
gridDados.Rows[12].Cells[1].Value = (AB7V2 != null && AB7V2.Leituras != null && AB7V2.Leituras.Count() > 1 ? AB7V2.Leituras[1] : 0).ToString("0.00");
gridDados.Rows[13].Cells[1].Value = (AB12V != null && AB12V.Leituras != null && AB12V.Leituras.Count() > 0 ? AB12V.Leituras[0] : 0).ToString("0.00");
gridDados.Rows[14].Cells[1].Value = (AB12V != null && AB12V.Leituras != null && AB12V.Leituras.Count() > 1 ? AB12V.Leituras[1] : 0).ToString("0.00");
gridDados.Rows[15].Cells[1].Value = Variaveis.OperacaoEmAndamento.DispAtu.Dados.PercentualReservatorio.ToString("00.00");
gridDados.Rows[16].Cells[1].Value = Variaveis.OperacaoEmAndamento.DispAtu.Dados.VolumeReservatorio.ToString("0.000");
gridDados.Rows[17].Cells[1].Value = Variaveis.OperacaoEmAndamento.DispAtu.Dados.PressaoLinha.ToString("0.00");

File diff suppressed because it is too large Load Diff

View File

@ -4,11 +4,13 @@ using AgroBase.Services;
using CefSharp.DevTools.Page;
using Emgu.CV;
using Newtonsoft.Json;
using OpenTK;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.IO;
using System.Linq;
using System.Security.Cryptography;
@ -16,6 +18,7 @@ using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Windows.Forms.DataVisualization.Charting;
using OpenTK.Graphics.OpenGL;
namespace AgroBase.Forms.Operacoes
{
@ -28,6 +31,7 @@ namespace AgroBase.Forms.Operacoes
List<AtuSensoriamentoLogModel> LogsAtuador = new List<AtuSensoriamentoLogModel>();
List<SenSensoriamentoLogModel> LogsSensoriamento = new List<SenSensoriamentoLogModel>();
List<PzmSensoriamentoLogModel> LogsPzem = new List<PzmSensoriamentoLogModel>();
List<WitSensoriamentoLogModel> LogsWt901C = new List<WitSensoriamentoLogModel>();
string pathImagensCaminho = "";
string pathImagensSoloE = "";
string pathImagensSoloD = "";
@ -48,17 +52,37 @@ namespace AgroBase.Forms.Operacoes
GraficoInterativoModel graficoMovGeral;
GraficoInterativoModel graficoMovTemperatura;
GraficoInterativoModel graficoMovPotencia;
GraficoInterativoModel graficoMovTensao;
GraficoInterativoModel graficoMovVelocidade;
GraficoInterativoModel graficoAtu;
GraficoInterativoModel graficoSen;
private GLControl glControl;
public frmResultadosOperacao()
{
InitializeComponent();
InitializeGLControl();
}
private void InitializeGLControl()
{
// Inicialize o GLControl com os parâmetros corretos
glControl = new GLControl(new OpenTK.Graphics.GraphicsMode(32, 24, 0, 8));
glControl.Dock = DockStyle.Fill;
glControl.Paint += new PaintEventHandler(GLControl_Paint);
glControl.Resize += new EventHandler(GLControl_Resize);
glControl.TopLevel = false;
glControl.Visible = true;
glControl.FormBorderStyle = FormBorderStyle.None;
pnl3D.Controls.Add(glControl);
GL.Enable(EnableCap.DepthTest);
}
private void frmResultadosOperacao_Load(object sender, EventArgs e)
{
tmrPlay.Tick += TmrPlay_Tick;
@ -101,12 +125,13 @@ namespace AgroBase.Forms.Operacoes
OperacaoDadosModel data = JsonConvert.DeserializeObject<OperacaoDadosModel>(File.ReadAllText(ofd.FileName));
LogsOperacao = JsonConvert.DeserializeObject<OperacaoSensoriamentoLogModel[]>(DeserializarDadosOperacao(ofd.FileName, data.operacao)).ToList();
LogsGPS = JsonConvert.DeserializeObject<GPSModel[]>(DeserializarDadosOperacao(ofd.FileName, data.gps)).ToList();
LogsDirecional = JsonConvert.DeserializeObject<DirSensoriamentoLogModel[]>(DeserializarDadosOperacao(ofd.FileName, data.dir)).ToList();
LogsMovimentacao = JsonConvert.DeserializeObject<MovSensoriamentoLogModel[]>(DeserializarDadosOperacao(ofd.FileName, data.mov)).ToList();
LogsAtuador = JsonConvert.DeserializeObject<AtuSensoriamentoLogModel[]>(DeserializarDadosOperacao(ofd.FileName, data.atu)).ToList();
LogsSensoriamento = JsonConvert.DeserializeObject<SenSensoriamentoLogModel[]>(DeserializarDadosOperacao(ofd.FileName, data.sen)).ToList();
LogsPzem = JsonConvert.DeserializeObject<PzmSensoriamentoLogModel[]>(DeserializarDadosOperacao(ofd.FileName, data.pzm)).ToList();
LogsGPS = JsonConvert.DeserializeObject<GPSModel[]>(DeserializarDadosOperacao(ofd.FileName, data.gps ?? Enuns.T_Code.Gps.ToString())).ToList();
LogsDirecional = JsonConvert.DeserializeObject<DirSensoriamentoLogModel[]>(DeserializarDadosOperacao(ofd.FileName, data.dir ?? Enuns.T_Code.Dir.ToString())).ToList();
LogsMovimentacao = JsonConvert.DeserializeObject<MovSensoriamentoLogModel[]>(DeserializarDadosOperacao(ofd.FileName, data.mov ?? Enuns.T_Code.Mov.ToString())).ToList();
LogsAtuador = JsonConvert.DeserializeObject<AtuSensoriamentoLogModel[]>(DeserializarDadosOperacao(ofd.FileName, data.atu ?? Enuns.T_Code.Atu.ToString())).ToList();
LogsSensoriamento = JsonConvert.DeserializeObject<SenSensoriamentoLogModel[]>(DeserializarDadosOperacao(ofd.FileName, data.sen ?? Enuns.T_Code.Sen.ToString())).ToList();
LogsPzem = JsonConvert.DeserializeObject<PzmSensoriamentoLogModel[]>(DeserializarDadosOperacao(ofd.FileName, data.pzm ?? Enuns.T_Code.Pzm.ToString())).ToList();
LogsWt901C = JsonConvert.DeserializeObject<WitSensoriamentoLogModel[]>(DeserializarDadosOperacao(ofd.FileName, data.wit ?? Enuns.T_Code.Wit.ToString())).ToList();
pathImagensCaminho = ofd.FileName.Replace("data.lgop", data.caminho + "/");
pathImagensSoloE = ofd.FileName.Replace("data.lgop", data.soloE + "/");
pathImagensSoloD = ofd.FileName.Replace("data.lgop", data.soloD + "/");
@ -151,28 +176,28 @@ namespace AgroBase.Forms.Operacoes
new GraficoInterativoSerieModel()
{
Titulo = "EF",
Valores = LogsMovimentacao.Where(x => x.Modulo_ID == "EF").Select(x => x.RPM).ToList(),
Valores = LogsMovimentacao.Where(x => x.Modulo_ID == "EF").Select(x => x.RPM_Motor).ToList(),
Visivel = true,
MostrarValor = true
},
new GraficoInterativoSerieModel()
{
Titulo = "ET",
Valores = LogsMovimentacao.Where(x => x.Modulo_ID == "ET").Select(x => x.RPM).ToList(),
Valores = LogsMovimentacao.Where(x => x.Modulo_ID == "ET").Select(x => x.RPM_Motor).ToList(),
Visivel = true,
MostrarValor = true
},
new GraficoInterativoSerieModel()
{
Titulo = "DT",
Valores = LogsMovimentacao.Where(x => x.Modulo_ID == "DT").Select(x => x.RPM).ToList(),
Valores = LogsMovimentacao.Where(x => x.Modulo_ID == "DT").Select(x => x.RPM_Motor).ToList(),
Visivel = true,
MostrarValor = true
},
new GraficoInterativoSerieModel()
{
Titulo = "DF",
Valores = LogsMovimentacao.Where(x => x.Modulo_ID == "DF").Select(x => x.RPM).ToList(),
Valores = LogsMovimentacao.Where(x => x.Modulo_ID == "DF").Select(x => x.RPM_Motor).ToList(),
Visivel = true,
MostrarValor = true
},
@ -187,23 +212,75 @@ namespace AgroBase.Forms.Operacoes
Visivel = true
},
new GraficoInterativoSerieModel()
{
Titulo = "EF Driver",
Valores = LogsMovimentacao.Where(x => x.Modulo_ID == "EF").Select(x => x.TemperaturaDriver).ToList(),
Visivel = false
},
new GraficoInterativoSerieModel()
{
Titulo = "ET",
Valores = LogsMovimentacao.Where(x => x.Modulo_ID == "ET").Select(x => x.Temperatura).ToList(),
Visivel = true
},
new GraficoInterativoSerieModel()
{
Titulo = "ET Driver",
Valores = LogsMovimentacao.Where(x => x.Modulo_ID == "ET").Select(x => x.TemperaturaDriver).ToList(),
Visivel = false
},
new GraficoInterativoSerieModel()
{
Titulo = "DT",
Valores = LogsMovimentacao.Where(x => x.Modulo_ID == "DT").Select(x => x.Temperatura).ToList(),
Visivel = true
},
new GraficoInterativoSerieModel()
{
Titulo = "DT Driver",
Valores = LogsMovimentacao.Where(x => x.Modulo_ID == "DT").Select(x => x.TemperaturaDriver).ToList(),
Visivel = false
},
new GraficoInterativoSerieModel()
{
Titulo = "DF",
Valores = LogsMovimentacao.Where(x => x.Modulo_ID == "DF").Select(x => x.Temperatura).ToList(),
Visivel = true
},
new GraficoInterativoSerieModel()
{
Titulo = "DF Driver",
Valores = LogsMovimentacao.Where(x => x.Modulo_ID == "DF").Select(x => x.TemperaturaDriver).ToList(),
Visivel = false
},
});
graficoMovTensao = new GraficoInterativoModel(chartMovTensao, Momentos, new List<GraficoInterativoSerieModel>()
{
new GraficoInterativoSerieModel()
{
Titulo = "EF",
Valores = LogsMovimentacao.Where(x => x.Modulo_ID == "EF").Select(x => x.Tensao).ToList(),
Visivel = true
},
new GraficoInterativoSerieModel()
{
Titulo = "ET",
Valores = LogsMovimentacao.Where(x => x.Modulo_ID == "ET").Select(x => x.Tensao).ToList(),
Visivel = true
},
new GraficoInterativoSerieModel()
{
Titulo = "DT",
Valores = LogsMovimentacao.Where(x => x.Modulo_ID == "DT").Select(x => x.Tensao).ToList(),
Visivel = true
},
new GraficoInterativoSerieModel()
{
Titulo = "DF",
Valores = LogsMovimentacao.Where(x => x.Modulo_ID == "DF").Select(x => x.Tensao).ToList(),
Visivel = true
},
});
graficoMovVelocidade = new GraficoInterativoModel(chartMovVelocidade, Momentos, new List<GraficoInterativoSerieModel>()
@ -262,7 +339,7 @@ namespace AgroBase.Forms.Operacoes
},
new GraficoInterativoSerieModel()
{
Titulo = "Percentual",
Titulo = "Reservatório",
Valores = LogsAtuador.Select(x => x?.PercentualReservatorio ?? 0).ToList(),
Visivel = true,
},
@ -534,6 +611,8 @@ namespace AgroBase.Forms.Operacoes
int ID = Convert.ToInt32(Variaveis.IsAgroMonitor ? Variaveis.OperacaoEmAndamento.DispSen.Dados.LoRaParametrosBase.address : Variaveis.ConexaoLoRa.parametros.address);
GPSService.EnviarCoordenadasParaMapa(Log?.Latitude ?? 0, Log?.Longitude ?? 0, Log?.Orientacao ?? 0, true, ID);
lblGPS.ForeColor = !Log.Inicializado ? Color.Red : Color.Black;
pnlOrientacaoGPS.Invalidate();
}
@ -585,7 +664,7 @@ namespace AgroBase.Forms.Operacoes
graficoMovGeral.AtualizarDados(idxMomentoAtual);
graficoMovTemperatura.AtualizarDados(idxMomentoAtual);
//graficoMovPotencia.AtualizarDados(idxMomentoAtual);
graficoMovTensao.AtualizarDados(idxMomentoAtual);
graficoMovVelocidade.AtualizarDados(idxMomentoAtual);
AtulizarDadosMotorMovimentacao("DF");
@ -599,8 +678,13 @@ namespace AgroBase.Forms.Operacoes
var Log = LogsMovimentacao.FirstOrDefault(x => x.Momento == MomentoAtual && x.Modulo_ID == ID);
GroupBox gpbRpm = FuncoesGlobais.FindControlRecursive<GroupBox>(tabMovGreal, "gpbMOV_Geral_" + ID);
gpbRpm.ForeColor = !Log.Inicializado ? Color.Red : Color.Black;
CheckBox chbAlm = FuncoesGlobais.FindControlRecursive<CheckBox>(gpbRpm, "chbMOV_Alm_" + ID);
chbAlm.Checked = Log.CodAlarme > 0;
CheckBox chbEn = FuncoesGlobais.FindControlRecursive<CheckBox>(gpbRpm, "chbMOV_En_" + ID);
chbEn.Checked = Log.Ativado;
CheckBox chbBrk = FuncoesGlobais.FindControlRecursive<CheckBox>(gpbRpm, "chbMOV_Brk_" + ID);
chbBrk.Checked = Log.EmFreio;
TextBox txtSentidoSP = FuncoesGlobais.FindControlRecursive<TextBox>(gpbRpm, "txtMOV_SentidoSP_" + ID);
txtSentidoSP.Text = Log.Sentido_SP.ToString();
TextBox txtSentido = FuncoesGlobais.FindControlRecursive<TextBox>(gpbRpm, "txtMOV_Sentido_" + ID);
@ -617,6 +701,18 @@ namespace AgroBase.Forms.Operacoes
txtMOV_Temperatura_Media.Text = LogsMovimentacao.Where(x => x.Momento <= MomentoAtual).Average(x => x.Temperatura).ToString("0.00");
txtMOV_Temperatura_Mediana.Text = FuncoesMatematicas.CalcularMediana(LogsMovimentacao.Where(x => x.Momento <= MomentoAtual).Select(x => x.Temperatura).ToList()).ToString("0.00");
txtMOV_Temperatura_Moda.Text = FuncoesMatematicas.CalcularModa(LogsMovimentacao.Where(x => x.Momento <= MomentoAtual).Select(x => x.Temperatura).ToList()).ToString("0.00");
GroupBox gpbTns = FuncoesGlobais.FindControlRecursive<GroupBox>(tabMovTensao, "gpbMOV_Tensao_" + ID);
TextBox txtTnsAtual = FuncoesGlobais.FindControlRecursive<TextBox>(gpbTns, "txtMOV_TensaoAt_" + ID);
txtTnsAtual.Text = Log.Tensao.ToString();
TextBox txtTnsMinima = FuncoesGlobais.FindControlRecursive<TextBox>(gpbTns, "txtMOV_TensaoMn_" + ID);
txtTnsMinima.Text = LogsMovimentacao.Where(x => x.Momento <= MomentoAtual && x.Modulo_ID == ID).Min(x => x.Tensao).ToString("0.00");
TextBox txtTnsMaxima = FuncoesGlobais.FindControlRecursive<TextBox>(gpbTns, "txtMOV_TensaoMx_" + ID);
txtTnsMaxima.Text = LogsMovimentacao.Where(x => x.Momento <= MomentoAtual && x.Modulo_ID == ID).Max(x => x.Tensao).ToString("0.00");
txtMOV_Tensao_Media.Text = LogsMovimentacao.Where(x => x.Momento <= MomentoAtual).Average(x => x.Tensao).ToString("0.00");
txtMOV_Tensao_Mediana.Text = FuncoesMatematicas.CalcularMediana(LogsMovimentacao.Where(x => x.Momento <= MomentoAtual).Select(x => x.Tensao).ToList()).ToString("0.00");
txtMOV_Tensao_Moda.Text = FuncoesMatematicas.CalcularModa(LogsMovimentacao.Where(x => x.Momento <= MomentoAtual).Select(x => x.Tensao).ToList()).ToString("0.00");
}
private void AtualizarInformacoesAtuador()
@ -643,7 +739,16 @@ namespace AgroBase.Forms.Operacoes
txtSen_Maximo.Text = Valores.Max().ToString("0.00");
}
var LogWit = LogsWt901C.FirstOrDefault(x => x.Momento == MomentoAtual);
lblMagnetometro.ForeColor = !LogWit.Inicializado ? Color.Red : Color.Black;
pnlOrientacaoMagnetometro.Invalidate();
pnlInclinacao.Invalidate();
glControl.Invalidate();
var LogSen = LogsSensoriamento.FirstOrDefault(x => x.Momento == MomentoAtual);
pnlManual.BackColor = LogSen.StatusSinaleiroMN == Enuns.StatusLED.Aceso ? Color.Yellow : Color.Gold;
pnlAutomatico.BackColor = LogSen.StatusSinaleiroAT == Enuns.StatusLED.Aceso ? Color.Yellow : Color.Gold;
pnlOperacao.BackColor = LogSen.StatusSinaleiroOP == Enuns.StatusLED.Aceso ? Color.Green : Color.DarkGreen;
}
@ -664,8 +769,8 @@ namespace AgroBase.Forms.Operacoes
private void pnlOrientacaoMagnetometro_Paint(object sender, PaintEventArgs e)
{
var Log = LogsSensoriamento.FirstOrDefault(x => x.Momento == MomentoAtual);
double Angulo = Log?.OrientacaoMagnetica ?? 0;
var Log = LogsWt901C.FirstOrDefault(x => x.Momento == MomentoAtual);
double Angulo = Log?.AngleZ ?? 0;
FuncoesGlobais.DesenharInclinacao((Panel)sender, e, (float)Angulo, -90);
}
@ -759,6 +864,145 @@ namespace AgroBase.Forms.Operacoes
}
}
private void GLControl_Paint(object sender, PaintEventArgs e)
{
Render();
}
private void GLControl_Resize(object sender, EventArgs e)
{
GL.Viewport(0, 0, glControl.Width, glControl.Height);
GL.MatrixMode(MatrixMode.Projection);
GL.LoadIdentity();
Matrix4 perspective = Matrix4.CreatePerspectiveFieldOfView((float)Math.PI / 4, glControl.Width / (float)glControl.Height, 1.0f, 64.0f);
GL.LoadMatrix(ref perspective);
}
private void Render()
{
var Log = LogsWt901C.FirstOrDefault(x => x.Momento == MomentoAtual);
GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
GL.MatrixMode(MatrixMode.Modelview);
GL.LoadIdentity();
// Ajuste a matriz de visualização para garantir que a câmera esteja fora do cubo
Matrix4 lookAt = Matrix4.LookAt(new Vector3(4, 3, 3), Vector3.Zero, Vector3.UnitY);
GL.LoadMatrix(ref lookAt);
GL.Rotate((Log?.AngleY ?? 0), 1.0f, 0.0f, 0.0f);
GL.Rotate((Log?.AngleZ ?? 0), 0.0f, 1.0f, 0.0f);
GL.Rotate((Log?.AngleX ?? 0), 0.0f, 0.0f, 1.0f);
GL.Begin(PrimitiveType.Quads);
// Frente (Vermelho)
GL.Color3(1.0f, 0.0f, 0.0f);
GL.Vertex3(1.0f, 1.0f, -1.0f);
GL.Vertex3(-1.0f, 1.0f, -1.0f);
GL.Vertex3(-1.0f, -1.0f, -1.0f);
GL.Vertex3(1.0f, -1.0f, -1.0f);
// Trás (Verde)
GL.Color3(0.0f, 1.0f, 0.0f);
GL.Vertex3(1.0f, -1.0f, 1.0f);
GL.Vertex3(-1.0f, -1.0f, 1.0f);
GL.Vertex3(-1.0f, 1.0f, 1.0f);
GL.Vertex3(1.0f, 1.0f, 1.0f);
// Esquerda (Azul)
GL.Color3(0.0f, 0.0f, 1.0f);
GL.Vertex3(-1.0f, 1.0f, 1.0f);
GL.Vertex3(-1.0f, 1.0f, -1.0f);
GL.Vertex3(-1.0f, -1.0f, -1.0f);
GL.Vertex3(-1.0f, -1.0f, 1.0f);
// Direita (Amarelo)
GL.Color3(1.0f, 1.0f, 0.0f);
GL.Vertex3(1.0f, 1.0f, -1.0f);
GL.Vertex3(1.0f, 1.0f, 1.0f);
GL.Vertex3(1.0f, -1.0f, 1.0f);
GL.Vertex3(1.0f, -1.0f, -1.0f);
// Topo (Ciano)
GL.Color3(0.0f, 1.0f, 1.0f);
GL.Vertex3(1.0f, 1.0f, 1.0f);
GL.Vertex3(-1.0f, 1.0f, 1.0f);
GL.Vertex3(-1.0f, 1.0f, -1.0f);
GL.Vertex3(1.0f, 1.0f, -1.0f);
// Fundo (Magenta)
GL.Color3(1.0f, 0.0f, 1.0f);
GL.Vertex3(1.0f, -1.0f, -1.0f);
GL.Vertex3(-1.0f, -1.0f, -1.0f);
GL.Vertex3(-1.0f, -1.0f, 1.0f);
GL.Vertex3(1.0f, -1.0f, 1.0f);
GL.End();
glControl.SwapBuffers();
}
private void pnlInclinacao_Paint(object sender, PaintEventArgs e)
{
var Log = LogsWt901C.FirstOrDefault(x => x.Momento == MomentoAtual);
Graphics g = e.Graphics;
int centerX = pnlInclinacao.Width / 2;
int centerY = pnlInclinacao.Height / 2;
int radius = 10;
// Desenhar fundo com bordas arredondadas
GraphicsPath path = new GraphicsPath();
int cornerRadius = 20;
path.AddArc(0, 0, cornerRadius, cornerRadius, 180, 90);
path.AddArc(pnlInclinacao.Width - cornerRadius, 0, cornerRadius, cornerRadius, 270, 90);
path.AddArc(pnlInclinacao.Width - cornerRadius, pnlInclinacao.Height - cornerRadius, cornerRadius, cornerRadius, 0, 90);
path.AddArc(0, pnlInclinacao.Height - cornerRadius, cornerRadius, cornerRadius, 90, 90);
path.CloseAllFigures();
g.SmoothingMode = SmoothingMode.AntiAlias;
g.FillPath(new SolidBrush(Color.LightBlue), path);
g.DrawPath(new Pen(Color.DarkBlue, 2), path);
// Desenhar linhas de referência
Pen pen = new Pen(Color.Gray, 1);
g.DrawLine(pen, centerX, 0, centerX, pnlInclinacao.Height);
g.DrawLine(pen, 0, centerY, pnlInclinacao.Width, centerY);
// Desenhar linhas adicionais para ângulos
for (int i = -90; i <= 90; i += 15)
{
int posX = centerX + (int)(i * (pnlInclinacao.Width / 2 - radius) / 90);
int posY = centerY - (int)(i * (pnlInclinacao.Height / 2 - radius) / 90);
g.DrawLine(pen, centerX, centerY, posX, centerY);
g.DrawLine(pen, centerX, centerY, centerX, posY);
}
// Desenhar régua na linha central
for (int i = -90; i <= 90; i += 15)
{
int posX = centerX + (int)(i * (pnlInclinacao.Width / 2 - radius) / 90);
int posY = centerY - (int)(i * (pnlInclinacao.Height / 2 - radius) / 90);
// Marcas horizontais
g.DrawLine(pen, posX, centerY - 5, posX, centerY + 5);
g.DrawString(i.ToString(), new Font("Arial", 8), Brushes.Black, posX - 10, centerY + 10);
// Marcas verticais
g.DrawLine(pen, centerX - 5, posY, centerX + 5, posY);
g.DrawString(i.ToString(), new Font("Arial", 8), Brushes.Black, centerX + 10, posY - 5);
}
// Calcular a posição do círculo com base nos ângulos
int circlePosX = centerX + (int)((Log?.AngleX ?? 0) * (pnlInclinacao.Width / 2 - radius) / 90);
int circlePosY = centerY - (int)((Log?.AngleY ?? 0) * (pnlInclinacao.Height / 2 - radius) / 90);
// Desenhar o círculo
Brush brush = new SolidBrush(Color.Red);
g.FillEllipse(brush, circlePosX - radius, circlePosY - radius, radius * 2, radius * 2);
}
}
}

View File

@ -64,9 +64,7 @@ namespace AgroBase.Forms
foreach (var Modulo in Variaveis.OperacaoEmAndamento.DispMvd.Dados.Modulos)
{
CheckBox chbControlar = pnlFundo.Controls.OfType<CheckBox>().FirstOrDefault(ctrl => ctrl.Name == "chb" + Modulo.Modulo_ID + "Controlar");
chbControlar.Checked = Modulo.DirMotor.Controlar;
CheckBox chbLivre = pnlFundo.Controls.OfType<CheckBox>().FirstOrDefault(ctrl => ctrl.Name == "chb" + Modulo.Modulo_ID + "Livre");
chbLivre.Checked = Modulo.DirMotor.Livre;
chbControlar.Checked = Modulo.DirMotor.Comandar;
}
}
@ -103,15 +101,15 @@ namespace AgroBase.Forms
lblDistanciaTotal.Text = "Distancia percorrida total: " + DispMvd.Dados.DistanciaPercorridaTotal.ToString("0.00") + " m";
lblDistanciaParcial.Text = "Distancia percorrida parcial: " + DispMvd.Dados.DistanciaPercorridaParcial.ToString("0.00") + " m";
foreach (var Modulo in DispMvd.Dados.Modulos.Where(x => x.Conectado || x.MovMotor.DadosDriver.Iniciado))
foreach (var Modulo in DispMvd.Dados.Modulos)
{
Label lblTitulo = pnlFundo.Controls.OfType<Label>().FirstOrDefault(ctrl => ctrl.Name == "lblM_" + Modulo.Modulo_ID);
lblTitulo.ForeColor = Modulo.MovMotor.Comandar ? Modulo.MovMotor.Inicializado ? Color.Green : Color.Red : Color.Black;
lblTitulo.Text = lblTitulo.Text.Split(' ')[0] + " (" + Modulo.Modulo_ID + ") - Alm: " + Modulo.MovMotor.CodigoAlarme;
Label lblM_RPMSP = pnlFundo.Controls.OfType<Label>().FirstOrDefault(ctrl => ctrl.Name == "lbl" + Modulo.Modulo_ID + "M_RPMSP");
lblM_RPMSP.Text = "RPM SP: " + Variaveis.OperacaoEmAndamento.Controle.RPM.ToString("0.00");
lblM_RPMSP.Text = "RPM SP: " + Variaveis.OperacaoEmAndamento.Controle.RPM_SP.ToString("0.00");
Label lblM_RPM = pnlFundo.Controls.OfType<Label>().FirstOrDefault(ctrl => ctrl.Name == "lbl" + Modulo.Modulo_ID + "M_RPM");
lblM_RPM.Text = "RPM: " + Modulo.MovMotor.RPM.ToString("0.00");
lblM_RPM.Text = "RPM Roda: " + Modulo.MovMotor.RPM_Roda.ToString("0.00");
Label lblM_Velocidade = pnlFundo.Controls.OfType<Label>().FirstOrDefault(ctrl => ctrl.Name == "lbl" + Modulo.Modulo_ID + "M_Velocidade");
lblM_Velocidade.Text = "Velocidade: " + Modulo.MovMotor.VelocidadeInstantanea.ToString("0.00") + " Km/h";
Label lblM_SentidoSP = pnlFundo.Controls.OfType<Label>().FirstOrDefault(ctrl => ctrl.Name == "lbl" + Modulo.Modulo_ID + "M_SentidoSP");
@ -159,12 +157,12 @@ namespace AgroBase.Forms
Minimo = Logs.Any() && Logs.Min(x => x.RPM_SP) < Minimo ? Logs.Min(x => x.RPM_SP) : Minimo;
Maximo = Logs.Any() && Logs.Min(x => x.RPM_SP) > Maximo ? Logs.Min(x => x.RPM_SP) : Maximo;
var serieRPM = new Series("RPM: " + (Log != null ? Log.RPM : 0));
serieRPM.Points.DataBindXY(Momentos, Logs.Select(x => x.RPM).ToList());
serieRPM.ChartType = SeriesChartType.Spline;
chart.Series.Add(serieRPM);
Minimo = Logs.Any() && Logs.Min(x => x.RPM) < Minimo ? Logs.Min(x => x.RPM) : Minimo;
Maximo = Logs.Any() && Logs.Max(x => x.RPM) > Maximo ? Logs.Max(x => x.RPM) : Maximo;
var serieRPMRoda = new Series("RPM Roda: " + (Log != null ? Log.RPM_Motor : 0));
serieRPMRoda.Points.DataBindXY(Momentos, Logs.Select(x => x.RPM_Motor).ToList());
serieRPMRoda.ChartType = SeriesChartType.Spline;
chart.Series.Add(serieRPMRoda);
Minimo = Logs.Any() && Logs.Min(x => x.RPM_Motor) < Minimo ? Logs.Min(x => x.RPM_Motor) : Minimo;
Maximo = Logs.Any() && Logs.Max(x => x.RPM_Motor) > Maximo ? Logs.Max(x => x.RPM_Motor) : Maximo;
var serieTemperatura = new Series("Motor ºC: " + (Log != null ? Log.Temperatura : 0));
serieTemperatura.Points.DataBindXY(Momentos, Logs.Select(x => x.Temperatura).ToList());
@ -378,14 +376,14 @@ namespace AgroBase.Forms
{
string ID = ((CheckBox)sender).Name.Substring(3, 2);
var Modulo = Variaveis.OperacaoEmAndamento.DispMvd.Dados.Modulos.FirstOrDefault(x => x.Modulo_ID == ID);
Modulo.DirMotor.Livre = ((CheckBox)sender).Checked;
//Modulo.DirMotor.Livre = ((CheckBox)sender).Checked;
}
private void ChbControlar_CheckedChanged(object sender, EventArgs e)
{
string ID = ((CheckBox)sender).Name.Substring(3, 2);
var Modulo = Variaveis.OperacaoEmAndamento.DispMvd.Dados.Modulos.FirstOrDefault(x => x.Modulo_ID == ID);
Modulo.DirMotor.Controlar = ((CheckBox)sender).Checked;
Modulo.DirMotor.Comandar = ((CheckBox)sender).Checked;
}

View File

@ -10,11 +10,14 @@ using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using static AgroBase.Services.BLD300RService;
namespace AgroBase.Forms
{
public partial class frmBLD : Form
{
byte Addr = 0x02;
public frmBLD()
{
InitializeComponent();
@ -23,9 +26,9 @@ namespace AgroBase.Forms
private void frmBLD_Load(object sender, EventArgs e)
{
btnAtualizar_Click(sender, e);
LoopAtualizacao().ConfigureAwait(false);
//LoopAtualizacao().ConfigureAwait(false);
this.Text += " - " + ModbusService._PortaModbus.PortName;
this.Text += " - " + BLD300RService._PortaBLD.PortName;
}
private async Task LoopAtualizacao()
@ -138,6 +141,17 @@ namespace AgroBase.Forms
/*var parametro = BLD300RService.Parametros.First(x => x.Chave == "Enabled");
var comando = ModbusService.ComandoSetParametro(BLD300RService.slaveAddress, parametro, BLD300RService.UltimaLeitura.Ativado ? 0 : 1);
ModbusService.EnviarComando(comando).ConfigureAwait(false);*/
var Leitura = BLD300RService.DadosLeitura.FirstOrDefault(x => x.Endereco == Addr && x.parametros.Any(y => y.Registro == 0x0066));
BLD300RService.AdicionarComandoNaFila(new BLDComandoModel()
{
Endereco = Addr,
Parametro = BLD300RService.Parametros.First(x => x.Chave == "Enabled"),
Valor = Leitura != null ? (Leitura.Ativado ? 0 : 1) : 0,
Get = false,
AguardaResposta = true,
TimeoutResposta = 200,
});
}
private void btnSentido_Click(object sender, EventArgs e)
@ -145,6 +159,17 @@ namespace AgroBase.Forms
/*var parametro = BLD300RService.Parametros.First(x => x.Chave == "Direction");
var comando = ModbusService.ComandoSetParametro(BLD300RService.slaveAddress, parametro, BLD300RService.UltimaLeitura.Direcao == Enuns.Sentido.Horario ? 0 : 1);
ModbusService.EnviarComando(comando).ConfigureAwait(false);*/
var Leitura = BLD300RService.DadosLeitura.FirstOrDefault(x => x.Endereco == Addr && x.parametros.Any(y => y.Registro == 0x006D));
BLD300RService.AdicionarComandoNaFila(new BLDComandoModel()
{
Endereco = Addr,
Parametro = BLD300RService.Parametros.First(x => x.Chave == "Direction"),
Valor = Leitura != null ? (Leitura.Direcao == Enuns.Sentido.Horario ? 0 : 1) : 0,
Get = false,
AguardaResposta = true,
TimeoutResposta = 200,
});
}
private void btnFrear_Click(object sender, EventArgs e)
@ -152,6 +177,17 @@ namespace AgroBase.Forms
/*var parametro = BLD300RService.Parametros.First(x => x.Chave == "Breaked");
var comando = ModbusService.ComandoSetParametro(BLD300RService.slaveAddress, parametro, BLD300RService.UltimaLeitura.Freado ? 0 : 1);
ModbusService.EnviarComando(comando).ConfigureAwait(false);*/
var Leitura = BLD300RService.DadosLeitura.FirstOrDefault(x => x.Endereco == Addr && x.parametros.Any(y => y.Registro == 0x006A));
BLD300RService.AdicionarComandoNaFila(new BLDComandoModel()
{
Endereco = Addr,
Parametro = BLD300RService.Parametros.First(x => x.Chave == "Breaked"),
Valor = Leitura != null ? (Leitura.Freado ? 0 : 1) : 0,
Get = false,
AguardaResposta = true,
TimeoutResposta = 200,
});
}
private void trbRPMSP_MouseUp(object sender, MouseEventArgs e)
@ -159,6 +195,18 @@ namespace AgroBase.Forms
/*var parametro = BLD300RService.Parametros.First(x => x.Chave == "RPM_SP");
var comando = ModbusService.ComandoSetParametro(BLD300RService.slaveAddress, parametro, trbRPMSP.Value);
ModbusService.EnviarComando(comando).ConfigureAwait(false);*/
var Leitura = BLD300RService.DadosLeitura.FirstOrDefault(x => x.Endereco == Addr && x.parametros.Any(y => y.Registro == 0x0056));
float rpm = (float)((Leitura != null ? Leitura.RPM_Max : 800.0) * (trbRPMSP.Value / 10.0));
BLD300RService.AdicionarComandoNaFila(new BLDComandoModel()
{
Endereco = Addr,
Parametro = BLD300RService.Parametros.First(x => x.Chave == "RPM_SP"),
Valor = rpm,
Get = false,
AguardaResposta = true,
TimeoutResposta = 200,
});
}
}
}

View File

@ -36,6 +36,8 @@ namespace AgroBase.Forms
{
InitializeComponent();
FilaService.Inicializar();
BLD300RService.IniciarRotinas();
MKS057DService.IniciarRotinas();
}
private void frmInstancial_Shown(object sender, EventArgs e)

View File

@ -127,6 +127,11 @@ namespace AgroBase.Forms
ID = x.ID,
Funcoes = x.Funcoes
}));
Dispositivos.AddRange(Disp.Dados.Servos.Select(x => new DispositivoDataModel()
{
ID = x.ID,
Funcoes = x.Funcoes
}));
break;
}
case T_Code.Atu:

View File

@ -393,14 +393,14 @@ namespace AgroBase
//
this.trkRPM.Location = new System.Drawing.Point(4, 37);
this.trkRPM.Margin = new System.Windows.Forms.Padding(2);
this.trkRPM.Maximum = 500;
this.trkRPM.Maximum = 100;
this.trkRPM.Minimum = 5;
this.trkRPM.Name = "trkRPM";
this.trkRPM.Size = new System.Drawing.Size(158, 45);
this.trkRPM.TabIndex = 20;
this.trkRPM.TickFrequency = 20;
this.trkRPM.TickFrequency = 5;
this.trkRPM.Value = 5;
this.trkRPM.ValueChanged += new System.EventHandler(this.trkRPM_ValueChanged);
this.trkRPM.Scroll += new System.EventHandler(this.trkRPM_Scroll);
//
// lblRPM
//

View File

@ -56,10 +56,13 @@ namespace AgroBase
tkbAngulo.Minimum = -90;
tkbAngulo.Maximum = 90;
tkbAngulo.Value = Convert.ToInt32(Variaveis.OperacaoEmAndamento.Controle.Angulo);
trkRPM.Minimum = Variaveis.OperacaoEmAndamento.Controle.RPM_Min;
trkRPM.Maximum = Variaveis.OperacaoEmAndamento.Controle.RPM_Max;
trkRPM.Value = Variaveis.OperacaoEmAndamento.Controle.RPM;
trkRPM.Maximum = VariaveisEquipamento.RPM_Max_Roda;
trkRPM.Value = Variaveis.OperacaoEmAndamento.Controle.RPM_SP;
trkKmh.Minimum = 0;
trkKmh.Maximum = Convert.ToInt32(MovimentacaoModel.CalculaVelocidadeRPM(trkRPM.Maximum));
cmbModoOperacao.Items.Clear();
cmbModoOperacao.Items.AddRange(Enum.GetNames(typeof(ModoOperacao)));
@ -127,9 +130,9 @@ namespace AgroBase
Text =
x.FirstOrDefault().PortaCOM + " - " + Enum.GetName(typeof(T_Code), x.Key) + " v" + x.FirstOrDefault().Versao +
(x.FirstOrDefault().Dispositivo == T_Code.Mvd ? (" (" + string.Join(", ", x.Select(y => y.Mod_ID)) + ")") :
(x.FirstOrDefault().Dispositivo == T_Code.Bld ? (" (" + string.Join(", ", x.Select(y => y.Mod_ID)) + ")") :
"")) + " - " +
(SerialService.DispositivosMultiplos.Contains(x.FirstOrDefault().Dispositivo) ? (" (" + string.Join(", ", x.Select(y => y.Mod_ID)) + ")") :
"") + " - " +
(x.Any(y => y.Conectado) ? "Conectado" : "Desconectado")
/*(x.FirstOrDefault().Dispositivo == T_Code.Gps ? (GPSService.Iniciado ? "Conectado" : "Desconectado") :
@ -157,12 +160,6 @@ namespace AgroBase
Variaveis.OperacaoEmAndamento = OperacaoModel.CarregarParametrosOperacaoPadrao((ModoOperacao)cmbModoOperacao.SelectedIndex);
}
if (Variaveis.OperacaoEmAndamento.DispMvd != null && Variaveis.OperacaoEmAndamento.Controle.RPM_Max != trkRPM.Maximum)
{
trkRPM.Maximum = Convert.ToInt32(Variaveis.OperacaoEmAndamento.Controle.RPM_Max);
trkKmh.Maximum = Convert.ToInt32(MovimentacaoModel.CalculaVelocidadeRPM(trkRPM.Maximum));
}
Variaveis.DispositivosConectados.ForEach(x =>
{
x.AcaoConexao();
@ -236,8 +233,8 @@ namespace AgroBase
trkRPM.Value = valor;
trkKmh.Value = Convert.ToInt32(Velocidade);
Variaveis.OperacaoEmAndamento.Controle.RPM = trkRPM.Value;
lblRPM.Text = "RPM: " + Variaveis.OperacaoEmAndamento.Controle.RPM;
Variaveis.OperacaoEmAndamento.Controle.RPM_SP = trkRPM.Value;
lblRPM.Text = "RPM: " + Variaveis.OperacaoEmAndamento.Controle.RPM_SP;
lblKmh.Text = "Velocidade: " + Velocidade.ToString("0.00") + " km/h";
}
}
@ -254,7 +251,7 @@ namespace AgroBase
lblAngulo.Text = "Angulo: " + Variaveis.OperacaoEmAndamento.Controle.Angulo + "º";
}
private void trkRPM_ValueChanged(object sender, EventArgs e)
private void trkRPM_Scroll(object sender, EventArgs e)
{
try
{
@ -389,7 +386,7 @@ namespace AgroBase
private void btnBLD300R_Click(object sender, EventArgs e)
{
/*if (BLD300RService.Iniciado)
if (BLD300RService.Iniciado)
{
frmBLD frm = new frmBLD();
frm.Show();
@ -397,7 +394,7 @@ namespace AgroBase
else
{
MessageBox.Show("Driver BLD-300R não está conectado!");
}*/
}
}
private void btnMKS_Click(object sender, EventArgs e)
@ -406,7 +403,9 @@ namespace AgroBase
frm.Show();
}
#endregion
}
}

View File

@ -343,7 +343,7 @@ namespace AgroBase.Forms
double anguloControle = Variaveis.OperacaoEmAndamento.Controle.Angulo;
txtAnguloControle.Text = anguloControle.ToString("0.00");
double velocidade = MovimentacaoModel.CalculaVelocidadeRPM(Variaveis.OperacaoEmAndamento.Controle.RPM);
double velocidade = MovimentacaoModel.CalculaVelocidadeRPM(Variaveis.OperacaoEmAndamento.Controle.RPM_SP);
double velocidadeMs = MovimentacaoModel.ConverteKmhParaMs(velocidade);
txtVelocidade.Text = velocidade.ToString("0.00");

View File

@ -4,36 +4,153 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static AgroBase.Models.Enuns;
using static AgroBase.Services.BLD300RService;
namespace AgroBase.Models
{
public class BLD300RModel
{
public int Versao { get; set; }
public bool ControleRS485 { get; set; }
public int CodigoAlarme { get; set; }
public int NumeroPolos { get; set; }
public int RPM_Max { get; set; }
public int Rampa { get; set; }
public int RPM_SP { get; set; }
public int RPM { get; set; }
public bool Ativado { get; set; }
public bool Freado { get; set; }
private bool _direcao;
public byte Endereco { get; set; }
public bool Iniciado { get; set; }
public bool Configurado { get; set; }
public int Versao
{
get
{
return ConvertByteArrayToInt(GetParametroValue(0x00BB));
}
}
public bool ControleRS485
{
get
{
return ConvertByteArrayToInt(GetParametroValue(0x00B6)) == 1;
}
}
public int CodigoAlarme
{
get
{
return ConvertByteArrayToInt(GetParametroValue(0x0076));
}
}
public int NumeroPolos
{
get
{
return ConvertByteArrayToInt(GetParametroValue(0x0086));
}
}
public int RPM_Max
{
get
{
return ConvertByteArrayToInt(GetParametroValue(0x0092));
}
}
public int Rampa
{
get
{
return ConvertByteArrayToInt(GetParametroValue(0x008A));
}
}
public int RPM_SP
{
get
{
return Convert.ToInt32(ConvertByteArrayToInt(GetParametroValue(0x0056)) * Parametros.First(x => x.Registro == 0x0056).Escala);
}
}
public int RPM
{
get
{
return Convert.ToInt32(ConvertByteArrayToInt(GetParametroValue(0x005F)) * Parametros.First(x => x.Registro == 0x005F).Escala);
}
}
public bool Ativado
{
get
{
return ConvertByteArrayToInt(GetParametroValue(0x0066)) == 1;
}
}
public bool Freado
{
get
{
return ConvertByteArrayToInt(GetParametroValue(0x006A)) == 1;
}
}
public Sentido Direcao
{
get
{
return _direcao ? Sentido.Horario : Sentido.Antihorario;
}
set
{
_direcao = value == Sentido.Horario ? true : false;
return ConvertByteArrayToInt(GetParametroValue(0x006D)) == 1 ? Sentido.Horario : Sentido.Antihorario;
}
}
public double Tensao { get; set; }
public double Temperatura { get; set; }
public double CorrenteMax { get; set; }
public double Tensao
{
get
{
var P_V = Parametros.First(x => x.Registro == 0x00C8);
double tensao = ConvertByteArrayToFloat(P_V.Valor);
return tensao;
}
}
public double Temperatura
{
get
{
var P_T = Parametros.First(x => x.Registro == 0x00d2);
double temperatura = ConvertByteArrayToFloat(P_T.Valor);
return temperatura;
}
}
public double CorrenteMax
{
get
{
var P_A = Parametros.First(x => x.Registro == 0x0096);
double corrente = ConvertByteArrayToFloat(P_A.Valor);
return corrente;
}
}
public List<BLDParametrosRequisitar> parametros { get; set; }
int ConvertByteArrayToInt(byte[] bytes)
{
if (bytes == null) return 0;
if (bytes.Length == 2)
{
return BitConverter.ToInt16(bytes.Reverse().ToArray(), 0);
}
else if (bytes.Length == 4)
{
return BitConverter.ToInt32(bytes.Reverse().ToArray(), 0);
}
return 0;
}
private static float ConvertByteArrayToFloat(byte[] bytes)
{
if (bytes == null || bytes.Length != 4)
return 0;
int intValue = BitConverter.ToInt32(bytes.Reverse().ToArray(), 0);
return BitConverter.ToSingle(BitConverter.GetBytes(intValue), 0);
}
byte[] GetParametroValue(byte registro)
{
var p = parametros.FirstOrDefault(x => x.Registro == registro);
return p != null ? p.Valor : null;
}
}
}

View File

@ -46,7 +46,10 @@ namespace AgroBase.Models
{
Iniciada = false;
Variaveis.MqttService.Topicos.Remove(camera._mqttTopico);
panel.Controls.Remove(browser);
if (panel != null)
{
panel.Controls.Remove(browser);
}
browser = null;
Variaveis.MqttService.UnsubscribeAsync(camera._mqttTopico).ConfigureAwait(false);
if (camera.pythonProcess != null)

View File

@ -44,7 +44,10 @@ namespace AgroBase.Models
{
Iniciada = false;
Variaveis.MqttService.Topicos.Remove(camera._mqttTopico);
panel.Controls.Remove(browser);
if (panel != null)
{
panel.Controls.Remove(browser);
}
browser = null;
Variaveis.MqttService.UnsubscribeAsync(camera._mqttTopico).ConfigureAwait(false);
if (camera.pythonProcess != null && !camera.pythonProcess.HasExited)

View File

@ -98,6 +98,7 @@ namespace AgroBase.Models
sMVD = 477,
sATU = 478,
sRLE = 479,
sFRO = 480,
}
public enum BotoesJoystick
@ -187,5 +188,12 @@ namespace AgroBase.Models
Geral = 2
}
public enum AcaoFreio
{
SemAcao = 0,
Ativar = 1,
Desativar = 2
}
}
}

View File

@ -11,6 +11,7 @@ namespace AgroBase.Models
public class GPSModel
{
public DateTime Momento { get; set; }
public bool Inicializado { get; set; }
public double Latitude { get; set; }
public double Longitude { get; set; }
public DateTime DataHora { get; set; }

View File

@ -459,9 +459,9 @@ namespace AgroBase
public static void EnviaComandoMotor(Keys Tecla, T_Code Disp = T_Code.Vzo, bool MensagemBase = false)
{
if (
!Variaveis.OperacaoEmAndamento.OperacaoLiberada ||
(!Variaveis.OperacaoEmAndamento.OperacaoLiberada ||
!Variaveis.OperacaoEmAndamento.Iniciado ||
Variaveis.OperacaoEmAndamento.Modo != ModoOperacao.Manual
Variaveis.OperacaoEmAndamento.Modo != ModoOperacao.Manual)
)
{
return;
@ -480,15 +480,18 @@ namespace AgroBase
if (Comando.Comando == Keys.Escape)
{
var ComandosDisp = Disp == T_Code.Vzo ? Comandos : Comandos.Where(x => x.Dispositivo == Disp).ToList();
Comando.Dispositivo = ComandosDisp[ComandosDisp.Count - 1].Dispositivo;
Comando.IDcontrolar = ComandosDisp[ComandosDisp.Count - 1].IDcontrolar;
DirecaoAtual = Direcao.Parado;
Pressionado = true;
var _disp = DispCon.FirstOrDefault(x => x.Dispositivo == Comando.Dispositivo);
if (_disp != null)
if (ComandosDisp.Any())
{
_disp.LimparBufferSerial(true);
Comando.Dispositivo = ComandosDisp[ComandosDisp.Count - 1].Dispositivo;
Comando.IDcontrolar = ComandosDisp[ComandosDisp.Count - 1].IDcontrolar;
DirecaoAtual = Direcao.Parado;
Pressionado = true;
var _disp = DispCon.FirstOrDefault(x => x.Dispositivo == Comando.Dispositivo);
if (_disp != null)
{
_disp.LimparBufferSerial(true);
}
}
}
// Controle de Velocidade (MOV RPM SP)

View File

@ -31,6 +31,8 @@ namespace AgroBase.Models
public double Velocidade { get; set; }
public double Aceleracao { get; set; }
public string Mensagem { get; set; }
public string HV { get; set; }
public string FV { get; set; }
}
public class MKS057ComandoModel

View File

@ -1,5 +1,6 @@
using AgroBase.Services;
using Emgu.CV.Ocl;
using Emgu.CV.Structure;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
@ -7,6 +8,7 @@ using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static AgroBase.Models.Enuns;
namespace AgroBase.Models.Modules
@ -268,7 +270,7 @@ namespace AgroBase.Models.Modules
Dados._LeituraPeriodo = 0;
Dados._LeituraPressao = 0;
Dados._LeituraPulsos = 0;
Dados._MassaLeitura = 0;
Dados._MassaLeitura = Dados._MassaLeituraExtra;
}
public Dictionary<string, List<string>> ProtocoloConfiguracao(bool Conectar)

View File

@ -417,7 +417,7 @@ namespace AgroBase.Models
RPM_SP =
DirecaoAtual == Direcao.Parado ? 0 :
CmdAlarme ? 0 :
Variaveis.OperacaoEmAndamento.Controle.RPM;
Variaveis.OperacaoEmAndamento.Controle.RPM_SP;
switch (DirecaoAtual)
{

View File

@ -9,6 +9,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static AgroBase.Models.Enuns;
using static AgroBase.Services.BLD300RService;
namespace AgroBase.Models.Modules
{
@ -35,6 +36,14 @@ namespace AgroBase.Models.Modules
public int TempoEmAtividade { get; set; } = 0;
public double DistanciaPercorridaTotal { get; set; } = 0;
public double DistanciaPercorridaParcial { get; set; } = 0;
public double RelacaoRPM
{
get
{
double RelacaoRPM = Modulos.Average(x => x.MovMotor.RPM_Max) / VariaveisEquipamento.RPM_Max_Roda;
return RelacaoRPM;
}
}
public static MovimentacaoUnificadaModel CarregarParametrosIniciais()
@ -86,7 +95,9 @@ namespace AgroBase.Models.Modules
x.MovMotor.LogGrafico = new List<MvdMotorMOVSensorimanetoGrafico>();
x.MovMotor.TemperaturaDriver = 0;
x.MovMotor.Temperatura = 0;
x.MovMotor.RPM = 0;
x.MovMotor.RPM_Motor = 0;
x.MovMotor.RPM_SP = 0;
x.MovMotor.RPM_SP_C = 0;
x.MovMotor.Corrente_Max = 0;
x.MovMotor.Sentido = Sentido.Parado;
x.MovMotor.CodigoAlarme = 0;
@ -94,7 +105,7 @@ namespace AgroBase.Models.Modules
x.MovMotor.Tensao = 0;
x.DirMotor.Inicializado = false;
//x.DirMotor.Angulo = 0;
x.DirMotor.Angulo = 0;
x.DirMotor.Angulo_SP = 0;
x.DirMotor.Sentido = Sentido.Parado;
x.DirMotor.Sentido_SP = Sentido.Parado;
@ -144,7 +155,7 @@ namespace AgroBase.Models.Modules
Modulo.MovMotor.Inicializado = Dados[2] == "1";
double rpm = 0;
double.TryParse(Dados[3].Replace(".", ","), out rpm);
Modulo.MovMotor.RPM = rpm;
Modulo.MovMotor.RPM_Motor = rpm;
double temperatura = 0;
double.TryParse(Dados[4].Replace(".", ","), out temperatura);
temperatura = FuncoesMatematicas.CalcularTemperatura(temperatura, 0.0);
@ -169,7 +180,7 @@ namespace AgroBase.Models.Modules
double.TryParse(Dados[11].Replace(".", ","), out tempDriver);
Modulo.MovMotor.TemperaturaDriver = tempDriver;
RegistrarLog(Modulo);
RegistrarLogMov(Modulo);
break;
}
@ -203,7 +214,7 @@ namespace AgroBase.Models.Modules
Modulo.MovMotor.Inicializado = Dados[2] == "1";
double rpm = 0;
double.TryParse(Dados[3].Replace(".", ","), out rpm);
Modulo.MovMotor.RPM = rpm;
Modulo.MovMotor.RPM_Motor = rpm;
double temperatura = 0;
double.TryParse(Dados[4].Replace(".", ","), out temperatura);
temperatura = FuncoesMatematicas.CalcularTemperatura(temperatura, 0.0);
@ -247,7 +258,7 @@ namespace AgroBase.Models.Modules
double.TryParse(Dados[6].ToString().Replace(".", ","), out _angulo);
Modulo.DirMotor.Angulo = _angulo;*/
RegistrarLog(Modulo);
RegistrarLogMov(Modulo);
break;
}
@ -267,14 +278,15 @@ namespace AgroBase.Models.Modules
}
}
public void RegistrarLog(ModuloMvdModel Modulo)
public void RegistrarLogMov(ModuloMvdModel Modulo)
{
Modulo.MovMotor.LogGrafico.Add(new MvdMotorMOVSensorimanetoGrafico()
{
Momento = DateTime.Now,
Modulo_ID = Modulo.Modulo_ID,
RPM_SP = Variaveis.OperacaoEmAndamento.Controle.RPM,
RPM = Modulo.MovMotor.RPM,
RPM_SP = Modulo.MovMotor.RPM_SP,
RPM_Motor = Modulo.MovMotor.RPM_Motor,
RPM_Roda = Modulo.MovMotor.RPM_Roda,
Corrente = Modulo.MovMotor.Corrente,
Sentido = Modulo.MovMotor.Sentido,
Temperatura = Modulo.MovMotor.Temperatura,
@ -323,7 +335,6 @@ namespace AgroBase.Models.Modules
{
x.MovMotor.Inicializado = false;
x.DirMotor.Inicializado = false;
x.MovMotor.DadosDriver.Iniciado = false;
});
LoopRegistrador().ConfigureAwait(false);
}
@ -389,7 +400,7 @@ namespace AgroBase.Models.Modules
{
get
{
return MovMotor.Inicializado || DirMotor.Inicializado;
return MovMotor.BLD_Inicializado || DirMotor.MKS_Inicializado;
}
}
public DateTime UltimoProtocoloRecebido { get; set; } = DateTime.MaxValue;
@ -485,6 +496,64 @@ namespace AgroBase.Models.Modules
}
public void AtualizarSensoresMotor(SensorModel Sensor)
{
bool Computar = true;
double leitura0 = Sensor.Leituras.Count() > 0 ? Sensor.Leituras[0] : 0;
switch (Sensor.Componente)
{
case S_Code.sTMP:
MovMotor.Temperatura = leitura0;
break;
case S_Code.sCOR:
MovMotor.Corrente = Sensor.Leituras[0];
MovMotor.Tensao = Sensor.Leituras[1];
break;
default:
Computar = false;
break;
}
if (!Computar)
{
return;
}
AlarmeModel _Alarme = new AlarmeModel()
{
Tipo = Sensor.Componente,
Valor = leitura0,
Maximo = leitura0 > Sensor.LimiteMaximo,
Minimo = leitura0 < Sensor.LimiteMinimo,
ParaMaximo = false,
ParaMinimo = false
};
bool Adicionado = false;
var Alm = MovMotor.Alarmes.FirstOrDefault(x => x.Tipo == _Alarme.Tipo);
if (Alm == null)
{
Alm = _Alarme;
MovMotor.Alarmes.Add(Alm);
Adicionado = true;
}
bool AlarmeAnterior = (Alm.Maximo && Alm.ParaMaximo) || (Alm.Minimo && Alm.ParaMinimo);
bool AlarmeAtual = (_Alarme.Maximo && _Alarme.ParaMaximo) || (_Alarme.Minimo && _Alarme.ParaMinimo);
if (MovMotor.BLD_Inicializado && (!AlarmeAnterior || Adicionado) && AlarmeAtual) // Motor iniciado, Não estava em alarme anteriormente ou foi adicionado agora, alarme atual
{
//Variaveis.OperacaoEmAndamento.DispMov.AdicionarMensagemFila(Variaveis.OperacaoEmAndamento.DispMov.Dados.Modulo_ID, ProtocoloComando(Direcao.Frente, true), true, false);
}
Alm.Valor = _Alarme.Valor;
Alm.Maximo = _Alarme.Maximo;
Alm.Minimo = _Alarme.Minimo;
MovMotor.Alarme = MovMotor.Alarmes.Any(x => (x.Maximo && x.ParaMaximo) || (x.Minimo && x.ParaMinimo));
}
}
public class MvdMotorBLDC
@ -496,27 +565,35 @@ namespace AgroBase.Models.Modules
public bool Ligado { get; set; } = false;
public bool Freio { get; set; } = false;
public int CodigoAlarme { get; set; } = 0;
//public int RPM_SP { get; set; } = 0;
public int RPM_SP { get; set; } = 0;
public int RPM_SP_C { get; set; } = 0;
public Sentido Sentido_SP { get; set; } = Sentido.Parado;
public int NumeroPolos { get; set; } = 2;
public int Rampa { get; set; } = 0;
public int RPM_Max { get; set; } = 800;
public int Reducao { get; set; } = 27;
// GETs
public double RPM { get; set; } = 0;
public double RPM_Motor { get; set; } = 0;
public Sentido Sentido { get; set; } = Sentido.Parado;
public double Temperatura { get; set; } = 0;
public double TemperaturaDriver { get; set; } = 0;
public double Tensao { get; set; } = 0;
public double Corrente_Max { get; set; } = 0;
public double Corrente { get; set; } = 0;
public double RPM_Roda
{
get
{
return Convert.ToInt32(RPM_Motor / Variaveis.OperacaoEmAndamento.DispMvd.Dados.RelacaoRPM);
}
}
public double VelocidadeInstantanea
{
get
{
return MovimentacaoModel.CalculaVelocidadeRPM(RPM);
return MovimentacaoModel.CalculaVelocidadeRPM(RPM_Roda);
}
}
@ -524,14 +601,21 @@ namespace AgroBase.Models.Modules
public bool Comandar { get; set; } = false;
public bool Alarme { get; set; } = false;
public bool Inicializado { get; set; } = false;
public bool BLD_Inicializado
{
get
{
return BLD300RService.DadosLeitura.Any(x => x.Iniciado && Convert.ToByte(Endereco.Replace("0x", ""), 16) == x.Endereco);
}
}
public BLD300RService DadosDriver { get; set; } = new BLD300RService("0x01");
public ConfiguracaoSentidoMotor ConfigSentidos { get; set; }
public List<FuncoesPinout> Funcoes { get; set; }
public List<MvdMotorMOVSensorimanetoGrafico> LogGrafico { get; set; } = new List<MvdMotorMOVSensorimanetoGrafico>();
public List<AlarmeModel> Alarmes { get; set; } = new List<AlarmeModel>();
public static MvdMotorBLDC CarregarParametrosIniciais(string Mod_ID, string _Endereco)
@ -555,7 +639,6 @@ namespace AgroBase.Models.Modules
FuncoesPinout.PWM,
FuncoesPinout.BRK,
},
DadosDriver = new BLD300RService(_Endereco)
};
}
@ -585,16 +668,23 @@ namespace AgroBase.Models.Modules
public string ProtocoloComando(Direcao DirecaoAtual, bool CmdAlarme = false)
{
if (Inicializado && Comandar && (!Alarme || CmdAlarme))
string ProtocoloMotor = "";
AcaoFreio AcaoDoFreio = AcaoFreio.SemAcao;
if (Comandar && (!Alarme || CmdAlarme))
{
if (!CmdAlarme)
{
MovimentacaoUnificadaModel.UltimaDirecao = DirecaoAtual;
}
Variaveis.OperacaoEmAndamento.Controle.RPM =
RPM_SP_C = Variaveis.OperacaoEmAndamento.Controle.RPM_Motor;
RPM_SP =
DirecaoAtual == Direcao.Parado || CmdAlarme ? 0 :
Variaveis.OperacaoEmAndamento.Controle.RPM;
Variaveis.OperacaoEmAndamento.Controle.RPM_Motor;
Ligado = RPM_SP > 0;
switch (DirecaoAtual)
{
@ -604,33 +694,89 @@ namespace AgroBase.Models.Modules
case Direcao.Tras:
Sentido_SP = ConfigSentidos.Tras;
break;
case Direcao.Esquerda:
Sentido_SP = ConfigSentidos.Esquerda;
break;
case Direcao.Direita:
Sentido_SP = ConfigSentidos.Direita;
break;
case Direcao.Parado:
case Direcao.EmFreio:
default:
Sentido_SP = ConfigSentidos.Parado;
break;
}
Freio = DirecaoAtual == Direcao.EmFreio;
string ProtocoloMotor = "";
if (BLD_Inicializado)
{
byte Addr = Convert.ToByte(Endereco.Replace("0x", ""), 16);
var Leitura = BLD300RService.DadosLeitura.FirstOrDefault(x => x.Endereco == Addr);
ProtocoloMotor =
((int)F_Code.Cmd).ToString() + SerialService.SplitMessage +
ID + SerialService.SplitParams +
((int)Sentido_SP).ToString() + SerialService.SplitParams +
Variaveis.OperacaoEmAndamento.Controle.RPM.ToString() + SerialService.SplitParams +
(Freio ? "1" : "0");
if (Leitura == null || Leitura.Direcao != Sentido_SP)
{
BLD300RService.AdicionarComandoNaFila(new BLDComandoModel()
{
Endereco = Addr,
Parametro = BLD300RService.Parametros.First(x => x.Chave == "Direction"),
Valor = Sentido_SP == Sentido.Horario ? 1 : 0,
Get = false,
AguardaResposta = true,
TimeoutResposta = 200,
});
}
if (Ligado && Leitura == null || Leitura.RPM_SP != RPM_SP_C)
{
BLD300RService.AdicionarComandoNaFila(new BLDComandoModel()
{
Endereco = Addr,
Parametro = BLD300RService.Parametros.First(x => x.Chave == "RPM_SP"),
Valor = RPM_SP,
Get = false,
AguardaResposta = true,
TimeoutResposta = 200,
});
}
if (Leitura == null || Leitura.Ativado != Ligado)
{
BLD300RService.AdicionarComandoNaFila(new BLDComandoModel()
{
Endereco = Addr,
Parametro = BLD300RService.Parametros.First(x => x.Chave == "Enabled"),
Valor = RPM_SP > 0 ? 1 : 0,
Get = false,
AguardaResposta = true,
TimeoutResposta = 200,
});
}
if (Leitura == null || Leitura.Freado != Freio)
{
BLD300RService.AdicionarComandoNaFila(new BLDComandoModel()
{
Endereco = Addr,
Parametro = BLD300RService.Parametros.First(x => x.Chave == "Breaked"),
Valor = Freio ? 1 : 0,
Get = false,
AguardaResposta = true,
TimeoutResposta = 200,
});
return ProtocoloMotor;
AcaoDoFreio = Freio ? AcaoFreio.Ativar : AcaoFreio.Desativar;
}
}
else if (Inicializado)
{
ProtocoloMotor =
((int)F_Code.Cmd).ToString() + SerialService.SplitMessage +
ID + SerialService.SplitParams +
((int)Sentido_SP).ToString() + SerialService.SplitParams +
RPM_SP.ToString() + SerialService.SplitParams +
(Freio ? "1" : "0");
}
}
return "";
if (AcaoDoFreio != AcaoFreio.SemAcao)
{
string Mod_ID = Variaveis.OperacaoEmAndamento.DispMvd.Dados.Modulos.FirstOrDefault(x => x.MovMotor.Endereco == Endereco)?.Modulo_ID ?? "";
var ServoFreio = Variaveis.OperacaoEmAndamento.DispSen.Dados.Servos.FirstOrDefault(x => x.ID.Contains(Mod_ID) && x.Inicializado && x.Controlar);
if (ServoFreio != null)
{
ServoFreio._AnguloControle = VariaveisEquipamento.AnguloFreio[AcaoDoFreio];
Variaveis.OperacaoEmAndamento.DispSen.AdicionarMensagemFila(Variaveis.OperacaoEmAndamento.DispSen.Dados.Modulo_ID, ServoFreio.ProtocoloComando(), true, false);
}
}
return ProtocoloMotor;
}
@ -646,8 +792,8 @@ namespace AgroBase.Models.Modules
public double Angulo_SP { get; set; } = 0;
//public int Velocidade { get; set; } = 50;
public double Angulo_Offset { get; set; } = 0;
public bool Estabilizar { get; set; } = false;
public bool Livre { get; set; } = false;
//public bool Estabilizar { get; set; } = false;
//public bool Livre { get; set; } = false;
// GETs
public Sentido Sentido { get; set; } = Sentido.Parado;
@ -655,7 +801,7 @@ namespace AgroBase.Models.Modules
public bool Comandar { get; set; } = false;
public bool Controlar { get; set; } = false;
//public bool Controlar { get; set; } = false;
public bool Inicializado { get; set; } = false;
public bool MKS_Inicializado
{
@ -708,7 +854,7 @@ namespace AgroBase.Models.Modules
((int)F_Code.Cfg).ToString() + SerialService.SplitMessage +
ID + SerialService.SplitParams +
(Conectar ? "1" : "0") + SerialService.SplitParams +
(Estabilizar ? "1" : "0") + SerialService.SplitParams +
//(Estabilizar ? "1" : "0") + SerialService.SplitParams +
Angulo_Offset.ToString() + SerialService.SplitParams +
PinoutModel.PinoProtocolo(_pinout, Funcoes);
@ -717,15 +863,17 @@ namespace AgroBase.Models.Modules
public string ProtocoloComando(Direcao Direcao)
{
if (Comandar && Controlar)
string ProtocoloMotor = "";
if (Comandar)
{
Angulo_SP = Livre ? -1 : (Direcao != Direcao.Esquerda && Direcao != Direcao.Direita) ? 0 : Variaveis.OperacaoEmAndamento.Controle.Angulo;
Angulo_SP = (Direcao != Direcao.Esquerda && Direcao != Direcao.Direita) ? 0 : Variaveis.OperacaoEmAndamento.Controle.Angulo;
Sentido_SP =
Direcao == Direcao.Direita ? ConfigSentidos.Direita :
Direcao == Direcao.Esquerda ? ConfigSentidos.Esquerda :
!Livre && Sentido_SP == Sentido.Horario ? Sentido.Antihorario :
!Livre && Sentido_SP == Sentido.Antihorario ? Sentido.Horario :
Sentido_SP == Sentido.Horario ? Sentido.Antihorario :
Sentido_SP == Sentido.Antihorario ? Sentido.Horario :
Sentido.Parado;
if (MKS_Inicializado)
@ -746,19 +894,18 @@ namespace AgroBase.Models.Modules
AguardaResposta = false,
}).ConfigureAwait(false);
}
if (Inicializado)
else if (Inicializado)
{
string ProtocoloMotor =
ProtocoloMotor =
((int)F_Code.Cmd).ToString() + SerialService.SplitMessage +
ID + SerialService.SplitParams +
((int)Sentido_SP).ToString() + SerialService.SplitParams +
Angulo_SP.ToString() + SerialService.SplitParams +
Variaveis.OperacaoEmAndamento.Controle.VelocidadeMP.ToString();
return ProtocoloMotor;
}
}
return "";
return ProtocoloMotor;
}
}
@ -768,7 +915,8 @@ namespace AgroBase.Models.Modules
public DateTime Momento { get; set; }
public string Modulo_ID { get; set; }
public int RPM_SP { get; set; }
public double RPM { get; set; }
public double RPM_Motor { get; set; }
public double RPM_Roda { get; set; }
public double Temperatura { get; set; }
public double TemperaturaDriver { get; set; }
public Sentido Sentido { get; set; }

View File

@ -360,7 +360,8 @@ namespace AgroBase.Models.Modules
EncoderAbsoluto,
ModbusDI,
ModbusRO,
ModbusDE_RE
ModbusDE_RE,
ServoFreio
}
public static class PinoutUtils

View File

@ -1,5 +1,6 @@
using AgroBase.Forms;
using AgroBase.Services;
using CefSharp;
using Emgu.CV.ML;
using Emgu.CV.Structure;
using Newtonsoft.Json;
@ -42,6 +43,7 @@ namespace AgroBase.Models.Modules
public List<SensorModel> Sensores { get; set; }
public List<SensorSinaleiroModel> Sinaleiros { get; set; }
public List<SensorReleModel> Reles { get; set; }
public List<SensorServoModel> Servos { get; set; }
public string CameraID_Caminho { get; set; } = "";
public List<string> CameraID_Solo { get; set; } = new List<string>();
public double BateriaCargaConsumida { get; set; }
@ -186,7 +188,7 @@ namespace AgroBase.Models.Modules
new string[] { "V offset", "-1.038" },
},
},
new SensorModel()
/*new SensorModel()
{
ID = "AB3V",
Prioridade = 10,
@ -206,7 +208,7 @@ namespace AgroBase.Models.Modules
new string[] { "Endereço I2C", "0x44" },
new string[] { "CI", "219" }
},
},
},*/
new SensorModel()
{
ID = "AB5V",
@ -225,10 +227,10 @@ namespace AgroBase.Models.Modules
Parametros = new List<string[]>()
{
new string[] { "Endereço I2C", "0x41" },
new string[] { "CI", "219" }
new string[] { "Corrente Max", "3.2" }
},
},
new SensorModel()
/*new SensorModel()
{
ID = "AB7V2",
Prioridade = 10,
@ -248,7 +250,7 @@ namespace AgroBase.Models.Modules
new string[] { "Endereço I2C", "0x40" },
new string[] { "CI", "219" }
},
},
},*/
new SensorModel()
{
ID = "AB12V",
@ -266,8 +268,8 @@ namespace AgroBase.Models.Modules
UnidadeMedida = "A",
Parametros = new List<string[]>()
{
new string[] { "Endereço I2C", "0x43" },
new string[] { "CI", "226" }
new string[] { "Endereço I2C", "0x40" },
new string[] { "Corrente Max", "100" }
},
},
new SensorModel()
@ -290,7 +292,7 @@ namespace AgroBase.Models.Modules
new string[] { "V offset", "0.0000" },
},
},
new SensorModel()
/*new SensorModel()
{
ID = "SUESQ",
Descricao = "Sensor Ultrassom Esquerdo",
@ -368,7 +370,7 @@ namespace AgroBase.Models.Modules
},
LimiteMinimo = 40,
LimiteMaximo = 9999,
},
},*/
},
Reles = new List<SensorReleModel>()
@ -378,12 +380,64 @@ namespace AgroBase.Models.Modules
ID = "RLLRA",
Descricao = "Relé modo operação LoRa",
Componente = S_Code.sRLE,
Controlar = true,
Funcoes = new List<FuncoesPinout>()
{
FuncoesPinout.Rele,
},
StatusControle = Estado.Desligado,
},
},
Servos = new List<SensorServoModel>()
{
new SensorServoModel()
{
ID = "FRO_ET",
Descricao = "Freio Motor ET",
Componente = S_Code.sFRO,
Controlar = true,
Funcoes = new List<FuncoesPinout>()
{
FuncoesPinout.ServoFreio,
},
_AnguloControle = 0,
},
new SensorServoModel()
{
ID = "FRO_EF",
Descricao = "Freio Motor EF",
Componente = S_Code.sFRO,
Controlar = false,
Funcoes = new List<FuncoesPinout>()
{
FuncoesPinout.ServoFreio,
},
_AnguloControle = 0,
},
new SensorServoModel()
{
ID = "FRO_DT",
Descricao = "Freio Motor DT",
Componente = S_Code.sFRO,
Controlar = true,
Funcoes = new List<FuncoesPinout>()
{
FuncoesPinout.ServoFreio,
},
_AnguloControle = 0,
},
new SensorServoModel()
{
ID = "FRO_DF",
Descricao = "Freio Motor DF",
Componente = S_Code.sFRO,
Controlar = false,
Funcoes = new List<FuncoesPinout>()
{
FuncoesPinout.ServoFreio,
},
_AnguloControle = 0,
},
}
};
}
@ -392,8 +446,17 @@ namespace AgroBase.Models.Modules
{
Dados.Conectado = false;
Dados.BateriaCargaConsumida = 0;
Dados.Reles.ForEach(x => x.Inicializado = false);
Dados.Sinaleiros.ForEach(x => x.Inicializado = false);
Dados.Reles.ForEach(x =>
{
x.Inicializado = false;
x.StatusLeitura = Estado.Desligado;
x.StatusControle = Estado.Desligado;
});
Dados.Sinaleiros.ForEach(x =>
{
x.Inicializado = false;
x.StatusLED = StatusLED.Apagado;
});
Dados.Sensores.ForEach(x =>
{
x.Inicializado = false;
@ -401,6 +464,12 @@ namespace AgroBase.Models.Modules
x.ValorMinimo = 0;
x.ValorMaximo = 0;
});
Dados.Servos.ForEach(x =>
{
x.Inicializado = false;
x._AnguloLeitura = 0;
x._AnguloControle = 0;
});
}
public Dictionary<string, List<string>> ProtocoloConfiguracao(bool Conectar)
@ -423,10 +492,18 @@ namespace AgroBase.Models.Modules
// Adicionar configurações dos Reles
var relesConfig = Reles
.Where(x => x.Controlar)
.Select(x => x.ProtocoloConfiguracaoRele(Pinout, Conectar))
.ToList();
configDictionary[Modulo_ID].AddRange(relesConfig);
// Adicionar configurações dos Servos
var servosConfig = Servos
.Where(x => x.Controlar)
.Select(x => x.ProtocoloConfiguracaoFreio(Pinout, Conectar))
.ToList();
configDictionary[Modulo_ID].AddRange(servosConfig);
// Adicionar configuração do ProtocoloMOD
string protocoloMOD =
((int)F_Code.Cfg).ToString() + SerialService.SplitMessage +
@ -490,10 +567,13 @@ namespace AgroBase.Models.Modules
}
S_Code TipoSensor = (S_Code)(cod);
SensorModel Sensor = Sensores.FirstOrDefault(x => x.ID == Dados[1]);
SensorSinaleiroModel Sinaleiro = Sinaleiros.FirstOrDefault(x => x.ID == Dados[1]);
SensorReleModel Rele = Reles.FirstOrDefault(x => x.ID == Dados[1]);
if (Sensor == null && Sinaleiro == null && Rele == null)
SensorServoModel Servo = Servos.FirstOrDefault(x => x.ID == Dados[1]);
if (Sensor == null && Sinaleiro == null && Rele == null && Servo == null)
{
if (Dados[1] == "MD")
{
@ -522,6 +602,10 @@ namespace AgroBase.Models.Modules
{
Rele.Inicializado = iniciado;
}
else if (Servo != null)
{
Servo.Inicializado = iniciado;
}
break;
case S_Code.sCOR:
{
@ -735,10 +819,10 @@ namespace AgroBase.Models.Modules
Variaveis.OperacaoEmAndamento.DispMvd.Dados.Conectado
)
{
foreach (var Modulo in Variaveis.OperacaoEmAndamento.DispMvd.Dados.Modulos)
foreach (var _Modulo in Variaveis.OperacaoEmAndamento.DispMvd.Dados.Modulos)
{
string ProtocoloParada = Modulo.MovMotor.ProtocoloComando(Direcao.Frente, true);
Variaveis.OperacaoEmAndamento.DispMvd.AdicionarMensagemFila(Modulo.Modulo_ID, ProtocoloParada, true, false);
string ProtocoloParada = _Modulo.MovMotor.ProtocoloComando(Direcao.Frente, true);
Variaveis.OperacaoEmAndamento.DispMvd.AdicionarMensagemFila(_Modulo.Modulo_ID, ProtocoloParada, true, false);
}
}
}
@ -754,7 +838,11 @@ namespace AgroBase.Models.Modules
Rele.Inicializado = Dados[2] == "1";
Rele.StatusLeitura = (Estado)Enum.Parse(typeof(Estado), Dados[3]);
break;
case S_Code.sFRO:
Servo.Inicializado = Dados[2] == "1";
int.TryParse(Dados[3], out int _angulo);
Servo._AnguloLeitura = _angulo;
break;
}
@ -768,15 +856,12 @@ namespace AgroBase.Models.Modules
{
Sensor.ValorMinimo = Sensor.Leituras[0];
}
}
MovSensoriamentoMotor Motor =
Variaveis.DispositivosConectados.Any(x => x.Dispositivo == T_Code.Mov) ?
((MovimentacaoModel)(Variaveis.DispositivosConectados.FirstOrDefault(x => x.Dispositivo == T_Code.Mov).Dados)).Motores.FirstOrDefault(x => Sensor.ID.Contains(x.ID)) :
null;
if (Motor != null)
{
Motor.AtualizarSensoresMotor(Sensor);
var Modulo = Variaveis.OperacaoEmAndamento.DispMvd.Dados.Modulos.FirstOrDefault(x => Sensor.ID.Contains(x.Modulo_ID));
if (Modulo != null)
{
Modulo.AtualizarSensoresMotor(Sensor);
}
}
if (AtualizaGrafico)
@ -952,6 +1037,7 @@ namespace AgroBase.Models.Modules
public S_Code Componente { get; set; }
public List<FuncoesPinout> Funcoes { get; set; }
public bool Controlar { get; set; }
public bool Inicializado { get; set; }
public Estado StatusControle { get; set; }
public Estado StatusLeitura { get; set; }
@ -974,12 +1060,52 @@ namespace AgroBase.Models.Modules
public string ProtocoloComando()
{
string ProtocoloSinaleiro =
string ProtocoloRele =
((int)F_Code.Cmd).ToString() + SerialService.SplitMessage +
ID + SerialService.SplitParams +
(int)StatusControle;
return ProtocoloSinaleiro;
return ProtocoloRele;
}
}
public class SensorServoModel
{
public string ID { get; set; }
public string Descricao { get; set; }
public S_Code Componente { get; set; }
public List<FuncoesPinout> Funcoes { get; set; }
public bool Controlar { get; set; }
public bool Inicializado { get; set; }
public int _AnguloControle { get; set; }
public int _AnguloLeitura { get; set; }
public string ProtocoloConfiguracaoFreio(PinoutDataModel Pinout, bool Conectar)
{
var _pinout = new PinoutDataModel()
{
ExpansorGPIO = Pinout.ExpansorGPIO,
EnderecoExpansor = Pinout.EnderecoExpansor,
Pinos = Pinout.Pinos.ToList(),
};
_pinout.Pinos = _pinout.Pinos.Where(x => x.ComponenteID == ID).ToList();
string Protocolo = ((int)F_Code.Cfg).ToString() + SerialService.SplitMessage +
ID + SerialService.SplitParams +
(Conectar ? "1" : "0") + SerialService.SplitParams +
PinoutModel.PinoProtocolo(_pinout, Funcoes);
return Protocolo;
}
public string ProtocoloComando()
{
string ProtocoloFreio =
((int)F_Code.Cmd).ToString() + SerialService.SplitMessage +
ID + SerialService.SplitParams +
_AnguloControle;
return ProtocoloFreio;
}
}

View File

@ -82,12 +82,12 @@ namespace AgroBase.Models.Operacoes
if (statusCarroRua == StatusCarroMapa.Manobrando)
{
Variaveis.OperacaoEmAndamento.DispMvd.Dados.Modulos.ForEach(x => x.DirMotor.Controlar = true);
Variaveis.OperacaoEmAndamento.DispMvd.Dados.Modulos.ForEach(x => x.DirMotor.Comandar = true);
}
else
{
Variaveis.OperacaoEmAndamento.DispMvd.Dados.Modulos.ForEach(x => x.DirMotor.Controlar = false);
Variaveis.OperacaoEmAndamento.DispMvd.Dados.Modulos.Where(x => x.Modulo_ID == "EF" || x.Modulo_ID == "DF").ToList().ForEach(x => x.DirMotor.Controlar = true);
Variaveis.OperacaoEmAndamento.DispMvd.Dados.Modulos.ForEach(x => x.DirMotor.Comandar = false);
Variaveis.OperacaoEmAndamento.DispMvd.Dados.Modulos.Where(x => x.Modulo_ID == "EF" || x.Modulo_ID == "DF").ToList().ForEach(x => x.DirMotor.Comandar = true);
}
}
@ -149,7 +149,7 @@ namespace AgroBase.Models.Operacoes
public void CalculaDadosMovimentacaoAutonoma()
{
if (Variaveis.OperacaoEmAndamento.Modo == ModoOperacao.MapaGPS)
if (Variaveis.OperacaoEmAndamento.Modo != ModoOperacao.MapaGPS)
{
return;
}
@ -163,48 +163,48 @@ namespace AgroBase.Models.Operacoes
var BicosNaoAtuados = new List<AtuadorBicoModel>(Variaveis.OperacaoEmAndamento.DispAtu.Dados.BicosPulverizadores);
BicosNaoAtuados.ForEach(x => x.Atuado = false);
Variaveis.OperacaoEmAndamento.Controle.BicosAtuados = BicosNaoAtuados.ToList();
Variaveis.OperacaoEmAndamento.Controle.RPM = 0;
Variaveis.OperacaoEmAndamento.Controle.RPM_SP = 0;
Variaveis.OperacaoEmAndamento.Controle.Angulo = 0;
}
else if (statusAtual == StatusCarroMapa.Direcionando)
{
if (Variaveis.OperacaoEmAndamento.Sensoriamento.SonarFrontal.DesvioNecessario)
{
Variaveis.OperacaoEmAndamento.Controle.RPM = Variaveis.OperacaoEmAndamento.Controle.RPM_Min;
Variaveis.OperacaoEmAndamento.Controle.RPM_SP = Variaveis.OperacaoEmAndamento.Controle.RPM_Min;
}
else
{
Variaveis.OperacaoEmAndamento.Controle.RPM = Variaveis.OperacaoEmAndamento.Controle.RPM_Max;
Variaveis.OperacaoEmAndamento.Controle.RPM_SP = Variaveis.OperacaoEmAndamento.Controle.RPM_Max;
}
}
else if (statusAtual == StatusCarroMapa.EntrandoRua)
{
Variaveis.OperacaoEmAndamento.Controle.RPM = Variaveis.OperacaoEmAndamento.Controle.RPM_Min;
Variaveis.OperacaoEmAndamento.Controle.RPM_SP = Variaveis.OperacaoEmAndamento.Controle.RPM_Min;
}
else if (statusAtual == StatusCarroMapa.SaindoRua)
{
Variaveis.OperacaoEmAndamento.Controle.RPM = Variaveis.OperacaoEmAndamento.Controle.RPM_Min;
Variaveis.OperacaoEmAndamento.Controle.RPM_SP = Variaveis.OperacaoEmAndamento.Controle.RPM_Min;
}
else if (statusAtual == StatusCarroMapa.CaminhandoRua)
{
if (Sensoriamento.ErvasNoRadar == 0)
{
Variaveis.OperacaoEmAndamento.Controle.RPM = Variaveis.OperacaoEmAndamento.Controle.RPM_Max;
Variaveis.OperacaoEmAndamento.Controle.RPM_SP = Variaveis.OperacaoEmAndamento.Controle.RPM_Max;
}
else
{
Variaveis.OperacaoEmAndamento.Controle.RPM = Convert.ToInt32(Variaveis.OperacaoEmAndamento.Controle.RPM_Max * 0.85);
Variaveis.OperacaoEmAndamento.Controle.RPM_SP = Convert.ToInt32(Variaveis.OperacaoEmAndamento.Controle.RPM_Max * 0.85);
}
double margemAngulo = 5;
if (Variaveis.OperacaoEmAndamento.Controle.Angulo > margemAngulo || Variaveis.OperacaoEmAndamento.Controle.Angulo < (margemAngulo * -1))
{
Variaveis.OperacaoEmAndamento.Controle.RPM = Variaveis.OperacaoEmAndamento.Controle.RPM_Min;
Variaveis.OperacaoEmAndamento.Controle.RPM_SP = Variaveis.OperacaoEmAndamento.Controle.RPM_Min;
}
}
else if (statusAtual == StatusCarroMapa.Manobrando)
{
Variaveis.OperacaoEmAndamento.Controle.RPM = Variaveis.OperacaoEmAndamento.Controle.RPM_Max / 2;
Variaveis.OperacaoEmAndamento.Controle.RPM_SP = Variaveis.OperacaoEmAndamento.Controle.RPM_Max / 2;
}
}

View File

@ -354,7 +354,7 @@ namespace AgroBase.Models
PressaoLinha = Parametros.AtuPressaoLinha,
Angulo = 0,
Direcao = Direcao.Parado,
RPM = 0,
RPM_SP = 0,
PIDdirecional = new PIDModel(),
TiposControle = Variaveis.OperacaoEmAndamento.Controle.TiposControle.ToList()
};
@ -471,7 +471,7 @@ namespace AgroBase.Models
{
new OperacaoModulosMandatoriosModel()
{
Dispositivo = T_Code.Mvd,
Dispositivo = T_Code.Bld,
Mandatorio = false
},
new OperacaoModulosMandatoriosModel()
@ -535,7 +535,7 @@ namespace AgroBase.Models
{
new OperacaoModulosMandatoriosModel()
{
Dispositivo = T_Code.Mvd,
Dispositivo = T_Code.Bld,
Mandatorio = true,
},
new OperacaoModulosMandatoriosModel()
@ -858,7 +858,7 @@ namespace AgroBase.Models
if (Modo == ModoOperacao.MapaGPS)
{
Controle.Angulo = 0;
Controle.RPM = 0;
Controle.RPM_SP = 0;
AtualizarDadosControle();
}
if (DispAtu.Dados.BombaPressurizadora.Inicializado)
@ -922,14 +922,14 @@ namespace AgroBase.Models
OperacaoControleTipoModel ControleDir = Controle.TiposControle != null ? Controle.TiposControle.FirstOrDefault(x => x.Tipo == T_Code.Dir) : null;
OperacaoControleTipoModel ControleAtu = Controle.TiposControle != null ? Controle.TiposControle.FirstOrDefault(x => x.Tipo == T_Code.Atu) : null;
if (ControleMov != null && Controle.RPM != ControleAnterior.RPM && (Agora - ControleMov.UltimoComando).TotalMilliseconds > ControleMov.DelayEnvioComando)
if (ControleMov != null && Controle.RPM_SP != ControleAnterior.RPM_SP && (Agora - ControleMov.UltimoComando).TotalMilliseconds > ControleMov.DelayEnvioComando)
{
// Enviar comando MOV
var Protocolos = EnviarProtocoloComando(Variaveis.OperacaoEmAndamento.DispMvd, T_Code.Mov);
ControleMov.UltimoComando = Agora;
ControleMov.Comandos.AddRange(Protocolos);
ControleAnterior.RPM = Controle.RPM;
ControleAnterior.RPM_SP = Controle.RPM_SP;
}
if (ControleDir != null && Convert.ToInt32(Controle.Angulo) != Convert.ToInt32(ControleAnterior.Angulo) && (Agora - ControleDir.UltimoComando).TotalMilliseconds > ControleDir.DelayEnvioComando)
{
@ -959,22 +959,22 @@ namespace AgroBase.Models
public List<string> EnviarProtocoloComando(IDispositivosService Dispositivo, T_Code Tipo)
{
if (Dispositivo == null)
if (Dispositivo == null || !Iniciado)
{
return new List<string>();
}
if (Tipo == T_Code.Mov)
{
if (Controle.RPM == 0)
if (Controle.RPM_SP == 0)
{
Controle.Direcao = Direcao.Parado;
}
else
{
if (Controle.RPM < 0)
if (Controle.RPM_SP < 0)
{
Controle.RPM *= -1;
Controle.RPM_SP *= -1;
Controle.Direcao = Direcao.Tras;
}
else
@ -1261,7 +1261,8 @@ namespace AgroBase.Models
// Calcula a média de cada propriedade no grupo
Momento = new DateTime((long)g.Average(x => x.Log.Momento.Ticks)),
Velocidade = g.Average(x => x.Log.Velocidade),
RPM = Convert.ToInt32(g.Average(x => x.Log.RPM)),
RPM_Motor = Convert.ToInt32(g.Average(x => x.Log.RPM_Motor)),
RPM_Roda = Convert.ToInt32(g.Average(x => x.Log.RPM_Roda)),
RPM_SP = Convert.ToInt32(g.Average(x => x.Log.RPM_SP)),
Temperatura = g.Average(x => x.Log.Temperatura),
Tensao = g.Average(x => x.Log.Tensao),
@ -1294,22 +1295,29 @@ namespace AgroBase.Models
serieVelocidade.Points.DataBindXY(Momentos, Logs.Select(x => x.Velocidade).ToList());
serieVelocidade.ChartType = SeriesChartType.Line;
chart.Series.Add(serieVelocidade);
Minimo = Logs.Min(x => x.Velocidade) < Minimo ? Logs.Min(x => x.Velocidade) : Minimo;
Maximo = Logs.Min(x => x.Velocidade) > Maximo ? Logs.Min(x => x.Velocidade) : Maximo;
Minimo = !Logs.Any() ? 0 : Logs.Min(x => x.Velocidade) < Minimo ? Logs.Min(x => x.Velocidade) : Minimo;
Maximo = !Logs.Any() ? 0 : Logs.Min(x => x.Velocidade) > Maximo ? Logs.Min(x => x.Velocidade) : Maximo;
var serieRPMsp = new Series("RPM SP: " + (Log != null ? Log.RPM_SP : 0));
serieRPMsp.Points.DataBindXY(Momentos, Logs.Select(x => x.RPM_SP).ToList());
serieRPMsp.ChartType = SeriesChartType.Spline;
chart.Series.Add(serieRPMsp);
Minimo = Logs.Min(x => x.RPM_SP) < Minimo ? Logs.Min(x => x.RPM_SP) : Minimo;
Maximo = Logs.Max(x => x.RPM_SP) > Maximo ? Logs.Max(x => x.RPM_SP) : Maximo;
Minimo = !Logs.Any() ? 0 : Logs.Min(x => x.RPM_SP) < Minimo ? Logs.Min(x => x.RPM_SP) : Minimo;
Maximo = !Logs.Any() ? 0 : Logs.Max(x => x.RPM_SP) > Maximo ? Logs.Max(x => x.RPM_SP) : Maximo;
var serieRPM = new Series("RPM Roda: " + (Log != null ? Log.RPM_Roda : 0));
serieRPM.Points.DataBindXY(Momentos, Logs.Select(x => x.RPM_Roda).ToList());
serieRPM.ChartType = SeriesChartType.Spline;
chart.Series.Add(serieRPM);
Minimo = !Logs.Any() ? 0 : Logs.Min(x => x.RPM_Roda) < Minimo ? Logs.Min(x => x.RPM_Roda) : Minimo;
Maximo = !Logs.Any() ? 0 : Logs.Max(x => x.RPM_Roda) > Maximo ? Logs.Max(x => x.RPM_Roda) : Maximo;
var serieTemperatura = new Series("Temperatura: " + (Log != null ? Log.Temperatura : 0));
serieTemperatura.Points.DataBindXY(Momentos, Logs.Select(x => x.Temperatura).ToList());
serieTemperatura.ChartType = SeriesChartType.Line;
chart.Series.Add(serieTemperatura);
Minimo = Logs.Min(x => x.Temperatura) < Minimo ? Logs.Min(x => x.Temperatura) : Minimo;
Maximo = Logs.Max(x => x.Temperatura) > Maximo ? Logs.Max(x => x.Temperatura) : Maximo;
Minimo = !Logs.Any() ? 0 : Logs.Min(x => x.Temperatura) < Minimo ? Logs.Min(x => x.Temperatura) : Minimo;
Maximo = !Logs.Any() ? 0 : Logs.Max(x => x.Temperatura) > Maximo ? Logs.Max(x => x.Temperatura) : Maximo;
foreach (var legend in chart.Legends)
{
@ -1376,7 +1384,7 @@ namespace AgroBase.Models
}
// Salvar estado anterior
int oldRPM = Controle.RPM;
int oldRPM = Controle.RPM_SP;
double oldAngulo = Controle.Angulo;
double oldVelocidadeMP = Controle.VelocidadeMP;
Dictionary<string, bool> oldControleMov = Variaveis.OperacaoEmAndamento.DispMvd.Dados.Modulos.ToDictionary(x => x.Modulo_ID, x => x.MovMotor.Comandar);
@ -1384,7 +1392,7 @@ namespace AgroBase.Models
// Atualizar estado atual com os valores do controleBase
Controle.RPM = controleBase.RPM;
Controle.RPM_SP = controleBase.RPM;
Controle.Angulo = controleBase.AnguloMP;
Controle.VelocidadeMP = controleBase.VelocidadeMP;
Variaveis.OperacaoEmAndamento.DispMvd.Dados.Modulos.ForEach(x =>
@ -1394,21 +1402,19 @@ namespace AgroBase.Models
x.MovMotor.Comandar = controlarMov;
x.DirMotor.Comandar = controlarDir;
x.DirMotor.Controlar = controlarDir;
});
// Enviar comando
GeneralJoystick.EnviaComandoMotor(controleBase.Tecla, controleBase.Dispositivo, true);
// Restaurar estado anterior
Controle.RPM = oldRPM;
Controle.RPM_SP = oldRPM;
Controle.Angulo = oldAngulo;
Controle.VelocidadeMP = oldVelocidadeMP;
Variaveis.OperacaoEmAndamento.DispMvd.Dados.Modulos.ForEach(x =>
{
x.MovMotor.Comandar = oldControleMov[x.Modulo_ID];
x.DirMotor.Comandar = oldControleDir[x.Modulo_ID];
x.DirMotor.Controlar = oldControleDir[x.Modulo_ID];
});
}
@ -1464,6 +1470,7 @@ namespace AgroBase.Models
GPSModel logGps = new GPSModel()
{
Momento = Agora,
Inicializado = GPSService.Iniciado,
DataHora = GPSService.UltimaLeitura.DataHora,
Altitude = GPSService.UltimaLeitura.Altitude,
DirecaoTrecho = GPSService.UltimaLeitura.DirecaoTrecho,
@ -1483,16 +1490,20 @@ namespace AgroBase.Models
{
Momento = Agora,
Modulo_ID = Modulo.Modulo_ID,
Inicializado = Modulo.MovMotor.Inicializado,
RPM_SP = Variaveis.OperacaoEmAndamento.Controle.RPM,
RPM = Modulo.MovMotor.RPM,
Inicializado = Modulo.MovMotor.BLD_Inicializado,
RPM_SP = Modulo.MovMotor.RPM_SP,
RPM_Motor = Modulo.MovMotor.RPM_Motor,
RPM_Roda = Modulo.MovMotor.RPM_Roda,
Corrente = Modulo.MovMotor.Corrente,
Temperatura = Modulo.MovMotor.Temperatura,
TemperaturaDriver = Modulo.MovMotor.TemperaturaDriver,
Tensao = Modulo.MovMotor.Tensao,
Sentido_SP = Modulo.MovMotor.Sentido_SP,
Sentido = Modulo.MovMotor.Sentido,
Velocidade = Modulo.MovMotor.VelocidadeInstantanea,
CodAlarme = Modulo.MovMotor.CodigoAlarme,
EmFreio = Modulo.MovMotor.Freio,
Ativado = Modulo.MovMotor.Ligado,
};
SalvarLog(T_Code.Mov.ToString(), logMov, false);
@ -1500,10 +1511,10 @@ namespace AgroBase.Models
{
Momento = Agora,
Modulo_ID = Modulo.Modulo_ID,
Inicializado = Modulo.MovMotor.Inicializado,
Inicializado = Modulo.DirMotor.MKS_Inicializado,
Angulo = Modulo.DirMotor.Angulo,
Angulo_SP = Modulo.DirMotor.Angulo_SP,
Controlar = Modulo.DirMotor.Controlar,
Controlar = Modulo.DirMotor.Comandar,
Sentido_SP = Modulo.MovMotor.Sentido_SP,
Sentido = Modulo.MovMotor.Sentido,
Velocidade = Modulo.MovMotor.VelocidadeInstantanea,
@ -1514,6 +1525,7 @@ namespace AgroBase.Models
AtuSensoriamentoLogModel logAtu = new AtuSensoriamentoLogModel()
{
Momento = Agora,
Inicializado = DispAtu.Dados.Conectado,
MassaReservatorio = DispAtu.Dados.MassaReservatorio,
PercentualReservatorio = DispAtu.Dados.PercentualReservatorio,
VolumeReservatorio = DispAtu.Dados.VolumeReservatorio,
@ -1541,6 +1553,7 @@ namespace AgroBase.Models
SenSensoriamentoLogModel logSen = new SenSensoriamentoLogModel()
{
Momento = Agora,
Inicializado = DispSen.Dados.Conectado,
Barramento3v3Corrente = DispSen.Dados.Sensores.FirstOrDefault(x => x.ID == "AB3V" && x.Inicializado)?.Leituras?[0] ?? -1,
Barramento3v3Tensao = DispSen.Dados.Sensores.FirstOrDefault(x => x.ID == "AB3V" && x.Inicializado)?.Leituras?[1] ?? -1,
Barramento5vCorrente = DispSen.Dados.Sensores.FirstOrDefault(x => x.ID == "AB5V" && x.Inicializado)?.Leituras?[0] ?? -1,
@ -1550,12 +1563,21 @@ namespace AgroBase.Models
Barramento12vCorrente = DispSen.Dados.Sensores.FirstOrDefault(x => x.ID == "AB12V" && x.Inicializado)?.Leituras?[0] ?? -1,
Barramento12vTensao = DispSen.Dados.Sensores.FirstOrDefault(x => x.ID == "AB12V" && x.Inicializado)?.Leituras?[1] ?? -1,
OrientacaoMagnetica = DispSen.Dados.Sensores.FirstOrDefault(x => x.ID == "SMAG" && x.Inicializado)?.Leituras?[0] ?? -1,
StatusSinaleiroMN = DispSen.Dados.Sinaleiros.FirstOrDefault(x => x.ID == "LEDMN" && x.Inicializado)?.StatusLED ?? StatusLED.Apagado,
StatusSinaleiroAT = DispSen.Dados.Sinaleiros.FirstOrDefault(x => x.ID == "LEDAT" && x.Inicializado)?.StatusLED ?? StatusLED.Apagado,
StatusSinaleiroOP = DispSen.Dados.Sinaleiros.FirstOrDefault(x => x.ID == "LEDOP" && x.Inicializado)?.StatusLED ?? StatusLED.Apagado,
StatusReleLoRa = DispSen.Dados.Reles.FirstOrDefault(x => x.ID == "RLLRA" && x.Inicializado)?.StatusLeitura ?? Estado.Desligado,
AnguloFreioET = DispSen.Dados.Servos.FirstOrDefault(x => x.ID == "FRO_ET" && x.Inicializado)?._AnguloLeitura ?? -1,
AnguloFreioEF = DispSen.Dados.Servos.FirstOrDefault(x => x.ID == "FRO_EF" && x.Inicializado)?._AnguloLeitura ?? -1,
AnguloFreioDT = DispSen.Dados.Servos.FirstOrDefault(x => x.ID == "FRO_DT" && x.Inicializado)?._AnguloLeitura ?? -1,
AnguloFreioDF = DispSen.Dados.Servos.FirstOrDefault(x => x.ID == "FRO_DF" && x.Inicializado)?._AnguloLeitura ?? -1,
};
SalvarLog(DispSen.Dispositivo.ToString(), logSen, false);
PzmSensoriamentoLogModel logPzm = new PzmSensoriamentoLogModel()
{
Momento = Agora,
Inicializado = PZEMService.Iniciado,
DataHora = PZEMService.UltimaLeitura.DataHora,
Tensao = PZEMService.UltimaLeitura.Tensao,
Corrente = PZEMService.UltimaLeitura.Corrente,
@ -1569,6 +1591,7 @@ namespace AgroBase.Models
WitSensoriamentoLogModel logWit = new WitSensoriamentoLogModel()
{
Momento = Agora,
Inicializado = WT901CService.Iniciado,
DataHora = WT901CService.DadosLeitura.DataHora,
AccM = WT901CService.DadosLeitura.AccM,
Altitude = WT901CService.DadosLeitura.Altitude,
@ -1597,6 +1620,7 @@ namespace AgroBase.Models
atu = T_Code.Atu.ToString(),
sen = T_Code.Sen.ToString(),
pzm = T_Code.Pzm.ToString(),
wit = T_Code.Wit.ToString(),
caminho = "caminho",
soloE = "soloE",
soloD = "soloD"
@ -1829,14 +1853,21 @@ namespace AgroBase.Models
public class OperacaoControleModel
{
public int RPM_Max { get; set; } = 45;
public int RPM_Min { get; set; } = 15;
public int RPM_Max { get; set; } = 600;
public int RPM_Min { get; set; } = 3;
public double Angulo_Max { get; set; } = 30;
public double Angulo_Min { get; set; } = -30;
public double VelocidadeMP { get; set; } = 50;
public double Angulo { get; set; } = 0;
public int RPM { get; set; } = 15;
public int RPM_SP { get; set; } = 15;
public int RPM_Motor
{
get
{
return Convert.ToInt32(RPM_SP * Variaveis.OperacaoEmAndamento.DispMvd.Dados.RelacaoRPM);
}
}
public Direcao Direcao { get; set; } = Direcao.Parado;
public double PercentualInicioPulverizacao { get; set; } = 0.3;
@ -1896,6 +1927,7 @@ namespace AgroBase.Models
public string atu { get; set; }
public string sen { get; set; }
public string pzm { get; set; }
public string wit { get; set; }
public string caminho { get; set; }
public string soloE { get; set; }
public string soloD { get; set; }
@ -1997,6 +2029,7 @@ namespace AgroBase.Models
{
public DateTime Momento { get; set; }
public DateTime DataHora { get; set; }
public bool Inicializado { get; set; }
public double Tensao { get; set; }
public double Corrente { get; set; }
public double Potencia { get; set; }
@ -2009,6 +2042,7 @@ namespace AgroBase.Models
{
public DateTime Momento { get; set; }
public DateTime DataHora { get; set; }
public bool Inicializado { get; set; }
public double AccM { get; set; }
public double AsM { get; set; }
public double AngleX { get; set; }
@ -2039,19 +2073,24 @@ namespace AgroBase.Models
public string Modulo_ID { get; set; }
public bool Inicializado { get; set; }
public double RPM_SP { get; set; }
public double RPM { get; set; }
public double RPM_Motor { get; set; }
public double RPM_Roda { get; set; }
public double Velocidade { get; set; }
public Sentido Sentido_SP { get; set; }
public Sentido Sentido { get; set; }
public double Temperatura { get; set; }
public double TemperaturaDriver { get; set; }
public double Corrente { get; set; }
public double Tensao { get; set; }
public int CodAlarme { get; set; }
public bool EmFreio { get; set; }
public bool Ativado { get; set; }
}
public class AtuSensoriamentoLogModel
{
public DateTime Momento { get; set; }
public bool Inicializado { get; set; }
public double MassaReservatorio { get; set; }
public double PressaoLinha_SP { get; set; }
public double PressaoLinha { get; set; }
@ -2079,6 +2118,7 @@ namespace AgroBase.Models
public class SenSensoriamentoLogModel
{
public DateTime Momento { get; set; }
public bool Inicializado { get; set; }
public double Barramento3v3Tensao { get; set; }
public double Barramento3v3Corrente { get; set; }
public double Barramento5vTensao { get; set; }
@ -2088,6 +2128,14 @@ namespace AgroBase.Models
public double Barramento12vTensao { get; set; }
public double Barramento12vCorrente { get; set; }
public double OrientacaoMagnetica { get; set; }
public StatusLED StatusSinaleiroMN { get; set; }
public StatusLED StatusSinaleiroAT { get; set; }
public StatusLED StatusSinaleiroOP { get; set; }
public Estado StatusReleLoRa { get; set; }
public int AnguloFreioET { get; set; }
public int AnguloFreioEF { get; set; }
public int AnguloFreioDT { get; set; }
public int AnguloFreioDF { get; set; }
}
public class CamSoloSensoriamentoLogModel

View File

@ -133,7 +133,13 @@ namespace AgroBase.Models
public static double DiametroRoda { get; set; } = 0.3556;
public static double BateriaMax { get; set; } = 20;
public static double ReducaoDirecional { get; set; } = 20.0;
public static int RPM_Max_Roda { get; set; } = 100;
public static int TempoEntrePingsConexao { get; set; } = 10000;
public static Dictionary<AcaoFreio, int> AnguloFreio { get; } = new Dictionary<AcaoFreio, int>()
{
{ AcaoFreio.Ativar, 90 },
{ AcaoFreio.Desativar, 0 }
};
}
public static class VariaveisOperacao
@ -583,7 +589,7 @@ namespace AgroBase.Models
double Beta = 3950; // VALOR DE BETA
double To = 298.15; // VALOR EM KELVIN REFERENTE A 25° CELSIUS
double Ro = 10000; // RESISTÊNCIA DO NTC A 25°C
double adcMax = 1024.0;
double adcMax = 4096.0;
double Vout, Rt = 0;
double T, Tc, Tf, adc = 0;

View File

@ -9,91 +9,20 @@ using System.Threading.Tasks;
using static AgroBase.Models.Enuns;
using System.Windows.Forms;
using Emgu.CV.Structure;
using System.Drawing.Printing;
namespace AgroBase.Services
{
public class BLD300RService
{
public BLD300RService(string _Endereco)
{
slaveAddress = Convert.ToByte(_Endereco.Replace("0x", ""), 16);
}
public bool Iniciado { get; set; }
public int TaxaAmostragem { get; set; } = 1000;
public byte slaveAddress = 0x01;
public BLD300RModel UltimaLeitura
{
get
{
// Função auxiliar para converter byte[] para int
int ConvertByteArrayToInt(byte[] bytes)
{
if (bytes == null) return 0;
if (bytes.Length == 2)
{
return BitConverter.ToInt16(bytes.Reverse().ToArray(), 0);
}
else if (bytes.Length == 4)
{
return BitConverter.ToInt32(bytes.Reverse().ToArray(), 0);
}
return 0;
}
// Função auxiliar para verificar a existência de uma chave e obter o valor correspondente
byte[] GetParametroValue(string chave)
{
var parametro = Parametros.FirstOrDefault(x => x.Chave == chave);
return parametro != null ? parametro.Valor : null;
}
// Obtenção e conversão dos parâmetros
int versao = ConvertByteArrayToInt(GetParametroValue("Versao"));
int codigoAlarme = ConvertByteArrayToInt(GetParametroValue("AlarmeCode"));
int numeroPolos = ConvertByteArrayToInt(GetParametroValue("NumPolos"));
int rpmMax = ConvertByteArrayToInt(GetParametroValue("RPM_Max"));
int rampa = ConvertByteArrayToInt(GetParametroValue("Rampa"));
int rpmSp = Convert.ToInt32(ConvertByteArrayToInt(GetParametroValue("RPM_SP")) * Parametros.First(x => x.Chave == "RPM_SP").Escala);
int rpm = Convert.ToInt32(ConvertByteArrayToInt(GetParametroValue("RPM")) * Parametros.First(x => x.Chave == "RPM").Escala);
bool controleRS485 = ConvertByteArrayToInt(GetParametroValue("ControleRS485")) == 1;
bool ativado = ConvertByteArrayToInt(GetParametroValue("Enabled")) == 1;
bool freado = ConvertByteArrayToInt(GetParametroValue("Breaked")) == 1;
Sentido direcao = ConvertByteArrayToInt(GetParametroValue("Direction")) == 1 ? Sentido.Horario : Sentido.Antihorario;
var P_V = Parametros.First(x => x.Chave == "Tensao");
double tensao = ConvertByteArrayToInt(P_V.Valor) * P_V.Escala;
var P_T = Parametros.First(x => x.Chave == "Temperatura");
double temperatura = ConvertByteArrayToInt(P_T.Valor) * P_T.Escala;
var P_A = Parametros.First(x => x.Chave == "LimiteCorrente");
double corrente = ConvertByteArrayToInt(P_A.Valor) * P_A.Escala;
// Criação do modelo com os valores obtidos
BLD300RModel model = new BLD300RModel()
{
Versao = versao,
ControleRS485 = controleRS485,
CodigoAlarme = codigoAlarme,
NumeroPolos = numeroPolos,
RPM_Max = rpmMax,
Rampa = rampa,
RPM_SP = rpmSp,
RPM = rpm,
Ativado = ativado,
Freado = freado,
Direcao = direcao,
Tensao = tensao,
Temperatura = temperatura,
CorrenteMax = FuncoesMatematicas.Map(corrente, 15780, 16799, 0, 20.6)
};
return model;
}
}
public static bool Iniciado { get; set; }
public static int TaxaAmostragem { get; set; } = 1000;
public static SerialPort _PortaBLD = new SerialPort();
public static List<BLD300RModel> DadosLeitura = new List<BLD300RModel>();
public static bool EnvioLiberado = true;
public static bool FilaEmEspera = false;
public static bool Respondido = false;
public static List<ModbusParametrosModel> Parametros = new List<ModbusParametrosModel>()
{
@ -104,7 +33,7 @@ namespace AgroBase.Services
FuncaoGet = 0x03,
FuncaoSet = 0x06,
Escala = 1,
LeituraLoop = true,
LeituraLoop = false,
LeituraGeral = true,
N_Registros = 0x0001,
Registro = 0x00BB
@ -281,79 +210,113 @@ namespace AgroBase.Services
};
private static List<BLDComandoModel> FilaComandos = new List<BLDComandoModel>();
public async Task<bool> VerificaPortaBLD(SerialPort porta)
public static async Task<bool> VerificaPortaBLD(SerialPort porta)
{
ModbusService.Verificando = true;
porta.BaudRate = 9600;
var Parametro = Parametros.First(x => x.Chave == "Versao");
var comando = ModbusService.ComandoGetParametro(slaveAddress, Parametro);
EnviarComando(porta, comando);
await Task.Delay(1000);
var resposta = SerialService.VerificarRespostaPortasDesconhecidas(porta);
ModbusService.Verificando = false;
Iniciado = DecifrarResposta(resposta, Parametro) != null;
if (resposta.Length >= 5 && resposta[1] == Parametro.FuncaoGet && Iniciado)
{
AtualizarPortaCOM(porta);
return Iniciado;
}
if (!ModbusService.Iniciado)
if (!Iniciado)
{
porta.Close();
porta.BaudRate = 9600;
AtualizarPortaCOM(porta);
}
var Parametro = Parametros.First(x => x.Chave == "Versao");
return false;
}
List<string> Mod_IDs = new List<string>();
public void AtualizarPortaCOM(SerialPort Porta)
{
if (ModbusService._PortaModbus == null || !ModbusService.Iniciado)
foreach (var Modulo in Variaveis.OperacaoEmAndamento.DispMvd.Dados.Modulos.Where(x => !x.MovMotor.BLD_Inicializado))
{
lock (ModbusService._lock)
byte Addr = 0;
try
{
ModbusService._PortaModbus = new SerialPort();
ModbusService._PortaModbus.BaudRate = Porta.BaudRate;
ModbusService._PortaModbus.PortName = Porta.PortName;
Addr = Convert.ToByte(Modulo.MovMotor.Endereco, 16);
}
catch
{
Console.WriteLine("Erro ao definir endereco");
}
if (DadosLeitura.Any(x => x.Endereco == Addr && x.Iniciado))
{
continue;
}
var comando = ModbusService.ComandoGetParametro(Addr, Parametro);
EnviarComando(_PortaBLD, comando);
var resposta = await SerialService.LerDadosDaPortaSerialAsync(_PortaBLD, 7, 1000);
DecifrarResposta(resposta, Parametro, Addr);
if (DadosLeitura.Any(x => x.Endereco == Addr && x.Iniciado))
{
Mod_IDs.Add(Modulo.Modulo_ID);
}
}
if (ModbusService._PortaModbus != null && !ModbusService._PortaModbus.IsOpen)
{
Porta.Close();
}
Iniciado = DadosLeitura.Any(x => x.Iniciado);
if (Iniciado)
{
bool i = ModbusService.Iniciado;
DefinirDispositivo();
ReceberDados().ConfigureAwait(false);
DefinirDispositivo(Mod_IDs);
}
else
{
_PortaBLD.Close();
_PortaBLD = null;
}
return Iniciado;
}
private void DefinirDispositivo()
public static void AtualizarPortaCOM(SerialPort Porta)
{
_PortaBLD = new SerialPort();
_PortaBLD.PortName = Porta.PortName;
_PortaBLD.BaudRate = Porta.BaudRate;
_PortaBLD.Open();
}
private static void DefinirDispositivo(List<string> Mod_IDs)
{
if (Iniciado)
{
SerialService.DispositivosMapeados.Add(new SerialService.DispositivoDetalhesModel()
foreach (var Mod_ID in Mod_IDs)
{
PortaCOM = ModbusService._PortaModbus.PortName,
Dispositivo = T_Code.Bld,
Erro = !Iniciado,
Versao = UltimaLeitura.Versao.ToString(),
Mod_ID = Variaveis.OperacaoEmAndamento.DispMvd.Dados.Modulos.FirstOrDefault(x => Convert.ToByte(x.MovMotor.Endereco.Replace("0x", ""), 16) == slaveAddress).Modulo_ID,
});
var Modulo = Variaveis.OperacaoEmAndamento.DispMvd.Dados.Modulos.FirstOrDefault(x => x.Modulo_ID == Mod_ID);
byte Addr = Convert.ToByte(Modulo.MovMotor.Endereco.Replace("0x", ""), 16);
if (DadosLeitura.Any(x => x.Endereco == Addr && !x.Configurado))
{
ConfigurarDriver(Addr);
}
if (!SerialService.DispositivosMapeados.Any(x => x.Dispositivo == T_Code.Bld && x.Mod_ID == Mod_ID))
{
var leitura = DadosLeitura.FirstOrDefault(x => x.Endereco == Addr);
SerialService.DispositivosMapeados.Add(new SerialService.DispositivoDetalhesModel()
{
PortaCOM = _PortaBLD.PortName,
Dispositivo = T_Code.Bld,
Erro = leitura.CodigoAlarme > 0,
Versao = leitura.Versao.ToString(),
Mod_ID = Mod_ID,
});
}
}
}
}
public void EnviarComando(SerialPort _Porta, byte[] Comando)
public static void IniciarRotinas()
{
LoopEnvioComandos().ConfigureAwait(false);
ReceberDados().ConfigureAwait(false);
}
private static void EnviarComando(SerialPort _Porta, byte[] Comando)
{
if (_Porta != null)
{
@ -368,106 +331,278 @@ namespace AgroBase.Services
}
}
private async Task<bool> ReceberDados()
private static async Task ReceberDados()
{
foreach (var Parametro in Parametros.Where(x => x.LeituraLoop))
while (true)
{
await ModbusService.EnviarComando(ModbusService.ComandoGetParametro(slaveAddress, Parametro));
await Task.Delay(TaxaAmostragem);
byte[] resposta = SerialService.VerificarRespostaPortasDesconhecidas(ModbusService._PortaModbus);
if (!Iniciado)
{
continue;
}
Iniciado = DecifrarResposta(resposta, Parametro) != null;
foreach (var Leitura in DadosLeitura.Where(x => x.Iniciado).OrderBy(x => x.Endereco))
{
foreach (var Parametro in Parametros.Where(x => x.LeituraLoop))
{
var Comando = new BLDComandoModel()
{
Endereco = Leitura.Endereco,
AguardaResposta = true,
Parametro = Parametro,
Get = true,
TimeoutResposta = 300
};
AdicionarComandoNaFila(Comando);
}
var Modulo = Variaveis.OperacaoEmAndamento.DispMvd.Dados.Modulos.FirstOrDefault(x => Convert.ToByte(x.MovMotor.Endereco.Replace("0x", ""), 16) == Leitura.Endereco);
if (Modulo != null)
{
Modulo.MovMotor.RPM_Motor = Leitura.RPM;
Modulo.MovMotor.TemperaturaDriver = Math.Round(Leitura.Temperatura, 2);
Modulo.MovMotor.Corrente_Max = Math.Round(Leitura.CorrenteMax, 2);
Modulo.MovMotor.Tensao = Math.Round(Leitura.Tensao, 2);
Modulo.MovMotor.Ligado = Leitura.Ativado;
Modulo.MovMotor.Freio = Leitura.Freado;
Modulo.MovMotor.Sentido = Leitura.Direcao;
Modulo.MovMotor.CodigoAlarme = Leitura.CodigoAlarme;
Variaveis.OperacaoEmAndamento.DispMvd.Dados.RegistrarLogMov(Modulo);
}
}
}
var Modulo = Variaveis.OperacaoEmAndamento.DispMvd.Dados.Modulos.FirstOrDefault(x => Convert.ToByte(x.MovMotor.Endereco.Replace("0x", ""), 16) == slaveAddress);
if (Modulo != null)
{
Modulo.MovMotor.RPM = UltimaLeitura.RPM;
Modulo.MovMotor.TemperaturaDriver = UltimaLeitura.Temperatura;
Modulo.MovMotor.Corrente_Max = UltimaLeitura.CorrenteMax;
Modulo.MovMotor.Tensao = UltimaLeitura.Tensao;
Modulo.MovMotor.Ligado = UltimaLeitura.Ativado;
Modulo.MovMotor.Freio = UltimaLeitura.Freado;
Modulo.MovMotor.Sentido = UltimaLeitura.Direcao;
Modulo.MovMotor.CodigoAlarme = UltimaLeitura.CodigoAlarme;
Variaveis.OperacaoEmAndamento.DispMvd.Dados.RegistrarLog(Modulo);
}
await Task.Delay(TaxaAmostragem);
return await ReceberDados();
}
public BLD300RModel DecifrarResposta(byte[] resposta, ModbusParametrosModel Parametro)
private static void DecifrarResposta(byte[] resposta, ModbusParametrosModel Parametro, byte Addr)
{
try
{
/*if (!VerificarCrc(resposta))
var Leitura = DadosLeitura.FirstOrDefault(x => x.Endereco == Addr);
if (Leitura == null)
{
Console.Write("CRC inválido. A resposta pode estar corrompida.");
return null;
}*/
Leitura = new BLD300RModel()
{
Endereco = Addr,
Iniciado = false,
parametros = new List<BLDParametrosRequisitar>()
{
new BLDParametrosRequisitar()
{
Registro = Parametro.Registro,
Escala = Parametro.Escala,
Valor = null
}
}
};
DadosLeitura.Add(Leitura);
}
var ParametroLeitura = Leitura.parametros.FirstOrDefault(x => x.Registro == Parametro.Registro);
if (ParametroLeitura == null)
{
ParametroLeitura = new BLDParametrosRequisitar()
{
Registro = Parametro.Registro,
Escala = Parametro.Escala,
Valor = null
};
Leitura.parametros.Add(ParametroLeitura);
}
if (resposta.Length > 3)
{
if (Parametros.Any(x => x.FuncaoGet == resposta[1]))
{
int num_registros = resposta[2];
byte[] bytes_resposta = resposta.Skip(3).Take(num_registros).ToArray();
byte[] bytes_resposta = resposta.Skip(3).Take(num_registros).ToArray(); // Ajustando para pegar 2 bytes por registro
Parametro.Valor = bytes_resposta;
Parametro.UltimaRequisicao = DateTime.MaxValue;
}
else if (Parametros.Any(x => x.FuncaoSet == resposta[1]))
{
string parametro_raw = "0x" + (resposta[2].ToString("X").Length == 1 ? "0" : "") + resposta[2].ToString("X") + (resposta[3].ToString("X").Length == 1 ? "0" : "") + resposta[3].ToString("X");
int parametro = Convert.ToInt32(parametro_raw, 16);
string valor_raw = "0x" + (resposta[4].ToString("X").Length == 1 ? "0" : "") + resposta[4].ToString("X") + (resposta[5].ToString("X").Length == 1 ? "0" : "") + resposta[5].ToString("X");
int valor = Convert.ToInt32(valor_raw, 16);
Parametros.First(x => x.Registro == parametro).Valor = resposta.Skip(4).Take(2).ToArray();
//MessageBox.Show("Parâmetro gravado com sucesso!");
Parametro.Valor = resposta.Skip(4).Take(2).ToArray();
}
else
{
Console.WriteLine("Resposta inválida ou código de função incorreto.");
}
}
else
{
return null;
}
return new BLD300RModel();
ParametroLeitura.Valor = Parametro.Valor;
Leitura.Iniciado = true;
}
}
catch (Exception ex)
{
}
return null;
}
public async Task AtualizarDadosDriver()
private static void ConfigurarDriver(byte Addr)
{
await ModbusService.EnviarComando(ModbusService.ComandoSetParametro(slaveAddress, Parametros.First(x => x.Chave == "ControleRS485"), 1));
await ModbusService.EnviarComando(ModbusService.ComandoSetParametro(slaveAddress, Parametros.First(x => x.Chave == "AlarmeCode"), 0));
await ModbusService.EnviarComando(ModbusService.ComandoSetParametro(slaveAddress, Parametros.First(x => x.Chave == "NumPolos"), Variaveis.OperacaoEmAndamento.DispMvd.Dados.Modulos.First().MovMotor.NumeroPolos));
await ModbusService.EnviarComando(ModbusService.ComandoSetParametro(slaveAddress, Parametros.First(x => x.Chave == "RPM_Max"), Variaveis.OperacaoEmAndamento.DispMvd.Dados.Modulos.First().MovMotor.RPM_Max));
await ModbusService.EnviarComando(ModbusService.ComandoSetParametro(slaveAddress, Parametros.First(x => x.Chave == "Rampa"), Variaveis.OperacaoEmAndamento.DispMvd.Dados.Modulos.First().MovMotor.Rampa));
await ModbusService.EnviarComando(ModbusService.ComandoSetParametro(slaveAddress, Parametros.First(x => x.Chave == "ControleRS485"), 0));
foreach (var Parametro in Parametros.Where(x => x.LeituraGeral))
var Modulo = Variaveis.OperacaoEmAndamento.DispMvd.Dados.Modulos.FirstOrDefault(x => Convert.ToByte(x.MovMotor.Endereco.Replace("0x", ""), 16) == Addr);
AdicionarComandoNaFila(new BLDComandoModel()
{
await ModbusService.EnviarComando(ModbusService.ComandoGetParametro(slaveAddress, Parametro));
Endereco = Addr,
AguardaResposta = true,
TimeoutResposta = 200,
Get = false,
Parametro = Parametros.First(x => x.Chave == "ControleRS485"),
Valor = 1
});
AdicionarComandoNaFila(new BLDComandoModel()
{
Endereco = Addr,
AguardaResposta = true,
TimeoutResposta = 200,
Get = false,
Parametro = Parametros.First(x => x.Chave == "AlarmeCode"),
Valor = 0
});
AdicionarComandoNaFila(new BLDComandoModel()
{
Endereco = Addr,
AguardaResposta = true,
TimeoutResposta = 200,
Get = false,
Parametro = Parametros.First(x => x.Chave == "NumPolos"),
Valor = Modulo.MovMotor.NumeroPolos
});
AdicionarComandoNaFila(new BLDComandoModel()
{
Endereco = Addr,
AguardaResposta = true,
TimeoutResposta = 200,
Get = false,
Parametro = Parametros.First(x => x.Chave == "RPM_Max"),
Valor = Modulo.MovMotor.RPM_Max
});
AdicionarComandoNaFila(new BLDComandoModel()
{
Endereco = Addr,
AguardaResposta = true,
TimeoutResposta = 200,
Get = false,
Parametro = Parametros.First(x => x.Chave == "Rampa"),
Valor = Modulo.MovMotor.Rampa
});
AdicionarComandoNaFila(new BLDComandoModel()
{
Endereco = Addr,
AguardaResposta = true,
TimeoutResposta = 200,
Get = false,
Parametro = Parametros.First(x => x.Chave == "Enabled"),
Valor = 0
});
DadosLeitura.Where(x => x.Endereco == Addr).First().Configurado = true;
}
byte[] resposta = SerialService.VerificarRespostaPortasDesconhecidas(ModbusService._PortaModbus);
public static async Task EnviarComandoControle(BLDComandoModel Comando)
{
while (!EnvioLiberado)
{
await Task.Delay(FilaEmEspera ? 200 : 100);
FilaEmEspera = true;
}
Iniciado = DecifrarResposta(resposta, Parametro) != null;
EnvioLiberado = false;
FilaEmEspera = false;
Respondido = false;
byte[] comando = null;
if (Comando.Get)
{
comando = ModbusService.ComandoGetParametro(Comando.Endereco, Comando.Parametro);
}
else
{
comando = ModbusService.ComandoSetParametro(Comando.Endereco, Comando.Parametro, Comando.Valor);
}
if (comando != null && comando.Length > 0)
{
EnviarComando(_PortaBLD, comando);
Comando.Enviado = true;
if (Comando.AguardaResposta)
{
byte[] resposta = await SerialService.LerDadosDaPortaSerialAsync(_PortaBLD, 7, Comando.TimeoutResposta);
DecifrarResposta(resposta, Comando.Parametro, Comando.Endereco);
Respondido = true;
}
}
EnvioLiberado = true;
}
public static void AdicionarComandoNaFila(BLDComandoModel Comando)
{
if (!FilaComandos.Any(x => x.Endereco == Comando.Endereco && x.Parametro.Registro == Comando.Parametro.Registro && x.Get == Comando.Get && !x.Enviado))
{
FilaComandos.Add(Comando);
}
}
private static async Task LoopEnvioComandos()
{
while (true)
{
await Task.Delay(100);
await ProcessarFilaPrioridade();
var FilaLeitura = FilaComandos.Where(x => !x.Enviado && x.Get).OrderBy(x => x.Momento).ToList();
foreach (var Comando in FilaLeitura)
{
await EnviarComandoControle(Comando);
await ProcessarFilaPrioridade();
}
}
}
private static async Task ProcessarFilaPrioridade()
{
var FilaPrioridade = FilaComandos.Where(x => !x.Enviado && !x.Get).OrderBy(x => x.Momento).ToList();
while (FilaPrioridade.Count > 0)
{
foreach (var Comando in FilaPrioridade)
{
await EnviarComandoControle(Comando);
}
FilaPrioridade = FilaComandos.Where(x => !x.Enviado && !x.Get).OrderBy(x => x.Momento).ToList();
}
}
public class BLDParametrosRequisitar
{
public byte Registro { get; set; }
public byte[] Valor { get; set; }
public double Escala { get; set; }
}
public class BLDComandoModel
{
public DateTime Momento { get; set; } = DateTime.Now;
public bool Enviado { get; set; } = false;
public byte Endereco { get; set; }
public ModbusParametrosModel Parametro { get; set; }
public float Valor { get; set; }
public bool Get { get; set; }
public bool AguardaResposta { get; set; } = false;
public int TimeoutResposta { get; set; } = 1000;
}
}
}

View File

@ -406,6 +406,18 @@ namespace AgroBase.Comum
clbDispositivos.Items.Add(Sensor.ID);
clbDispositivos.SetItemChecked(clbDispositivos.Items.Count - 1, Sensor.Aferir);
}
var Reles = senModel.Reles;
foreach (var Rele in Reles)
{
clbDispositivos.Items.Add(Rele.ID);
clbDispositivos.SetItemChecked(clbDispositivos.Items.Count - 1, Rele.Controlar);
}
var Servos = senModel.Servos;
foreach (var Servo in Servos)
{
clbDispositivos.Items.Add(Servo.ID);
clbDispositivos.SetItemChecked(clbDispositivos.Items.Count - 1, Servo.Controlar);
}
}
else if (Dados is AtuadorModel atuModel && Dispositivo == T_Code.Atu)
{
@ -647,9 +659,22 @@ namespace AgroBase.Comum
if (Dados is SensoriamentoModel senModel)
{
senModel.Sensores.ForEach(x => x.Aferir = false);
senModel.Reles.ForEach(x => x.Controlar = false);
senModel.Servos.ForEach(x => x.Controlar = false);
foreach (var Item in ((CheckedListBox)sender).CheckedItems)
{
senModel.Sensores.First(x => x.ID == Item.ToString()).Aferir = true;
if (senModel.Sensores.Any(x => x.ID == Item.ToString()))
{
senModel.Sensores.First(x => x.ID == Item.ToString()).Aferir = true;
}
else if (senModel.Reles.Any(x => x.ID == Item.ToString()))
{
senModel.Reles.First(x => x.ID == Item.ToString()).Controlar = true;
}
else if (senModel.Servos.Any(x => x.ID == Item.ToString()))
{
senModel.Servos.First(x => x.ID == Item.ToString()).Controlar = true;
}
}
}
break;

View File

@ -22,15 +22,20 @@ namespace AgroBase.Services
public static async Task<bool> VerificaPortaMKS(SerialPort porta)
{
porta.Close();
porta.BaudRate = 38400;
AtualizarPortaCOM(porta);
if (!Iniciado)
{
porta.Close();
porta.BaudRate = 38400;
AtualizarPortaCOM(porta);
}
string oldHV = "";
string oldFV = "";
foreach (var Modulo in Variaveis.OperacaoEmAndamento.DispMvd.Dados.Modulos)
List<string> Mod_IDs = new List<string>();
foreach (var Modulo in Variaveis.OperacaoEmAndamento.DispMvd.Dados.Modulos.Where(x => !x.DirMotor.MKS_Inicializado))
{
try
{
@ -41,41 +46,22 @@ namespace AgroBase.Services
Console.WriteLine("Erro ao definir endereco");
}
if (DadosLeitura.Any(x => x.Endereco == Addr && x.Iniciado))
{
continue;
}
DataSended = Convert.ToByte("43");
await SendRelevantData(QueryCommand[DataSended]);
await Task.Delay(500);
//ProcessarDadosRecebidos();
if (!DadosLeitura.Any(x => x.Endereco == Addr))
{
DadosLeitura.Add(new MKS057DModel() { Endereco = Addr });
}
await Task.Delay(1000);
if (string.IsNullOrEmpty(oldHV) && !string.IsNullOrEmpty(HV))
if (DadosLeitura.Any(x => x.Endereco == Addr && x.Iniciado))
{
oldHV = HV;
HV = "";
}
if (string.IsNullOrEmpty(oldFV) && !string.IsNullOrEmpty(FV))
{
oldFV = FV;
FV = "";
Mod_IDs.Add(Modulo.Modulo_ID);
}
}
HV = oldHV;
FV = oldFV;
Iniciado = DadosLeitura.Any(x => x.Iniciado);
if (Iniciado)
{
DefinirDispositivo();
DefinirDispositivo(Mod_IDs);
}
else
{
@ -98,22 +84,37 @@ namespace AgroBase.Services
_PortaMKS.Open();
}
private static void DefinirDispositivo()
private static void DefinirDispositivo(List<string> Mod_IDs)
{
//_PortaMKS.DataReceived -= port_DataReceived;
//_PortaMKS.DataReceived += port_DataReceived;
SerialService.DispositivosMapeados.Add(new SerialService.DispositivoDetalhesModel()
if (Iniciado)
{
PortaCOM = _PortaMKS.PortName,
Dispositivo = T_Code.Mks,
Erro = !Iniciado,
Versao = "HV: " + HV + ", FV: " + FV,
});
foreach (var Mod_ID in Mod_IDs)
{
var Modulo = Variaveis.OperacaoEmAndamento.DispMvd.Dados.Modulos.FirstOrDefault(x => x.Modulo_ID == Mod_ID);
byte Addr = Convert.ToByte(Modulo.DirMotor.Endereco.Replace("0x", ""), 16);
if (!SerialService.DispositivosMapeados.Any(x => x.Dispositivo == T_Code.Mks && x.Mod_ID == Mod_ID))
{
var Leitura = DadosLeitura.FirstOrDefault(x => x.Endereco == Addr);
SerialService.DispositivosMapeados.Add(new SerialService.DispositivoDetalhesModel()
{
PortaCOM = _PortaMKS.PortName,
Dispositivo = T_Code.Mks,
Erro = Leitura.Mensagem != "",
Versao = Leitura.FV.ToString(),
Mod_ID = Mod_ID,
});
}
}
}
}
public static void IniciarRotinas()
{
ReceberDados().ConfigureAwait(false);
}
public static void EnviarComando(SerialPort _Porta, byte[] Comando)
{
if (_Porta != null)
@ -149,7 +150,6 @@ namespace AgroBase.Services
static byte[] SerialBuffer_RX;
static int Data_Number;
static string str;
static string HV, FV;
static byte[] FV1 = new byte[] { 0, 0, 0 };
static int Temp1 = 0;
static readonly string[] UartBaud = { "9600", "19200", "25000", "38400", "57600", "115200", "256000" };
@ -396,26 +396,19 @@ namespace AgroBase.Services
private static async Task<bool> ReceberDados()
{
if (!ModbusService.Iniciado)
while (true)
{
Iniciado = false;
return false;
}
await Task.Delay(TaxaAmostragem);
foreach (var Modulo in Variaveis.OperacaoEmAndamento.DispMvd.Dados.Modulos.Where(x => x.DirMotor.Inicializado))
{
await EnviarComandoRequisicao(Modulo.DirMotor.Endereco);
}
if (!Iniciado)
{
continue;
}
await Task.Delay(TaxaAmostragem);
if (ModbusService.Iniciado)
{
return await ReceberDados();
}
else
{
return false;
foreach (var Modulo in Variaveis.OperacaoEmAndamento.DispMvd.Dados.Modulos.Where(x => x.DirMotor.MKS_Inicializado))
{
await EnviarComandoRequisicao(Modulo.DirMotor.Endereco);
}
}
}
@ -1966,8 +1959,8 @@ namespace AgroBase.Services
case 0x40:// 43 Informação de Versão
try
{
HV = HardVersion[SerialBuffer_RX[3]];
FV = "V" + SerialBuffer_RX[4] + "." + SerialBuffer_RX[5] + "." + SerialBuffer_RX[6];
leitura.HV = HardVersion[SerialBuffer_RX[3]];
leitura.FV = "V" + SerialBuffer_RX[4] + "." + SerialBuffer_RX[5] + "." + SerialBuffer_RX[6];
for (int a = 0; a < 3; a++)
{
FV1[a] = SerialBuffer_RX[a + 4];
@ -1976,7 +1969,7 @@ namespace AgroBase.Services
{
if (leitura.Iniciado)
{
MessageBox.Show("Versão do hardware: " + HV + "\nVersão da firmware: " + FV, "Versão");
MessageBox.Show("Versão do hardware: " + leitura.HV + "\nVersão da firmware: " + leitura.FV, "Versão");
}
DataSended = 0;
}

View File

@ -26,6 +26,7 @@ namespace AgroBase.Services
public static List<T_Code> DispositivosMotores = new List<T_Code>() { T_Code.Mov, T_Code.Dir };
public static List<T_Code> DispositivosConexaoInicial = new List<T_Code>() { T_Code.Mvd, T_Code.Atu, T_Code.Sen };
public static List<T_Code> DispositivosModbus = new List<T_Code>() { T_Code.Pzm, T_Code.Wit };
public static List<T_Code> DispositivosMultiplos = new List<T_Code>() { T_Code.Bld, T_Code.Mks, T_Code.Mvd };
public class DispositivoDetalhesModel
{
@ -58,7 +59,7 @@ namespace AgroBase.Services
}
else if (Dispositivo == T_Code.Bld)
{
DispositivoConectado = Variaveis.OperacaoEmAndamento.DispMvd.Dados.Modulos.Any(x => x.MovMotor.DadosDriver.Iniciado);
DispositivoConectado = BLD300RService.Iniciado;
}
else
{
@ -223,6 +224,17 @@ namespace AgroBase.Services
MKS057DService.Iniciado = false;
}
}
if (BLD300RService.Iniciado)
{
if (DispositivosMapeados.Any(x => x.Dispositivo == T_Code.Bld))
{
await ProcuraDispositivoBLD(BLD300RService._PortaBLD);
}
else
{
MKS057DService.Iniciado = false;
}
}
/*if (DispositivosMapeados.Any(x => x.Dispositivo == T_Code.Mvd) && Variaveis.OperacaoEmAndamento.DispMvd.Dados.Modulos.Any(x => !DispositivosMapeados.Any(y => y.Mod_ID == x.Modulo_ID)))
{
await ProcuraDispositivoMvd(new SerialPort() { PortName = DispositivosMapeados.First(x => x.Dispositivo == T_Code.Mvd).PortaCOM, BaudRate = 115200 });
@ -342,6 +354,12 @@ namespace AgroBase.Services
return true;
}
bool DispBld = await ProcuraDispositivoBLD(porta);
if (DispBld)
{
return true;
}
bool DispMks = await ProcuraDispositivoMKS(porta);
if (DispMks)
{
@ -452,7 +470,7 @@ namespace AgroBase.Services
return Encontrado;
}
}
if (false && Variaveis.OperacaoEmAndamento.DispMvd != null && Variaveis.OperacaoEmAndamento.DispMvd.Dados.Modulos.Any(x => !x.MovMotor.DadosDriver.Iniciado))
/*if (Variaveis.OperacaoEmAndamento.DispMvd != null && Variaveis.OperacaoEmAndamento.DispMvd.Dados.Modulos.Any(x => !x.MovMotor.DadosDriver.Iniciado))
{
foreach (var Modulo in Variaveis.OperacaoEmAndamento.DispMvd.Dados.Modulos.Where(x => !x.MovMotor.DadosDriver.Iniciado))
{
@ -466,11 +484,31 @@ namespace AgroBase.Services
}
}
}
}
}*/
return Encontrado;
}
private static async Task<bool> ProcuraDispositivoBLD(SerialPort porta)
{
if (BLD300RService.Iniciado && porta.PortName != BLD300RService._PortaBLD.PortName)
{
return false;
}
if (!BLD300RService.Iniciado || BLD300RService.DadosLeitura.Any(x => !x.Iniciado))
{
bool Encontrado = await BLD300RService.VerificaPortaBLD(porta);
if (Encontrado)
{
return Encontrado;
}
}
return BLD300RService.Iniciado;
}
private static async Task<bool> ProcuraDispositivoMKS(SerialPort porta)
{
if (MKS057DService.Iniciado && porta.PortName != MKS057DService._PortaMKS.PortName)
@ -554,6 +592,24 @@ namespace AgroBase.Services
return buffer.ToArray();
}
public static async Task<byte[]> LerDadosDaPortaSerialAsync(SerialPort porta, int tamanhoEsperado, int Timeout = 500)
{
DateTime inicio = DateTime.Now;
List<byte> buffer = new List<byte>();
while (buffer.Count < tamanhoEsperado && inicio.AddMilliseconds(Timeout) > DateTime.Now)
{
await Task.Delay(50);
int bytesDisponiveis = porta.BytesToRead;
if (bytesDisponiveis > 0)
{
byte[] tempBuffer = new byte[bytesDisponiveis];
int bytesLidos = porta.Read(tempBuffer, 0, bytesDisponiveis);
buffer.AddRange(tempBuffer.Take(bytesLidos));
}
}
return buffer.ToArray();
}
public static async Task AguardaRespostaPorta(SerialPort _Porta, int Timeout)
{
DateTime inicio = DateTime.Now;

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1 +0,0 @@
[{"Momento":"2024-07-10T08:39:23.3589694-03:00","Protocolo":"@1;Sen;258;AB3V,1,322,1,500,10,0,-1,0x44,219$","Enviado":true},{"Momento":"2024-07-10T08:39:24.3694897-03:00","Protocolo":"Sen;AB3V nao iniciado, endereco 68 nao encontrado!\r","Enviado":false},{"Momento":"2024-07-10T08:39:24.3804912-03:00","Protocolo":"Sen;#211;AB3V;0$\r","Enviado":false},{"Momento":"2024-07-10T08:39:24.3925012-03:00","Protocolo":"Sen;655;1;$\r","Enviado":false},{"Momento":"2024-07-10T08:39:24.400499-03:00","Protocolo":"@2;Sen;258;AB5V,1,322,1,500,10,0,-1,0x41,219$","Enviado":true},{"Momento":"2024-07-10T08:39:25.4110382-03:00","Protocolo":"Sen;AB5V nao iniciado, endereco 65 nao encontrado!\r","Enviado":false},{"Momento":"2024-07-10T08:39:25.4220386-03:00","Protocolo":"Sen;#211;AB5V;0$\r","Enviado":false},{"Momento":"2024-07-10T08:39:25.4330408-03:00","Protocolo":"Sen;655;2;$\r","Enviado":false},{"Momento":"2024-07-10T08:39:25.4400382-03:00","Protocolo":"@3;Sen;258;AB7V2,1,322,1,500,10,0,-1,0x40,219$","Enviado":true},{"Momento":"2024-07-10T08:39:26.4513499-03:00","Protocolo":"Sen;AB7V2 nao iniciado, endereco 64 nao encontrado!\r","Enviado":false},{"Momento":"2024-07-10T08:39:26.462346-03:00","Protocolo":"Sen;#211;AB7V2;0$\r","Enviado":false},{"Momento":"2024-07-10T08:39:26.4733464-03:00","Protocolo":"Sen;655;3;$\r","Enviado":false},{"Momento":"2024-07-10T08:39:26.4793466-03:00","Protocolo":"@4;Sen;258;AB12V,1,322,1,500,10,0,-1,0x45,226$","Enviado":true},{"Momento":"2024-07-10T08:39:27.4902106-03:00","Protocolo":"Sen;AB12V nao iniciado, endereco 69 nao encontrado!\r","Enviado":false},{"Momento":"2024-07-10T08:39:27.5012083-03:00","Protocolo":"Sen;#211;AB12V;0$\r","Enviado":false},{"Momento":"2024-07-10T08:40:01.4208361-03:00","Protocolo":"@5;Sen;258;LEDMN,1,0,4$","Enviado":true},{"Momento":"2024-07-10T08:40:01.443839-03:00","Protocolo":"Sen;655;4;$\r","Enviado":false},{"Momento":"2024-07-10T08:40:17.027587-03:00","Protocolo":"@9;Sen;258;AB3V,1,322,1,500,10,0,-1,0x44,219$","Enviado":true},{"Momento":"2024-07-10T08:40:40.5801669-03:00","Protocolo":"@17;Sen;258;AB3V,1,322,1,500,10,0,-1,0x44,219$","Enviado":true},{"Momento":"2024-07-10T08:40:41.5919103-03:00","Protocolo":"Sen;AB3V nao iniciado, endereco 68 nao encontrado!\r","Enviado":false},{"Momento":"2024-07-10T08:40:41.6029108-03:00","Protocolo":"Sen;#211;AB3V;0$\r","Enviado":false},{"Momento":"2024-07-10T08:40:41.6129005-03:00","Protocolo":"Sen;655;17;$\r","Enviado":false},{"Momento":"2024-07-10T08:40:41.6179-03:00","Protocolo":"@18;Sen;258;AB5V,1,322,1,500,10,0,-1,0x41,219$","Enviado":true},{"Momento":"2024-07-10T08:40:42.6291612-03:00","Protocolo":"Sen;AB5V nao iniciado, endereco 65 nao encontrado!\r","Enviado":false},{"Momento":"2024-07-10T08:40:42.6401643-03:00","Protocolo":"Sen;#211;AB5V;0$\r","Enviado":false},{"Momento":"2024-07-10T08:40:42.6511698-03:00","Protocolo":"Sen;655;18;$\r","Enviado":false}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1 +0,0 @@
[{"Momento":"2024-07-18T10:31:00.5719479-03:00","Protocolo":"@1;Sen;258;LEDMN,1,0,4$","Enviado":true},{"Momento":"2024-07-18T10:31:00.5779483-03:00","Protocolo":"Sen;#211;LEDMN;1$\r","Enviado":false},{"Momento":"2024-07-18T10:31:00.5879474-03:00","Protocolo":"Sen;655;1;$\r","Enviado":false},{"Momento":"2024-07-18T10:31:00.5969457-03:00","Protocolo":"@2;Sen;258;LEDAT,1,0,16$","Enviado":true},{"Momento":"2024-07-18T10:31:00.6029476-03:00","Protocolo":"Sen;#211;LEDAT;1$\r","Enviado":false},{"Momento":"2024-07-18T10:31:00.6139481-03:00","Protocolo":"Sen;655;2;$\r","Enviado":false},{"Momento":"2024-07-18T10:31:00.6279458-03:00","Protocolo":"@3;Sen;258;LEDOP,1,0,17$","Enviado":true},{"Momento":"2024-07-18T10:31:00.6339471-03:00","Protocolo":"Sen;#211;LEDOP;1$\r","Enviado":false},{"Momento":"2024-07-18T10:31:00.6448645-03:00","Protocolo":"Sen;655;3;$\r","Enviado":false},{"Momento":"2024-07-18T10:31:00.6611572-03:00","Protocolo":"@4;Sen;258;RLLRA,1,0,23$","Enviado":true},{"Momento":"2024-07-18T10:31:00.6671568-03:00","Protocolo":"Sen;#211;RLLRA;1$\r","Enviado":false},{"Momento":"2024-07-18T10:31:00.6771563-03:00","Protocolo":"Sen;655;4;$\r","Enviado":false},{"Momento":"2024-07-18T10:31:00.6921602-03:00","Protocolo":"@5;Sen;258;MD,1,500,0,0,21,0,22$","Enviado":true},{"Momento":"2024-07-18T10:31:00.6991567-03:00","Protocolo":"Sen;#211;MD;1$\r","Enviado":false},{"Momento":"2024-07-18T10:31:00.8101669-03:00","Protocolo":"Sen;655;5;$\r","Enviado":false},{"Momento":"2024-07-18T10:31:00.8211646-03:00","Protocolo":"@6;Sen;293;LEDOP,1,0,0,0$","Enviado":true},{"Momento":"2024-07-18T10:31:00.8271713-03:00","Protocolo":"Sen;655;6;$\r","Enviado":false},{"Momento":"2024-07-18T10:31:00.8381669-03:00","Protocolo":"@7;Sen;293;LEDMN,1,0,0,0$","Enviado":true},{"Momento":"2024-07-18T10:31:00.8441708-03:00","Protocolo":"Sen;655;7;$\r","Enviado":false}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1 +0,0 @@
[{"Momento":"2024-07-18T08:38:22.4018863-03:00","Protocolo":"@1;Sen;258;LEDMN,1,0,4$","Enviado":true},{"Momento":"2024-07-18T08:38:22.4078872-03:00","Protocolo":"Sen;#211;LEDMN;1$\r","Enviado":false},{"Momento":"2024-07-18T08:38:22.4178858-03:00","Protocolo":"Sen;655;1;$\r","Enviado":false},{"Momento":"2024-07-18T08:38:22.4258877-03:00","Protocolo":"@2;Sen;258;LEDAT,1,0,16$","Enviado":true},{"Momento":"2024-07-18T08:38:22.4308861-03:00","Protocolo":"Sen;#211;LEDAT;1$\r","Enviado":false},{"Momento":"2024-07-18T08:38:22.4418871-03:00","Protocolo":"Sen;655;2;$\r","Enviado":false},{"Momento":"2024-07-18T08:38:22.4568857-03:00","Protocolo":"@3;Sen;258;LEDOP,1,0,17$","Enviado":true},{"Momento":"2024-07-18T08:38:22.4628866-03:00","Protocolo":"Sen;#211;LEDOP;1$\r","Enviado":false},{"Momento":"2024-07-18T08:38:22.4738886-03:00","Protocolo":"Sen;655;3;$\r","Enviado":false},{"Momento":"2024-07-18T08:38:22.4918878-03:00","Protocolo":"@4;Sen;258;MD,1,500,0,0,21,0,22,0,23$","Enviado":true},{"Momento":"2024-07-18T08:38:22.4998876-03:00","Protocolo":"Sen;#211;MD;1$\r","Enviado":false},{"Momento":"2024-07-18T08:38:22.6108868-03:00","Protocolo":"Sen;655;4;$\r","Enviado":false}

View File

@ -1 +0,0 @@
[{"Momento":"2024-07-18T12:42:12.0286033-03:00","Protocolo":"@1;Sen;258;LEDMN,1,0,4$","Enviado":true},{"Momento":"2024-07-18T12:42:12.0346045-03:00","Protocolo":"Sen;#211;LEDMN;1$\r","Enviado":false},{"Momento":"2024-07-18T12:42:12.0456036-03:00","Protocolo":"Sen;655;1;$\r","Enviado":false},{"Momento":"2024-07-18T12:42:12.0526028-03:00","Protocolo":"@2;Sen;258;LEDAT,1,0,16$","Enviado":true},{"Momento":"2024-07-18T12:42:12.0586044-03:00","Protocolo":"Sen;#211;LEDAT;1$\r","Enviado":false},{"Momento":"2024-07-18T12:42:12.0686041-03:00","Protocolo":"Sen;655;2;$\r","Enviado":false},{"Momento":"2024-07-18T12:42:12.0846044-03:00","Protocolo":"@3;Sen;258;LEDOP,1,0,17$","Enviado":true},{"Momento":"2024-07-18T12:42:12.0906058-03:00","Protocolo":"Sen;#211;LEDOP;1$\r","Enviado":false},{"Momento":"2024-07-18T12:42:12.1006054-03:00","Protocolo":"Sen;655;3;$\r","Enviado":false},{"Momento":"2024-07-18T12:42:12.1186045-03:00","Protocolo":"@4;Sen;258;RLLRA,1,0,23$","Enviado":true},{"Momento":"2024-07-18T12:42:12.1246054-03:00","Protocolo":"Sen;#211;RLLRA;1$\r","Enviado":false},{"Momento":"2024-07-18T12:42:12.1346036-03:00","Protocolo":"Sen;655;4;$\r","Enviado":false},{"Momento":"2024-07-18T12:42:12.149605-03:00","Protocolo":"@5;Sen;258;MD,1,500,0,0,21,0,22$","Enviado":true},{"Momento":"2024-07-18T12:42:12.1566038-03:00","Protocolo":"Sen;#211;MD;1$\r","Enviado":false},{"Momento":"2024-07-18T12:42:12.2667719-03:00","Protocolo":"Sen;655;5;$\r","Enviado":false},{"Momento":"2024-07-18T12:42:24.7971916-03:00","Protocolo":"@6;Sen;293;RLLRA,1$","Enviado":true},{"Momento":"2024-07-18T12:42:24.8021957-03:00","Protocolo":"Sen;655;6;$\r","Enviado":false},{"Momento":"2024-07-18T12:42:26.8207954-03:00","Protocolo":"@7;Sen;293;RLLRA,0$","Enviado":true},{"Momento":"2024-07-18T12:42:26.8258-03:00","Protocolo":"Sen;655;7;$\r","Enviado":false},{"Momento":"2024-07-18T12:44:51.055255-03:00","Protocolo":"@8;Sen;293;RLLRA,1$","Enviado":true},{"Momento":"2024-07-18T12:44:51.0602609-03:00","Protocolo":"Sen;655;8;$\r","Enviado":false}

View File

@ -1 +0,0 @@
[{"Momento":"2024-07-18T13:45:23.7007478-03:00","Protocolo":"@1;Sen;258;LEDMN,1,0,4$","Enviado":true},{"Momento":"2024-07-18T13:45:23.7077489-03:00","Protocolo":"Sen;#211;LEDMN;1$\r","Enviado":false},{"Momento":"2024-07-18T13:45:23.7187492-03:00","Protocolo":"Sen;655;1;$\r","Enviado":false},{"Momento":"2024-07-18T13:45:23.7257507-03:00","Protocolo":"@2;Sen;258;LEDAT,1,0,16$","Enviado":true},{"Momento":"2024-07-18T13:45:23.7307473-03:00","Protocolo":"Sen;#211;LEDAT;1$\r","Enviado":false},{"Momento":"2024-07-18T13:45:23.7417504-03:00","Protocolo":"Sen;655;2;$\r","Enviado":false},{"Momento":"2024-07-18T13:45:23.7577487-03:00","Protocolo":"@3;Sen;258;LEDOP,1,0,17$","Enviado":true},{"Momento":"2024-07-18T13:45:23.7637472-03:00","Protocolo":"Sen;#211;LEDOP;1$\r","Enviado":false},{"Momento":"2024-07-18T13:45:23.7747505-03:00","Protocolo":"Sen;655;3;$\r","Enviado":false},{"Momento":"2024-07-18T13:45:23.7917483-03:00","Protocolo":"@4;Sen;258;RLLRA,1,0,23$","Enviado":true},{"Momento":"2024-07-18T13:45:23.7967479-03:00","Protocolo":"Sen;#211;RLLRA;1$\r","Enviado":false},{"Momento":"2024-07-18T13:45:23.8077525-03:00","Protocolo":"Sen;655;4;$\r","Enviado":false},{"Momento":"2024-07-18T13:45:23.8227479-03:00","Protocolo":"@5;Sen;258;MD,1,500,0,0,21,0,22$","Enviado":true},{"Momento":"2024-07-18T13:45:23.8297478-03:00","Protocolo":"Sen;#211;MD;1$\r","Enviado":false},{"Momento":"2024-07-18T13:45:23.9407503-03:00","Protocolo":"Sen;655;5;$\r","Enviado":false}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1 +0,0 @@
[{"Momento":"2024-07-18T10:59:46.9597192-03:00","Protocolo":"@1;Sen;258;LEDMN,1,0,4$","Enviado":true},{"Momento":"2024-07-18T10:59:46.9667176-03:00","Protocolo":"Sen;#211;LEDMN;1$\r","Enviado":false},{"Momento":"2024-07-18T10:59:46.975715-03:00","Protocolo":"Sen;655;1;$\r","Enviado":false},{"Momento":"2024-07-18T10:59:46.9887134-03:00","Protocolo":"@2;Sen;258;LEDAT,1,0,16$","Enviado":true},{"Momento":"2024-07-18T10:59:46.9957155-03:00","Protocolo":"Sen;#211;LEDAT;1$\r","Enviado":false},{"Momento":"2024-07-18T10:59:47.0057171-03:00","Protocolo":"Sen;655;2;$\r","Enviado":false},{"Momento":"2024-07-18T10:59:47.0197132-03:00","Protocolo":"@3;Sen;258;LEDOP,1,0,17$","Enviado":true},{"Momento":"2024-07-18T10:59:47.0267164-03:00","Protocolo":"Sen;#211;LEDOP;1$\r","Enviado":false},{"Momento":"2024-07-18T10:59:47.0367162-03:00","Protocolo":"Sen;655;3;$\r","Enviado":false},{"Momento":"2024-07-18T10:59:47.0537162-03:00","Protocolo":"@4;Sen;258;RLLRA,1,0,23$","Enviado":true},{"Momento":"2024-07-18T10:59:47.060716-03:00","Protocolo":"Sen;#211;RLLRA;1$\r","Enviado":false},{"Momento":"2024-07-18T10:59:47.0707143-03:00","Protocolo":"Sen;655;4;$\r","Enviado":false},{"Momento":"2024-07-18T10:59:47.0857148-03:00","Protocolo":"@5;Sen;258;MD,1,500,0,0,21,0,22$","Enviado":true},{"Momento":"2024-07-18T10:59:47.0927151-03:00","Protocolo":"Sen;#211;MD;1$\r","Enviado":false},{"Momento":"2024-07-18T10:59:47.2037335-03:00","Protocolo":"Sen;655;5;$\r","Enviado":false},{"Momento":"2024-07-18T10:59:59.8146301-03:00","Protocolo":"@6;Sen;293;RLLRA,1$","Enviado":true},{"Momento":"2024-07-18T10:59:59.8200443-03:00","Protocolo":"Sen;655;6;$\r","Enviado":false},{"Momento":"2024-07-18T11:00:01.8483459-03:00","Protocolo":"@7;Sen;293;RLLRA,0$","Enviado":true},{"Momento":"2024-07-18T11:00:01.8533469-03:00","Protocolo":"Sen;655;7;$\r","Enviado":false},{"Momento":"2024-07-18T11:00:18.0009745-03:00","Protocolo":"@8;Sen;293;LEDMN,1,0,0,0$","Enviado":true},{"Momento":"2024-07-18T11:00:18.0059764-03:00","Protocolo":"Sen;655;8;$\r","Enviado":false},{"Momento":"2024-07-18T11:00:19.3602684-03:00","Protocolo":"@9;Sen;887;LEDMN,445,$","Enviado":true},{"Momento":"2024-07-18T11:00:19.3642682-03:00","Protocolo":"Sen;#445;LEDMN;1;1$\r","Enviado":false},{"Momento":"2024-07-18T11:00:19.3742676-03:00","Protocolo":"Sen;655;9;$\r","Enviado":false},{"Momento":"2024-07-18T11:00:20.362903-03:00","Protocolo":"@10;Sen;293;LEDMN,0,0,0,0$","Enviado":true},{"Momento":"2024-07-18T11:00:20.3679029-03:00","Protocolo":"Sen;655;10;$\r","Enviado":false},{"Momento":"2024-07-18T11:00:21.350307-03:00","Protocolo":"@11;Sen;887;LEDMN,445,$","Enviado":true},{"Momento":"2024-07-18T11:00:21.3573104-03:00","Protocolo":"Sen;#445;LEDMN;1;0$\r","Enviado":false},{"Momento":"2024-07-18T11:00:21.3673086-03:00","Protocolo":"Sen;655;11;$\r","Enviado":false}

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1 @@
{"type":"FeatureCollection","features":[{"type":"Feature","properties":{"Id":"1517","Name":"22_07_2024_17_00_05","Length":0.0,"Dist1":0.0,"Dist2":0.0},"geometry":{"id":null,"type":"LineString","coordinates":[[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0]]}}]}

View File

@ -0,0 +1 @@
{"type":"FeatureCollection","features":[{"type":"Feature","properties":{"Id":"1517","Name":"23_07_2024_13_59_37","Length":0.0,"Dist1":0.0,"Dist2":0.0},"geometry":{"id":null,"type":"LineString","coordinates":[[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0]]}}]}

View File

@ -0,0 +1 @@
{"type":"FeatureCollection","features":[{"type":"Feature","properties":{"Id":"1517","Name":"23_07_2024_14_12_05","Length":0.0,"Dist1":0.0,"Dist2":0.0},"geometry":{"id":null,"type":"LineString","coordinates":[[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0],[0.0,0.0]]}}]}

File diff suppressed because one or more lines are too long

View File

@ -1 +1 @@
{"Modulo_ID":"Atu","RequisitarDados":false,"Conectado":false,"QuantidadeBicos":4,"DensidadeHerbicida":1.05,"AtuacaoNivelAlto":true,"BicosPulverizadores":[{"ID":"B01","Posicao":1,"Atuado":false,"Comandar":true,"Inicializado":false,"Testando":false,"Funcoes":[21],"StatusBico":false,"MediaNivelFluxo":0.0},{"ID":"B02","Posicao":2,"Atuado":false,"Comandar":true,"Inicializado":false,"Testando":false,"Funcoes":[21],"StatusBico":false,"MediaNivelFluxo":0.0},{"ID":"B03","Posicao":3,"Atuado":false,"Comandar":true,"Inicializado":false,"Testando":false,"Funcoes":[21],"StatusBico":false,"MediaNivelFluxo":0.0},{"ID":"B04","Posicao":4,"Atuado":false,"Comandar":true,"Inicializado":false,"Testando":false,"Funcoes":[21],"StatusBico":false,"MediaNivelFluxo":0.0}],"BombaPressurizadora":{"ID":"BOMBA","BombaAtuada":false,"Ligado":false,"Comandar":true,"Inicializado":false,"Testando":false,"Funcoes":[14,35,36,37,5],"Pressao":0.0,"Potencia":0.0},"Sensores":[{"LogGrafico":[],"ID":"FLXLN","Prioridade":23,"Descricao":"Fluxo na linha principal","Componente":198,"Aferir":true,"DelayAmostragem":300,"Inicializado":false,"Testando":false,"Funcoes":[25],"Parametros":[],"UnidadeMedida":"mL/s","Leituras":[],"ValorMinimo":0.0,"ValorMaximo":0.0,"LimiteMaximo":0.0,"LimiteMinimo":0.0},{"LogGrafico":[],"ID":"MASRS","Prioridade":3,"Descricao":"Massa do reservatório de herbicida","Componente":532,"Aferir":true,"DelayAmostragem":1000,"Inicializado":false,"Testando":false,"Funcoes":[22,23],"Parametros":[],"UnidadeMedida":"Kg","Leituras":[],"ValorMinimo":0.0,"ValorMaximo":0.0,"LimiteMaximo":50.0,"LimiteMinimo":5.0},{"LogGrafico":[],"ID":"PRSLN","Prioridade":3,"Descricao":"Pressão na linha principal","Componente":333,"Aferir":true,"DelayAmostragem":1000,"Inicializado":false,"Testando":false,"Funcoes":[24],"Parametros":[["Vmin","000.00"],["Vmax","004.50"],["Pmax","174.04"]],"UnidadeMedida":"psi","Leituras":[],"ValorMinimo":0.0,"ValorMaximo":0.0,"LimiteMaximo":120.0,"LimiteMinimo":60.0}],"ScriptDeteccaoErvas":"weed-detector-v7.py","_MassaRef":0.8,"_MassaLeituraRef":40876.37,"_MassaLeituraExtra":1895800.0,"_MassaLeitura":0.0,"MassaReservatorio":37.103098929772877,"VolumeReservatorio":35.336284695021789,"PercentualReservatorio":117.78761565007262,"VolumeVazaoAferido":0.0,"_FluxoMlRef":102.0,"_FluxoPulsoRef":80.0,"_LeituraPulsos":0,"_LeituraPeriodo":0,"VazaoFluxoMLpS":0.0,"VolumeVazaoML":0.0,"_PressaoVmin":0.0,"_PressaoVmax":4.5,"_PressaoMax":174.045,"_LeituraPressao":0.0,"PressaoLinha":0.0,"PressaoLinhaCalc":0.0}
{"Modulo_ID":"Atu","RequisitarDados":false,"Conectado":false,"QuantidadeBicos":4,"DensidadeHerbicida":1.05,"AtuacaoNivelAlto":true,"BicosPulverizadores":[{"ID":"B01","Posicao":1,"Atuado":false,"Comandar":true,"Inicializado":false,"Testando":false,"Funcoes":[21],"StatusBico":false,"MediaNivelFluxo":0.0},{"ID":"B02","Posicao":2,"Atuado":false,"Comandar":true,"Inicializado":false,"Testando":false,"Funcoes":[21],"StatusBico":false,"MediaNivelFluxo":0.0},{"ID":"B03","Posicao":3,"Atuado":false,"Comandar":true,"Inicializado":false,"Testando":false,"Funcoes":[21],"StatusBico":false,"MediaNivelFluxo":0.0},{"ID":"B04","Posicao":4,"Atuado":false,"Comandar":true,"Inicializado":false,"Testando":false,"Funcoes":[21],"StatusBico":false,"MediaNivelFluxo":0.0}],"BombaPressurizadora":{"ID":"BOMBA","BombaAtuada":false,"Ligado":false,"Comandar":true,"Inicializado":false,"Testando":false,"Funcoes":[14,35,36,37,5],"Pressao":0.0,"Potencia":0.0},"Sensores":[{"LogGrafico":[],"ID":"FLXLN","Prioridade":23,"Descricao":"Fluxo na linha principal","Componente":198,"Aferir":true,"DelayAmostragem":300,"Inicializado":false,"Testando":false,"Funcoes":[25],"Parametros":[],"UnidadeMedida":"mL/s","Leituras":[],"ValorMinimo":0.0,"ValorMaximo":0.0,"LimiteMaximo":0.0,"LimiteMinimo":0.0},{"LogGrafico":[],"ID":"MASRS","Prioridade":3,"Descricao":"Massa do reservatório de herbicida","Componente":532,"Aferir":true,"DelayAmostragem":1000,"Inicializado":false,"Testando":false,"Funcoes":[22,23],"Parametros":[],"UnidadeMedida":"Kg","Leituras":[],"ValorMinimo":0.0,"ValorMaximo":0.0,"LimiteMaximo":50.0,"LimiteMinimo":5.0},{"LogGrafico":[],"ID":"PRSLN","Prioridade":3,"Descricao":"Pressão na linha principal","Componente":333,"Aferir":true,"DelayAmostragem":1000,"Inicializado":false,"Testando":false,"Funcoes":[24],"Parametros":[["Vmin","000.00"],["Vmax","004.50"],["Pmax","174.04"]],"UnidadeMedida":"psi","Leituras":[],"ValorMinimo":0.0,"ValorMaximo":0.0,"LimiteMaximo":120.0,"LimiteMinimo":60.0}],"ScriptDeteccaoErvas":"weed-detector-v7.py","_MassaRef":0.8,"_MassaLeituraRef":40876.37,"_MassaLeituraExtra":1895800.0,"_MassaLeitura":1895800.0,"MassaReservatorio":0.0,"VolumeReservatorio":0.0,"PercentualReservatorio":0.0,"VolumeVazaoAferido":0.0,"_FluxoMlRef":102.0,"_FluxoPulsoRef":80.0,"_LeituraPulsos":0,"_LeituraPeriodo":0,"VazaoFluxoMLpS":0.0,"VolumeVazaoML":0.0,"_PressaoVmin":0.0,"_PressaoVmax":4.5,"_PressaoMax":174.045,"_LeituraPressao":0.0,"PressaoLinha":0.0,"PressaoLinhaCalc":0.0}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1 +1 @@
{"ExpansorGPIO":false,"EnderecoExpansor":"","Pinos":[{"Controlador":1,"Barramento":0,"Pino":99,"Descricao":"1","Funcao":0,"Habilitado":false,"ComponenteID":""},{"Controlador":1,"Barramento":0,"Pino":98,"Descricao":"2","Funcao":0,"Habilitado":false,"ComponenteID":""},{"Controlador":1,"Barramento":0,"Pino":36,"Descricao":"3","Funcao":0,"Habilitado":true,"ComponenteID":""},{"Controlador":1,"Barramento":0,"Pino":39,"Descricao":"4","Funcao":0,"Habilitado":true,"ComponenteID":""},{"Controlador":1,"Barramento":0,"Pino":34,"Descricao":"5","Funcao":0,"Habilitado":true,"ComponenteID":""},{"Controlador":1,"Barramento":0,"Pino":35,"Descricao":"6","Funcao":0,"Habilitado":true,"ComponenteID":""},{"Controlador":1,"Barramento":0,"Pino":32,"Descricao":"7","Funcao":0,"Habilitado":true,"ComponenteID":""},{"Controlador":1,"Barramento":0,"Pino":33,"Descricao":"8","Funcao":0,"Habilitado":true,"ComponenteID":""},{"Controlador":1,"Barramento":0,"Pino":25,"Descricao":"9","Funcao":0,"Habilitado":true,"ComponenteID":""},{"Controlador":1,"Barramento":0,"Pino":26,"Descricao":"10","Funcao":0,"Habilitado":true,"ComponenteID":""},{"Controlador":1,"Barramento":0,"Pino":27,"Descricao":"11","Funcao":0,"Habilitado":true,"ComponenteID":""},{"Controlador":1,"Barramento":0,"Pino":14,"Descricao":"12","Funcao":0,"Habilitado":true,"ComponenteID":""},{"Controlador":1,"Barramento":0,"Pino":12,"Descricao":"13","Funcao":0,"Habilitado":true,"ComponenteID":""},{"Controlador":1,"Barramento":0,"Pino":97,"Descricao":"14","Funcao":0,"Habilitado":false,"ComponenteID":""},{"Controlador":1,"Barramento":0,"Pino":13,"Descricao":"15","Funcao":0,"Habilitado":true,"ComponenteID":""},{"Controlador":1,"Barramento":0,"Pino":9,"Descricao":"16","Funcao":0,"Habilitado":false,"ComponenteID":""},{"Controlador":1,"Barramento":0,"Pino":10,"Descricao":"17","Funcao":0,"Habilitado":false,"ComponenteID":""},{"Controlador":1,"Barramento":0,"Pino":11,"Descricao":"18","Funcao":0,"Habilitado":false,"ComponenteID":""},{"Controlador":1,"Barramento":0,"Pino":96,"Descricao":"19","Funcao":0,"Habilitado":false,"ComponenteID":""},{"Controlador":1,"Barramento":0,"Pino":6,"Descricao":"26","Funcao":0,"Habilitado":false,"ComponenteID":""},{"Controlador":1,"Barramento":0,"Pino":7,"Descricao":"27","Funcao":0,"Habilitado":false,"ComponenteID":""},{"Controlador":1,"Barramento":0,"Pino":8,"Descricao":"28","Funcao":0,"Habilitado":false,"ComponenteID":""},{"Controlador":1,"Barramento":0,"Pino":15,"Descricao":"29","Funcao":0,"Habilitado":true,"ComponenteID":""},{"Controlador":1,"Barramento":0,"Pino":2,"Descricao":"30","Funcao":0,"Habilitado":true,"ComponenteID":""},{"Controlador":1,"Barramento":0,"Pino":0,"Descricao":"31","Funcao":0,"Habilitado":true,"ComponenteID":""},{"Controlador":1,"Barramento":0,"Pino":4,"Descricao":"32","Funcao":38,"Habilitado":true,"ComponenteID":"LEDMN"},{"Controlador":1,"Barramento":0,"Pino":16,"Descricao":"33","Funcao":38,"Habilitado":true,"ComponenteID":"LEDAT"},{"Controlador":1,"Barramento":0,"Pino":17,"Descricao":"34","Funcao":38,"Habilitado":true,"ComponenteID":"LEDOP"},{"Controlador":1,"Barramento":0,"Pino":5,"Descricao":"35","Funcao":0,"Habilitado":true,"ComponenteID":""},{"Controlador":1,"Barramento":0,"Pino":18,"Descricao":"36","Funcao":0,"Habilitado":true,"ComponenteID":""},{"Controlador":1,"Barramento":0,"Pino":19,"Descricao":"37","Funcao":0,"Habilitado":true,"ComponenteID":""},{"Controlador":1,"Barramento":0,"Pino":95,"Descricao":"38","Funcao":0,"Habilitado":false,"ComponenteID":""},{"Controlador":1,"Barramento":0,"Pino":21,"Descricao":"39","Funcao":33,"Habilitado":true,"ComponenteID":"Sen"},{"Controlador":1,"Barramento":0,"Pino":3,"Descricao":"40","Funcao":0,"Habilitado":false,"ComponenteID":""},{"Controlador":1,"Barramento":0,"Pino":1,"Descricao":"41","Funcao":0,"Habilitado":false,"ComponenteID":""},{"Controlador":1,"Barramento":0,"Pino":22,"Descricao":"42","Funcao":34,"Habilitado":true,"ComponenteID":"Sen"},{"Controlador":1,"Barramento":0,"Pino":23,"Descricao":"43","Funcao":26,"Habilitado":true,"ComponenteID":"RLLRA"},{"Controlador":1,"Barramento":0,"Pino":94,"Descricao":"44","Funcao":0,"Habilitado":false,"ComponenteID":""}]}
{"ExpansorGPIO":false,"EnderecoExpansor":"","Pinos":[{"Controlador":1,"Barramento":0,"Pino":99,"Descricao":"1","Funcao":0,"Habilitado":false,"ComponenteID":""},{"Controlador":1,"Barramento":0,"Pino":98,"Descricao":"2","Funcao":0,"Habilitado":false,"ComponenteID":""},{"Controlador":1,"Barramento":0,"Pino":36,"Descricao":"3","Funcao":12,"Habilitado":true,"ComponenteID":"TMVET"},{"Controlador":1,"Barramento":0,"Pino":39,"Descricao":"4","Funcao":12,"Habilitado":true,"ComponenteID":"TMVEF"},{"Controlador":1,"Barramento":0,"Pino":34,"Descricao":"5","Funcao":12,"Habilitado":true,"ComponenteID":"TMVDT"},{"Controlador":1,"Barramento":0,"Pino":35,"Descricao":"6","Funcao":12,"Habilitado":true,"ComponenteID":"TMVDF"},{"Controlador":1,"Barramento":0,"Pino":32,"Descricao":"7","Funcao":45,"Habilitado":true,"ComponenteID":"FRO_ET"},{"Controlador":1,"Barramento":0,"Pino":33,"Descricao":"8","Funcao":0,"Habilitado":true,"ComponenteID":""},{"Controlador":1,"Barramento":0,"Pino":25,"Descricao":"9","Funcao":45,"Habilitado":true,"ComponenteID":"FRO_DT"},{"Controlador":1,"Barramento":0,"Pino":26,"Descricao":"10","Funcao":0,"Habilitado":true,"ComponenteID":""},{"Controlador":1,"Barramento":0,"Pino":27,"Descricao":"11","Funcao":0,"Habilitado":true,"ComponenteID":""},{"Controlador":1,"Barramento":0,"Pino":14,"Descricao":"12","Funcao":0,"Habilitado":true,"ComponenteID":""},{"Controlador":1,"Barramento":0,"Pino":12,"Descricao":"13","Funcao":0,"Habilitado":true,"ComponenteID":""},{"Controlador":1,"Barramento":0,"Pino":97,"Descricao":"14","Funcao":0,"Habilitado":false,"ComponenteID":""},{"Controlador":1,"Barramento":0,"Pino":13,"Descricao":"15","Funcao":0,"Habilitado":true,"ComponenteID":""},{"Controlador":1,"Barramento":0,"Pino":9,"Descricao":"16","Funcao":0,"Habilitado":false,"ComponenteID":""},{"Controlador":1,"Barramento":0,"Pino":10,"Descricao":"17","Funcao":0,"Habilitado":false,"ComponenteID":""},{"Controlador":1,"Barramento":0,"Pino":11,"Descricao":"18","Funcao":0,"Habilitado":false,"ComponenteID":""},{"Controlador":1,"Barramento":0,"Pino":96,"Descricao":"19","Funcao":0,"Habilitado":false,"ComponenteID":""},{"Controlador":1,"Barramento":0,"Pino":6,"Descricao":"26","Funcao":0,"Habilitado":false,"ComponenteID":""},{"Controlador":1,"Barramento":0,"Pino":7,"Descricao":"27","Funcao":0,"Habilitado":false,"ComponenteID":""},{"Controlador":1,"Barramento":0,"Pino":8,"Descricao":"28","Funcao":0,"Habilitado":false,"ComponenteID":""},{"Controlador":1,"Barramento":0,"Pino":15,"Descricao":"29","Funcao":0,"Habilitado":true,"ComponenteID":""},{"Controlador":1,"Barramento":0,"Pino":2,"Descricao":"30","Funcao":0,"Habilitado":true,"ComponenteID":""},{"Controlador":1,"Barramento":0,"Pino":0,"Descricao":"31","Funcao":0,"Habilitado":true,"ComponenteID":""},{"Controlador":1,"Barramento":0,"Pino":4,"Descricao":"32","Funcao":38,"Habilitado":true,"ComponenteID":"LEDMN"},{"Controlador":1,"Barramento":0,"Pino":16,"Descricao":"33","Funcao":38,"Habilitado":true,"ComponenteID":"LEDAT"},{"Controlador":1,"Barramento":0,"Pino":17,"Descricao":"34","Funcao":38,"Habilitado":true,"ComponenteID":"LEDOP"},{"Controlador":1,"Barramento":0,"Pino":5,"Descricao":"35","Funcao":0,"Habilitado":true,"ComponenteID":""},{"Controlador":1,"Barramento":0,"Pino":18,"Descricao":"36","Funcao":0,"Habilitado":true,"ComponenteID":""},{"Controlador":1,"Barramento":0,"Pino":19,"Descricao":"37","Funcao":0,"Habilitado":true,"ComponenteID":""},{"Controlador":1,"Barramento":0,"Pino":95,"Descricao":"38","Funcao":0,"Habilitado":false,"ComponenteID":""},{"Controlador":1,"Barramento":0,"Pino":21,"Descricao":"39","Funcao":33,"Habilitado":true,"ComponenteID":"Sen"},{"Controlador":1,"Barramento":0,"Pino":3,"Descricao":"40","Funcao":0,"Habilitado":false,"ComponenteID":""},{"Controlador":1,"Barramento":0,"Pino":1,"Descricao":"41","Funcao":0,"Habilitado":false,"ComponenteID":""},{"Controlador":1,"Barramento":0,"Pino":22,"Descricao":"42","Funcao":34,"Habilitado":true,"ComponenteID":"Sen"},{"Controlador":1,"Barramento":0,"Pino":23,"Descricao":"43","Funcao":26,"Habilitado":true,"ComponenteID":"RLLRA"},{"Controlador":1,"Barramento":0,"Pino":94,"Descricao":"44","Funcao":0,"Habilitado":false,"ComponenteID":""}]}

File diff suppressed because one or more lines are too long

View File

@ -25,7 +25,7 @@
<meta name="viewport" content="width=device-width,
initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<style>
#map_c9c1ab5892aff8d9c826bc4f4046e077 {
#map_b31ec6c46295a93816d012b677435bed {
position: relative;
width: 100.0%;
height: 100.0%;
@ -39,14 +39,14 @@
<body>
<div class="folium-map" id="map_c9c1ab5892aff8d9c826bc4f4046e077" ></div>
<div class="folium-map" id="map_b31ec6c46295a93816d012b677435bed" ></div>
</body>
<script>
var map_c9c1ab5892aff8d9c826bc4f4046e077 = L.map(
"map_c9c1ab5892aff8d9c826bc4f4046e077",
var map_b31ec6c46295a93816d012b677435bed = L.map(
"map_b31ec6c46295a93816d012b677435bed",
{
center: [0.0, 0.0],
crs: L.CRS.EPSG3857,
@ -60,13 +60,13 @@
var tile_layer_dbb350a72df19d23428934428aae795b = L.tileLayer(
var tile_layer_2b280f3b467b982ed24f52c1e8f8d3f1 = L.tileLayer(
"https://tile.openstreetmap.org/{z}/{x}/{y}.png",
{"attribution": "\u0026copy; \u003ca href=\"https://www.openstreetmap.org/copyright\"\u003eOpenStreetMap\u003c/a\u003e contributors", "detectRetina": false, "maxNativeZoom": 19, "maxZoom": 19, "minZoom": 0, "noWrap": false, "opacity": 1, "subdomains": "abc", "tms": false}
);
tile_layer_dbb350a72df19d23428934428aae795b.addTo(map_c9c1ab5892aff8d9c826bc4f4046e077);
tile_layer_2b280f3b467b982ed24f52c1e8f8d3f1.addTo(map_b31ec6c46295a93816d012b677435bed);
</script>
@ -87,7 +87,7 @@
}
trajeto_json_add({"features": []});
trajeto_json.addTo(map_c9c1ab5892aff8d9c826bc4f4046e077);
trajeto_json.addTo(map_b31ec6c46295a93816d012b677435bed);
function adicionarGeometria(novaGeometria) {
trajeto_json.addData(novaGeometria);
@ -145,7 +145,7 @@
var marcadorDinamico = L.marker([0, 0], {
icon: customIcon
}).addTo(map_c9c1ab5892aff8d9c826bc4f4046e077);
}).addTo(map_b31ec6c46295a93816d012b677435bed);
// Conectar ao broker MQTT
const client = mqtt.connect('ws://localhost:9001'); // Use wss para conexão segura
@ -183,7 +183,7 @@
marcadorDinamico.setRotationAngle(angulo);
adicionarCoordenada("Tj", [novaLongitude, novaLatitude]);
map_c9c1ab5892aff8d9c826bc4f4046e077.setView(novaPosicao, map_c9c1ab5892aff8d9c826bc4f4046e077.getZoom());
map_b31ec6c46295a93816d012b677435bed.setView(novaPosicao, map_b31ec6c46295a93816d012b677435bed.getZoom());
});
function calcularOrientacao(P1latitude, P1longitude, P2latitude, P2longitude) {

File diff suppressed because one or more lines are too long

Binary file not shown.

View File

@ -0,0 +1,564 @@
/*!
* @file Adafruit_INA219.cpp
*
* @mainpage Adafruit INA219 current/power monitor IC
*
* @section intro_sec Introduction
*
* Driver for the INA219 current sensor
*
* This is a library for the Adafruit INA219 breakout
* ----> https://www.adafruit.com/product/904
*
* Adafruit invests time and resources providing this open source code,
* please support Adafruit and open-source hardware by purchasing
* products from Adafruit!
*
* @section author Author
*
* Written by Bryan Siepert and Kevin "KTOWN" Townsend for Adafruit Industries.
*
* @section license License
*
* BSD license, all text here must be included in any redistribution.
*
*/
#include "Arduino.h"
#include <Wire.h>
#include "Adafruit_INA219.h"
/*!
* @brief Instantiates a new INA219 class
* @param addr the I2C address the device can be found on. Default is 0x40
*/
Adafruit_INA219::Adafruit_INA219(uint8_t addr) {
ina219_i2caddr = addr;
ina219_currentDivider_mA = 0;
ina219_powerMultiplier_mW = 0.0f;
}
/*!
* @brief INA219 class destructor
*/
Adafruit_INA219::~Adafruit_INA219() { delete i2c_dev; }
/*!
* @brief Sets up the HW (defaults to 32V and 2A for calibration values)
* @param theWire the TwoWire object to use
* @return true: success false: Failed to start I2C
*/
bool Adafruit_INA219::begin(TwoWire *theWire) {
if (!i2c_dev) {
i2c_dev = new Adafruit_I2CDevice(ina219_i2caddr, theWire);
}
if (!i2c_dev->begin()) {
return false;
}
init();
return true;
}
/*!
* @brief begin I2C and set up the hardware
*/
void Adafruit_INA219::init() {
// Set chip to large range config values to start
setCalibration_32V_2A();
}
/*!
* @brief Gets the raw bus voltage (16-bit signed integer, so +-32767)
* @return the raw bus voltage reading
*/
int16_t Adafruit_INA219::getBusVoltage_raw() {
uint16_t value;
Adafruit_BusIO_Register bus_voltage_reg =
Adafruit_BusIO_Register(i2c_dev, INA219_REG_BUSVOLTAGE, 2, MSBFIRST);
_success = bus_voltage_reg.read(&value);
// Shift to the right 3 to drop CNVR and OVF and multiply by LSB
return (int16_t)((value >> 3) * 4);
}
/*!
* @brief Gets the raw shunt voltage (16-bit signed integer, so +-32767)
* @return the raw shunt voltage reading
*/
int16_t Adafruit_INA219::getShuntVoltage_raw() {
uint16_t value;
Adafruit_BusIO_Register shunt_voltage_reg =
Adafruit_BusIO_Register(i2c_dev, INA219_REG_SHUNTVOLTAGE, 2, MSBFIRST);
_success = shunt_voltage_reg.read(&value);
return value;
}
/*!
* @brief Gets the raw current value (16-bit signed integer, so +-32767)
* @return the raw current reading
*/
int16_t Adafruit_INA219::getCurrent_raw() {
uint16_t value;
// Sometimes a sharp load will reset the INA219, which will
// reset the cal register, meaning CURRENT and POWER will
// not be available ... avoid this by always setting a cal
// value even if it's an unfortunate extra step
Adafruit_BusIO_Register calibration_reg =
Adafruit_BusIO_Register(i2c_dev, INA219_REG_CALIBRATION, 2, MSBFIRST);
calibration_reg.write(ina219_calValue, 2);
// Now we can safely read the CURRENT register!
Adafruit_BusIO_Register current_reg =
Adafruit_BusIO_Register(i2c_dev, INA219_REG_CURRENT, 2, MSBFIRST);
_success = current_reg.read(&value);
return value;
}
/*!
* @brief Gets the raw power value (16-bit signed integer, so +-32767)
* @return raw power reading
*/
int16_t Adafruit_INA219::getPower_raw() {
uint16_t value;
// Sometimes a sharp load will reset the INA219, which will
// reset the cal register, meaning CURRENT and POWER will
// not be available ... avoid this by always setting a cal
// value even if it's an unfortunate extra step
Adafruit_BusIO_Register calibration_reg =
Adafruit_BusIO_Register(i2c_dev, INA219_REG_CALIBRATION, 2, MSBFIRST);
calibration_reg.write(ina219_calValue, 2);
// Now we can safely read the POWER register!
Adafruit_BusIO_Register power_reg =
Adafruit_BusIO_Register(i2c_dev, INA219_REG_POWER, 2, MSBFIRST);
_success = power_reg.read(&value);
return value;
}
/*!
* @brief Gets the shunt voltage in mV (so +-327mV)
* @return the shunt voltage converted to millivolts
*/
float Adafruit_INA219::getShuntVoltage_mV() {
int16_t value;
value = getShuntVoltage_raw();
return value * 0.01;
}
/*!
* @brief Gets the bus voltage in volts
* @return the bus voltage converted to volts
*/
float Adafruit_INA219::getBusVoltage_V() {
int16_t value = getBusVoltage_raw();
return value * 0.001;
}
/*!
* @brief Gets the current value in mA, taking into account the
* config settings and current LSB
* @return the current reading convereted to milliamps
*/
float Adafruit_INA219::getCurrent_mA() {
float valueDec = getCurrent_raw();
valueDec /= ina219_currentDivider_mA;
return valueDec;
}
/*!
* @brief Gets the power value in mW, taking into account the
* config settings and current LSB
* @return power reading converted to milliwatts
*/
float Adafruit_INA219::getPower_mW() {
float valueDec = getPower_raw();
valueDec *= ina219_powerMultiplier_mW;
return valueDec;
}
/*!
* @brief Configures to INA219 to be able to measure up to 32V and 2A
* of current. Each unit of current corresponds to 100uA, and
* each unit of power corresponds to 2mW. Counter overflow
* occurs at 3.2A.
* @note These calculations assume a 0.1 ohm resistor is present
*/
void Adafruit_INA219::setCalibration_32V_2A() {
// By default we use a pretty huge range for the input voltage,
// which probably isn't the most appropriate choice for system
// that don't use a lot of power. But all of the calculations
// are shown below if you want to change the settings. You will
// also need to change any relevant register settings, such as
// setting the VBUS_MAX to 16V instead of 32V, etc.
// VBUS_MAX = 32V (Assumes 32V, can also be set to 16V)
// VSHUNT_MAX = 0.32 (Assumes Gain 8, 320mV, can also be 0.16, 0.08,
// 0.04) RSHUNT = 0.1 (Resistor value in ohms)
// 1. Determine max possible current
// MaxPossible_I = VSHUNT_MAX / RSHUNT
// MaxPossible_I = 3.2A
// 2. Determine max expected current
// MaxExpected_I = 2.0A
// 3. Calculate possible range of LSBs (Min = 15-bit, Max = 12-bit)
// MinimumLSB = MaxExpected_I/32767
// MinimumLSB = 0.000061 (61uA per bit)
// MaximumLSB = MaxExpected_I/4096
// MaximumLSB = 0,000488 (488uA per bit)
// 4. Choose an LSB between the min and max values
// (Preferrably a roundish number close to MinLSB)
// CurrentLSB = 0.0001 (100uA per bit)
// 5. Compute the calibration register
// Cal = trunc (0.04096 / (Current_LSB * RSHUNT))
// Cal = 4096 (0x1000)
ina219_calValue = 4096;
// 6. Calculate the power LSB
// PowerLSB = 20 * CurrentLSB
// PowerLSB = 0.002 (2mW per bit)
// 7. Compute the maximum current and shunt voltage values before overflow
//
// Max_Current = Current_LSB * 32767
// Max_Current = 3.2767A before overflow
//
// If Max_Current > Max_Possible_I then
// Max_Current_Before_Overflow = MaxPossible_I
// Else
// Max_Current_Before_Overflow = Max_Current
// End If
//
// Max_ShuntVoltage = Max_Current_Before_Overflow * RSHUNT
// Max_ShuntVoltage = 0.32V
//
// If Max_ShuntVoltage >= VSHUNT_MAX
// Max_ShuntVoltage_Before_Overflow = VSHUNT_MAX
// Else
// Max_ShuntVoltage_Before_Overflow = Max_ShuntVoltage
// End If
// 8. Compute the Maximum Power
// MaximumPower = Max_Current_Before_Overflow * VBUS_MAX
// MaximumPower = 3.2 * 32V
// MaximumPower = 102.4W
// Set multipliers to convert raw current/power values
ina219_currentDivider_mA = 10; // Current LSB = 100uA per bit (1000/100 = 10)
ina219_powerMultiplier_mW = 2; // Power LSB = 1mW per bit (2/1)
// Set Calibration register to 'Cal' calculated above
Adafruit_BusIO_Register calibration_reg =
Adafruit_BusIO_Register(i2c_dev, INA219_REG_CALIBRATION, 2, MSBFIRST);
calibration_reg.write(ina219_calValue, 2);
// Set Config register to take into account the settings above
uint16_t config = INA219_CONFIG_BVOLTAGERANGE_32V |
INA219_CONFIG_GAIN_8_320MV | INA219_CONFIG_BADCRES_12BIT |
INA219_CONFIG_SADCRES_12BIT_1S_532US |
INA219_CONFIG_MODE_SANDBVOLT_CONTINUOUS;
Adafruit_BusIO_Register config_reg =
Adafruit_BusIO_Register(i2c_dev, INA219_REG_CONFIG, 2, MSBFIRST);
_success = config_reg.write(config, 2);
}
/*!
* @brief Configures to INA219 to be able to measure up to 32V and 100A
* of current. Each unit of current corresponds to 100uA, and
* each unit of power corresponds to 2mW. Counter overflow
* occurs at 100A.
* @note These calculations assume a 0.1 ohm resistor is present
*/
void Adafruit_INA219::setCalibration_100A_75mV() {
// Configuração para shunt de 100A 75mV
// VBUS_MAX = 32V (Assumes 32V, pode ser ajustado para 16V)
// VSHUNT_MAX = 0.075V (75mV no shunt de 100A)
// RSHUNT = 0.00075Ω (Resistor shunt de 100A 75mV, 75mV / 100A = 0.00075Ω)
// 1. Determine max possível de corrente
// MaxPossible_I = VSHUNT_MAX / RSHUNT
// MaxPossible_I = 0.075 / 0.00075
// MaxPossible_I = 100A
// 2. Determine max corrente esperada
// MaxExpected_I = 100A
// 3. Calcular o range possível de LSBs (Min = 15-bit, Max = 12-bit)
// MinimumLSB = MaxExpected_I / 32767
// MinimumLSB = 100 / 32767
// MinimumLSB = 0.0030518 (3.0518mA por bit)
// MaximumLSB = MaxExpected_I / 4096
// MaximumLSB = 100 / 4096
// MaximumLSB = 0.02441 (24.41mA por bit)
// 4. Escolher um LSB entre os valores min e max
// (Preferencialmente um número arredondado próximo ao MinimumLSB)
// CurrentLSB = 0.01 (10mA por bit)
// 5. Calcular o registrador de calibração
// Cal = trunc (0.04096 / (Current_LSB * RSHUNT))
// Cal = trunc (0.04096 / (0.01 * 0.00075))
// Cal = trunc (0.04096 / 0.0000075)
// Cal = 5461.33 (arredondado para 5461)
ina219_calValue = 5461;
// 6. Calcular o Power LSB
// PowerLSB = 20 * CurrentLSB
// PowerLSB = 20 * 0.01
// PowerLSB = 0.2 (200mW por bit)
// 7. Calcular os valores máximos de corrente e tensão de shunt antes do overflow
// Max_Current = Current_LSB * 32767
// Max_Current = 0.01 * 32767
// Max_Current = 327.67A (limite teórico, mas nosso shunt é limitado a 100A)
// Max_ShuntVoltage = Max_Current * RSHUNT
// Max_ShuntVoltage = 327.67 * 0.00075
// Max_ShuntVoltage = 0.245V (mas nosso VSHUNT_MAX é 75mV)
// 8. Calcular o máximo de potência
// MaximumPower = Max_Current * VBUS_MAX
// MaximumPower = 100A * 32V
// MaximumPower = 3200W
// Definir multiplicadores para converter valores brutos de corrente/potência
ina219_currentDivider_mA = 100; // Current LSB = 10mA por bit (1000 / 10 = 100)
ina219_powerMultiplier_mW = 0.2; // Power LSB = 200mW por bit
// Definir o registrador de calibração com o valor calculado
Adafruit_BusIO_Register calibration_reg = Adafruit_BusIO_Register(i2c_dev, INA219_REG_CALIBRATION, 2, MSBFIRST);
calibration_reg.write(ina219_calValue, 2);
// Definir o registrador de configuração considerando as configurações acima
uint16_t config = INA219_CONFIG_BVOLTAGERANGE_32V |
INA219_CONFIG_GAIN_8_320MV |
INA219_CONFIG_BADCRES_12BIT |
INA219_CONFIG_SADCRES_12BIT_1S_532US |
INA219_CONFIG_MODE_SANDBVOLT_CONTINUOUS;
Adafruit_BusIO_Register config_reg = Adafruit_BusIO_Register(i2c_dev, INA219_REG_CONFIG, 2, MSBFIRST);
_success = config_reg.write(config, 2);
}
/*!
* @brief Set power save mode according to parameters
* @param on
* boolean value
*/
void Adafruit_INA219::powerSave(bool on) {
Adafruit_BusIO_Register config_reg =
Adafruit_BusIO_Register(i2c_dev, INA219_REG_CONFIG, 2, MSBFIRST);
Adafruit_BusIO_RegisterBits mode_bits =
Adafruit_BusIO_RegisterBits(&config_reg, 3, 0);
if (on) {
_success = mode_bits.write(INA219_CONFIG_MODE_POWERDOWN);
} else {
_success = mode_bits.write(INA219_CONFIG_MODE_SANDBVOLT_CONTINUOUS);
}
}
/*!
* @brief Configures to INA219 to be able to measure up to 32V and 1A
* of current. Each unit of current corresponds to 40uA, and each
* unit of power corresponds to 800uW. Counter overflow occurs at
* 1.3A.
* @note These calculations assume a 0.1 ohm resistor is present
*/
void Adafruit_INA219::setCalibration_32V_1A() {
// By default we use a pretty huge range for the input voltage,
// which probably isn't the most appropriate choice for system
// that don't use a lot of power. But all of the calculations
// are shown below if you want to change the settings. You will
// also need to change any relevant register settings, such as
// setting the VBUS_MAX to 16V instead of 32V, etc.
// VBUS_MAX = 32V (Assumes 32V, can also be set to 16V)
// VSHUNT_MAX = 0.32 (Assumes Gain 8, 320mV, can also be 0.16, 0.08, 0.04)
// RSHUNT = 0.1 (Resistor value in ohms)
// 1. Determine max possible current
// MaxPossible_I = VSHUNT_MAX / RSHUNT
// MaxPossible_I = 3.2A
// 2. Determine max expected current
// MaxExpected_I = 1.0A
// 3. Calculate possible range of LSBs (Min = 15-bit, Max = 12-bit)
// MinimumLSB = MaxExpected_I/32767
// MinimumLSB = 0.0000305 (30.5uA per bit)
// MaximumLSB = MaxExpected_I/4096
// MaximumLSB = 0.000244 (244uA per bit)
// 4. Choose an LSB between the min and max values
// (Preferrably a roundish number close to MinLSB)
// CurrentLSB = 0.0000400 (40uA per bit)
// 5. Compute the calibration register
// Cal = trunc (0.04096 / (Current_LSB * RSHUNT))
// Cal = 10240 (0x2800)
ina219_calValue = 10240;
// 6. Calculate the power LSB
// PowerLSB = 20 * CurrentLSB
// PowerLSB = 0.0008 (800uW per bit)
// 7. Compute the maximum current and shunt voltage values before overflow
//
// Max_Current = Current_LSB * 32767
// Max_Current = 1.31068A before overflow
//
// If Max_Current > Max_Possible_I then
// Max_Current_Before_Overflow = MaxPossible_I
// Else
// Max_Current_Before_Overflow = Max_Current
// End If
//
// ... In this case, we're good though since Max_Current is less than
// MaxPossible_I
//
// Max_ShuntVoltage = Max_Current_Before_Overflow * RSHUNT
// Max_ShuntVoltage = 0.131068V
//
// If Max_ShuntVoltage >= VSHUNT_MAX
// Max_ShuntVoltage_Before_Overflow = VSHUNT_MAX
// Else
// Max_ShuntVoltage_Before_Overflow = Max_ShuntVoltage
// End If
// 8. Compute the Maximum Power
// MaximumPower = Max_Current_Before_Overflow * VBUS_MAX
// MaximumPower = 1.31068 * 32V
// MaximumPower = 41.94176W
// Set multipliers to convert raw current/power values
ina219_currentDivider_mA = 25; // Current LSB = 40uA per bit (1000/40 = 25)
ina219_powerMultiplier_mW = 0.8f; // Power LSB = 800uW per bit
// Set Calibration register to 'Cal' calculated above
Adafruit_BusIO_Register calibration_reg =
Adafruit_BusIO_Register(i2c_dev, INA219_REG_CALIBRATION, 2, MSBFIRST);
calibration_reg.write(ina219_calValue, 2);
// Set Config register to take into account the settings above
uint16_t config = INA219_CONFIG_BVOLTAGERANGE_32V |
INA219_CONFIG_GAIN_8_320MV | INA219_CONFIG_BADCRES_12BIT |
INA219_CONFIG_SADCRES_12BIT_1S_532US |
INA219_CONFIG_MODE_SANDBVOLT_CONTINUOUS;
Adafruit_BusIO_Register config_reg =
Adafruit_BusIO_Register(i2c_dev, INA219_REG_CONFIG, 2, MSBFIRST);
_success = config_reg.write(config, 2);
}
/*!
* @brief set device to alibration which uses the highest precision for
* current measurement (0.1mA), at the expense of
* only supporting 16V at 400mA max.
*/
void Adafruit_INA219::setCalibration_16V_400mA() {
// Calibration which uses the highest precision for
// current measurement (0.1mA), at the expense of
// only supporting 16V at 400mA max.
// VBUS_MAX = 16V
// VSHUNT_MAX = 0.04 (Assumes Gain 1, 40mV)
// RSHUNT = 0.1 (Resistor value in ohms)
// 1. Determine max possible current
// MaxPossible_I = VSHUNT_MAX / RSHUNT
// MaxPossible_I = 0.4A
// 2. Determine max expected current
// MaxExpected_I = 0.4A
// 3. Calculate possible range of LSBs (Min = 15-bit, Max = 12-bit)
// MinimumLSB = MaxExpected_I/32767
// MinimumLSB = 0.0000122 (12uA per bit)
// MaximumLSB = MaxExpected_I/4096
// MaximumLSB = 0.0000977 (98uA per bit)
// 4. Choose an LSB between the min and max values
// (Preferrably a roundish number close to MinLSB)
// CurrentLSB = 0.00005 (50uA per bit)
// 5. Compute the calibration register
// Cal = trunc (0.04096 / (Current_LSB * RSHUNT))
// Cal = 8192 (0x2000)
ina219_calValue = 8192;
// 6. Calculate the power LSB
// PowerLSB = 20 * CurrentLSB
// PowerLSB = 0.001 (1mW per bit)
// 7. Compute the maximum current and shunt voltage values before overflow
//
// Max_Current = Current_LSB * 32767
// Max_Current = 1.63835A before overflow
//
// If Max_Current > Max_Possible_I then
// Max_Current_Before_Overflow = MaxPossible_I
// Else
// Max_Current_Before_Overflow = Max_Current
// End If
//
// Max_Current_Before_Overflow = MaxPossible_I
// Max_Current_Before_Overflow = 0.4
//
// Max_ShuntVoltage = Max_Current_Before_Overflow * RSHUNT
// Max_ShuntVoltage = 0.04V
//
// If Max_ShuntVoltage >= VSHUNT_MAX
// Max_ShuntVoltage_Before_Overflow = VSHUNT_MAX
// Else
// Max_ShuntVoltage_Before_Overflow = Max_ShuntVoltage
// End If
//
// Max_ShuntVoltage_Before_Overflow = VSHUNT_MAX
// Max_ShuntVoltage_Before_Overflow = 0.04V
// 8. Compute the Maximum Power
// MaximumPower = Max_Current_Before_Overflow * VBUS_MAX
// MaximumPower = 0.4 * 16V
// MaximumPower = 6.4W
// Set multipliers to convert raw current/power values
ina219_currentDivider_mA = 20; // Current LSB = 50uA per bit (1000/50 = 20)
ina219_powerMultiplier_mW = 1.0f; // Power LSB = 1mW per bit
// Set Calibration register to 'Cal' calculated above
Adafruit_BusIO_Register calibration_reg =
Adafruit_BusIO_Register(i2c_dev, INA219_REG_CALIBRATION, 2, MSBFIRST);
calibration_reg.write(ina219_calValue, 2);
// Set Config register to take into account the settings above
uint16_t config = INA219_CONFIG_BVOLTAGERANGE_16V |
INA219_CONFIG_GAIN_1_40MV | INA219_CONFIG_BADCRES_12BIT |
INA219_CONFIG_SADCRES_12BIT_1S_532US |
INA219_CONFIG_MODE_SANDBVOLT_CONTINUOUS;
Adafruit_BusIO_Register config_reg =
Adafruit_BusIO_Register(i2c_dev, INA219_REG_CONFIG, 2, MSBFIRST);
_success = config_reg.write(config, 2);
}
/*!
* @brief Provides the the underlying return value from the last operation
* called on the device.
* @return true: Last operation was successful false: Last operation failed
* @note For function calls that have intermediary device operations,
* e.g. calibration before read/write, only the final operation's
* result is stored.
*/
bool Adafruit_INA219::success() { return _success; }

View File

@ -0,0 +1,199 @@
/*!
* @file Adafruit_INA219.h
*
* This is a library for the Adafruit INA219 breakout board
* ----> https://www.adafruit.com/product/904
*
* Adafruit invests time and resources providing this open source code,
* please support Adafruit and open-source hardware by purchasing
* products from Adafruit!
*
* Written by Bryan Siepert and Kevin "KTOWN" Townsend for Adafruit Industries.
*
* BSD license, all text here must be included in any redistribution.
*
*/
#ifndef _LIB_ADAFRUIT_INA219_
#define _LIB_ADAFRUIT_INA219_
#include "Arduino.h"
#include <Adafruit_BusIO_Register.h>
#include <Adafruit_I2CDevice.h>
#include <Wire.h>
/** calculated I2C address: 0 = GND, 1 = V+ **/
/* The address is controlled by the A0 and A1 inputs on the INA219:
*
* Calculated address: b100ABCD
* A0 controls C and D: GND = 00, V+ = 01, SDA = 10, SCL = 11
* A1 controls A and B: GND = 00, V+ = 01, SDA = 10, SCL = 11
*
* E.g. if A0 is tied to ground and A1 is tied to V+,
* the resulting address is b1000100 = 0x44
*
* SDA and SCL options aren't implemented.
*/
#define INA219_CALC_ADDRESS(INA_ADDR0, INA_ADDR1) \
(0x40 | (INA_ADDR0 != 0 ? 0x01 : 0x00) | (INA_ADDR1 != 0 ? 0x04 : 0x00))
/** default I2C address **/
#define INA219_ADDRESS (0x40) // 1000000 (A0+A1=GND)
/** read **/
#define INA219_READ (0x01)
/*=========================================================================
CONFIG REGISTER (R/W)
**************************************************************************/
/** config register address **/
#define INA219_REG_CONFIG (0x00)
/** reset bit **/
#define INA219_CONFIG_RESET (0x8000) // Reset Bit
/** mask for bus voltage range **/
#define INA219_CONFIG_BVOLTAGERANGE_MASK (0x2000) // Bus Voltage Range Mask
/** bus voltage range values **/
enum {
INA219_CONFIG_BVOLTAGERANGE_16V = (0x0000), // 0-16V Range
INA219_CONFIG_BVOLTAGERANGE_32V = (0x2000), // 0-32V Range
};
/** mask for gain bits **/
#define INA219_CONFIG_GAIN_MASK (0x1800) // Gain Mask
/** values for gain bits **/
enum {
INA219_CONFIG_GAIN_1_40MV = (0x0000), // Gain 1, 40mV Range
INA219_CONFIG_GAIN_2_80MV = (0x0800), // Gain 2, 80mV Range
INA219_CONFIG_GAIN_4_160MV = (0x1000), // Gain 4, 160mV Range
INA219_CONFIG_GAIN_8_320MV = (0x1800), // Gain 8, 320mV Range
};
/** mask for bus ADC resolution bits **/
#define INA219_CONFIG_BADCRES_MASK (0x0780)
/** values for bus ADC resolution **/
enum {
INA219_CONFIG_BADCRES_9BIT = (0x0000), // 9-bit bus res = 0..511
INA219_CONFIG_BADCRES_10BIT = (0x0080), // 10-bit bus res = 0..1023
INA219_CONFIG_BADCRES_11BIT = (0x0100), // 11-bit bus res = 0..2047
INA219_CONFIG_BADCRES_12BIT = (0x0180), // 12-bit bus res = 0..4097
INA219_CONFIG_BADCRES_12BIT_2S_1060US =
(0x0480), // 2 x 12-bit bus samples averaged together
INA219_CONFIG_BADCRES_12BIT_4S_2130US =
(0x0500), // 4 x 12-bit bus samples averaged together
INA219_CONFIG_BADCRES_12BIT_8S_4260US =
(0x0580), // 8 x 12-bit bus samples averaged together
INA219_CONFIG_BADCRES_12BIT_16S_8510US =
(0x0600), // 16 x 12-bit bus samples averaged together
INA219_CONFIG_BADCRES_12BIT_32S_17MS =
(0x0680), // 32 x 12-bit bus samples averaged together
INA219_CONFIG_BADCRES_12BIT_64S_34MS =
(0x0700), // 64 x 12-bit bus samples averaged together
INA219_CONFIG_BADCRES_12BIT_128S_69MS =
(0x0780), // 128 x 12-bit bus samples averaged together
};
/** mask for shunt ADC resolution bits **/
#define INA219_CONFIG_SADCRES_MASK \
(0x0078) // Shunt ADC Resolution and Averaging Mask
/** values for shunt ADC resolution **/
enum {
INA219_CONFIG_SADCRES_9BIT_1S_84US = (0x0000), // 1 x 9-bit shunt sample
INA219_CONFIG_SADCRES_10BIT_1S_148US = (0x0008), // 1 x 10-bit shunt sample
INA219_CONFIG_SADCRES_11BIT_1S_276US = (0x0010), // 1 x 11-bit shunt sample
INA219_CONFIG_SADCRES_12BIT_1S_532US = (0x0018), // 1 x 12-bit shunt sample
INA219_CONFIG_SADCRES_12BIT_2S_1060US =
(0x0048), // 2 x 12-bit shunt samples averaged together
INA219_CONFIG_SADCRES_12BIT_4S_2130US =
(0x0050), // 4 x 12-bit shunt samples averaged together
INA219_CONFIG_SADCRES_12BIT_8S_4260US =
(0x0058), // 8 x 12-bit shunt samples averaged together
INA219_CONFIG_SADCRES_12BIT_16S_8510US =
(0x0060), // 16 x 12-bit shunt samples averaged together
INA219_CONFIG_SADCRES_12BIT_32S_17MS =
(0x0068), // 32 x 12-bit shunt samples averaged together
INA219_CONFIG_SADCRES_12BIT_64S_34MS =
(0x0070), // 64 x 12-bit shunt samples averaged together
INA219_CONFIG_SADCRES_12BIT_128S_69MS =
(0x0078), // 128 x 12-bit shunt samples averaged together
};
/** mask for operating mode bits **/
#define INA219_CONFIG_MODE_MASK (0x0007) // Operating Mode Mask
/** values for operating mode **/
enum {
INA219_CONFIG_MODE_POWERDOWN = 0x00, /**< power down */
INA219_CONFIG_MODE_SVOLT_TRIGGERED = 0x01, /**< shunt voltage triggered */
INA219_CONFIG_MODE_BVOLT_TRIGGERED = 0x02, /**< bus voltage triggered */
INA219_CONFIG_MODE_SANDBVOLT_TRIGGERED =
0x03, /**< shunt and bus voltage triggered */
INA219_CONFIG_MODE_ADCOFF = 0x04, /**< ADC off */
INA219_CONFIG_MODE_SVOLT_CONTINUOUS = 0x05, /**< shunt voltage continuous */
INA219_CONFIG_MODE_BVOLT_CONTINUOUS = 0x06, /**< bus voltage continuous */
INA219_CONFIG_MODE_SANDBVOLT_CONTINUOUS =
0x07, /**< shunt and bus voltage continuous */
};
/** shunt voltage register **/
#define INA219_REG_SHUNTVOLTAGE (0x01)
/** bus voltage register **/
#define INA219_REG_BUSVOLTAGE (0x02)
/** power register **/
#define INA219_REG_POWER (0x03)
/** current register **/
#define INA219_REG_CURRENT (0x04)
/** calibration register **/
#define INA219_REG_CALIBRATION (0x05)
/*!
* @brief Class that stores state and functions for interacting with INA219
* current/power monitor IC
*/
class Adafruit_INA219 {
public:
Adafruit_INA219(uint8_t addr = INA219_ADDRESS);
~Adafruit_INA219();
bool begin(TwoWire *theWire = &Wire);
void setCalibration_32V_2A();
void setCalibration_32V_1A();
void setCalibration_16V_400mA();
void setCalibration_100A_75mV();
float getBusVoltage_V();
float getShuntVoltage_mV();
float getCurrent_mA();
float getPower_mW();
void powerSave(bool on);
bool success();
private:
Adafruit_I2CDevice *i2c_dev = NULL;
bool _success;
uint8_t ina219_i2caddr = -1;
uint32_t ina219_calValue;
// The following multipliers are used to convert raw current and power
// values to mA and mW, taking into account the current config settings
uint32_t ina219_currentDivider_mA;
float ina219_powerMultiplier_mW;
void init();
int16_t getBusVoltage_raw();
int16_t getShuntVoltage_raw();
int16_t getCurrent_raw();
int16_t getPower_raw();
};
#endif

View File

@ -0,0 +1,16 @@
# Adafruit INA219 Library [![Build Status](https://github.com/adafruit/Adafruit_INA219/workflows/Arduino%20Library%20CI/badge.svg)](https://github.com/adafruit/Adafruit_INA219/actions)[![Documentation](https://github.com/adafruit/ci-arduino/blob/master/assets/doxygen_badge.svg)](http://adafruit.github.io/Adafruit_INA219/html/index.html)
<a href="https://www.adafruit.com/products/904"><img src="assets/board.jpg" width="500px" /></a>
This is a library for the Adafruit INA219 high side DC current sensor boards:
* https://www.adafruit.com/products/904
* https://www.adafruit.com/product/3650
Check out the links above for our tutorials and wiring diagrams. This chip uses I2C to communicate.
To install, use the Arduino Library Manager and search for 'Adafruit INA219' and install the library.
Adafruit invests time and resources providing this open source code, please support Adafruit and open-source hardware by purchasing products from Adafruit!
Written by Ktown for Adafruit Industries.
MIT license, all text above must be included in any redistribution

Binary file not shown.

After

Width:  |  Height:  |  Size: 252 KiB

View File

@ -0,0 +1,127 @@
# Adafruit Community Code of Conduct
## Our Pledge
In the interest of fostering an open and welcoming environment, we as
contributors and leaders pledge to making participation in our project and
our community a harassment-free experience for everyone, regardless of age, body
size, disability, ethnicity, gender identity and expression, level or type of
experience, education, socio-economic status, nationality, personal appearance,
race, religion, or sexual identity and orientation.
## Our Standards
We are committed to providing a friendly, safe and welcoming environment for
all.
Examples of behavior that contributes to creating a positive environment
include:
* Be kind and courteous to others
* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Collaborating with other community members
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members
Examples of unacceptable behavior by participants include:
* The use of sexualized language or imagery and sexual attention or advances
* The use of inappropriate images, including in a community member's avatar
* The use of inappropriate language, including in a community member's nickname
* Any spamming, flaming, baiting or other attention-stealing behavior
* Excessive or unwelcome helping; answering outside the scope of the question
asked
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic
address, without explicit permission
* Other conduct which could reasonably be considered inappropriate
The goal of the standards and moderation guidelines outlined here is to build
and maintain a respectful community. We ask that you dont just aim to be
"technically unimpeachable", but rather try to be your best self.
We value many things beyond technical expertise, including collaboration and
supporting others within our community. Providing a positive experience for
other community members can have a much more significant impact than simply
providing the correct answer.
## Our Responsibilities
Project leaders are responsible for clarifying the standards of acceptable
behavior and are expected to take appropriate and fair corrective action in
response to any instances of unacceptable behavior.
Project leaders have the right and responsibility to remove, edit, or
reject messages, comments, commits, code, issues, and other contributions
that are not aligned to this Code of Conduct, or to ban temporarily or
permanently any community member for other behaviors that they deem
inappropriate, threatening, offensive, or harmful.
## Moderation
Instances of behaviors that violate the Adafruit Community Code of Conduct
may be reported by any member of the community. Community members are
encouraged to report these situations, including situations they witness
involving other community members.
You may report in the following ways:
In any situation, you may send an email to <support@adafruit.com>.
On the Adafruit Discord, you may send an open message from any channel
to all Community Helpers by tagging @community helpers. You may also send an
open message from any channel, or a direct message to @kattni#1507,
@tannewt#4653, @Dan Halbert#1614, @cater#2442, @sommersoft#0222, or
@Andon#8175.
Email and direct message reports will be kept confidential.
In situations on Discord where the issue is particularly egregious, possibly
illegal, requires immediate action, or violates the Discord terms of service,
you should also report the message directly to Discord.
These are the steps for upholding our communitys standards of conduct.
1. Any member of the community may report any situation that violates the
Adafruit Community Code of Conduct. All reports will be reviewed and
investigated.
2. If the behavior is an egregious violation, the community member who
committed the violation may be banned immediately, without warning.
3. Otherwise, moderators will first respond to such behavior with a warning.
4. Moderators follow a soft "three strikes" policy - the community member may
be given another chance, if they are receptive to the warning and change their
behavior.
5. If the community member is unreceptive or unreasonable when warned by a
moderator, or the warning goes unheeded, they may be banned for a first or
second offense. Repeated offenses will result in the community member being
banned.
## Scope
This Code of Conduct and the enforcement policies listed above apply to all
Adafruit Community venues. This includes but is not limited to any community
spaces (both public and private), the entire Adafruit Discord server, and
Adafruit GitHub repositories. Examples of Adafruit Community spaces include
but are not limited to meet-ups, audio chats on the Adafruit Discord, or
interaction at a conference.
This Code of Conduct applies both within project spaces and in public spaces
when an individual is representing the project or its community. As a community
member, you are representing our community, and are expected to behave
accordingly.
## Attribution
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
version 1.4, available at
<https://www.contributor-covenant.org/version/1/4/code-of-conduct.html>,
and the [Rust Code of Conduct](https://www.rust-lang.org/en-US/conduct.html).
For other projects adopting the Adafruit Community Code of
Conduct, please contact the maintainers of those projects for enforcement.
If you wish to use this code of conduct for your own project, consider
explicitly mentioning your moderation policy or making a copy with your
own moderation policy so as to avoid confusion.

View File

@ -0,0 +1,54 @@
#include <Wire.h>
#include <Adafruit_INA219.h>
Adafruit_INA219 ina219;
void setup(void)
{
Serial.begin(115200);
while (!Serial) {
// will pause Zero, Leonardo, etc until serial console opens
delay(1);
}
Serial.println("Hello!");
// Initialize the INA219.
// By default the initialization will use the largest range (32V, 2A). However
// you can call a setCalibration function to change this range (see comments).
if (! ina219.begin()) {
Serial.println("Failed to find INA219 chip");
while (1) { delay(10); }
}
// To use a slightly lower 32V, 1A range (higher precision on amps):
//ina219.setCalibration_32V_1A();
// Or to use a lower 16V, 400mA range (higher precision on volts and amps):
//ina219.setCalibration_16V_400mA();
Serial.println("Measuring voltage and current with INA219 ...");
}
void loop(void)
{
float shuntvoltage = 0;
float busvoltage = 0;
float current_mA = 0;
float loadvoltage = 0;
float power_mW = 0;
shuntvoltage = ina219.getShuntVoltage_mV();
busvoltage = ina219.getBusVoltage_V();
current_mA = ina219.getCurrent_mA();
power_mW = ina219.getPower_mW();
loadvoltage = busvoltage + (shuntvoltage / 1000);
Serial.print("Bus Voltage: "); Serial.print(busvoltage); Serial.println(" V");
Serial.print("Shunt Voltage: "); Serial.print(shuntvoltage); Serial.println(" mV");
Serial.print("Load Voltage: "); Serial.print(loadvoltage); Serial.println(" V");
Serial.print("Current: "); Serial.print(current_mA); Serial.println(" mA");
Serial.print("Power: "); Serial.print(power_mW); Serial.println(" mW");
Serial.println("");
delay(2000);
}

View File

@ -0,0 +1,262 @@
// Feather Power Meter
//
// Small Feather-based power monitor using an INA219 breakout and
// monochrome OLED display.
//
// Author: Tony DiCola (modded by ladyada)
//
// Released under a MIT license: http://opensource.org/licenses/MIT
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_NeoPixel.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <Adafruit_INA219.h>
// Configure orientation of the display.
// 0 = none, 1 = 90 degrees clockwise, 2 = 180 degrees, 3 = 270 degrees CW
#define ROTATION 0
#define NEO_PIN 6
// Create NeoPixel, OLED and INA219 globals.
Adafruit_SSD1306 display;
Adafruit_INA219 ina219;
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(144, NEO_PIN, NEO_GRB + NEO_KHZ800);
// Keep track of total time and milliamp measurements for milliamp-hour computation.
uint32_t total_sec = 0;
float total_mA = 0.0;
uint8_t counter = 0;
void pixel_show_and_powerupdate() {
pixels.show();
if (counter == 0) {
update_power_display();
} else {
counter = (counter+1) % 10 ;
}
}
void setup() {
Serial.begin(115200);
while (!Serial) {
// will pause Zero, Leonardo, etc until serial console opens
delay(1);
}
pixels.begin();
pixels.show(); // Initialize all pixels to 'off'
// Try to initialize the INA219
if (! ina219.begin()) {
Serial.println("Failed to find INA219 chip");
while (1) { delay(10); }
}
// By default the INA219 will be calibrated with a range of 32V, 2A.
// However uncomment one of the below to change the range. A smaller
// range can't measure as large of values but will measure with slightly
// better precision.
//ina219.setCalibration_32V_1A();
//ina219.setCalibration_16V_400mA();
// Setup the OLED display.
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
Wire.setClock(400000);
// Clear the display.
display.clearDisplay();
display.display();
// Set rotation.
display.setRotation(ROTATION);
// Set text size and color.
display.setTextSize(2);
display.setTextColor(WHITE);
}
void loop() {
// Some example procedures showing how to display to the pixels:
colorWipe(pixels.Color(255, 0, 0), 50); // Red
colorWipe(pixels.Color(0, 255, 0), 50); // Green
colorWipe(pixels.Color(0, 0, 255), 50); // Blue
//colorWipe(pixels.Color(0, 0, 0, 255), 50); // White RGBW
// Send a theater pixel chase in...
theaterChase(pixels.Color(127, 127, 127), 50); // White
theaterChase(pixels.Color(127, 0, 0), 50); // Red
theaterChase(pixels.Color(0, 0, 127), 50); // Blue
rainbow(20);
rainbowCycle(20);
theaterChaseRainbow(50);
}
// Fill the dots one after the other with a color
void colorWipe(uint32_t c, uint8_t wait) {
for(uint16_t i=0; i<pixels.numPixels(); i++) {
pixels.setPixelColor(i, c);
pixel_show_and_powerupdate();
delay(wait);
}
}
void rainbow(uint8_t wait) {
uint16_t i, j;
for(j=0; j<256; j++) {
for(i=0; i<pixels.numPixels(); i++) {
pixels.setPixelColor(i, Wheel((i+j) & 255));
}
pixel_show_and_powerupdate();
delay(wait);
}
}
// Slightly different, this makes the rainbow equally distributed throughout
void rainbowCycle(uint8_t wait) {
uint16_t i, j;
for(j=0; j<256*5; j++) { // 5 cycles of all colors on wheel
for(i=0; i< pixels.numPixels(); i++) {
pixels.setPixelColor(i, Wheel(((i * 256 / pixels.numPixels()) + j) & 255));
}
pixel_show_and_powerupdate();
delay(wait);
}
}
//Theatre-style crawling lights.
void theaterChase(uint32_t c, uint8_t wait) {
for (int j=0; j<10; j++) { //do 10 cycles of chasing
for (int q=0; q < 3; q++) {
for (uint16_t i=0; i < pixels.numPixels(); i=i+3) {
pixels.setPixelColor(i+q, c); //turn every third pixel on
}
pixel_show_and_powerupdate();
delay(wait);
for (uint16_t i=0; i < pixels.numPixels(); i=i+3) {
pixels.setPixelColor(i+q, 0); //turn every third pixel off
}
}
}
}
//Theatre-style crawling lights with rainbow effect
void theaterChaseRainbow(uint8_t wait) {
for (int j=0; j < 256; j++) { // cycle all 256 colors in the wheel
for (int q=0; q < 3; q++) {
for (uint16_t i=0; i < pixels.numPixels(); i=i+3) {
pixels.setPixelColor(i+q, Wheel( (i+j) % 255)); //turn every third pixel on
}
pixel_show_and_powerupdate();
delay(wait);
for (uint16_t i=0; i < pixels.numPixels(); i=i+3) {
pixels.setPixelColor(i+q, 0); //turn every third pixel off
}
}
}
}
// Input a value 0 to 255 to get a color value.
// The colours are a transition r - g - b - back to r.
uint32_t Wheel(byte WheelPos) {
WheelPos = 255 - WheelPos;
if(WheelPos < 85) {
return pixels.Color(255 - WheelPos * 3, 0, WheelPos * 3);
}
if(WheelPos < 170) {
WheelPos -= 85;
return pixels.Color(0, WheelPos * 3, 255 - WheelPos * 3);
}
WheelPos -= 170;
return pixels.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
}
void update_power_display() {
// Read voltage and current from INA219.
float shuntvoltage = ina219.getShuntVoltage_mV();
float busvoltage = ina219.getBusVoltage_V();
float current_mA = ina219.getCurrent_mA();
// Compute load voltage, power, and milliamp-hours.
float loadvoltage = busvoltage + (shuntvoltage / 1000);
float power_mW = loadvoltage * current_mA;
(void)power_mW;
total_mA += current_mA;
total_sec += 1;
float total_mAH = total_mA / 3600.0;
(void)total_mAH;
// Update display.
display.clearDisplay();
display.setCursor(0,0);
// Mode 0, display volts and amps.
printSIValue(loadvoltage, "V:", 2, 10);
display.setCursor(0, 16);
printSIValue(current_mA/1000.0, "A:", 5, 10);
display.display();
}
void printSIValue(float value, const char* units, int precision, int maxWidth) {
// Print a value in SI units with the units left justified and value right justified.
// Will switch to milli prefix if value is below 1.
// Add milli prefix if low value.
if (fabs(value) < 1.0) {
display.print('m');
maxWidth -= 1;
value *= 1000.0;
precision = max(0, precision-3);
}
// Print units.
display.print(units);
maxWidth -= strlen(units);
// Leave room for negative sign if value is negative.
if (value < 0.0) {
maxWidth -= 1;
}
// Find how many digits are in value.
int digits = ceil(log10(fabs(value)));
if (fabs(value) < 1.0) {
digits = 1; // Leave room for 0 when value is below 0.
}
// Handle if not enough width to display value, just print dashes.
if (digits > maxWidth) {
// Fill width with dashes (and add extra dash for negative values);
for (int i=0; i < maxWidth; ++i) {
display.print('-');
}
if (value < 0.0) {
display.print('-');
}
return;
}
// Compute actual precision for printed value based on space left after
// printing digits and decimal point. Clamp within 0 to desired precision.
int actualPrecision = constrain(maxWidth-digits-1, 0, precision);
// Compute how much padding to add to right justify.
int padding = maxWidth-digits-1-actualPrecision;
for (int i=0; i < padding; ++i) {
display.print(' ');
}
// Finally, print the value!
display.print(value, actualPrecision);
}

Some files were not shown because too many files have changed in this diff Show More