Referenciamento com uso do sensor AS5600
This commit is contained in:
parent
84962cb7de
commit
15c0bb29cd
|
|
@ -353,12 +353,62 @@ namespace AgroBase.Models.Modules
|
||||||
|
|
||||||
public async Task ReferenciaMotor()
|
public async Task ReferenciaMotor()
|
||||||
{
|
{
|
||||||
|
if (Referenciando || !Inicializado) return;
|
||||||
|
|
||||||
Referenciando = true;
|
Referenciando = true;
|
||||||
|
|
||||||
await Task.Delay(1000);
|
await Task.Delay(1000);
|
||||||
|
|
||||||
Referenciado = false;
|
Referenciado = false;
|
||||||
|
|
||||||
|
bool sensorAngRealConectado = (SensorAnguloReal?.Inicializado ?? false);
|
||||||
|
|
||||||
|
if (sensorAngRealConectado)
|
||||||
|
{
|
||||||
|
Referenciado = await ReferenciaMotorAbsoluto();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Referenciado = await ReferenciaMotorRelativo();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Referenciado)
|
||||||
|
{
|
||||||
|
await SetZero();
|
||||||
|
Console.WriteLine($"[DIR {Mod_ID}] - Referenciamento Concluído!");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Console.WriteLine($"[DIR {Mod_ID}] - Referenciamento Falhou!");
|
||||||
|
}
|
||||||
|
|
||||||
|
Referenciando = false;
|
||||||
|
|
||||||
|
UltimoReferenciamento = DateTime.Now;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<bool> ReferenciaMotorAbsoluto()
|
||||||
|
{
|
||||||
|
double angControle = Math.Abs(AnguloReal);
|
||||||
|
|
||||||
|
if (angControle <= 0.8)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"[DIR {Mod_ID}] - RefAbs: AnguloReal já dentro da tolerância ({AnguloReal:F2}°).");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
int velocidade = 10;
|
||||||
|
Sentido _sentido = AnguloReal > 0 ? Sentido.Antihorario : Sentido.Horario;
|
||||||
|
MKS057DCanService.Movimento(_EnderecoCAN_Tx, _EnderecoCAN_Rx, angControle, velocidade, _sentido);
|
||||||
|
|
||||||
|
bool AtingiuSP() => AtingiuAnguloSP;
|
||||||
|
await FuncoesGlobais.AguardarCondicaoAsync(AtingiuSP, 5000, 200);
|
||||||
|
|
||||||
|
return AtingiuSP();
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<bool> ReferenciaMotorRelativo()
|
||||||
|
{
|
||||||
await SetZero();
|
await SetZero();
|
||||||
|
|
||||||
bool Sucesso = false;
|
bool Sucesso = false;
|
||||||
|
|
@ -409,21 +459,18 @@ namespace AgroBase.Models.Modules
|
||||||
anguloAnterior = AnguloLeitura;
|
anguloAnterior = AnguloLeitura;
|
||||||
|
|
||||||
Sucesso = AnguloEntrada != 9999 && AnguloSaida != 9999 && (FuncoesMatematicas.ValorEstaEntre(Leitura.AnguloEstimado(), _anguloSP, 0.5));
|
Sucesso = AnguloEntrada != 9999 && AnguloSaida != 9999 && (FuncoesMatematicas.ValorEstaEntre(Leitura.AnguloEstimado(), _anguloSP, 0.5));
|
||||||
if (Sucesso)
|
|
||||||
{
|
|
||||||
await SetZero();
|
|
||||||
Console.WriteLine($"[DIR {Mod_ID}] - Referenciamento Concluído!");
|
|
||||||
Referenciado = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
DateTime Inicio = DateTime.Now;
|
DateTime Inicio = DateTime.Now;
|
||||||
bool NovoDado() => MKS057DCanService.DadosLeitura.Any(x => x.EnderecoRx == _EnderecoCAN_Rx && x.UltimoComandoRecebido > Inicio);
|
bool NovoDado() => MKS057DCanService.DadosLeitura.Any(x => x.EnderecoRx == _EnderecoCAN_Rx && x.UltimoComandoRecebido > Inicio);
|
||||||
await FuncoesGlobais.AguardarCondicaoAsync(NovoDado, 500, 100);
|
await FuncoesGlobais.AguardarCondicaoAsync(NovoDado, 500, 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
Referenciando = false;
|
if (!Sucesso)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"[DIR {Mod_ID}] - ReferenciaMotorRelativo falhou (timeout ou não inicializado). Entrada={AnguloEntrada}, Saida={AnguloSaida}");
|
||||||
|
}
|
||||||
|
|
||||||
UltimoReferenciamento = DateTime.Now;
|
return Sucesso;
|
||||||
}
|
}
|
||||||
|
|
||||||
private int DefineVelocidadeReferenciamento()
|
private int DefineVelocidadeReferenciamento()
|
||||||
|
|
@ -477,6 +524,9 @@ namespace AgroBase.Models.Modules
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public void RequisitarDadosSensoresExternos()
|
public void RequisitarDadosSensoresExternos()
|
||||||
{
|
{
|
||||||
|
|
@ -490,7 +540,7 @@ namespace AgroBase.Models.Modules
|
||||||
{
|
{
|
||||||
if (SensorAnguloReal != null)
|
if (SensorAnguloReal != null)
|
||||||
{
|
{
|
||||||
double angulo = SensorAnguloReal.ValoresLeituras.FirstOrDefault(x => x.funcao == FuncoesPinout.LeituraAngulo)?.atual?.valor ?? double.NaN;
|
double angulo = SensorAnguloReal.ValoresLeituras?.FirstOrDefault(x => x.funcao == FuncoesPinout.LeituraAngulo)?.atual?.valor ?? double.NaN;
|
||||||
if (!double.IsNaN(angulo))
|
if (!double.IsNaN(angulo))
|
||||||
{
|
{
|
||||||
double bruto = angulo + OffsetAnguloReal;
|
double bruto = angulo + OffsetAnguloReal;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue