610 lines
28 KiB
C#
610 lines
28 KiB
C#
using AgroBase.Forms;
|
|
using AgroBase.Models.Modules;
|
|
using AgroBase.Services;
|
|
using Newtonsoft.Json;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
using static AgroBase.Models.Enuns;
|
|
|
|
namespace AgroBase.Models
|
|
{
|
|
public class MovimentacaoModel : DispositivoBaseModel
|
|
{
|
|
public static int _TaxaAmostragem { get; set; } = 500;
|
|
public static int RampaMin { get; set; } = 0;
|
|
public static int RampaMax { get; set; } = 1023;
|
|
public static int PulsosPorRevolucao { get; set; } = 22;
|
|
public static bool _FOC { get; set; } = true;
|
|
public static double Kp { get; set; } = 1.75;
|
|
public static double Ki { get; set; } = 2.1;
|
|
public static double Kd { get; set; } = 0.08;
|
|
public static int _DelayBalanceamento { get; set; } = 2000;
|
|
public static int _MargemRPM { get; set; } = 5;
|
|
public static int _MaxOffsetRPM { get; set; } = 25;
|
|
public static double DiametroRoda { get; set; } = 0.3556;
|
|
public bool Conectado { get; set; } = false;
|
|
public static int LogsManter { get; set; } = 60;
|
|
public static List<PinoutModel> Pinout { get; set; }
|
|
public static List<FuncoesPinout> Funcoes { get; set; } = new List<FuncoesPinout>() { FuncoesPinout.Geral };
|
|
public List<MovSensoriamentoMotor> Motores { get; set; }
|
|
public static Direcao UltimaDirecao { get; set; } = Direcao.Parado;
|
|
public int TempoEmAtividade { get; set; } = 0;
|
|
public double DistanciaPercorridaTotal { get; set; } = 0;
|
|
public double DistanciaPercorridaParcial { get; set; } = 0;
|
|
public Timer tmrRegistrador { get; set; }
|
|
|
|
|
|
|
|
public static MovimentacaoModel CarregarParametrosIniciais()
|
|
{
|
|
return new MovimentacaoModel()
|
|
{
|
|
Motores = new List<MovSensoriamentoMotor>()
|
|
{
|
|
new MovSensoriamentoMotor() {
|
|
Canal = 0,
|
|
ID = "ET",
|
|
Descricao = "Esquerdo Trás",
|
|
ConfigSentidos = new ConfiguracaoSentidoMotor() {
|
|
Direita = Sentido.Antihorario,
|
|
Esquerda = Sentido.Horario,
|
|
Frente = Sentido.Horario,
|
|
Tras = Sentido.Antihorario
|
|
},
|
|
Funcoes = new List<FuncoesPinout>() {
|
|
FuncoesPinout.PWM,
|
|
FuncoesPinout.HallA,
|
|
FuncoesPinout.HallB,
|
|
FuncoesPinout.HallC,
|
|
FuncoesPinout.DIR,
|
|
FuncoesPinout.BRK,
|
|
FuncoesPinout.STP,
|
|
FuncoesPinout.TMP,
|
|
}
|
|
},
|
|
new MovSensoriamentoMotor() {
|
|
Canal = 1,
|
|
ID = "EF",
|
|
Descricao = "Esquerdo Frente",
|
|
ConfigSentidos = new ConfiguracaoSentidoMotor() {
|
|
Direita = Sentido.Antihorario,
|
|
Esquerda = Sentido.Horario,
|
|
Frente = Sentido.Horario,
|
|
Tras = Sentido.Antihorario
|
|
},
|
|
Funcoes = new List<FuncoesPinout>() {
|
|
FuncoesPinout.PWM,
|
|
FuncoesPinout.HallA,
|
|
FuncoesPinout.HallB,
|
|
FuncoesPinout.HallC,
|
|
FuncoesPinout.DIR,
|
|
FuncoesPinout.BRK,
|
|
FuncoesPinout.STP,
|
|
FuncoesPinout.TMP,
|
|
}
|
|
},
|
|
new MovSensoriamentoMotor() {
|
|
Canal = 2,
|
|
ID = "DT",
|
|
Descricao = "Direito Trás",
|
|
ConfigSentidos = new ConfiguracaoSentidoMotor() {
|
|
Direita = Sentido.Horario,
|
|
Esquerda = Sentido.Antihorario,
|
|
Frente = Sentido.Horario,
|
|
Tras = Sentido.Antihorario
|
|
},
|
|
Funcoes = new List<FuncoesPinout>() {
|
|
FuncoesPinout.PWM,
|
|
FuncoesPinout.HallA,
|
|
FuncoesPinout.HallB,
|
|
FuncoesPinout.HallC,
|
|
FuncoesPinout.DIR,
|
|
FuncoesPinout.BRK,
|
|
FuncoesPinout.STP,
|
|
FuncoesPinout.TMP,
|
|
}
|
|
},
|
|
new MovSensoriamentoMotor() {
|
|
Canal = 3,
|
|
ID = "DF",
|
|
Descricao = "Direito Frente",
|
|
ConfigSentidos = new ConfiguracaoSentidoMotor() {
|
|
Direita = Sentido.Antihorario,
|
|
Esquerda = Sentido.Horario,
|
|
Frente = Sentido.Antihorario,
|
|
Tras = Sentido.Horario
|
|
},
|
|
Funcoes = new List<FuncoesPinout>() {
|
|
FuncoesPinout.PWM,
|
|
FuncoesPinout.HallA,
|
|
FuncoesPinout.HallB,
|
|
FuncoesPinout.HallC,
|
|
FuncoesPinout.DIR,
|
|
FuncoesPinout.BRK,
|
|
FuncoesPinout.STP,
|
|
FuncoesPinout.TMP,
|
|
}
|
|
}
|
|
},
|
|
};
|
|
}
|
|
|
|
public List<string> ProtocoloConfiguracao(bool Conectar)
|
|
{
|
|
List<string> Config = Motores.Select(x => x.ProtocoloConfiguracaoMotor(Conectar)).ToList();
|
|
string ProtocoloMOD = ((int)F_Code.Cfg).ToString() +
|
|
"MD" + ";" + // 0 ~ 1
|
|
(Conectar ? "1" : "0") + ";" + // 3
|
|
_TaxaAmostragem.ToString("00000") + ";" + // 5 ~ 9
|
|
(Pinout.Any(x => x.Funcao == FuncoesPinout.Geral) ? Pinout.FirstOrDefault(x => x.Funcao == FuncoesPinout.Geral).Pino.ToString("00") : "-1") + ";" + // 11 ~ 12
|
|
RampaMin.ToString("0000") + ";" + // 14 ~ 17
|
|
RampaMax.ToString("0000") + ";" + // 19 ~ 22
|
|
PulsosPorRevolucao.ToString("000") + ";" + // 24 ~ 26
|
|
_DelayBalanceamento.ToString("00000") + ";" + // 28 ~ 32
|
|
_MargemRPM.ToString("00") + ";" + // 34 ~ 35
|
|
_MaxOffsetRPM.ToString("00"); // 37 ~ 38
|
|
Config.Add(ProtocoloMOD);
|
|
return Config;
|
|
}
|
|
|
|
public void RecebeProtocoloSerial(string Protocolo)
|
|
{
|
|
if (!string.IsNullOrEmpty(Protocolo) && Protocolo[0].ToString() == SerialService.BeginSensor)
|
|
{
|
|
try
|
|
{
|
|
string[] Dados = Protocolo.Replace(SerialService.BeginSensor, "").Split(SerialService.EndLine[0])[0].Split(';');
|
|
S_Code TipoSensor = (S_Code)(int.Parse(Dados[0]));
|
|
MovSensoriamentoMotor Motor = Motores.FirstOrDefault(x => x.ID == Dados[1]);
|
|
if (Motor == null)
|
|
{
|
|
if (Dados[1] == "MD")
|
|
{
|
|
Conectado = Dados[2] == "1";
|
|
}
|
|
return;
|
|
}
|
|
bool AtualizaGrafico = false;
|
|
try
|
|
{
|
|
switch (TipoSensor)
|
|
{
|
|
case S_Code.sRPM:
|
|
{
|
|
double rpm = 0;
|
|
double.TryParse(Dados[2].Replace(".", ","), out rpm);
|
|
Motor.RPM = rpm;
|
|
double potencia = 0;
|
|
double.TryParse(Dados[3].Replace(".", ","), out potencia);
|
|
Motor.Potencia = potencia;
|
|
int aceleracao = 0;
|
|
int.TryParse(Dados[4], out aceleracao);
|
|
Motor.Aceleracao = (StatusMotor)aceleracao;
|
|
int sentido = 0;
|
|
int.TryParse(Dados[5], out sentido);
|
|
Motor.Sentido = (Sentido)sentido;
|
|
Motor.Revertendo = Dados[6] == "1";
|
|
double rpm_offset = 0;
|
|
double.TryParse(Dados[7].Replace(".", ","), out rpm_offset);
|
|
Motor.RPM_Offset = rpm_offset;
|
|
AtualizaGrafico = true;
|
|
break;
|
|
}
|
|
case S_Code.sTST:
|
|
{
|
|
bool testando = Dados[2] == "1";
|
|
if (!Motor.Testando && testando)
|
|
{
|
|
Motor.LogTestes = new List<SensoriamentoMotorTestes>();
|
|
}
|
|
Motor.Testando = testando;
|
|
if (Motor.Testando && Dados.Length >= 5)
|
|
{
|
|
string componente = Dados[1];
|
|
string resultado = Dados[2];
|
|
string comando = Dados[3];
|
|
string leitura = Dados[4];
|
|
Motor.LogTestes.Add(new SensoriamentoMotorTestes()
|
|
{
|
|
Componente = componente,
|
|
Sucesso = resultado == "SUCESSO",
|
|
Resultado = resultado,
|
|
Comando = comando,
|
|
Leitura = leitura,
|
|
Momento = DateTime.Now
|
|
});
|
|
}
|
|
break;
|
|
}
|
|
case S_Code.sCFG:
|
|
{
|
|
Motor.Inicializado = Dados[2] == "1";
|
|
break;
|
|
}
|
|
case S_Code.sTMP:
|
|
{
|
|
double t = 0;
|
|
double.TryParse(Dados[2].Replace(".", ","), out t);
|
|
Motor.Temperatura = t;
|
|
/*double u = 0;
|
|
double.TryParse(Dados[3].Replace(".", ","), out u);
|
|
Motor.Umidade = u;
|
|
long i = 0;
|
|
long.TryParse(Dados[4].Replace(".", ","), out i);
|
|
Motor.IndiceCalor = i;*/
|
|
AtualizaGrafico = true;
|
|
break;
|
|
}
|
|
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Console.WriteLine(ex.Message);
|
|
}
|
|
|
|
if (AtualizaGrafico)
|
|
{
|
|
Motor.LogGrafico.Add(new MovSensorimanetoGrafico()
|
|
{
|
|
Momento = DateTime.Now,
|
|
ComponenteID = Motor.ID,
|
|
RPM_SP = Motor.RPM_SP,
|
|
RPM = Motor.RPM,
|
|
RPM_Offset = Motor.RPM_Offset,
|
|
Periodo = Motor.Intervalo,
|
|
Potencia = Motor.Potencia,
|
|
PotenciaSP = Motor.Potencia_SP,
|
|
Kp = Kp,
|
|
Ki = Ki,
|
|
Kd = Kd,
|
|
Temperatura = Motor.Temperatura,
|
|
Umidade = Motor.Umidade,
|
|
IndiceCalor = Motor.IndiceCalor,
|
|
Sentido = Motor.Sentido,
|
|
Velocidade = Motor.VelocidadeInstantanea,
|
|
});
|
|
|
|
if (Motor.LogGrafico.Count() > LogsManter)
|
|
{
|
|
Motor.LogGrafico.RemoveAt(0);
|
|
}
|
|
|
|
//frmInstancial.frmPlotMovimentacao.AtualizaGrafico();
|
|
/*if (frmPrincipal.Dispositivos.Any(x => x.Dispositivo == T_Code.Mov))
|
|
{
|
|
((frmMovPlot)(frmPrincipal.Dispositivos.First(x => x.Dispositivo == T_Code.Mov).frmPlot)).AtualizaGrafico();
|
|
}*/
|
|
frmInstancial.frmAcompanhamento.AtualizaGrafico();
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Console.WriteLine(ex.Message);
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
public string GetTaxaAmostragem()
|
|
{
|
|
return _TaxaAmostragem.ToString("00000");
|
|
}
|
|
|
|
public void SetTaxaAmostragem(int TaxaAmostragem)
|
|
{
|
|
_TaxaAmostragem = TaxaAmostragem;
|
|
}
|
|
|
|
public bool GetStatusConexao()
|
|
{
|
|
return Conectado;
|
|
}
|
|
|
|
public void PopulaGridSensoriamento()
|
|
{
|
|
frmInstancial.frmPrincipal.gridSenMotores.Rows.Clear();
|
|
frmInstancial.frmPrincipal.gridSenMotores.Columns.Clear();
|
|
frmInstancial.frmPrincipal.gridSenMotores.Columns.Add("clMotor", "Motor");
|
|
frmInstancial.frmPrincipal.gridSenMotores.Columns.Add("clInicializado", "Inicializado");
|
|
frmInstancial.frmPrincipal.gridSenMotores.Columns.Add("clSentidoSP", "Sentido SP");
|
|
frmInstancial.frmPrincipal.gridSenMotores.Columns.Add("clSentido", "Sentido");
|
|
frmInstancial.frmPrincipal.gridSenMotores.Columns.Add("clStatus", "Status");
|
|
frmInstancial.frmPrincipal.gridSenMotores.Columns.Add("clPotencia", "Potencia");
|
|
frmInstancial.frmPrincipal.gridSenMotores.Columns.Add("clRPMOffset", "RPM Offset");
|
|
frmInstancial.frmPrincipal.gridSenMotores.Columns.Add("clRPM", "RPM");
|
|
frmInstancial.frmPrincipal.gridSenMotores.Columns.Add("clVelocidade", "Velocidade");
|
|
frmInstancial.frmPrincipal.gridSenMotores.Columns.Add("clTemperatura", "Temperatura");
|
|
//frmInstancial.frmPrincipal.gridSenMotores.Columns.Add("clUmidade", "Umidade");
|
|
foreach (var Motor in Motores)
|
|
{
|
|
frmInstancial.frmPrincipal.gridSenMotores.Rows.Add(new string[]
|
|
{
|
|
Motor.Descricao,
|
|
Motor.Inicializado ? "Sim" : "Não",
|
|
Enum.GetName(typeof(Sentido), Motor.Sentido_SP),
|
|
Enum.GetName(typeof(Sentido), Motor.Sentido),
|
|
Enum.GetName(typeof(StatusMotor), Motor.Aceleracao),
|
|
Motor.Potencia.ToString(),
|
|
Motor.RPM_Offset.ToString(),
|
|
Motor.RPM.ToString(),
|
|
Motor.VelocidadeInstantanea.ToString(),
|
|
Motor.Temperatura.ToString(),
|
|
//Motor.Umidade.ToString(),
|
|
});
|
|
}
|
|
}
|
|
|
|
public void AtualizaGridSensoriamento()
|
|
{
|
|
foreach (var Motor in Motores)
|
|
{
|
|
Motor.VelocidadeInstantanea = CalculaVelocidadeRPM(Motor.RPM);
|
|
frmInstancial.frmPrincipal.gridSenMotores.Rows[Motor.Canal].Cells[1].Value = Motor.Inicializado ? "Sim" : "Não";
|
|
frmInstancial.frmPrincipal.gridSenMotores.Rows[Motor.Canal].Cells[2].Value = Enum.GetName(typeof(Sentido), Motor.Sentido_SP);
|
|
frmInstancial.frmPrincipal.gridSenMotores.Rows[Motor.Canal].Cells[3].Value = Enum.GetName(typeof(Sentido), Motor.Sentido);
|
|
frmInstancial.frmPrincipal.gridSenMotores.Rows[Motor.Canal].Cells[4].Value = Enum.GetName(typeof(StatusMotor), Motor.Aceleracao);
|
|
frmInstancial.frmPrincipal.gridSenMotores.Rows[Motor.Canal].Cells[5].Value = Motor.Potencia.ToString();
|
|
frmInstancial.frmPrincipal.gridSenMotores.Rows[Motor.Canal].Cells[6].Value = Motor.RPM_Offset.ToString();
|
|
frmInstancial.frmPrincipal.gridSenMotores.Rows[Motor.Canal].Cells[7].Value = Motor.RPM.ToString();
|
|
frmInstancial.frmPrincipal.gridSenMotores.Rows[Motor.Canal].Cells[8].Value = Motor.VelocidadeInstantanea.ToString();
|
|
frmInstancial.frmPrincipal.gridSenMotores.Rows[Motor.Canal].Cells[9].Value = Motor.Temperatura.ToString();
|
|
//frmInstancial.frmPrincipal.gridSenMotores.Rows[Motor.Canal].Cells[10].Value = Motor.Umidade.ToString();
|
|
}
|
|
}
|
|
|
|
public List<PinoutModel> CarregarPinout(string nomeArquivo)
|
|
{
|
|
if (!File.Exists(nomeArquivo))
|
|
{
|
|
var newPinout = PinoutModel.CarregarPinoutPadrao_S3();
|
|
File.WriteAllText(nomeArquivo, JsonConvert.SerializeObject(newPinout));
|
|
}
|
|
var pinoutText = File.ReadAllText(nomeArquivo);
|
|
Pinout = JsonConvert.DeserializeObject<PinoutModel[]>(pinoutText).ToList();
|
|
return Pinout;
|
|
}
|
|
|
|
public void SalvarPinout(List<PinoutModel> newPinout, string nomeArquivo)
|
|
{
|
|
File.WriteAllText(nomeArquivo, JsonConvert.SerializeObject(newPinout));
|
|
}
|
|
|
|
public void IniciarRegistrador()
|
|
{
|
|
tmrRegistrador = new Timer()
|
|
{
|
|
Interval = 1000,
|
|
Enabled = false
|
|
};
|
|
tmrRegistrador.Tick += TmrRegistrador_Tick;
|
|
tmrRegistrador.Start();
|
|
}
|
|
|
|
private void TmrRegistrador_Tick(object sender, EventArgs e)
|
|
{
|
|
if (UltimaDirecao != Direcao.Parado)
|
|
{
|
|
TempoEmAtividade++;
|
|
double VelocidadeMedia = Motores.Average(x => x.VelocidadeInstantanea * 1000 / 3600);
|
|
DistanciaPercorridaTotal += 1 * VelocidadeMedia;
|
|
DistanciaPercorridaParcial += (UltimaDirecao == Direcao.Frente ? 1 : UltimaDirecao == Direcao.Tras ? -1 : 0) * VelocidadeMedia;
|
|
}
|
|
}
|
|
|
|
public static double CalculaVelocidadeRPM(double RPM)
|
|
{
|
|
double VelocidadeInstantanea = Math.Round((Math.PI * DiametroRoda * 60 * RPM) / 1000, 2); // Km/h
|
|
return VelocidadeInstantanea;
|
|
}
|
|
|
|
public static double CalculaRPMVelocidade(double Velocidade)
|
|
{
|
|
double RPM = Math.Round((Velocidade * 1000) / (Math.PI * DiametroRoda * 60), 2);
|
|
return RPM;
|
|
}
|
|
|
|
|
|
}
|
|
|
|
public class MovSensoriamentoMotor
|
|
{
|
|
public int Canal { get; set; }
|
|
public string ID { get; set; }
|
|
public string Descricao { get; set; }
|
|
public bool Comandar { get; set; } = false;
|
|
public bool Alarme { get; set; } = false;
|
|
public bool Inicializado { get; set; } = false;
|
|
public bool Revertendo { get; set; } = false;
|
|
public int RPM_SP { get; set; } = 0;
|
|
public double Potencia { get; set; } = 0;
|
|
public double Potencia_SP { get; set; } = 0;
|
|
public int Rampa { get; set; } = 0;
|
|
public int Precisao { get; set; } = 0;
|
|
public Sentido Sentido_SP { get; set; } = Sentido.Parado;
|
|
public Sentido Sentido { get; set; } = Sentido.Parado;
|
|
public StatusMotor Aceleracao { get; set; } = StatusMotor.Estavel;
|
|
public double RPM { get; set; } = 0;
|
|
public double RPM_Offset { get; set; } = 0;
|
|
public long Intervalo { get; set; } = 0;
|
|
public double VelocidadeInstantanea { get; set; } = 0;
|
|
public double Temperatura { get; set; } = 0;
|
|
public double Umidade { get; set; } = 0;
|
|
public double IndiceCalor { get; set; } = 0;
|
|
public ConfiguracaoSentidoMotor ConfigSentidos { get; set; }
|
|
public bool Testando { get; set; } = false;
|
|
public List<AlarmeModel> Alarmes { get; set; } = new List<AlarmeModel>();
|
|
public List<SensoriamentoMotorTestes> LogTestes { get; set; } = new List<SensoriamentoMotorTestes>();
|
|
public List<MovSensorimanetoGrafico> LogGrafico { get; set; } = new List<MovSensorimanetoGrafico>();
|
|
public List<FuncoesPinout> Funcoes { get; set; }
|
|
|
|
public string ProtocoloConfiguracaoMotor(bool Conectar)
|
|
{
|
|
var _pinout = MovimentacaoModel.Pinout.Where(x => x.ComponenteID == ID).ToList();
|
|
return ((int)F_Code.Cfg).ToString() +
|
|
ID + ";" + // 0 ~ 1
|
|
(Conectar ? "1" : "0") + ";" + // 3
|
|
Canal.ToString() + ";" + // 5
|
|
(Alarme ? "1" : "0") + ";" + // 7
|
|
(Comandar ? "1" : "0") + ";" + // 9
|
|
MovimentacaoModel.Kp.ToString("0.000").Replace(",", ".") + "," + // 11 ~ 15
|
|
MovimentacaoModel.Ki.ToString("0.000").Replace(",", ".") + "," + // 17 ~ 21
|
|
MovimentacaoModel.Kd.ToString("0.000").Replace(",", ".") + "," + // 23 ~ 27
|
|
(_pinout.Any(x => x.Funcao == FuncoesPinout.PWM) ? _pinout.FirstOrDefault(x => x.Funcao == FuncoesPinout.PWM).Pino.ToString("00") : "-1") + "," + // 29 ~ 30
|
|
(_pinout.Any(x => x.Funcao == FuncoesPinout.DIR) ? _pinout.FirstOrDefault(x => x.Funcao == FuncoesPinout.DIR).Pino.ToString("00") : "-1") + "," + // 32 ~ 33
|
|
(_pinout.Any(x => x.Funcao == FuncoesPinout.BRK) ? _pinout.FirstOrDefault(x => x.Funcao == FuncoesPinout.BRK).Pino.ToString("00") : "-1") + "," + // 35 ~ 36
|
|
(_pinout.Any(x => x.Funcao == FuncoesPinout.STP) ? _pinout.FirstOrDefault(x => x.Funcao == FuncoesPinout.STP).Pino.ToString("00") : "-1") + "," + // 38 ~ 39
|
|
(_pinout.Any(x => x.Funcao == FuncoesPinout.HallA) ? _pinout.FirstOrDefault(x => x.Funcao == FuncoesPinout.HallA).Pino.ToString("00") : "-1") + "," + // 41 ~ 42
|
|
(_pinout.Any(x => x.Funcao == FuncoesPinout.HallB) ? _pinout.FirstOrDefault(x => x.Funcao == FuncoesPinout.HallB).Pino.ToString("00") : "-1") + "," + // 44 ~ 45
|
|
(_pinout.Any(x => x.Funcao == FuncoesPinout.HallC) ? _pinout.FirstOrDefault(x => x.Funcao == FuncoesPinout.HallC).Pino.ToString("00") : "-1") + "," + // 47 ~ 48
|
|
(_pinout.Any(x => x.Funcao == FuncoesPinout.TMP) ? _pinout.FirstOrDefault(x => x.Funcao == FuncoesPinout.TMP).Pino.ToString("00") : "-1"); // 50 ~ 51
|
|
|
|
}
|
|
|
|
public string ProtocoloComando(Direcao DirecaoAtual, bool CmdAlarme = false)
|
|
{
|
|
if (Comandar && (!Alarme || CmdAlarme))
|
|
{
|
|
if (!CmdAlarme)
|
|
{
|
|
MovimentacaoModel.UltimaDirecao = DirecaoAtual;
|
|
}
|
|
|
|
RPM_SP =
|
|
DirecaoAtual == Direcao.Parado ? 0 :
|
|
CmdAlarme ? 0 :
|
|
GeneralJoystick.RPM;
|
|
|
|
switch (DirecaoAtual)
|
|
{
|
|
case Direcao.Frente:
|
|
Sentido_SP = ConfigSentidos.Frente;
|
|
break;
|
|
case Direcao.Tras:
|
|
Sentido_SP = ConfigSentidos.Tras;
|
|
break;
|
|
case Direcao.Esquerda:
|
|
Sentido_SP = ConfigSentidos.Esquerda;
|
|
break;
|
|
case Direcao.Direita:
|
|
Sentido_SP = ConfigSentidos.Direita;
|
|
break;
|
|
case Direcao.Parado:
|
|
default:
|
|
Sentido_SP = ConfigSentidos.Parado;
|
|
break;
|
|
}
|
|
|
|
string ProtocoloMotor = "";
|
|
|
|
if (Revertendo && false)
|
|
{
|
|
return ProtocoloMotor;
|
|
}
|
|
|
|
ProtocoloMotor =
|
|
((int)F_Code.Cmd).ToString() +
|
|
ID + ";" + // 0 ~ 1
|
|
((int)Sentido_SP).ToString() + ";" + // 3
|
|
RPM_SP.ToString("000") + ";" + // 5 ~ 7
|
|
(Alarme ? "1" : "0"); // 9
|
|
|
|
if (Sentido_SP != Sentido.Parado)
|
|
{
|
|
Revertendo = true;
|
|
}
|
|
|
|
return ProtocoloMotor;
|
|
}
|
|
return "";
|
|
}
|
|
|
|
public string ProtocoloTeste()
|
|
{
|
|
if (Comandar)
|
|
{
|
|
string ProtocoloMotor =
|
|
((int)F_Code.Tst).ToString() +
|
|
ID;
|
|
return ProtocoloMotor;
|
|
}
|
|
return "";
|
|
}
|
|
|
|
public void AtualizarTemperaturaMotor(SensorModel Sensor)
|
|
{
|
|
Temperatura = Sensor.Leituras[0];
|
|
AlarmeModel _Alarme = new AlarmeModel()
|
|
{
|
|
Tipo = S_Code.sTMP,
|
|
Valor = Sensor.Leituras[0],
|
|
Maximo = Temperatura > Sensor.LimiteMaximo,
|
|
Minimo = Temperatura < Sensor.LimiteMinimo,
|
|
ParaMaximo = true,
|
|
ParaMinimo = true
|
|
};
|
|
|
|
bool Adicionado = false;
|
|
var Alm = Alarmes.FirstOrDefault(x => x.Tipo == _Alarme.Tipo);
|
|
if (Alm == null)
|
|
{
|
|
Alarmes.Add(_Alarme);
|
|
Alm = Alarmes.FirstOrDefault(x => x.Tipo == _Alarme.Tipo);
|
|
Adicionado = true;
|
|
}
|
|
|
|
bool AlarmeAnterior = (Alm.Maximo && Alm.ParaMaximo) || (Alm.Minimo && Alm.ParaMinimo);
|
|
bool AlarmeAtual = (_Alarme.Maximo && _Alarme.ParaMaximo) || (_Alarme.Minimo && _Alarme.ParaMinimo);
|
|
|
|
if (Inicializado && (!AlarmeAnterior || Adicionado) && AlarmeAtual) // Motor iniciado, Não estava em alarme anteriormente ou foi adicionado agora, alarme atual
|
|
{
|
|
Variaveis.DispositivosConectados.FirstOrDefault(x => x.Dispositivo == T_Code.Mov).EnviarDadosSerial(ProtocoloComando(Direcao.Frente, true));
|
|
}
|
|
|
|
Alm.Valor = _Alarme.Valor;
|
|
Alm.Maximo = _Alarme.Maximo;
|
|
Alm.Minimo = _Alarme.Minimo;
|
|
|
|
Alarme = Alarmes.Any(x => (x.Maximo && x.ParaMaximo) || (x.Minimo && x.ParaMinimo));
|
|
}
|
|
|
|
}
|
|
|
|
public class SensoriamentoMotorTestes
|
|
{
|
|
public DateTime Momento { get; set; }
|
|
public string Componente { get; set; }
|
|
public bool Sucesso { get; set; }
|
|
public string Resultado { get; set; }
|
|
public string Comando { get; set; }
|
|
public string Leitura { get; set; }
|
|
}
|
|
|
|
public class MovSensorimanetoGrafico
|
|
{
|
|
public DateTime Momento { get; set; }
|
|
public string ComponenteID { get; set; }
|
|
public int RPM_SP { get; set; }
|
|
public double RPM { get; set; }
|
|
public double RPM_Offset { get; set; }
|
|
public long Periodo { get; set; }
|
|
public double Potencia { get; set; }
|
|
public double PotenciaSP { get; set; }
|
|
public double Kp { get; set; }
|
|
public double Ki { get; set; }
|
|
public double Kd { get; set; }
|
|
public double Temperatura { get; set; }
|
|
public double Umidade { get; set; }
|
|
public double IndiceCalor { get; set; }
|
|
public Sentido Sentido { get; set; }
|
|
public double Velocidade { get; set; }
|
|
}
|
|
|
|
|
|
}
|