ajustes de parametros dos sensores

This commit is contained in:
Diego Freitas 2024-01-23 14:10:34 -03:00
parent 4f13738426
commit c963625920
33 changed files with 1560 additions and 357 deletions

Binary file not shown.

View File

@ -240,6 +240,12 @@
<Compile Include="Forms\Sensoriamento\frmSenCamera.Designer.cs"> <Compile Include="Forms\Sensoriamento\frmSenCamera.Designer.cs">
<DependentUpon>frmSenCamera.cs</DependentUpon> <DependentUpon>frmSenCamera.cs</DependentUpon>
</Compile> </Compile>
<Compile Include="Forms\Sensoriamento\frmSenConfig.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Forms\Sensoriamento\frmSenConfig.Designer.cs">
<DependentUpon>frmSenConfig.cs</DependentUpon>
</Compile>
<Compile Include="Models\CameraModel.cs" /> <Compile Include="Models\CameraModel.cs" />
<Compile Include="Models\GPSModel.cs" /> <Compile Include="Models\GPSModel.cs" />
<Compile Include="Models\MapasModel.cs" /> <Compile Include="Models\MapasModel.cs" />
@ -316,6 +322,9 @@
<EmbeddedResource Include="Forms\Sensoriamento\frmSenCamera.resx"> <EmbeddedResource Include="Forms\Sensoriamento\frmSenCamera.resx">
<DependentUpon>frmSenCamera.cs</DependentUpon> <DependentUpon>frmSenCamera.cs</DependentUpon>
</EmbeddedResource> </EmbeddedResource>
<EmbeddedResource Include="Forms\Sensoriamento\frmSenConfig.resx">
<DependentUpon>frmSenConfig.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Properties\Resources.resx"> <EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator> <Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput> <LastGenOutput>Resources.Designer.cs</LastGenOutput>

View File

@ -0,0 +1,114 @@
namespace AgroBase.Forms.Sensoriamento
{
partial class frmSenConfig
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.gridsTEN = new System.Windows.Forms.DataGridView();
this.gridsCOR = new System.Windows.Forms.DataGridView();
this.btnSalvar = new System.Windows.Forms.Button();
this.lblTensao = new System.Windows.Forms.Label();
this.lblCorrente = new System.Windows.Forms.Label();
((System.ComponentModel.ISupportInitialize)(this.gridsTEN)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.gridsCOR)).BeginInit();
this.SuspendLayout();
//
// gridsTEN
//
this.gridsTEN.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.gridsTEN.Location = new System.Drawing.Point(12, 25);
this.gridsTEN.Name = "gridsTEN";
this.gridsTEN.Size = new System.Drawing.Size(270, 124);
this.gridsTEN.TabIndex = 1;
//
// gridsCOR
//
this.gridsCOR.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.gridsCOR.Location = new System.Drawing.Point(288, 25);
this.gridsCOR.Name = "gridsCOR";
this.gridsCOR.Size = new System.Drawing.Size(270, 124);
this.gridsCOR.TabIndex = 1;
//
// btnSalvar
//
this.btnSalvar.Location = new System.Drawing.Point(483, 155);
this.btnSalvar.Name = "btnSalvar";
this.btnSalvar.Size = new System.Drawing.Size(75, 23);
this.btnSalvar.TabIndex = 3;
this.btnSalvar.Text = "Salvar";
this.btnSalvar.UseVisualStyleBackColor = true;
this.btnSalvar.Click += new System.EventHandler(this.btnSalvar_Click);
//
// lblTensao
//
this.lblTensao.AutoSize = true;
this.lblTensao.Location = new System.Drawing.Point(12, 9);
this.lblTensao.Name = "lblTensao";
this.lblTensao.Size = new System.Drawing.Size(43, 13);
this.lblTensao.TabIndex = 4;
this.lblTensao.Text = "Tensão";
//
// lblCorrente
//
this.lblCorrente.AutoSize = true;
this.lblCorrente.Location = new System.Drawing.Point(285, 9);
this.lblCorrente.Name = "lblCorrente";
this.lblCorrente.Size = new System.Drawing.Size(47, 13);
this.lblCorrente.TabIndex = 5;
this.lblCorrente.Text = "Corrente";
//
// frmSenConfig
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(571, 188);
this.Controls.Add(this.lblCorrente);
this.Controls.Add(this.lblTensao);
this.Controls.Add(this.gridsCOR);
this.Controls.Add(this.gridsTEN);
this.Controls.Add(this.btnSalvar);
this.MaximizeBox = false;
this.Name = "frmSenConfig";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Sensoriamento - Parametrização";
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.frmSenConfig_FormClosing);
this.Load += new System.EventHandler(this.frmSenConfig_Load);
((System.ComponentModel.ISupportInitialize)(this.gridsTEN)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.gridsCOR)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.DataGridView gridsTEN;
private System.Windows.Forms.DataGridView gridsCOR;
private System.Windows.Forms.Button btnSalvar;
private System.Windows.Forms.Label lblTensao;
private System.Windows.Forms.Label lblCorrente;
}
}

View File

@ -0,0 +1,88 @@
using AgroBase.Comum;
using AgroBase.Models;
using AgroBase.Models.Modules;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using static AgroBase.Models.Enuns;
namespace AgroBase.Forms.Sensoriamento
{
public partial class frmSenConfig : Form
{
DispositivosService<SensoriamentoModel> Disp = (DispositivosService<SensoriamentoModel>)Variaveis.DispositivosConectados.FirstOrDefault(x => x.Dispositivo == T_Code.Sen);
public frmSenConfig()
{
InitializeComponent();
}
private void frmSenConfig_Load(object sender, EventArgs e)
{
if (Disp == null)
{
return;
}
foreach (var Sensor in Disp.Dados.Sensores)
{
string gridName = "grid" + Enum.GetName(typeof(S_Code), Sensor.Componente);
DataGridView grid = this.Controls.OfType<DataGridView>().ToList().FirstOrDefault(x => x.Name == gridName);
if (grid != null)
{
grid.Rows.Clear();
grid.Columns.Clear();
grid.Columns.Add("clParametro", "Parâmetro");
grid.Columns.Add("clValor", "Valor");
foreach (var Parametro in Sensor.Parametros)
{
grid.Rows.Add(Parametro[0], Parametro[1]);
}
//grid.Rows.RemoveAt(grid.Rows.Count - 1);
}
}
}
private void frmSenConfig_FormClosing(object sender, FormClosingEventArgs e)
{
e.Cancel = true;
this.Visible = false;
}
private void btnSalvar_Click(object sender, EventArgs e)
{
if (Disp == null)
{
return;
}
foreach (var Sensor in Disp.Dados.Sensores)
{
string gridName = "grid" + Enum.GetName(typeof(S_Code), Sensor.Componente);
DataGridView grid = this.Controls.OfType<DataGridView>().ToList().FirstOrDefault(x => x.Name == gridName);
if (grid != null && grid.Rows.Count > 1)
{
Sensor.Parametros = new List<string[]>();
foreach (DataGridViewRow Row in grid.Rows)
{
if (Row.Cells[0].Value != null)
{
Sensor.Parametros.Add(new string[] { Row.Cells[0].Value.ToString(), Row.Cells[1].Value.ToString() });
}
}
}
}
}
}
}

View File

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -124,6 +124,8 @@ namespace AgroBase.Forms
this.btnEFReferenciar = new System.Windows.Forms.Button(); this.btnEFReferenciar = new System.Windows.Forms.Button();
this.lblM1 = new System.Windows.Forms.Label(); this.lblM1 = new System.Windows.Forms.Label();
this.picEF = new System.Windows.Forms.PictureBox(); this.picEF = new System.Windows.Forms.PictureBox();
this.lblCorrente = new System.Windows.Forms.Label();
this.lblTensao = new System.Windows.Forms.Label();
this.pnlFundo.SuspendLayout(); this.pnlFundo.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.chartET)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.chartET)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.chartDT)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.chartDT)).BeginInit();
@ -140,6 +142,8 @@ namespace AgroBase.Forms
// //
this.pnlFundo.AutoScroll = true; this.pnlFundo.AutoScroll = true;
this.pnlFundo.BackColor = System.Drawing.Color.White; this.pnlFundo.BackColor = System.Drawing.Color.White;
this.pnlFundo.Controls.Add(this.lblCorrente);
this.pnlFundo.Controls.Add(this.lblTensao);
this.pnlFundo.Controls.Add(this.lblDistanciaParcial); this.pnlFundo.Controls.Add(this.lblDistanciaParcial);
this.pnlFundo.Controls.Add(this.lblDistanciaTotal); this.pnlFundo.Controls.Add(this.lblDistanciaTotal);
this.pnlFundo.Controls.Add(this.lblTempoEmMovimento); this.pnlFundo.Controls.Add(this.lblTempoEmMovimento);
@ -223,7 +227,7 @@ namespace AgroBase.Forms
this.pnlFundo.Controls.Add(this.picEF); this.pnlFundo.Controls.Add(this.picEF);
this.pnlFundo.Dock = System.Windows.Forms.DockStyle.Fill; this.pnlFundo.Dock = System.Windows.Forms.DockStyle.Fill;
this.pnlFundo.Location = new System.Drawing.Point(0, 0); this.pnlFundo.Location = new System.Drawing.Point(0, 0);
this.pnlFundo.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); this.pnlFundo.Margin = new System.Windows.Forms.Padding(2);
this.pnlFundo.Name = "pnlFundo"; this.pnlFundo.Name = "pnlFundo";
this.pnlFundo.Size = new System.Drawing.Size(1484, 749); this.pnlFundo.Size = new System.Drawing.Size(1484, 749);
this.pnlFundo.TabIndex = 0; this.pnlFundo.TabIndex = 0;
@ -272,7 +276,7 @@ namespace AgroBase.Forms
// //
this.chbDTLivre.AutoSize = true; this.chbDTLivre.AutoSize = true;
this.chbDTLivre.Location = new System.Drawing.Point(784, 725); this.chbDTLivre.Location = new System.Drawing.Point(784, 725);
this.chbDTLivre.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); this.chbDTLivre.Margin = new System.Windows.Forms.Padding(2);
this.chbDTLivre.Name = "chbDTLivre"; this.chbDTLivre.Name = "chbDTLivre";
this.chbDTLivre.Size = new System.Drawing.Size(49, 17); this.chbDTLivre.Size = new System.Drawing.Size(49, 17);
this.chbDTLivre.TabIndex = 166; this.chbDTLivre.TabIndex = 166;
@ -283,7 +287,7 @@ namespace AgroBase.Forms
// //
this.chbDTControlar.AutoSize = true; this.chbDTControlar.AutoSize = true;
this.chbDTControlar.Location = new System.Drawing.Point(764, 703); this.chbDTControlar.Location = new System.Drawing.Point(764, 703);
this.chbDTControlar.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); this.chbDTControlar.Margin = new System.Windows.Forms.Padding(2);
this.chbDTControlar.Name = "chbDTControlar"; this.chbDTControlar.Name = "chbDTControlar";
this.chbDTControlar.Size = new System.Drawing.Size(68, 17); this.chbDTControlar.Size = new System.Drawing.Size(68, 17);
this.chbDTControlar.TabIndex = 165; this.chbDTControlar.TabIndex = 165;
@ -294,7 +298,7 @@ namespace AgroBase.Forms
// //
this.chbETLivre.AutoSize = true; this.chbETLivre.AutoSize = true;
this.chbETLivre.Location = new System.Drawing.Point(639, 725); this.chbETLivre.Location = new System.Drawing.Point(639, 725);
this.chbETLivre.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); this.chbETLivre.Margin = new System.Windows.Forms.Padding(2);
this.chbETLivre.Name = "chbETLivre"; this.chbETLivre.Name = "chbETLivre";
this.chbETLivre.Size = new System.Drawing.Size(49, 17); this.chbETLivre.Size = new System.Drawing.Size(49, 17);
this.chbETLivre.TabIndex = 164; this.chbETLivre.TabIndex = 164;
@ -305,7 +309,7 @@ namespace AgroBase.Forms
// //
this.chbETControlar.AutoSize = true; this.chbETControlar.AutoSize = true;
this.chbETControlar.Location = new System.Drawing.Point(639, 703); this.chbETControlar.Location = new System.Drawing.Point(639, 703);
this.chbETControlar.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); this.chbETControlar.Margin = new System.Windows.Forms.Padding(2);
this.chbETControlar.Name = "chbETControlar"; this.chbETControlar.Name = "chbETControlar";
this.chbETControlar.Size = new System.Drawing.Size(68, 17); this.chbETControlar.Size = new System.Drawing.Size(68, 17);
this.chbETControlar.TabIndex = 163; this.chbETControlar.TabIndex = 163;
@ -316,7 +320,7 @@ namespace AgroBase.Forms
// //
this.chbDFLivre.AutoSize = true; this.chbDFLivre.AutoSize = true;
this.chbDFLivre.Location = new System.Drawing.Point(784, 86); this.chbDFLivre.Location = new System.Drawing.Point(784, 86);
this.chbDFLivre.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); this.chbDFLivre.Margin = new System.Windows.Forms.Padding(2);
this.chbDFLivre.Name = "chbDFLivre"; this.chbDFLivre.Name = "chbDFLivre";
this.chbDFLivre.Size = new System.Drawing.Size(49, 17); this.chbDFLivre.Size = new System.Drawing.Size(49, 17);
this.chbDFLivre.TabIndex = 162; this.chbDFLivre.TabIndex = 162;
@ -327,7 +331,7 @@ namespace AgroBase.Forms
// //
this.chbDFControlar.AutoSize = true; this.chbDFControlar.AutoSize = true;
this.chbDFControlar.Location = new System.Drawing.Point(764, 64); this.chbDFControlar.Location = new System.Drawing.Point(764, 64);
this.chbDFControlar.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); this.chbDFControlar.Margin = new System.Windows.Forms.Padding(2);
this.chbDFControlar.Name = "chbDFControlar"; this.chbDFControlar.Name = "chbDFControlar";
this.chbDFControlar.Size = new System.Drawing.Size(68, 17); this.chbDFControlar.Size = new System.Drawing.Size(68, 17);
this.chbDFControlar.TabIndex = 161; this.chbDFControlar.TabIndex = 161;
@ -338,7 +342,7 @@ namespace AgroBase.Forms
// //
this.chbEFLivre.AutoSize = true; this.chbEFLivre.AutoSize = true;
this.chbEFLivre.Location = new System.Drawing.Point(639, 86); this.chbEFLivre.Location = new System.Drawing.Point(639, 86);
this.chbEFLivre.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); this.chbEFLivre.Margin = new System.Windows.Forms.Padding(2);
this.chbEFLivre.Name = "chbEFLivre"; this.chbEFLivre.Name = "chbEFLivre";
this.chbEFLivre.Size = new System.Drawing.Size(49, 17); this.chbEFLivre.Size = new System.Drawing.Size(49, 17);
this.chbEFLivre.TabIndex = 160; this.chbEFLivre.TabIndex = 160;
@ -349,7 +353,7 @@ namespace AgroBase.Forms
// //
this.chbEFControlar.AutoSize = true; this.chbEFControlar.AutoSize = true;
this.chbEFControlar.Location = new System.Drawing.Point(639, 64); this.chbEFControlar.Location = new System.Drawing.Point(639, 64);
this.chbEFControlar.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); this.chbEFControlar.Margin = new System.Windows.Forms.Padding(2);
this.chbEFControlar.Name = "chbEFControlar"; this.chbEFControlar.Name = "chbEFControlar";
this.chbEFControlar.Size = new System.Drawing.Size(68, 17); this.chbEFControlar.Size = new System.Drawing.Size(68, 17);
this.chbEFControlar.TabIndex = 159; this.chbEFControlar.TabIndex = 159;
@ -363,7 +367,7 @@ namespace AgroBase.Forms
legend1.Name = "Legend1"; legend1.Name = "Legend1";
this.chartET.Legends.Add(legend1); this.chartET.Legends.Add(legend1);
this.chartET.Location = new System.Drawing.Point(201, 410); this.chartET.Location = new System.Drawing.Point(201, 410);
this.chartET.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); this.chartET.Margin = new System.Windows.Forms.Padding(2);
this.chartET.Name = "chartET"; this.chartET.Name = "chartET";
series1.ChartArea = "ChartArea1"; series1.ChartArea = "ChartArea1";
series1.Legend = "Legend1"; series1.Legend = "Legend1";
@ -380,7 +384,7 @@ namespace AgroBase.Forms
legend2.Name = "Legend1"; legend2.Name = "Legend1";
this.chartDT.Legends.Add(legend2); this.chartDT.Legends.Add(legend2);
this.chartDT.Location = new System.Drawing.Point(834, 410); this.chartDT.Location = new System.Drawing.Point(834, 410);
this.chartDT.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); this.chartDT.Margin = new System.Windows.Forms.Padding(2);
this.chartDT.Name = "chartDT"; this.chartDT.Name = "chartDT";
series2.ChartArea = "ChartArea1"; series2.ChartArea = "ChartArea1";
series2.Legend = "Legend1"; series2.Legend = "Legend1";
@ -397,7 +401,7 @@ namespace AgroBase.Forms
legend3.Name = "Legend1"; legend3.Name = "Legend1";
this.chartDF.Legends.Add(legend3); this.chartDF.Legends.Add(legend3);
this.chartDF.Location = new System.Drawing.Point(834, 4); this.chartDF.Location = new System.Drawing.Point(834, 4);
this.chartDF.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); this.chartDF.Margin = new System.Windows.Forms.Padding(2);
this.chartDF.Name = "chartDF"; this.chartDF.Name = "chartDF";
series3.ChartArea = "ChartArea1"; series3.ChartArea = "ChartArea1";
series3.Legend = "Legend1"; series3.Legend = "Legend1";
@ -414,7 +418,7 @@ namespace AgroBase.Forms
legend4.Name = "Legend1"; legend4.Name = "Legend1";
this.chartEF.Legends.Add(legend4); this.chartEF.Legends.Add(legend4);
this.chartEF.Location = new System.Drawing.Point(201, 4); this.chartEF.Location = new System.Drawing.Point(201, 4);
this.chartEF.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); this.chartEF.Margin = new System.Windows.Forms.Padding(2);
this.chartEF.Name = "chartEF"; this.chartEF.Name = "chartEF";
series4.ChartArea = "ChartArea1"; series4.ChartArea = "ChartArea1";
series4.Legend = "Legend1"; series4.Legend = "Legend1";
@ -428,7 +432,7 @@ namespace AgroBase.Forms
// //
this.picRobo.Image = ((System.Drawing.Image)(resources.GetObject("picRobo.Image"))); this.picRobo.Image = ((System.Drawing.Image)(resources.GetObject("picRobo.Image")));
this.picRobo.Location = new System.Drawing.Point(602, 206); this.picRobo.Location = new System.Drawing.Point(602, 206);
this.picRobo.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); this.picRobo.Margin = new System.Windows.Forms.Padding(2);
this.picRobo.Name = "picRobo"; this.picRobo.Name = "picRobo";
this.picRobo.Size = new System.Drawing.Size(265, 395); this.picRobo.Size = new System.Drawing.Size(265, 395);
this.picRobo.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom; this.picRobo.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
@ -758,7 +762,7 @@ namespace AgroBase.Forms
// btnDTReverter // btnDTReverter
// //
this.btnDTReverter.Location = new System.Drawing.Point(736, 774); this.btnDTReverter.Location = new System.Drawing.Point(736, 774);
this.btnDTReverter.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); this.btnDTReverter.Margin = new System.Windows.Forms.Padding(2);
this.btnDTReverter.Name = "btnDTReverter"; this.btnDTReverter.Name = "btnDTReverter";
this.btnDTReverter.Size = new System.Drawing.Size(93, 23); this.btnDTReverter.Size = new System.Drawing.Size(93, 23);
this.btnDTReverter.TabIndex = 125; this.btnDTReverter.TabIndex = 125;
@ -768,7 +772,7 @@ namespace AgroBase.Forms
// btnETReverter // btnETReverter
// //
this.btnETReverter.Location = new System.Drawing.Point(639, 774); this.btnETReverter.Location = new System.Drawing.Point(639, 774);
this.btnETReverter.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); this.btnETReverter.Margin = new System.Windows.Forms.Padding(2);
this.btnETReverter.Name = "btnETReverter"; this.btnETReverter.Name = "btnETReverter";
this.btnETReverter.Size = new System.Drawing.Size(93, 23); this.btnETReverter.Size = new System.Drawing.Size(93, 23);
this.btnETReverter.TabIndex = 124; this.btnETReverter.TabIndex = 124;
@ -778,7 +782,7 @@ namespace AgroBase.Forms
// btnDFReverter // btnDFReverter
// //
this.btnDFReverter.Location = new System.Drawing.Point(736, 37); this.btnDFReverter.Location = new System.Drawing.Point(736, 37);
this.btnDFReverter.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); this.btnDFReverter.Margin = new System.Windows.Forms.Padding(2);
this.btnDFReverter.Name = "btnDFReverter"; this.btnDFReverter.Name = "btnDFReverter";
this.btnDFReverter.Size = new System.Drawing.Size(93, 23); this.btnDFReverter.Size = new System.Drawing.Size(93, 23);
this.btnDFReverter.TabIndex = 123; this.btnDFReverter.TabIndex = 123;
@ -788,7 +792,7 @@ namespace AgroBase.Forms
// btnEFReverter // btnEFReverter
// //
this.btnEFReverter.Location = new System.Drawing.Point(639, 37); this.btnEFReverter.Location = new System.Drawing.Point(639, 37);
this.btnEFReverter.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); this.btnEFReverter.Margin = new System.Windows.Forms.Padding(2);
this.btnEFReverter.Name = "btnEFReverter"; this.btnEFReverter.Name = "btnEFReverter";
this.btnEFReverter.Size = new System.Drawing.Size(93, 23); this.btnEFReverter.Size = new System.Drawing.Size(93, 23);
this.btnEFReverter.TabIndex = 122; this.btnEFReverter.TabIndex = 122;
@ -838,7 +842,7 @@ namespace AgroBase.Forms
// btnDTReferenciar // btnDTReferenciar
// //
this.btnDTReferenciar.Location = new System.Drawing.Point(736, 747); this.btnDTReferenciar.Location = new System.Drawing.Point(736, 747);
this.btnDTReferenciar.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); this.btnDTReferenciar.Margin = new System.Windows.Forms.Padding(2);
this.btnDTReferenciar.Name = "btnDTReferenciar"; this.btnDTReferenciar.Name = "btnDTReferenciar";
this.btnDTReferenciar.Size = new System.Drawing.Size(93, 23); this.btnDTReferenciar.Size = new System.Drawing.Size(93, 23);
this.btnDTReferenciar.TabIndex = 117; this.btnDTReferenciar.TabIndex = 117;
@ -859,7 +863,7 @@ namespace AgroBase.Forms
// picDT // picDT
// //
this.picDT.Location = new System.Drawing.Point(1271, 432); this.picDT.Location = new System.Drawing.Point(1271, 432);
this.picDT.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); this.picDT.Margin = new System.Windows.Forms.Padding(2);
this.picDT.Name = "picDT"; this.picDT.Name = "picDT";
this.picDT.Size = new System.Drawing.Size(188, 203); this.picDT.Size = new System.Drawing.Size(188, 203);
this.picDT.TabIndex = 115; this.picDT.TabIndex = 115;
@ -908,7 +912,7 @@ namespace AgroBase.Forms
// btnDFReferenciar // btnDFReferenciar
// //
this.btnDFReferenciar.Location = new System.Drawing.Point(736, 9); this.btnDFReferenciar.Location = new System.Drawing.Point(736, 9);
this.btnDFReferenciar.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); this.btnDFReferenciar.Margin = new System.Windows.Forms.Padding(2);
this.btnDFReferenciar.Name = "btnDFReferenciar"; this.btnDFReferenciar.Name = "btnDFReferenciar";
this.btnDFReferenciar.Size = new System.Drawing.Size(93, 23); this.btnDFReferenciar.Size = new System.Drawing.Size(93, 23);
this.btnDFReferenciar.TabIndex = 108; this.btnDFReferenciar.TabIndex = 108;
@ -929,7 +933,7 @@ namespace AgroBase.Forms
// picDF // picDF
// //
this.picDF.Location = new System.Drawing.Point(1271, 27); this.picDF.Location = new System.Drawing.Point(1271, 27);
this.picDF.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); this.picDF.Margin = new System.Windows.Forms.Padding(2);
this.picDF.Name = "picDF"; this.picDF.Name = "picDF";
this.picDF.Size = new System.Drawing.Size(188, 203); this.picDF.Size = new System.Drawing.Size(188, 203);
this.picDF.TabIndex = 106; this.picDF.TabIndex = 106;
@ -978,7 +982,7 @@ namespace AgroBase.Forms
// btnETReferenciar // btnETReferenciar
// //
this.btnETReferenciar.Location = new System.Drawing.Point(639, 747); this.btnETReferenciar.Location = new System.Drawing.Point(639, 747);
this.btnETReferenciar.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); this.btnETReferenciar.Margin = new System.Windows.Forms.Padding(2);
this.btnETReferenciar.Name = "btnETReferenciar"; this.btnETReferenciar.Name = "btnETReferenciar";
this.btnETReferenciar.Size = new System.Drawing.Size(93, 23); this.btnETReferenciar.Size = new System.Drawing.Size(93, 23);
this.btnETReferenciar.TabIndex = 101; this.btnETReferenciar.TabIndex = 101;
@ -999,7 +1003,7 @@ namespace AgroBase.Forms
// picET // picET
// //
this.picET.Location = new System.Drawing.Point(9, 432); this.picET.Location = new System.Drawing.Point(9, 432);
this.picET.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); this.picET.Margin = new System.Windows.Forms.Padding(2);
this.picET.Name = "picET"; this.picET.Name = "picET";
this.picET.Size = new System.Drawing.Size(188, 203); this.picET.Size = new System.Drawing.Size(188, 203);
this.picET.TabIndex = 99; this.picET.TabIndex = 99;
@ -1048,7 +1052,7 @@ namespace AgroBase.Forms
// btnEFReferenciar // btnEFReferenciar
// //
this.btnEFReferenciar.Location = new System.Drawing.Point(639, 9); this.btnEFReferenciar.Location = new System.Drawing.Point(639, 9);
this.btnEFReferenciar.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); this.btnEFReferenciar.Margin = new System.Windows.Forms.Padding(2);
this.btnEFReferenciar.Name = "btnEFReferenciar"; this.btnEFReferenciar.Name = "btnEFReferenciar";
this.btnEFReferenciar.Size = new System.Drawing.Size(93, 23); this.btnEFReferenciar.Size = new System.Drawing.Size(93, 23);
this.btnEFReferenciar.TabIndex = 92; this.btnEFReferenciar.TabIndex = 92;
@ -1069,19 +1073,41 @@ namespace AgroBase.Forms
// picEF // picEF
// //
this.picEF.Location = new System.Drawing.Point(9, 27); this.picEF.Location = new System.Drawing.Point(9, 27);
this.picEF.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); this.picEF.Margin = new System.Windows.Forms.Padding(2);
this.picEF.Name = "picEF"; this.picEF.Name = "picEF";
this.picEF.Size = new System.Drawing.Size(188, 203); this.picEF.Size = new System.Drawing.Size(188, 203);
this.picEF.TabIndex = 90; this.picEF.TabIndex = 90;
this.picEF.TabStop = false; this.picEF.TabStop = false;
// //
// lblCorrente
//
this.lblCorrente.AutoSize = true;
this.lblCorrente.Font = new System.Drawing.Font("Microsoft Sans Serif", 6.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.lblCorrente.Location = new System.Drawing.Point(639, 619);
this.lblCorrente.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
this.lblCorrente.Name = "lblCorrente";
this.lblCorrente.Size = new System.Drawing.Size(202, 12);
this.lblCorrente.TabIndex = 172;
this.lblCorrente.Text = "Corrente atual: 0,00A - Mín: 0,00A - Máx: 0,00A";
//
// lblTensao
//
this.lblTensao.AutoSize = true;
this.lblTensao.Font = new System.Drawing.Font("Microsoft Sans Serif", 6.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.lblTensao.Location = new System.Drawing.Point(639, 606);
this.lblTensao.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0);
this.lblTensao.Name = "lblTensao";
this.lblTensao.Size = new System.Drawing.Size(196, 12);
this.lblTensao.TabIndex = 171;
this.lblTensao.Text = "Tensão atual: 0,00V - Mín: 0,00V - Máx: 0,00V";
//
// frmAcompanhamento // frmAcompanhamento
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(1484, 749); this.ClientSize = new System.Drawing.Size(1484, 749);
this.Controls.Add(this.pnlFundo); this.Controls.Add(this.pnlFundo);
this.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); this.Margin = new System.Windows.Forms.Padding(2);
this.Name = "frmAcompanhamento"; this.Name = "frmAcompanhamento";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Acompanhamento"; this.Text = "Acompanhamento";
@ -1187,5 +1213,7 @@ namespace AgroBase.Forms
private System.Windows.Forms.Label lblDistanciaTotal; private System.Windows.Forms.Label lblDistanciaTotal;
private System.Windows.Forms.Label lblTempoEmMovimento; private System.Windows.Forms.Label lblTempoEmMovimento;
private System.Windows.Forms.Label lblTempoConectado; private System.Windows.Forms.Label lblTempoConectado;
public System.Windows.Forms.Label lblCorrente;
public System.Windows.Forms.Label lblTensao;
} }
} }

View File

@ -397,5 +397,20 @@ namespace AgroBase.Forms
} }
delegate void AtualizarSensoresDelegate(string Texto);
public void AtualizarSensores(string Texto)
{
Label lbl = Texto.Contains("Corrente") ? lblCorrente : lblTensao;
if (lbl.InvokeRequired)
{
lbl.Invoke(new AtualizarSensoresDelegate(AtualizarSensores), Texto);
}
else
{
lbl.Text = Texto;
}
}
} }
} }

View File

@ -273,5 +273,7 @@ namespace AgroBase.Models.Modules
Leitura3, Leitura3,
Leitura4, Leitura4,
I2C, I2C,
Tensao,
Corrente,
} }
} }

View File

@ -41,6 +41,7 @@ namespace AgroBase.Models.Modules
FuncoesPinout.TMP, FuncoesPinout.TMP,
}, },
DelayAmostragem = 200, DelayAmostragem = 200,
Parametros = new List<string[]>(),
}, },
new SensorModel() new SensorModel()
{ {
@ -56,6 +57,7 @@ namespace AgroBase.Models.Modules
FuncoesPinout.TMP, FuncoesPinout.TMP,
}, },
DelayAmostragem = 200, DelayAmostragem = 200,
Parametros = new List<string[]>(),
}, },
new SensorModel() new SensorModel()
{ {
@ -71,6 +73,7 @@ namespace AgroBase.Models.Modules
FuncoesPinout.TMP, FuncoesPinout.TMP,
}, },
DelayAmostragem = 200, DelayAmostragem = 200,
Parametros = new List<string[]>(),
}, },
new SensorModel() new SensorModel()
{ {
@ -86,10 +89,11 @@ namespace AgroBase.Models.Modules
FuncoesPinout.TMP, FuncoesPinout.TMP,
}, },
DelayAmostragem = 200, DelayAmostragem = 200,
Parametros = new List<string[]>(),
}, },
new SensorModel() new SensorModel()
{ {
ID = "VBAT ", ID = "VBAT",
Descricao = "Tensão da bateria", Descricao = "Tensão da bateria",
Prioridade = 20, Prioridade = 20,
Componente = S_Code.sTEN, Componente = S_Code.sTEN,
@ -98,13 +102,19 @@ namespace AgroBase.Models.Modules
Testando = false, Testando = false,
Funcoes = new List<FuncoesPinout>() Funcoes = new List<FuncoesPinout>()
{ {
FuncoesPinout.Leitura1, FuncoesPinout.Tensao,
},
DelayAmostragem = 500,
Parametros = new List<string[]>()
{
new string[] { "V offset", "000.85" },
new string[] { "R1", "120000" },
new string[] { "R2", "010000" },
}, },
DelayAmostragem = 1000,
}, },
new SensorModel() new SensorModel()
{ {
ID = "ABAT ", ID = "ABAT",
Prioridade = 10, Prioridade = 10,
Descricao = "Corrente da bateria", Descricao = "Corrente da bateria",
Componente = S_Code.sCOR, Componente = S_Code.sCOR,
@ -113,9 +123,14 @@ namespace AgroBase.Models.Modules
Testando = false, Testando = false,
Funcoes = new List<FuncoesPinout>() Funcoes = new List<FuncoesPinout>()
{ {
FuncoesPinout.Leitura1, FuncoesPinout.Corrente,
},
DelayAmostragem = 500,
Parametros = new List<string[]>()
{
new string[] { "V offset", "00.413" },
new string[] { "Sensibilidade", "000.35" },
}, },
DelayAmostragem = 950,
}, },
} }
}; };
@ -146,7 +161,7 @@ namespace AgroBase.Models.Modules
} }
S_Code TipoSensor = (S_Code)(cod); S_Code TipoSensor = (S_Code)(cod);
SensorModel Sensor = Sensores.FirstOrDefault(x => x.ID == Dados[1]); SensorModel Sensor = Sensores.FirstOrDefault(x => x.ID == Dados[1].Trim());
if (Sensor == null) if (Sensor == null)
{ {
if (Dados[1] == "MD") if (Dados[1] == "MD")
@ -162,26 +177,60 @@ namespace AgroBase.Models.Modules
switch (TipoSensor) switch (TipoSensor)
{ {
case S_Code.sCOR: case S_Code.sCOR:
double l1 = -1; double leitura = -1;
double.TryParse(Dados[2], out l1); double.TryParse(Dados[2].Replace(".", ","), out leitura);
double l2 = -1; double vPin = -1;
double.TryParse(Dados[3], out l2); double.TryParse(Dados[3].Replace(".", ","), out vPin);
double l3 = -1; double corrente = -1;
double.TryParse(Dados[4], out l3); double.TryParse(Dados[4].Replace(".", ","), out corrente);
double l4 = -1;
double.TryParse(Dados[5], out l4);
Sensor.Leituras = new List<double>() Sensor.Leituras = new List<double>()
{ {
l1, leitura,
l2, vPin,
l3, corrente,
l4
}; };
if (corrente > Sensor.ValorMaximo)
{
Sensor.ValorMaximo = corrente;
}
else if (corrente < Sensor.ValorMinimo)
{
Sensor.ValorMinimo = corrente;
}
frmInstancial.frmAcompanhamento.AtualizarSensores("Corrente atual: " + corrente.ToString("0.00") + "A - Mín: " + Sensor.ValorMinimo.ToString("0.00") + "A - Máx: " + Sensor.ValorMaximo.ToString("0.00") + "A");
AtualizaGrafico = true; AtualizaGrafico = true;
break; break;
case S_Code.sTEN: case S_Code.sTEN:
double leituraV = -1;
double.TryParse(Dados[2].Replace(".", ","), out leituraV);
double vPinV = -1;
double.TryParse(Dados[3].Replace(".", ","), out vPinV);
double tensao = -1;
double.TryParse(Dados[4].Replace(".", ","), out tensao);
Sensor.Leituras = new List<double>()
{
leituraV,
vPinV,
tensao,
};
if (tensao > Sensor.ValorMaximo)
{
Sensor.ValorMaximo = tensao;
}
else if (tensao < Sensor.ValorMinimo)
{
Sensor.ValorMinimo = tensao;
}
frmInstancial.frmAcompanhamento.AtualizarSensores("Tensão atual: " + tensao.ToString("0.00") + "V - Mín: " + Sensor.ValorMinimo.ToString("0.00") + "V - Máx: " + Sensor.ValorMaximo.ToString("0.00") + "V");
AtualizaGrafico = true;
break; break;
case S_Code.sCFG: case S_Code.sCFG:
@ -325,6 +374,7 @@ namespace AgroBase.Models.Modules
public bool Inicializado { get; set; } = false; public bool Inicializado { get; set; } = false;
public bool Testando { get; set; } = false; public bool Testando { get; set; } = false;
public List<FuncoesPinout> Funcoes { get; set; } public List<FuncoesPinout> Funcoes { get; set; }
public List<string[]> Parametros { get; set;} = new List<string[]>();
public string UnidadeMedida { get; set; } public string UnidadeMedida { get; set; }
public List<double> Leituras { get; set; } public List<double> Leituras { get; set; }
@ -336,13 +386,17 @@ namespace AgroBase.Models.Modules
{ {
var _pinout = SensoriamentoModel.Pinout.Where(x => x.ComponenteID == ID).ToList(); var _pinout = SensoriamentoModel.Pinout.Where(x => x.ComponenteID == ID).ToList();
string Protocolo = ((int)F_Code.Cfg).ToString() + string Protocolo = ((int)F_Code.Cfg).ToString() +
ID + ";" + // 0 ~ 4 ID.PadRight(5, ' ') + ";" + // 0 ~ 4
(Conectar ? "1" : "0") + ";" + // 6 (Conectar ? "1" : "0") + ";" + // 6
((int)Componente).ToString() + ";" + // 8 ~ 10 ((int)Componente).ToString() + ";" + // 8 ~ 10
(Aferir ? "1" : "0") + ";" + // 12 (Aferir ? "1" : "0") + ";" + // 12
DelayAmostragem.ToString("00000") + ";" + // 14 ~ 18 DelayAmostragem.ToString("00000") + ";" + // 14 ~ 18
Prioridade.ToString("00") + ";" + // 20 ~ 21 Prioridade.ToString("00") + ";" + // 20 ~ 21
(_pinout.Any(x => x.Funcao != FuncoesPinout.NaoConectado) ? _pinout.FirstOrDefault(x => x.Funcao != FuncoesPinout.NaoConectado).Pino.ToString("00") : "-1"); // 23 ~ 24 (_pinout.Any(x => x.Funcao != FuncoesPinout.NaoConectado) ? _pinout.FirstOrDefault(x => x.Funcao != FuncoesPinout.NaoConectado).Pino.ToString("00") : "-1"); // 23 ~ 24
foreach (var Parametro in Parametros)
{
Protocolo += ";" + Parametro[1];
}
return Protocolo; return Protocolo;
} }
} }

View File

@ -1,6 +1,7 @@
using AgroBase.Forms; using AgroBase.Forms;
using AgroBase.Forms.Direcional; using AgroBase.Forms.Direcional;
using AgroBase.Forms.Movimentacao; using AgroBase.Forms.Movimentacao;
using AgroBase.Forms.Sensoriamento;
using AgroBase.Models; using AgroBase.Models;
using AgroBase.Models.Modules; using AgroBase.Models.Modules;
using AgroBase.Services; using AgroBase.Services;
@ -198,7 +199,7 @@ namespace AgroBase.Comum
break; break;
case T_Code.Sen: case T_Code.Sen:
Dados = CarregarParametros(SensoriamentoModel.CarregarParametrosIniciais()); Dados = CarregarParametros(SensoriamentoModel.CarregarParametrosIniciais());
//frmConfig = new frmSenConfig2(); frmConfig = new frmSenConfig();
break; break;
case T_Code.Atu: case T_Code.Atu:
Dados = CarregarParametros(AtuadorModel.CarregarParametrosIniciais()); Dados = CarregarParametros(AtuadorModel.CarregarParametrosIniciais());

View File

@ -1 +1 @@
{"Conectado":false,"Sensores":[{"LogGrafico":[],"ID":"TMVET","Prioridade":0,"Descricao":"Temperatura Motor Esquerdo Trás","Componente":411,"Aferir":true,"DelayAmostragem":200,"Inicializado":false,"Testando":false,"Funcoes":[12],"UnidadeMedida":null,"Leituras":[33.78],"ValorMinimo":0.0,"ValorMaximo":23935.0},{"LogGrafico":[],"ID":"TMVEF","Prioridade":0,"Descricao":"Temperatura Motor Esquerdo Frente","Componente":411,"Aferir":true,"DelayAmostragem":200,"Inicializado":false,"Testando":false,"Funcoes":[12],"UnidadeMedida":null,"Leituras":[29.35],"ValorMinimo":-27315.0,"ValorMaximo":12833.0},{"LogGrafico":[],"ID":"TMVDT","Prioridade":0,"Descricao":"Temperatura Motor Direito Trás","Componente":411,"Aferir":true,"DelayAmostragem":200,"Inicializado":false,"Testando":false,"Funcoes":[12],"UnidadeMedida":null,"Leituras":[29.69],"ValorMinimo":-27315.0,"ValorMaximo":7745.0},{"LogGrafico":[],"ID":"TMVDF","Prioridade":0,"Descricao":"Temperatura Motor Direito Frente","Componente":411,"Aferir":true,"DelayAmostragem":200,"Inicializado":false,"Testando":false,"Funcoes":[12],"UnidadeMedida":null,"Leituras":[30.38],"ValorMinimo":-27315.0,"ValorMaximo":7936.0},{"LogGrafico":[],"ID":"VBAT ","Prioridade":20,"Descricao":"Tensão da bateria","Componente":112,"Aferir":false,"DelayAmostragem":1000,"Inicializado":false,"Testando":false,"Funcoes":[23],"UnidadeMedida":null,"Leituras":null,"ValorMinimo":0.0,"ValorMaximo":0.0},{"LogGrafico":[],"ID":"ABAT ","Prioridade":10,"Descricao":"Corrente da bateria","Componente":322,"Aferir":false,"DelayAmostragem":950,"Inicializado":false,"Testando":false,"Funcoes":[23],"UnidadeMedida":null,"Leituras":null,"ValorMinimo":0.0,"ValorMaximo":0.0}]} {"Conectado":false,"Sensores":[{"LogGrafico":[],"ID":"TMVET","Prioridade":0,"Descricao":"Temperatura Motor Esquerdo Trás","Componente":411,"Aferir":false,"DelayAmostragem":200,"Inicializado":false,"Testando":false,"Funcoes":[12],"Parametros":[],"UnidadeMedida":null,"Leituras":null,"ValorMinimo":0.0,"ValorMaximo":0.0},{"LogGrafico":[],"ID":"TMVEF","Prioridade":0,"Descricao":"Temperatura Motor Esquerdo Frente","Componente":411,"Aferir":false,"DelayAmostragem":200,"Inicializado":false,"Testando":false,"Funcoes":[12],"Parametros":[],"UnidadeMedida":null,"Leituras":null,"ValorMinimo":0.0,"ValorMaximo":0.0},{"LogGrafico":[],"ID":"TMVDT","Prioridade":0,"Descricao":"Temperatura Motor Direito Trás","Componente":411,"Aferir":false,"DelayAmostragem":200,"Inicializado":false,"Testando":false,"Funcoes":[12],"Parametros":[],"UnidadeMedida":null,"Leituras":null,"ValorMinimo":0.0,"ValorMaximo":0.0},{"LogGrafico":[],"ID":"TMVDF","Prioridade":0,"Descricao":"Temperatura Motor Direito Frente","Componente":411,"Aferir":false,"DelayAmostragem":200,"Inicializado":false,"Testando":false,"Funcoes":[12],"Parametros":[],"UnidadeMedida":null,"Leituras":null,"ValorMinimo":0.0,"ValorMaximo":0.0},{"LogGrafico":[],"ID":"VBAT","Prioridade":20,"Descricao":"Tensão da bateria","Componente":112,"Aferir":true,"DelayAmostragem":500,"Inicializado":false,"Testando":false,"Funcoes":[28],"Parametros":[["V offset","000.85"],["R1","120000"],["R2","010000"]],"UnidadeMedida":null,"Leituras":[711.3,0.64,8.3],"ValorMinimo":0.0,"ValorMaximo":13.73},{"LogGrafico":[],"ID":"ABAT","Prioridade":10,"Descricao":"Corrente da bateria","Componente":322,"Aferir":true,"DelayAmostragem":500,"Inicializado":false,"Testando":false,"Funcoes":[29],"Parametros":[["V offset","00.370"],["Sensibilidade","000.35"]],"UnidadeMedida":null,"Leituras":[482.8,0.39,0.05],"ValorMinimo":-0.87,"ValorMaximo":0.23}]}

View File

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

View File

@ -1 +1 @@
5282e2e8323b29ea19e29f87e03985324ecefc8410e637b6614d0e3935fd65df 522c469433cd27a9bb1c105d2bee798bc5682bc54372eaac60a028a8592b0825

View File

@ -361,3 +361,4 @@ C:\ZendionInc\agrobot_base\AgroBase\AgroBase\obj\Debug\AgroBase.pdb
C:\ZendionInc\agrobot_base\AgroBase\AgroBase\bin\Debug\Python\Scripts\gps-viewer.py C:\ZendionInc\agrobot_base\AgroBase\AgroBase\bin\Debug\Python\Scripts\gps-viewer.py
C:\ZendionInc\agrobot_base\AgroBase\AgroBase\obj\Debug\AgroBase.Forms.frmGPS.resources C:\ZendionInc\agrobot_base\AgroBase\AgroBase\obj\Debug\AgroBase.Forms.frmGPS.resources
C:\ZendionInc\agrobot_base\AgroBase\AgroBase\obj\Debug\AgroBase.Forms.frmPinout.resources C:\ZendionInc\agrobot_base\AgroBase\AgroBase\obj\Debug\AgroBase.Forms.frmPinout.resources
C:\ZendionInc\agrobot_base\AgroBase\AgroBase\obj\Debug\AgroBase.Forms.Sensoriamento.frmSenConfig.resources

View File

@ -1,8 +1,8 @@
// Dispositivo: Atuador // Dispositivo: Atuador
// Versão Firmware: 1 // Versão Firmware: 1
// Ultima atualização: 22/12/2023 // Ultima atualização: 23/01/2024
#include "C:\Zendion Inc\agrobot_base\Firmware\Modulos\SerialService.h" #include "C:\ZendionInc\agrobot_base\Firmware\Modulos\SerialService.h"
#define D_Code Atu #define D_Code Atu
#define _pinoLED RGB_BUILTIN #define _pinoLED RGB_BUILTIN
@ -14,6 +14,7 @@ bool Conectado = false;
int _TaxaAmostragem = 500; int _TaxaAmostragem = 500;
int BicosAtivos = 10; int BicosAtivos = 10;
bool BicoLigado = false;
class BicoPulverizador { class BicoPulverizador {
public: public:
@ -36,7 +37,7 @@ public:
bool StatusBico; bool StatusBico;
// Entrada de dados // Entrada de dados
bool _BicoAtuado = false; bool _BicoAtuado = !BicoLigado;
void Inicializar() { void Inicializar() {
if (Iniciado) { if (Iniciado) {
@ -47,9 +48,9 @@ public:
if (_pinoSolenoide > -1) { if (_pinoSolenoide > -1) {
pinMode(_pinoSolenoide, OUTPUT); pinMode(_pinoSolenoide, OUTPUT);
digitalWrite(_pinoSolenoide, LOW); _BicoAtuado = !BicoLigado;
_BicoAtuado = false; digitalWrite(_pinoSolenoide, _BicoAtuado);
StatusBico = digitalRead(_pinoSolenoide) == 1; StatusBico = digitalRead(_pinoSolenoide) == (BicoLigado ? 1 : 0);
} }
if (_pinoSensor > -1) { if (_pinoSensor > -1) {
pinMode(_pinoSensor, INPUT); pinMode(_pinoSensor, INPUT);
@ -88,7 +89,7 @@ public:
void AlterarStatusBico() { void AlterarStatusBico() {
digitalWrite(_pinoSolenoide, _BicoAtuado); digitalWrite(_pinoSolenoide, _BicoAtuado);
StatusBico = digitalRead(_pinoSolenoide) == 1; StatusBico = digitalRead(_pinoSolenoide) == (BicoLigado ? 1 : 0);
} }
@ -151,9 +152,20 @@ BicoPulverizador* BicoPorID(String ID) {
return _bico; return _bico;
} }
void ZerarPinos() {
const int gpios[] = {2, 4, 5, 13, 14, 15, 16, 17, 18, 19, 21, 22, 23, 25, 26, 27, 32, 33};
for (int i = 0; i < sizeof(gpios) / sizeof(gpios[0]); i++) {
pinMode(gpios[i], OUTPUT);
digitalWrite(gpios[i], !BicoLigado);
}
}
void setup() { void setup() {
Serial.begin(_baudRate); Serial.begin(_baudRate);
ZerarPinos();
if (_pinoReleGeral > -1) { if (_pinoReleGeral > -1) {
pinMode(_pinoReleGeral, OUTPUT); pinMode(_pinoReleGeral, OUTPUT);
digitalWrite(_pinoReleGeral, LOW); digitalWrite(_pinoReleGeral, LOW);
@ -231,7 +243,7 @@ void loop() {
BicoPulverizador* _bico = BicoPorID(ID); BicoPulverizador* _bico = BicoPorID(ID);
_bico->_BicoAtuado = (String)Protocolo[4] == "1"; _bico->_BicoAtuado = (String)Protocolo[4] == (BicoLigado ? "1" : "0");
_bico->AlterarStatusBico(); _bico->AlterarStatusBico();
} }
else if (_funcao == Tst) { else if (_funcao == Tst) {

View File

@ -488,6 +488,16 @@ Motor M2("EF");
Motor M3("DT"); Motor M3("DT");
Motor M4("DF"); Motor M4("DF");
Motor* MotorPorID(String ID) {
Motor* _motor =
ID == "ET" ? &M1 :
ID == "EF" ? &M2 :
ID == "DT" ? &M3 :
ID == "DF" ? &M4 :
nullptr;
return _motor;
}
void setup() { void setup() {
Serial.begin(_baudRate); Serial.begin(_baudRate);
@ -543,7 +553,7 @@ void loop() {
EnviarDadosSerial(MontarProtocoloSensor(sCFG, "MD", Conectado ? "1" : "0")); EnviarDadosSerial(MontarProtocoloSensor(sCFG, "MD", Conectado ? "1" : "0"));
} }
else { else {
Motor* _motor = ID == "ET" ? &M1 : ID == "EF" ? &M2 : ID == "DT" ? &M3 : &M4; Motor* _motor = MotorPorID(ID);
int canal = ((String)Protocolo[5]).toInt(); int canal = ((String)Protocolo[5]).toInt();
bool motor_ativado = ((String)Protocolo[7]) == "1"; bool motor_ativado = ((String)Protocolo[7]) == "1";
@ -587,7 +597,7 @@ void loop() {
//0;0;000.00 //0;0;000.00
String ID = ((String)Protocolo[0] + (String)Protocolo[1]); String ID = ((String)Protocolo[0] + (String)Protocolo[1]);
Motor* _motor = ID == "ET" ? &M1 : ID == "EF" ? &M2 : ID == "DT" ? &M3 : &M4; Motor* _motor = MotorPorID(ID);
Sentido sentido = (Sentido)((String)Protocolo[3]).toInt(); Sentido sentido = (Sentido)((String)Protocolo[3]).toInt();
int angulo = ((String)Protocolo[5] + (String)Protocolo[6] + (String)Protocolo[7]).toInt(); int angulo = ((String)Protocolo[5] + (String)Protocolo[6] + (String)Protocolo[7]).toInt();
@ -614,7 +624,7 @@ void loop() {
else if (_funcao == Tst) { else if (_funcao == Tst) {
String ID = ((String)Protocolo[0] + (String)Protocolo[1]); String ID = ((String)Protocolo[0] + (String)Protocolo[1]);
Motor* _motor = ID == "ET" ? &M1 : ID == "EF" ? &M2 : ID == "DT" ? &M3 : &M4; Motor* _motor = MotorPorID(ID);
bool EmTeste = _motor->Testando; bool EmTeste = _motor->Testando;
if (!EmTeste) { if (!EmTeste) {

View File

@ -1,12 +1,10 @@
// Dispositivo: Movimentação // Dispositivo: Movimentação
// Versão Firmware: 9 // Versão Firmware: 14
// Ultima atualização: 21/11/2023 // Ultima atualização: 16/01/2024
#include "C:\ZendionInc\agrobot_base\Firmware\Modulos\SerialService.h" #include "C:\ZendionInc\agrobot_base\Firmware\Modulos\SerialService.h"
#include "C:\ZendionInc\agrobot_base\Firmware\Modulos\MemoryService.h"
#include "C:\ZendionInc\agrobot_base\Firmware\Modulos\utils.h" #include "C:\ZendionInc\agrobot_base\Firmware\Modulos\utils.h"
#include <PID_v1.h> #include <PID_v1.h>
#include "DHT.h"
#define D_Code Mov #define D_Code Mov
#define _pinoLED RGB_BUILTIN #define _pinoLED RGB_BUILTIN
@ -23,17 +21,11 @@ int RampaMin = 0;
int ZeroRampa = 0; int ZeroRampa = 0;
int RampaMax = 1023; int RampaMax = 1023;
int M1_US_Addr = 25;
int M2_US_Addr = 35;
int M3_US_Addr = 45;
int M4_US_Addr = 55;
class Motor { class Motor {
public: public:
// Construtor // Construtor
Motor(String desc, int SentidoAddr) { Motor(String desc) {
_ID = desc; _ID = desc;
_US_Addr = SentidoAddr;
} }
// Definições // Definições
@ -46,7 +38,6 @@ public:
int _pinoHLA; int _pinoHLA;
int _pinoHLB; int _pinoHLB;
int _pinoHLC; int _pinoHLC;
int _pinoTMP;
double _Kp; double _Kp;
double _Ki; double _Ki;
@ -67,12 +58,11 @@ public:
double RPM; double RPM;
double PotenciaAtual; double PotenciaAtual;
volatile int ultimaLeituraHallA = 0; volatile int ultimaLeituraHallA = 0;
volatile int ultimaLeituraHallB = 0;
volatile int ultimaLeituraHallC = 0;
volatile unsigned int tempoAnterior = 0; volatile unsigned int tempoAnterior = 0;
volatile float periodo = 0; volatile float periodo = 0;
// Sensores
DHT* dht;
// Entrada de dados // Entrada de dados
bool _MalhaFechada; bool _MalhaFechada;
int _PotMap; int _PotMap;
@ -103,7 +93,7 @@ public:
pinMode(_pinoDIR, OUTPUT); pinMode(_pinoDIR, OUTPUT);
digitalWrite(_pinoDIR, LOW); digitalWrite(_pinoDIR, LOW);
_SentidoM = (Sentido)LerMemoria(_US_Addr); _SentidoM = Parado;
} }
if (_pinoBRK > -1) { if (_pinoBRK > -1) {
pinMode(_pinoBRK, OUTPUT); pinMode(_pinoBRK, OUTPUT);
@ -131,14 +121,11 @@ public:
} }
if (_pinoHLB > -1) { if (_pinoHLB > -1) {
pinMode(_pinoHLB, INPUT); pinMode(_pinoHLB, INPUT);
ultimaLeituraHallB = digitalRead(_pinoHLB);
} }
if (_pinoHLC > -1) { if (_pinoHLC > -1) {
pinMode(_pinoHLC, INPUT); pinMode(_pinoHLC, INPUT);
} ultimaLeituraHallC = digitalRead(_pinoHLC);
if (_pinoTMP > -1) {
dht = new DHT(_pinoTMP, DHT22);
dht->begin();
xTaskCreatePinnedToCore(&Motor::DHT22TaskWrapper, "DHT22Task", 10000, this, 17 - _canal, &DHT22TaskHandle, tskNO_AFFINITY);
} }
@ -163,9 +150,6 @@ public:
if (_pinoHLA > -1) { if (_pinoHLA > -1) {
vTaskDelete(RPMTaskHandle); vTaskDelete(RPMTaskHandle);
} }
if (_pinoTMP > -1) {
vTaskDelete(DHT22TaskHandle);
}
// Desanexar o canal PWM // Desanexar o canal PWM
if (_pinoPWM > -1) { if (_pinoPWM > -1) {
@ -180,7 +164,6 @@ public:
pinMode(_pinoHLA, INPUT); pinMode(_pinoHLA, INPUT);
pinMode(_pinoHLB, INPUT); pinMode(_pinoHLB, INPUT);
pinMode(_pinoHLC, INPUT); pinMode(_pinoHLC, INPUT);
pinMode(_pinoTMP, INPUT);
// Outras redefinições de variáveis de estado, se necessário // Outras redefinições de variáveis de estado, se necessário
delete _PID; delete _PID;
@ -208,7 +191,6 @@ public:
void ReverterSentidoGiro() { void ReverterSentidoGiro() {
_SentidoM = _SentidoM == Horario ? Antihorario : Horario; _SentidoM = _SentidoM == Horario ? Antihorario : Horario;
GravarMemoria(_US_Addr, (int)_SentidoM);
} }
private: private:
@ -234,7 +216,7 @@ private:
} }
// Medir RPM apenas quando ocorrer um pulso no sensor HALL // Medir RPM apenas quando ocorrer um pulso no sensor HALL
int LeituraHa = digitalRead(_pinoHLA); bool LeituraHa = digitalRead(_pinoHLA) == 1;
if (LeituraHa != ultimaLeituraHallA) { if (LeituraHa != ultimaLeituraHallA) {
ultimaLeituraHallA = LeituraHa; ultimaLeituraHallA = LeituraHa;
pulsos++; pulsos++;
@ -320,10 +302,10 @@ private:
// Comparação das leituras atuais com as leituras anteriores // Comparação das leituras atuais com as leituras anteriores
if (LeituraHa == LeituraAnteriorHc && LeituraHc == LeituraAnteriorHa) { if (LeituraHa == LeituraAnteriorHc && LeituraHc == LeituraAnteriorHa) {
_Sentido = Horario; _Sentido = Antihorario;
} }
else if (LeituraHa == LeituraAnteriorHb && LeituraHb == LeituraAnteriorHa) { else if (LeituraHa == LeituraAnteriorHb && LeituraHb == LeituraAnteriorHa) {
_Sentido = Antihorario; _Sentido = Horario;
} }
else { else {
// Outros casos (não determinados) // Outros casos (não determinados)
@ -386,7 +368,7 @@ private:
} }
void RampaTask() { void RampaTask() {
unsigned long previousMillisRampa = millis(); unsigned long firstMilis = millis();
while (1) while (1)
{ {
if (!Conectado) { if (!Conectado) {
@ -416,16 +398,16 @@ private:
Revertendo = _SentidoSP != Parado && _SentidoSP != _SentidoM; Revertendo = _SentidoSP != Parado && _SentidoSP != _SentidoM;
if (Revertendo) { if (Revertendo) {
digitalWrite(_pinoDIR, HIGH); ledcWrite(_canal, ZeroRampa);
vTaskDelay(1500); vTaskDelay(400);
digitalWrite(_pinoDIR, LOW);
_SentidoM = _SentidoSP; _SentidoM = _SentidoSP;
GravarMemoria(_US_Addr, (int)_SentidoM);
Revertendo = false; Revertendo = false;
} }
digitalWrite(_pinoDIR, _SentidoSP == Horario);
} }
if (_pinoBRK > -1) { if (_pinoBRK > -1) {
digitalWrite(_pinoBRK, _Freio); digitalWrite(_pinoBRK, _Freio);
@ -444,62 +426,27 @@ private:
} }
} }
// TEMPERATURA E UMIDADE
TaskHandle_t DHT22TaskHandle = NULL;
static void DHT22TaskWrapper(void *pvParameters) {
Motor *motor = static_cast<Motor*>(pvParameters);
motor->DHT22Task();
}
void DHT22Task() {
unsigned long firstMilis = millis();
while (1)
{
if (!Conectado) {
vTaskDelay(1000);
continue;
}
long intMillis = (millis() - firstMilis);
if (intMillis >= _TaxaAmostragem + 2000) {
float t = dht->readTemperature();
yield();
vTaskDelay(500);
float h = dht->readHumidity();
yield();
vTaskDelay(500);
float hic = dht->computeHeatIndex(t, h, false);
yield();
vTaskDelay(500);
EnviarDadosSerial(MontarProtocoloSensor(sTMP, _ID, MontarDadosProtocoloDHT22(t, h, hic)));
firstMilis = millis();
}
vTaskDelay(100);
}
}
}; };
Motor M1("ET", M1_US_Addr); Motor M1("ET");
Motor M2("EF", M2_US_Addr); Motor M2("EF");
Motor M3("DT", M3_US_Addr); Motor M3("DT");
Motor M4("DF", M4_US_Addr); Motor M4("DF");
Motor* MotorPorID(String ID) {
Motor* _motor =
ID == "ET" ? &M1 :
ID == "EF" ? &M2 :
ID == "DT" ? &M3 :
ID == "DF" ? &M4 :
nullptr;
return _motor;
}
void setup() { void setup() {
Serial.begin(_baudRate); Serial.begin(_baudRate);
IniciarMemoria();
delay(10); delay(10);
/*LimparMemoria();
GravarMemoria(M1_US_Addr, (int)Horario);
GravarMemoria(M2_US_Addr, (int)Antihorario);
GravarMemoria(M3_US_Addr, (int)Antihorario);
GravarMemoria(M4_US_Addr, (int)Horario);*/
if (_pinoReleGeral > -1) { if (_pinoReleGeral > -1) {
pinMode(_pinoReleGeral, OUTPUT); pinMode(_pinoReleGeral, OUTPUT);
@ -569,9 +516,8 @@ void loop() {
int hallA = ((String)Protocolo[41] + (String)Protocolo[42]).toInt(); int hallA = ((String)Protocolo[41] + (String)Protocolo[42]).toInt();
int hallB = ((String)Protocolo[44] + (String)Protocolo[45]).toInt(); int hallB = ((String)Protocolo[44] + (String)Protocolo[45]).toInt();
int hallC = ((String)Protocolo[47] + (String)Protocolo[48]).toInt(); int hallC = ((String)Protocolo[47] + (String)Protocolo[48]).toInt();
int tmp = ((String)Protocolo[50] + (String)Protocolo[51]).toInt();
Motor* _motor = ID == "ET" ? &M1 : ID == "EF" ? &M2 : ID == "DT" ? &M3 : &M4; Motor* _motor = MotorPorID(ID);
if (motor_ativado) { if (motor_ativado) {
if (Conectar) { if (Conectar) {
_motor->_canal = canal; _motor->_canal = canal;
@ -582,7 +528,6 @@ void loop() {
_motor->_pinoHLA = hallA; _motor->_pinoHLA = hallA;
_motor->_pinoHLB = hallB; _motor->_pinoHLB = hallB;
_motor->_pinoHLC = hallC; _motor->_pinoHLC = hallC;
_motor->_pinoTMP = tmp;
_motor->_MalhaFechada = _foc; _motor->_MalhaFechada = _foc;
_motor->_Kp = _Kp; _motor->_Kp = _Kp;
_motor->_Ki = _Ki; _motor->_Ki = _Ki;
@ -602,7 +547,7 @@ void loop() {
//0;000;0;000;000;000 //0;000;0;000;000;000
String ID = ((String)Protocolo[0] + (String)Protocolo[1]); String ID = ((String)Protocolo[0] + (String)Protocolo[1]);
Motor* _motor = ID == "ET" ? &M1 : ID == "EF" ? &M2 : ID == "DT" ? &M3 : &M4; Motor* _motor = MotorPorID(ID);
_motor->_SentidoSP = (Sentido)((String)Protocolo[3]).toInt(); _motor->_SentidoSP = (Sentido)((String)Protocolo[3]).toInt();
_motor->_RPM_SP = ((String)Protocolo[5] + (String)Protocolo[6] + (String)Protocolo[7]).toInt(); _motor->_RPM_SP = ((String)Protocolo[5] + (String)Protocolo[6] + (String)Protocolo[7]).toInt();
@ -617,7 +562,7 @@ void loop() {
else if (_funcao == Tst) { else if (_funcao == Tst) {
String ID = ((String)Protocolo[0] +(String)Protocolo[1]); String ID = ((String)Protocolo[0] +(String)Protocolo[1]);
Motor* _motor = ID == "ET" ? &M1 : ID == "EF" ? &M2 : ID == "DT" ? &M3 : &M4; Motor* _motor = MotorPorID(ID);
bool EmTeste = _motor->Testando; bool EmTeste = _motor->Testando;
if (!EmTeste) { if (!EmTeste) {

View File

@ -1,8 +1,11 @@
// Dispositivo: Sensoriamento // Dispositivo: Sensoriamento
// Versão Firmware: 1 // Versão Firmware: 3
// Ultima atualização: 28/11/2023 // Ultima atualização: 23/01/2024
#include "C:\ZendionInc\agrobot_base\Firmware\Modulos\SerialService.h"
#include <SimpleKalmanFilter.h>
#include "C:\Zendion Inc\agrobot_base\Firmware\Modulos\SerialService.h"
#define D_Code Sen #define D_Code Sen
#define _pinoLED RGB_BUILTIN #define _pinoLED RGB_BUILTIN
@ -15,31 +18,20 @@ int _TaxaAmostragem;
int FrequenciaMaxima = 10000; int FrequenciaMaxima = 10000;
class Sensor { class SensorTemperatura {
public: public:
// Construtor SensorTemperatura(String desc) {
Sensor(String desc) {
_ID = desc; _ID = desc;
} }
// Definições // Definições
String _ID; String _ID;
S_Code _componente; S_Code _componente = sTMP;
int _prioridade; int _pino;
int _delayAmostragem; int _delayAmostragem;
bool _I2C; int _prioridade;
int _pinoLeitura1;
int _pinoLeitura2;
int _pinoLeitura3;
int _pinoLeitura4;
bool Iniciado = false; bool Iniciado = false;
bool Testando = false;
// Consumo
// Entrada de dados
void Inicializar() { void Inicializar() {
if (Iniciado) { if (Iniciado) {
@ -48,22 +40,13 @@ public:
return; return;
} }
if (_pinoLeitura1 > -1) { if (_pino > -1) {
pinMode(_pinoLeitura1, INPUT); pinMode(_pino, INPUT);
}
if (_pinoLeitura2 > -1) {
pinMode(_pinoLeitura2, INPUT);
}
if (_pinoLeitura3 > -1) {
pinMode(_pinoLeitura3, INPUT);
}
if (_pinoLeitura4 > -1) {
pinMode(_pinoLeitura4, INPUT);
} }
xTaskCreatePinnedToCore(&SensorTemperatura::STTaskWrapper, "STTask", 5000, this, _prioridade, &STTaskHandle, tskNO_AFFINITY);
xTaskCreatePinnedToCore(&Sensor::LeituraTaskWrapper, "LeituraTask", 5000, this, _prioridade, &LeituraTaskHandle, tskNO_AFFINITY); EnviarDadosSerial(_ID + " Iniciado");
Iniciado = true; Iniciado = true;
@ -78,22 +61,10 @@ public:
} }
// Parar a execução das tarefas // Parar a execução das tarefas
vTaskDelete(LeituraTaskHandle); vTaskDelete(STTaskHandle);
// Redefinir as configurações para os valores iniciais // Redefinir as configurações para os valores iniciais
if (_pinoLeitura1 > -1) { pinMode(_pino, INPUT);
pinMode(_pinoLeitura1, INPUT);
}
if (_pinoLeitura2 > -1) {
pinMode(_pinoLeitura2, INPUT);
}
if (_pinoLeitura3 > -1) {
pinMode(_pinoLeitura3, INPUT);
}
if (_pinoLeitura4 > -1) {
pinMode(_pinoLeitura4, INPUT);
}
EnviarDadosSerial(_ID + " Desligado"); EnviarDadosSerial(_ID + " Desligado");
@ -102,25 +73,24 @@ public:
EnviarDadosSerial(MontarProtocoloSensor(sCFG, _ID, Iniciado ? "1" : "0")); EnviarDadosSerial(MontarProtocoloSensor(sCFG, _ID, Iniciado ? "1" : "0"));
} }
void Testar() { private:
Testando = true;
Testando = false; // Variáveis
double Vs = 3.3; // TENSÃO DE SAIDA DO ESP32
double R1 = 10000; //RESISTOR UTILIZADO NO DIVISOR DE TENSÃO
double Beta = 3950; // VALOR DE BETA
double To = 298.15; // VALOR EM KELVIN REFERENTE A 25° CELSIUS
double Ro = 10000;
double adcMax = 4095.0;
TaskHandle_t STTaskHandle = NULL;
static void STTaskWrapper(void *pvParameters) {
SensorTemperatura *sensor = static_cast<SensorTemperatura*>(pvParameters);
sensor->STTask();
} }
void STTask() {
unsigned long firstMilis = millis();
private:
TaskHandle_t LeituraTaskHandle = NULL;
static void LeituraTaskWrapper(void *pvParameters) {
Sensor *sensor = static_cast<Sensor*>(pvParameters);
sensor->LeituraTask();
}
void LeituraTask() {
unsigned long previousMillisLeitura = millis();
while (1) while (1)
{ {
if (!Conectado) { if (!Conectado) {
@ -129,26 +99,288 @@ private:
continue; continue;
} }
// LEITURA AQUI long intMillis = (millis() - firstMilis);
unsigned long currentMillis = millis(); // A cada _TaxaAmostragem, enviar os dados para o software
if ((currentMillis - previousMillisLeitura) >= (_TaxaAmostragem + _delayAmostragem)) { if (intMillis >= (_TaxaAmostragem + _delayAmostragem)) {
previousMillisLeitura = currentMillis; AferirTemperatura();
EnviarDadosSerial(MontarProtocoloSensor(_componente, _ID, MontarDadosProtocoloSensorGenerico(""))); firstMilis = millis();
} }
// Aguarda metade do menor período possível entre leituras
vTaskDelay(1); vTaskDelay(1);
} }
} }
void AferirTemperatura() {
double Vout, Rt = 0;
double T, Tc, Tf, adc = 0;
adc = analogRead(_pino); // VARIÁVEL QUE RECEBE A LEITURA DO NTC10K
//float adcValue = tempKalman->updateEstimate(adc);
float adcValue = adc;
//CALCULOS PARA CONVERSÃO DA LEITURA RECEBIDA PELO ESP32 EM TEMPERATURA EM °C
Vout = adcValue * Vs / adcMax;
Rt = R1 * Vout / (Vs - Vout);
T = 1 / (1 / To + log(Rt / Ro) / Beta);
Tc = T - 273.15;
Tf = Tc * 9 / 5 + 32;
EnviarDadosSerial(MontarProtocoloSensor(sTMP, _ID, MontarDadosProtocoloNTC10K(Tc)));
}
};
class SensorTensao {
public:
SensorTensao(String desc) {
_ID = desc;
}
// Variáveis
const float Vcc = 3.3; // Tensão de alimentação
float Voffset = 0.85;
int R1 = 47000;
int R2 = 10000;
// Definições
String _ID;
S_Code _componente = sTEN;
int _pino;
int _delayAmostragem;
int _prioridade;
SimpleKalmanFilter* kalmanTEN;
bool Iniciado = false;
void Inicializar() {
if (Iniciado) {
EnviarDadosSerial(_ID + " ja inicializado");
EnviarDadosSerial(MontarProtocoloSensor(sCFG, _ID, Iniciado ? "1" : "0"));
return;
}
if (_pino > -1) {
pinMode(_pino, INPUT);
}
kalmanTEN = new SimpleKalmanFilter(2, 2, 0.01);
xTaskCreatePinnedToCore(&SensorTensao::SVTaskWrapper, "SVTask", 5000, this, _prioridade, &SVTaskHandle, tskNO_AFFINITY);
EnviarDadosSerial(_ID + " Iniciado");
Iniciado = true;
EnviarDadosSerial(MontarProtocoloSensor(sCFG, _ID, Iniciado ? "1" : "0"));
}
void Desligar() {
if (!Iniciado) {
EnviarDadosSerial(_ID + " nao esta inicializado");
EnviarDadosSerial(MontarProtocoloSensor(sCFG, _ID, Iniciado ? "1" : "0"));
return;
}
// Parar a execução das tarefas
vTaskDelete(SVTaskHandle);
// Redefinir as configurações para os valores iniciais
pinMode(_pino, INPUT);
delete kalmanTEN;
EnviarDadosSerial(_ID + " Desligado");
Iniciado = false;
EnviarDadosSerial(MontarProtocoloSensor(sCFG, _ID, Iniciado ? "1" : "0"));
}
private:
TaskHandle_t SVTaskHandle = NULL;
static void SVTaskWrapper(void *pvParameters) {
SensorTensao *sensor = static_cast<SensorTensao*>(pvParameters);
sensor->SVTask();
}
void SVTask() {
unsigned long firstMilis = millis();
while (1)
{
if (!Conectado) {
// Caso não esteja conectado, aguarda 1 segundo até a próxima verificação, liberando uso de CPU
vTaskDelay(1000);
continue;
}
long intMillis = (millis() - firstMilis);
// A cada _TaxaAmostragem, enviar os dados para o software
if (intMillis >= (_TaxaAmostragem + _delayAmostragem)) {
AferirTensao();
firstMilis = millis();
}
// Aguarda metade do menor período possível entre leituras
vTaskDelay(1);
}
}
void AferirTensao() {
float Razao = (R1 + R2) / (float)R2;
int adcV = analogRead(_pino);
float adcValueV = kalmanTEN->updateEstimate(adcV);
float voltageV = (adcValueV * (Vcc / 4095.0)) + (Voffset / Razao); // Convertendo o valor ADC para tensão
float realVoltage = voltageV * Razao;
EnviarDadosSerial(MontarProtocoloSensor(sTEN, _ID, MontarDadosProtocoloTensao(adcValueV, voltageV, realVoltage)));
}
}; };
Sensor sVBAT("VBAT"); class SensorCorrente {
Sensor sABAT("ABAT"); public:
SensorCorrente(String desc) {
_ID = desc;
}
// Variáveis
const float Vcc = 3.3; // Tensão de alimentação
float Voffset = 0.413;
float sensibilidade = 0.35;
// Definições
String _ID;
S_Code _componente = sCOR;
int _pino;
int _delayAmostragem;
int _prioridade;
SimpleKalmanFilter* kalmanCOR;
bool Iniciado = false;
void Inicializar() {
if (Iniciado) {
EnviarDadosSerial(_ID + " ja inicializado");
EnviarDadosSerial(MontarProtocoloSensor(sCFG, _ID, Iniciado ? "1" : "0"));
return;
}
if (_pino > -1) {
pinMode(_pino, INPUT);
}
kalmanCOR = new SimpleKalmanFilter(2, 2, 0.01);
xTaskCreatePinnedToCore(&SensorCorrente::SATaskWrapper, "SATask", 5000, this, _prioridade, &SATaskHandle, tskNO_AFFINITY);
EnviarDadosSerial(_ID + " Iniciado");
Iniciado = true;
EnviarDadosSerial(MontarProtocoloSensor(sCFG, _ID, Iniciado ? "1" : "0"));
}
void Desligar() {
if (!Iniciado) {
EnviarDadosSerial(_ID + " nao esta inicializado");
EnviarDadosSerial(MontarProtocoloSensor(sCFG, _ID, Iniciado ? "1" : "0"));
return;
}
// Parar a execução das tarefas
vTaskDelete(SATaskHandle);
// Redefinir as configurações para os valores iniciais
pinMode(_pino, INPUT);
delete kalmanCOR;
EnviarDadosSerial(_ID + " Desligado");
Iniciado = false;
EnviarDadosSerial(MontarProtocoloSensor(sCFG, _ID, Iniciado ? "1" : "0"));
}
private:
TaskHandle_t SATaskHandle = NULL;
static void SATaskWrapper(void *pvParameters) {
SensorCorrente *sensor = static_cast<SensorCorrente*>(pvParameters);
sensor->SATask();
}
void SATask() {
unsigned long firstMilis = millis();
while (1)
{
if (!Conectado) {
// Caso não esteja conectado, aguarda 1 segundo até a próxima verificação, liberando uso de CPU
vTaskDelay(1000);
continue;
}
long intMillis = (millis() - firstMilis);
// A cada _TaxaAmostragem, enviar os dados para o software
if (intMillis >= (_TaxaAmostragem + _delayAmostragem)) {
AferirCorrente();
firstMilis = millis();
}
// Aguarda metade do menor período possível entre leituras
vTaskDelay(1);
}
}
void AferirCorrente() {
int adcV = analogRead(_pino);
float adcValue = kalmanCOR->updateEstimate(adcV);
float voltage = adcValue * (Vcc / 4095.0); // Convertendo o valor ADC para tensão
float current = (voltage - Voffset) / sensibilidade; // Calculando a corrente em A
EnviarDadosSerial(MontarProtocoloSensor(sCOR, _ID, MontarDadosProtocoloCorrente(adcValue, voltage, current)));
}
};
SensorTemperatura TM1("TMVET");
SensorTemperatura TM2("TMVEF");
SensorTemperatura TM3("TMVDT");
SensorTemperatura TM4("TMVDF");
SensorTensao VBAT("VBAT ");
SensorCorrente ABAT("ABAT ");
SensorTemperatura* STPorID(String ID) {
SensorTemperatura* _sensor =
ID == "TMVET" ? &TM1 :
ID == "TMVEF" ? &TM2 :
ID == "TMVDT" ? &TM3 :
ID == "TMVDF" ? &TM4 :
nullptr;
return _sensor;
}
SensorTensao* SVPorID(String ID) {
SensorTensao* _sensor =
ID == "VBAT " ? &VBAT :
nullptr;
return _sensor;
}
SensorCorrente* SAPorID(String ID) {
SensorCorrente* _sensor =
ID == "ABAT " ? &ABAT :
nullptr;
return _sensor;
}
void setup() { void setup() {
Serial.begin(_baudRate); Serial.begin(_baudRate);
@ -176,59 +408,91 @@ void loop() {
if (_funcao == Chk) { if (_funcao == Chk) {
EnviarDadosSerial(MontarProtocoloVerificacao(D_Code)); EnviarDadosSerial(MontarProtocoloVerificacao(D_Code));
} } else if (_funcao == Cfg) {
else if (_funcao == Cfg) { String ID = ((String)Protocolo[0] + (String)Protocolo[1] + (String)Protocolo[2] + (String)Protocolo[3] + (String)Protocolo[4]);
String ID = ((String)Protocolo[0] + (String)Protocolo[1]); bool Conectar = (String)Protocolo[6] == "1";
bool Conectar = (String)Protocolo[3] == "1"; if (ID == "MD ") {
if (ID == "MD") { _TaxaAmostragem = ((String)Protocolo[8] + (String)Protocolo[9] + (String)Protocolo[10] + (String)Protocolo[11] + (String)Protocolo[12]).toInt();
_TaxaAmostragem = ((String)Protocolo[5] + (String)Protocolo[6] + (String)Protocolo[7] + (String)Protocolo[8] + (String)Protocolo[9]).toInt();
vTaskDelay(pdMS_TO_TICKS(100)); vTaskDelay(pdMS_TO_TICKS(100));
Conectado = Conectar; Conectado = Conectar;
EnviarDadosSerial(MontarProtocoloSensor(sCFG, "MD", Conectado ? "1" : "0")); EnviarDadosSerial(MontarProtocoloSensor(sCFG, "MD", Conectado ? "1" : "0"));
} }
else { else {
Sensor* _sensor = ID == "VBAT" ? &sVBAT : ID == "ABAT" ? &sABAT : nullptr; S_Code componente = (S_Code)((String)Protocolo[8] + (String)Protocolo[9] + (String)Protocolo[10]).toInt();
bool sensor_ativado = (String)Protocolo[12] == "1";
int delayAmostragem = ((String)Protocolo[14] + (String)Protocolo[15] + (String)Protocolo[16] + (String)Protocolo[17] + (String)Protocolo[18]).toInt();
int prioridade = ((String)Protocolo[20] + (String)Protocolo[21]).toInt();
int pino = ((String)Protocolo[23] + (String)Protocolo[24]).toInt();
if (_sensor == nullptr) { switch (componente) {
return; case sTMP: {
} SensorTemperatura* _sensor = STPorID(ID);
if (sensor_ativado) {
S_Code componente = (S_Code)((String)Protocolo[5]).toInt();
int prioridade = ((String)Protocolo[7] + (String)Protocolo[8]).toInt();
int delayAmostragem = ((String)Protocolo[10] + (String)Protocolo[11] + (String)Protocolo[12] + (String)Protocolo[13] + (String)Protocolo[14]).toInt();
bool aferir = ((String)Protocolo[16]) == "1";
bool i2c = ((String)Protocolo[18]) == "1";
int lei_1 = ((String)Protocolo[20] + (String)Protocolo[21]).toInt();
int lei_2 = ((String)Protocolo[23] + (String)Protocolo[24]).toInt();
int lei_3 = ((String)Protocolo[26] + (String)Protocolo[27]).toInt();
int lei_4 = ((String)Protocolo[29] + (String)Protocolo[30]).toInt();
if (aferir) {
if (Conectar) { if (Conectar) {
_sensor->_pino = pino;
_sensor->_prioridade = prioridade; _sensor->_prioridade = prioridade;
_sensor->_delayAmostragem = delayAmostragem; _sensor->_delayAmostragem = delayAmostragem;
_sensor->_I2C = i2c;
_sensor->_pinoLeitura1 = lei_1;
_sensor->_pinoLeitura2 = lei_2;
_sensor->_pinoLeitura3 = lei_3;
_sensor->_pinoLeitura4 = lei_4;
_sensor->Inicializar(); _sensor->Inicializar();
} }
else { else {
_sensor->Desligar(); _sensor->Desligar();
} }
vTaskDelay(pdMS_TO_TICKS(500));
} }
break;
} }
} case sTEN: {
else if (_funcao == Cmd) { SensorTensao* _sensor = SVPorID(ID);
if (sensor_ativado) {
double _voffset = ((String)Protocolo[26] + (String)Protocolo[27] + (String)Protocolo[28] + (String)Protocolo[29] + (String)Protocolo[30] + (String)Protocolo[31]).toDouble();
double _r1 = ((String)Protocolo[33] + (String)Protocolo[34] + (String)Protocolo[35] + (String)Protocolo[36] + (String)Protocolo[37] + (String)Protocolo[38]).toDouble();
double _r2 = ((String)Protocolo[40] + (String)Protocolo[41] + (String)Protocolo[42] + (String)Protocolo[43] + (String)Protocolo[44] + (String)Protocolo[45]).toDouble();
_sensor->Voffset = (float)_voffset;
_sensor->R1 = (int)_r1;
_sensor->R2 = (int)_r2;
if (Conectar) {
_sensor->_pino = pino;
_sensor->_prioridade = prioridade;
_sensor->_delayAmostragem = delayAmostragem;
_sensor->Inicializar();
}
else {
_sensor->Desligar();
}
}
break;
}
case sCOR: {
SensorCorrente* _sensor = SAPorID(ID);
if (sensor_ativado) {
double _voffset = ((String)Protocolo[26] + (String)Protocolo[27] + (String)Protocolo[28] + (String)Protocolo[29] + (String)Protocolo[30] + (String)Protocolo[31]).toDouble();
double _sensibilidade = ((String)Protocolo[33] + (String)Protocolo[34] + (String)Protocolo[35] + (String)Protocolo[36] + (String)Protocolo[37] + (String)Protocolo[38]).toDouble();
_sensor->Voffset = (float)_voffset;
_sensor->sensibilidade = (float)_sensibilidade;
if (Conectar) {
_sensor->_pino = pino;
_sensor->_prioridade = prioridade;
_sensor->_delayAmostragem = delayAmostragem;
_sensor->Inicializar();
}
else {
_sensor->Desligar();
}
}
break;
} }
else if (_funcao == Tst) {
} }
}
} else if (_funcao == Cmd) {
} else if (_funcao == Tst) {
}
} }
} }

View File

@ -93,4 +93,20 @@ String MontarDadosProtocoloNTC10K(float temperatura) {
return Protocolo; return Protocolo;
} }
String MontarDadosProtocoloTensao(float leitura, float vPin, float vReal) {
String Protocolo =
(String)leitura + ";" +
(String)vPin + ";" +
(String)vReal;
return Protocolo;
}
String MontarDadosProtocoloCorrente(float leitura, float vPin, float corrente) {
String Protocolo =
(String)leitura + ";" +
(String)vPin + ";" +
(String)corrente;
return Protocolo;
}
#endif #endif

View File

@ -429,6 +429,16 @@ Motor M2("EF");
Motor M3("DT"); Motor M3("DT");
Motor M4("DF"); Motor M4("DF");
Motor* MotorPorID(String ID) {
Motor* _motor =
ID == "ET" ? &M1 :
ID == "EF" ? &M2 :
ID == "DT" ? &M3 :
ID == "DF" ? &M4 :
nullptr;
return _motor;
}
void setup() { void setup() {
Serial.begin(_baudRate); Serial.begin(_baudRate);
@ -503,7 +513,7 @@ void loop() {
int hallB = ((String)Protocolo[44] + (String)Protocolo[45]).toInt(); int hallB = ((String)Protocolo[44] + (String)Protocolo[45]).toInt();
int hallC = ((String)Protocolo[47] + (String)Protocolo[48]).toInt(); int hallC = ((String)Protocolo[47] + (String)Protocolo[48]).toInt();
Motor* _motor = ID == "ET" ? &M1 : ID == "EF" ? &M2 : ID == "DT" ? &M3 : &M4; Motor* _motor = MotorPorID(ID);
if (motor_ativado) { if (motor_ativado) {
if (Conectar) { if (Conectar) {
_motor->_canal = canal; _motor->_canal = canal;
@ -533,7 +543,7 @@ void loop() {
//0;000;0;000;000;000 //0;000;0;000;000;000
String ID = ((String)Protocolo[0] + (String)Protocolo[1]); String ID = ((String)Protocolo[0] + (String)Protocolo[1]);
Motor* _motor = ID == "ET" ? &M1 : ID == "EF" ? &M2 : ID == "DT" ? &M3 : &M4; Motor* _motor = MotorPorID(ID);
_motor->_SentidoSP = (Sentido)((String)Protocolo[3]).toInt(); _motor->_SentidoSP = (Sentido)((String)Protocolo[3]).toInt();
_motor->_RPM_SP = ((String)Protocolo[5] + (String)Protocolo[6] + (String)Protocolo[7]).toInt(); _motor->_RPM_SP = ((String)Protocolo[5] + (String)Protocolo[6] + (String)Protocolo[7]).toInt();
@ -548,7 +558,7 @@ void loop() {
else if (_funcao == Tst) { else if (_funcao == Tst) {
String ID = ((String)Protocolo[0] +(String)Protocolo[1]); String ID = ((String)Protocolo[0] +(String)Protocolo[1]);
Motor* _motor = ID == "ET" ? &M1 : ID == "EF" ? &M2 : ID == "DT" ? &M3 : &M4; Motor* _motor = MotorPorID(ID);
bool EmTeste = _motor->Testando; bool EmTeste = _motor->Testando;
if (!EmTeste) { if (!EmTeste) {

View File

@ -1,6 +1,10 @@
#include "C:\Zendion Inc\agrobot_base\Firmware\Modulos\SerialService.h" // Dispositivo: Movimentação
#include "C:\Zendion Inc\agrobot_base\Firmware\Modulos\MemoryService.h" // Versão Firmware: 9
#include "C:\Zendion Inc\agrobot_base\Firmware\Modulos\utils.h" // Ultima atualização: 21/11/2023
#include "C:\ZendionInc\agrobot_base\Firmware\Modulos\SerialService.h"
#include "C:\ZendionInc\agrobot_base\Firmware\Modulos\MemoryService.h"
#include "C:\ZendionInc\agrobot_base\Firmware\Modulos\utils.h"
#include <PID_v1.h> #include <PID_v1.h>
#include "DHT.h" #include "DHT.h"
#define D_Code Mov #define D_Code Mov

View File

@ -0,0 +1,494 @@
#include "C:\ZendionInc\agrobot_base\Firmware\Modulos\SerialService.h"
#include <SimpleKalmanFilter.h>
#define D_Code Sen
#define _pinoLED RGB_BUILTIN
long _baudRate = 115200;
bool Conectado = false;
int _TaxaAmostragem;
int FrequenciaMaxima = 10000;
class SensorTemperatura {
public:
SensorTemperatura(String desc) {
_ID = desc;
}
// Definições
String _ID;
S_Code _componente = sTMP;
int _pino;
int _delayAmostragem;
int _prioridade;
bool Iniciado = false;
void Inicializar() {
if (Iniciado) {
EnviarDadosSerial(_ID + " ja inicializado");
EnviarDadosSerial(MontarProtocoloSensor(sCFG, _ID, Iniciado ? "1" : "0"));
return;
}
if (_pino > -1) {
pinMode(_pino, INPUT);
}
xTaskCreatePinnedToCore(&SensorTemperatura::STTaskWrapper, "STTask", 5000, this, _prioridade, &STTaskHandle, tskNO_AFFINITY);
EnviarDadosSerial(_ID + " Iniciado");
Iniciado = true;
EnviarDadosSerial(MontarProtocoloSensor(sCFG, _ID, Iniciado ? "1" : "0"));
}
void Desligar() {
if (!Iniciado) {
EnviarDadosSerial(_ID + " nao esta inicializado");
EnviarDadosSerial(MontarProtocoloSensor(sCFG, _ID, Iniciado ? "1" : "0"));
return;
}
// Parar a execução das tarefas
vTaskDelete(STTaskHandle);
// Redefinir as configurações para os valores iniciais
pinMode(_pino, INPUT);
EnviarDadosSerial(_ID + " Desligado");
Iniciado = false;
EnviarDadosSerial(MontarProtocoloSensor(sCFG, _ID, Iniciado ? "1" : "0"));
}
private:
// Variáveis
double Vs = 3.3; // TENSÃO DE SAIDA DO ESP32
double R1 = 10000; //RESISTOR UTILIZADO NO DIVISOR DE TENSÃO
double Beta = 3950; // VALOR DE BETA
double To = 298.15; // VALOR EM KELVIN REFERENTE A 25° CELSIUS
double Ro = 10000;
double adcMax = 4095.0;
TaskHandle_t STTaskHandle = NULL;
static void STTaskWrapper(void *pvParameters) {
SensorTemperatura *sensor = static_cast<SensorTemperatura*>(pvParameters);
sensor->STTask();
}
void STTask() {
unsigned long firstMilis = millis();
while (1)
{
if (!Conectado) {
// Caso não esteja conectado, aguarda 1 segundo até a próxima verificação, liberando uso de CPU
vTaskDelay(1000);
continue;
}
long intMillis = (millis() - firstMilis);
// A cada _TaxaAmostragem, enviar os dados para o software
if (intMillis >= (_TaxaAmostragem + _delayAmostragem)) {
AferirTemperatura();
firstMilis = millis();
}
// Aguarda metade do menor período possível entre leituras
vTaskDelay(1);
}
}
void AferirTemperatura() {
double Vout, Rt = 0;
double T, Tc, Tf, adc = 0;
adc = analogRead(_pino); // VARIÁVEL QUE RECEBE A LEITURA DO NTC10K
//float adcValue = tempKalman->updateEstimate(adc);
float adcValue = adc;
//CALCULOS PARA CONVERSÃO DA LEITURA RECEBIDA PELO ESP32 EM TEMPERATURA EM °C
Vout = adcValue * Vs / adcMax;
Rt = R1 * Vout / (Vs - Vout);
T = 1 / (1 / To + log(Rt / Ro) / Beta);
Tc = T - 273.15;
Tf = Tc * 9 / 5 + 32;
EnviarDadosSerial(MontarProtocoloSensor(sTMP, _ID, MontarDadosProtocoloNTC10K(Tc)));
}
};
class SensorTensao {
public:
SensorTensao(String desc) {
_ID = desc;
}
// Variáveis
const float Vcc = 3.3; // Tensão de alimentação
float Voffset = 0.85;
int R1 = 47000;
int R2 = 10000;
// Definições
String _ID;
S_Code _componente = sTEN;
int _pino;
int _delayAmostragem;
int _prioridade;
SimpleKalmanFilter* kalmanTEN;
bool Iniciado = false;
void Inicializar() {
if (Iniciado) {
EnviarDadosSerial(_ID + " ja inicializado");
EnviarDadosSerial(MontarProtocoloSensor(sCFG, _ID, Iniciado ? "1" : "0"));
return;
}
if (_pino > -1) {
pinMode(_pino, INPUT);
}
kalmanTEN = new SimpleKalmanFilter(2, 2, 0.01);
xTaskCreatePinnedToCore(&SensorTensao::SVTaskWrapper, "SVTask", 5000, this, _prioridade, &SVTaskHandle, tskNO_AFFINITY);
EnviarDadosSerial(_ID + " Iniciado");
Iniciado = true;
EnviarDadosSerial(MontarProtocoloSensor(sCFG, _ID, Iniciado ? "1" : "0"));
}
void Desligar() {
if (!Iniciado) {
EnviarDadosSerial(_ID + " nao esta inicializado");
EnviarDadosSerial(MontarProtocoloSensor(sCFG, _ID, Iniciado ? "1" : "0"));
return;
}
// Parar a execução das tarefas
vTaskDelete(SVTaskHandle);
// Redefinir as configurações para os valores iniciais
pinMode(_pino, INPUT);
delete kalmanTEN;
EnviarDadosSerial(_ID + " Desligado");
Iniciado = false;
EnviarDadosSerial(MontarProtocoloSensor(sCFG, _ID, Iniciado ? "1" : "0"));
}
private:
TaskHandle_t SVTaskHandle = NULL;
static void SVTaskWrapper(void *pvParameters) {
SensorTensao *sensor = static_cast<SensorTensao*>(pvParameters);
sensor->SVTask();
}
void SVTask() {
unsigned long firstMilis = millis();
while (1)
{
if (!Conectado) {
// Caso não esteja conectado, aguarda 1 segundo até a próxima verificação, liberando uso de CPU
vTaskDelay(1000);
continue;
}
long intMillis = (millis() - firstMilis);
// A cada _TaxaAmostragem, enviar os dados para o software
if (intMillis >= (_TaxaAmostragem + _delayAmostragem)) {
AferirTensao();
firstMilis = millis();
}
// Aguarda metade do menor período possível entre leituras
vTaskDelay(1);
}
}
void AferirTensao() {
float Razao = (R1 + R2) / (float)R2;
int adcV = analogRead(_pino);
float adcValueV = kalmanTEN->updateEstimate(adcV);
float voltageV = (adcValueV * (Vcc / 4095.0)) + (Voffset / Razao); // Convertendo o valor ADC para tensão
float realVoltage = voltageV * Razao;
EnviarDadosSerial(MontarProtocoloSensor(sTEN, _ID, MontarDadosProtocoloTensao(adcValueV, voltageV, realVoltage)));
}
};
class SensorCorrente {
public:
SensorCorrente(String desc) {
_ID = desc;
}
// Variáveis
const float Vcc = 3.3; // Tensão de alimentação
float Voffset = 0.413;
float sensibilidade = 0.35;
// Definições
String _ID;
S_Code _componente = sCOR;
int _pino;
int _delayAmostragem;
int _prioridade;
SimpleKalmanFilter* kalmanCOR;
bool Iniciado = false;
void Inicializar() {
if (Iniciado) {
EnviarDadosSerial(_ID + " ja inicializado");
EnviarDadosSerial(MontarProtocoloSensor(sCFG, _ID, Iniciado ? "1" : "0"));
return;
}
if (_pino > -1) {
pinMode(_pino, INPUT);
}
kalmanCOR = new SimpleKalmanFilter(2, 2, 0.01);
xTaskCreatePinnedToCore(&SensorCorrente::SATaskWrapper, "SATask", 5000, this, _prioridade, &SATaskHandle, tskNO_AFFINITY);
EnviarDadosSerial(_ID + " Iniciado");
Iniciado = true;
EnviarDadosSerial(MontarProtocoloSensor(sCFG, _ID, Iniciado ? "1" : "0"));
}
void Desligar() {
if (!Iniciado) {
EnviarDadosSerial(_ID + " nao esta inicializado");
EnviarDadosSerial(MontarProtocoloSensor(sCFG, _ID, Iniciado ? "1" : "0"));
return;
}
// Parar a execução das tarefas
vTaskDelete(SATaskHandle);
// Redefinir as configurações para os valores iniciais
pinMode(_pino, INPUT);
delete kalmanCOR;
EnviarDadosSerial(_ID + " Desligado");
Iniciado = false;
EnviarDadosSerial(MontarProtocoloSensor(sCFG, _ID, Iniciado ? "1" : "0"));
}
private:
TaskHandle_t SATaskHandle = NULL;
static void SATaskWrapper(void *pvParameters) {
SensorCorrente *sensor = static_cast<SensorCorrente*>(pvParameters);
sensor->SATask();
}
void SATask() {
unsigned long firstMilis = millis();
while (1)
{
if (!Conectado) {
// Caso não esteja conectado, aguarda 1 segundo até a próxima verificação, liberando uso de CPU
vTaskDelay(1000);
continue;
}
long intMillis = (millis() - firstMilis);
// A cada _TaxaAmostragem, enviar os dados para o software
if (intMillis >= (_TaxaAmostragem + _delayAmostragem)) {
AferirCorrente();
firstMilis = millis();
}
// Aguarda metade do menor período possível entre leituras
vTaskDelay(1);
}
}
void AferirCorrente() {
int adcV = analogRead(_pino);
float adcValue = kalmanCOR->updateEstimate(adcV);
float voltage = adcValue * (Vcc / 4095.0); // Convertendo o valor ADC para tensão
float current = (voltage - Voffset) / sensibilidade; // Calculando a corrente em A
EnviarDadosSerial(MontarProtocoloSensor(sCOR, _ID, MontarDadosProtocoloCorrente(adcValue, voltage, current)));
}
};
SensorTemperatura TM1("TMVET");
SensorTemperatura TM2("TMVEF");
SensorTemperatura TM3("TMVDT");
SensorTemperatura TM4("TMVDF");
SensorTensao VBAT("VBAT ");
SensorCorrente ABAT("ABAT ");
SensorTemperatura* STPorID(String ID) {
SensorTemperatura* _sensor =
ID == "TMVET" ? &TM1 :
ID == "TMVEF" ? &TM2 :
ID == "TMVDT" ? &TM3 :
ID == "TMVDF" ? &TM4 :
nullptr;
return _sensor;
}
SensorTensao* SVPorID(String ID) {
SensorTensao* _sensor =
ID == "VBAT " ? &VBAT :
nullptr;
return _sensor;
}
SensorCorrente* SAPorID(String ID) {
SensorCorrente* _sensor =
ID == "ABAT " ? &ABAT :
nullptr;
return _sensor;
}
void setup() {
Serial.begin(_baudRate);
}
void loop() {
if (Serial.available() > 3) {
String Protocolo = "";
F_Code _funcao = Nda;
while (Serial.available()) {
char Entrada = (char)Serial.read();
if (Entrada == EndLine) {
break;
}
Protocolo += Entrada;
if (Protocolo.length() == 3) {
if (_funcao == Nda) {
_funcao = (F_Code)((String)Protocolo[0] + (String)Protocolo[1] + (String)Protocolo[2]).toInt();
Protocolo = "";
}
}
}
EnviarDadosSerial("OK");
if (_funcao == Chk) {
EnviarDadosSerial(MontarProtocoloVerificacao(D_Code));
} else if (_funcao == Cfg) {
String ID = ((String)Protocolo[0] + (String)Protocolo[1] + (String)Protocolo[2] + (String)Protocolo[3] + (String)Protocolo[4]);
bool Conectar = (String)Protocolo[6] == "1";
if (ID == "MD ") {
_TaxaAmostragem = ((String)Protocolo[8] + (String)Protocolo[9] + (String)Protocolo[10] + (String)Protocolo[11] + (String)Protocolo[12]).toInt();
vTaskDelay(pdMS_TO_TICKS(100));
Conectado = Conectar;
EnviarDadosSerial(MontarProtocoloSensor(sCFG, "MD", Conectado ? "1" : "0"));
}
else {
S_Code componente = (S_Code)((String)Protocolo[8] + (String)Protocolo[9] + (String)Protocolo[10]).toInt();
bool sensor_ativado = (String)Protocolo[12] == "1";
int delayAmostragem = ((String)Protocolo[14] + (String)Protocolo[15] + (String)Protocolo[16] + (String)Protocolo[17] + (String)Protocolo[18]).toInt();
int prioridade = ((String)Protocolo[20] + (String)Protocolo[21]).toInt();
int pino = ((String)Protocolo[23] + (String)Protocolo[24]).toInt();
switch (componente) {
case sTMP: {
SensorTemperatura* _sensor = STPorID(ID);
if (sensor_ativado) {
if (Conectar) {
_sensor->_pino = pino;
_sensor->_prioridade = prioridade;
_sensor->_delayAmostragem = delayAmostragem;
_sensor->Inicializar();
}
else {
_sensor->Desligar();
}
}
break;
}
case sTEN: {
SensorTensao* _sensor = SVPorID(ID);
if (sensor_ativado) {
double _voffset = ((String)Protocolo[26] + (String)Protocolo[27] + (String)Protocolo[28] + (String)Protocolo[29] + (String)Protocolo[30] + (String)Protocolo[31]).toDouble();
double _r1 = ((String)Protocolo[33] + (String)Protocolo[34] + (String)Protocolo[35] + (String)Protocolo[36] + (String)Protocolo[37] + (String)Protocolo[38]).toDouble();
double _r2 = ((String)Protocolo[40] + (String)Protocolo[41] + (String)Protocolo[42] + (String)Protocolo[43] + (String)Protocolo[44] + (String)Protocolo[45]).toDouble();
_sensor->Voffset = (float)_voffset;
_sensor->R1 = (int)_r1;
_sensor->R2 = (int)_r2;
if (Conectar) {
_sensor->_pino = pino;
_sensor->_prioridade = prioridade;
_sensor->_delayAmostragem = delayAmostragem;
_sensor->Inicializar();
}
else {
_sensor->Desligar();
}
}
break;
}
case sCOR: {
SensorCorrente* _sensor = SAPorID(ID);
if (sensor_ativado) {
double _voffset = ((String)Protocolo[26] + (String)Protocolo[27] + (String)Protocolo[28] + (String)Protocolo[29] + (String)Protocolo[30] + (String)Protocolo[31]).toDouble();
double _sensibilidade = ((String)Protocolo[33] + (String)Protocolo[34] + (String)Protocolo[35] + (String)Protocolo[36] + (String)Protocolo[37] + (String)Protocolo[38]).toDouble();
_sensor->Voffset = (float)_voffset;
_sensor->sensibilidade = (float)_sensibilidade;
if (Conectar) {
_sensor->_pino = pino;
_sensor->_prioridade = prioridade;
_sensor->_delayAmostragem = delayAmostragem;
_sensor->Inicializar();
}
else {
_sensor->Desligar();
}
}
break;
}
}
}
} else if (_funcao == Cmd) {
} else if (_funcao == Tst) {
}
}
}

View File

@ -3,11 +3,8 @@
SimpleKalmanFilter kalmanCOR(2, 2, 0.01); SimpleKalmanFilter kalmanCOR(2, 2, 0.01);
SimpleKalmanFilter kalmanTEN(2, 2, 0.01); SimpleKalmanFilter kalmanTEN(2, 2, 0.01);
#define _pinoCOR 4 #define _pinoCOR 25
#define _pinoTEN 34 #define _pinoTEN 26
const float Vcc = 4.16; // Tensão de alimentação do ACS758
const float Voffset = 0.502; // Tensão de offset do ACS758
const float sensibilidade = 0.17; // Sensibilidade do ACS758 em V/A (40mV/A para este exemplo)
void setup() { void setup() {
Serial.begin(115200); Serial.begin(115200);
@ -16,6 +13,17 @@ void setup() {
} }
void loop() { void loop() {
AferirCorrente();
AferirTensao();
delay(100);
}
void AferirCorrente() {
const float Vcc = 3.3; // Tensão de alimentação do ACS758
const float Voffset = 0.413; // Tensão de offset do ACS758
const float sensibilidade = 0.35; // Sensibilidade do ACS758 em V/A (40mV/A para este exemplo)
int adcValueO = analogRead(_pinoCOR); int adcValueO = analogRead(_pinoCOR);
float adcValue = kalmanCOR.updateEstimate(adcValueO); float adcValue = kalmanCOR.updateEstimate(adcValueO);
@ -28,16 +36,24 @@ void loop() {
Serial.print(voltage, 3); // Mostra a tensão com 3 casas decimais Serial.print(voltage, 3); // Mostra a tensão com 3 casas decimais
Serial.print(" Current: "); Serial.print(" Current: ");
Serial.println(current, 3); // Mostra a corrente com 3 casas decimais Serial.println(current, 3); // Mostra a corrente com 3 casas decimais
}
delay(100); void AferirTensao() {
const float Vcc = 3.3; // Tensão de alimentação
const float Voffset = 0.85;
int R1 = 47000;
int R2 = 10000;
float Razao = (R1 + R2) / (float)R2;
int adcV = analogRead(_pinoTEN); int adcV = analogRead(_pinoTEN);
float adcValueV = kalmanTEN.updateEstimate(adcV); float adcValueV = kalmanTEN.updateEstimate(adcV);
float voltageV = adcValueV * (Vcc / 4095.0); // Convertendo o valor ADC para tensão float voltageV = (adcValueV * (Vcc / 4095.0)) + (Voffset / Razao); // Convertendo o valor ADC para tensão
float realVoltage = voltageV * Razao;
Serial.print("Leitura: "); Serial.print("Leitura: ");
Serial.print(adcValueV); Serial.print(adcValueV);
Serial.print(" - Tensao: "); Serial.print(" - Tensao pino: ");
Serial.println(voltageV); Serial.print(voltageV);
Serial.print(" - Tensão: ");
Serial.println(realVoltage);
} }