ajustes no controle direcional

This commit is contained in:
Diego Freitas 2025-03-26 10:04:52 -03:00
parent e4383254c1
commit 9338e6d39b
10 changed files with 55 additions and 35 deletions

Binary file not shown.

View File

@ -336,7 +336,7 @@ namespace AgroBase.Models.Modules
MKS057DService.AdicionarComandoNaFila(MKS057DService.MontarComandoRequisicaoIO(modAddr));
// Verifica se o angulo de set point do motor em questao e diferente do angulo atual, e se for, reenvia o comando para garantir que o motor esteja coerente com o set point
if (!MKS057DService.Referenciando && (Modulo.DirMotor.UltimoComandoEnviado.AddMilliseconds(500) < DateTime.Now) && !Modulo.DirMotor.AtingiuAnguloSP)
if (!MKS057DService.Referenciando && (Modulo.DirMotor.UltimoComandoEnviado.AddMilliseconds(MKS057DService.TaxaAmostragem) < DateTime.Now) && !Modulo.DirMotor.AtingiuAnguloSP)
{
var Controle = Variaveis.OperacaoEmAndamento.Controle.TiposControle?.FirstOrDefault(x => x.Tipo == T_Code.Dir);
if (Controle != null)
@ -347,7 +347,7 @@ namespace AgroBase.Models.Modules
}
}
MKS057DService.TaxaAmostragem = MKS057DService.Referenciando ? 200 : 1000;
MKS057DService.TaxaAmostragem = MKS057DService.Referenciando ? 200 : 500;
tmrRegistradorDIR.SetInterval(MKS057DService.TaxaAmostragem);
}

View File

@ -317,7 +317,7 @@ namespace AgroBase.Services
Endereco = Endereco,
AguardaResposta = true,
TamanhoResposta = 8,
TimeoutResposta = 200,
TimeoutResposta = 300,
};
}
@ -332,7 +332,7 @@ namespace AgroBase.Services
Endereco = Endereco,
AguardaResposta = true,
TamanhoResposta = 5,
TimeoutResposta = 200,
TimeoutResposta = 300,
};
}
@ -407,7 +407,7 @@ namespace AgroBase.Services
ModoControle = Controle,
AguardaResposta = true,
TamanhoResposta = 5,
TimeoutResposta = 200,
TimeoutResposta = 300,
};
}
@ -486,6 +486,7 @@ namespace AgroBase.Services
if (!resend)
{
await Task.Delay(50);
await EnviarComandoControle(Comando, true);
}
}
@ -505,6 +506,7 @@ namespace AgroBase.Services
}
finally
{
await Task.Delay(20);
FilaEmEspera = false;
}
}
@ -596,7 +598,7 @@ namespace AgroBase.Services
private static bool DecifrarRespostaDriver(byte[] resposta)
{
if (resposta == null || resposta.Length == 0)
if (resposta == null || resposta.Length <= 3)
{
return false;
}
@ -641,7 +643,8 @@ namespace AgroBase.Services
leitura.NumeroPulsos_Hex += "0x";
for (int a = 3; a < 7; a++)
{
str = Convert.ToString(_SerialBuffer_RX[a], 16).ToUpper();
byte f = a < _SerialBuffer_RX.Length ? _SerialBuffer_RX[a] : (byte)0;
str = Convert.ToString(f, 16).ToUpper();
leitura.NumeroPulsos_Hex += str.Length == 1 ? "0" + str : str;
}
}
@ -652,7 +655,8 @@ namespace AgroBase.Services
word32 = "0";
for (int a = 3; a < 7; a++)
{
str = Convert.ToString(_SerialBuffer_RX[a], 16).ToUpper();
byte f = a < _SerialBuffer_RX.Length ? _SerialBuffer_RX[a] : (byte)0;
str = Convert.ToString(f, 16).ToUpper();
word32 += str.Length == 1 ? "0" + str : str;
}
data32 = Convert.ToInt32(word32, 16);
@ -695,7 +699,8 @@ namespace AgroBase.Services
leitura.RPM_Hex += "0x";
for (int a = 3; a < 5; a++)
{
str = Convert.ToString(_SerialBuffer_RX[a], 16).ToUpper();
byte f = a < _SerialBuffer_RX.Length ? _SerialBuffer_RX[a] : (byte)0;
str = Convert.ToString(f, 16).ToUpper();
leitura.RPM_Hex += str.Length == 1 ? "0" + str : str;
}
}
@ -705,7 +710,8 @@ namespace AgroBase.Services
word16 = "0";
for (int a = 3; a < 5; a++)
{
str = Convert.ToString(_SerialBuffer_RX[a], 16).ToUpper();
byte f = a < _SerialBuffer_RX.Length ? _SerialBuffer_RX[a] : (byte)0;
str = Convert.ToString(f, 16).ToUpper();
word16 += str.Length == 1 ? "0" + str : str;
}
data16 = Convert.ToInt16(word16, 16);

View File

@ -28,6 +28,10 @@ namespace AgroBase.Services
public static double CorrenteMax { get; set; } = 20.0;
public static bool ModoLeitura = false;
private static double FatorLeituraTensao = 0.01;
private static double FatorLeituraCorrente = 0.025;
private static double FatorLeituraPotencia = 0.00001;
public static Dictionary<string, byte> CodigosFuncoes = new Dictionary<string, byte>()
{
@ -118,11 +122,11 @@ namespace AgroBase.Services
DataHora = DateTime.Now,
};
var tensao_raw = "0x" + resposta[3].ToString("X") + resposta[4].ToString("X");
modelo.Tensao = Convert.ToInt32(tensao_raw, 16) * 0.02; // 0.01;
modelo.Tensao = Convert.ToInt32(tensao_raw, 16) * FatorLeituraTensao;
var corrente_raw = "0x" + resposta[5].ToString("X") + resposta[6].ToString("X");
modelo.Corrente = Convert.ToInt32(corrente_raw, 16) * 0.002; // 0.0015;
modelo.Corrente = Convert.ToInt32(corrente_raw, 16) * FatorLeituraCorrente;
var potencia_raw = "0x" + resposta[7].ToString("X") + resposta[8].ToString("X") + resposta[9].ToString("X") + resposta[10].ToString("X");
modelo.Potencia = Convert.ToInt32(potencia_raw, 16) * 0.0001; // 0.1;
modelo.Potencia = Convert.ToInt32(potencia_raw, 16) * FatorLeituraPotencia;
var energia_raw = "0x" + resposta[11].ToString("X") + resposta[12].ToString("X") + resposta[13].ToString("X") + resposta[14].ToString("X");
modelo.Energia = Convert.ToInt32(energia_raw, 16) * 1.0;
var almMax_raw = "0x" + resposta[15].ToString("X") + resposta[16].ToString("X");

View File

@ -793,7 +793,7 @@ namespace AgroBase.Services
private static async Task<bool> ProcuraDispositivoBLD()
{
if (!BLD300RService.Iniciado || BLD300RService.DadosLeitura.Any(x => !x.Iniciado))
if (!BLD300RService.Iniciado || BLD300RService.DadosLeitura.Count(x => x.Iniciado) < (Variaveis.OperacaoEmAndamento.DispMvd?.Dados?.Modulos?.Count() ?? 4))
{
AtualizarConsole("Procurando dispositivos BLD");
bool Encontrado = await BLD300RService.VerificaPortaBLD();
@ -809,7 +809,7 @@ namespace AgroBase.Services
private static async Task<bool> ProcuraDispositivoOID()
{
if (!OIDService.Iniciado || OIDService.DadosLeitura.Any(x => !x.Iniciado))
if (!OIDService.Iniciado || OIDService.DadosLeitura.Count(x => x.Iniciado) < (Variaveis.OperacaoEmAndamento.DispMvd?.Dados?.Modulos?.Count() ?? 4))
{
AtualizarConsole("Procurando dispositivos OID");
bool Encontrado = await OIDService.VerificaPortaOID();
@ -825,7 +825,7 @@ namespace AgroBase.Services
private static async Task<bool> ProcuraDispositivoMKS()
{
if (!MKS057DService.Referenciando && (!MKS057DService.Iniciado || MKS057DService.DadosLeitura.Any(x => !x.Iniciado)))
if (!MKS057DService.Referenciando && (!MKS057DService.Iniciado || MKS057DService.DadosLeitura.Count(x => x.Iniciado) < (Variaveis.OperacaoEmAndamento.DispMvd?.Dados?.Modulos?.Count() ?? 4)))
{
AtualizarConsole("Procurando dispositivos MKS");
bool Encontrado = await MKS057DService.VerificaPortaMKS();

File diff suppressed because one or more lines are too long

View File

@ -37,11 +37,13 @@ class PinoModel {
}
}
else if (barramento == EXPANSOR_GPIO) {
if (tipo == _INPUT) {
mcp.pinMode(num, INPUT);
} else if (tipo == _OUTPUT) {
mcp.pinMode(num, OUTPUT);
set(statusInicial);
if (mcpInicializado) {
if (tipo == _INPUT) {
mcp.pinMode(num, INPUT);
} else if (tipo == _OUTPUT) {
mcp.pinMode(num, OUTPUT);
set(statusInicial);
}
}
}
}
@ -56,12 +58,14 @@ class PinoModel {
pinMode(num, INPUT);
}
else if (barramento == EXPANSOR_GPIO) {
mcp.pinMode(num, INPUT);
if (mcpInicializado) {
mcp.pinMode(num, INPUT);
}
}
}
}
int get(int leituras = 0) {
int get(int leituras = 1) {
if (Definido()) {
if (barramento == CONTROLADOR) {
if (leitura == DIGITAL) {
@ -77,17 +81,21 @@ class PinoModel {
}
}
else if (barramento == EXPANSOR_GPIO) {
return mcp.digitalRead(num);
if (mcpInicializado) {
return mcp.digitalRead(num);
}
}
else if (barramento == EXPANSOR_ADS) {
double l = 0;
for (int i = 0; i < leituras; i++) {
int leituraADC = (int)(ads.readADC_SingleEnded(num));
int leitura12bits = map(leituraADC, 0, 32767, 0, 4095);
l += leitura12bits;
delay(1);
if (adsInicializado) {
double l = 0;
for (int i = 0; i < leituras; i++) {
int leituraADC = (int)(ads.readADC_SingleEnded(num));
int leitura12bits = map(leituraADC, 0, 32767, 0, 4095);
l += leitura12bits;
delay(1);
}
return l / leituras;
}
return l / leituras;
}
}
return -1;
@ -99,7 +107,9 @@ class PinoModel {
digitalWrite(num, status ? HIGH : LOW);
}
else if (barramento == EXPANSOR_GPIO) {
mcp.digitalWrite(num, status ? HIGH : LOW);
if (mcpInicializado) {
mcp.digitalWrite(num, status ? HIGH : LOW);
}
}
}
}
@ -109,7 +119,7 @@ void iniciarMCP(T_Code Modulo, String Mod_ID, int sda, int scl, byte endereco, b
PrintTela("Iniciando MCP23X17...");
if (!mcpInicializado) {
bool init = Wire.begin(sda, scl);
String str = "SDA " + (String)sda + " SCL " + (String)scl + " Res " + init;
String str = "SDA " + (String)sda + " SCL " + (String)scl + " Res " + init + " - ";
PrintTela(str, false);
if (!mcp.begin_I2C(endereco, &Wire)) {
@ -136,7 +146,7 @@ void iniciarADS(T_Code Modulo, String Mod_ID, int sda, int scl, byte endereco, b
PrintTela("Iniciando ADS1115...");
if (!adsInicializado) {
bool init = Wire.begin(sda, scl);
String str = "SDA " + (String)sda + " SCL " + (String)scl + " Res " + init;
String str = "SDA " + (String)sda + " SCL " + (String)scl + " Res " + init + " - ";
PrintTela(str, false);
if (!ads.begin(endereco, &Wire)) {