629 lines
29 KiB
C#
629 lines
29 KiB
C#
using AgroBase.Models;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Windows.Forms;
|
|
using static AgroBase.Models.Enums;
|
|
using AgroBase.Services;
|
|
using AgroBase.Models.Modules;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace AgroBase.Forms.Operacoes
|
|
{
|
|
public partial class frmOperacaoManual : Form
|
|
{
|
|
AsyncTaskTimerModel tmrLeitura;
|
|
|
|
public frmOperacaoManual()
|
|
{
|
|
InitializeComponent();
|
|
|
|
// Ativa o double buffering
|
|
this.DoubleBuffered = true;
|
|
this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
|
|
this.SetStyle(ControlStyles.UserPaint, true);
|
|
this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
|
|
|
|
pnlAtuadores.GetType().GetMethod("SetStyle", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).Invoke(pnlAtuadores, new object[] { ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer, true });
|
|
pnlAnguloGPS.GetType().GetMethod("SetStyle", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).Invoke(pnlAnguloGPS, new object[] { ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer, true });
|
|
pnlAnguloMagnetometro.GetType().GetMethod("SetStyle", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).Invoke(pnlAnguloMagnetometro, new object[] { ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer, true });
|
|
pnlDir_DF.GetType().GetMethod("SetStyle", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).Invoke(pnlDir_DF, new object[] { ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer, true });
|
|
pnlDir_DT.GetType().GetMethod("SetStyle", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).Invoke(pnlDir_DT, new object[] { ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer, true });
|
|
pnlDir_EF.GetType().GetMethod("SetStyle", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).Invoke(pnlDir_EF, new object[] { ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer, true });
|
|
pnlDir_ET.GetType().GetMethod("SetStyle", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).Invoke(pnlDir_ET, new object[] { ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer, true });
|
|
}
|
|
|
|
private void frmOperacaoManual_Load(object sender, EventArgs e)
|
|
{
|
|
cmbTipoMovimento.Items.Clear();
|
|
cmbTipoMovimento.Items.AddRange(Enum.GetNames(typeof(TipoMovimentoDirecional)));
|
|
cmbTipoMovimento.SelectedIndex = (int)Variaveis.OperacaoEmAndamento.Controle.TipoMovimento;
|
|
|
|
flwCamerasSolo.Controls.Clear();
|
|
for (int i = 0; i < Variaveis.OperacaoEmAndamento.CamerasSolo.Count(); i++)
|
|
{
|
|
Panel pnlCam = new Panel()
|
|
{
|
|
Name = "pnlCamSolo_" + Variaveis.OperacaoEmAndamento.CamerasSolo[i].Nome,
|
|
Width = 290,
|
|
Height = 166,
|
|
BackgroundImageLayout = ImageLayout.Stretch,
|
|
BackColor = Color.Black,
|
|
};
|
|
flwCamerasSolo.Controls.Add(pnlCam);
|
|
}
|
|
|
|
Variaveis.OperacaoEmAndamento.AtualizaListaCameras(new List<Panel>() { pnlCameraRua, pnlDeteccoesRua }, flwCamerasSolo.Controls.OfType<Panel>().ToList(), true);
|
|
|
|
chbPulverizador.Checked = Variaveis.OperacaoEmAndamento.Controle.PulverizadorAutomatico;
|
|
chbMostrarGrade.Checked = KinectService.MostrarGrade;
|
|
chbSonarAtivado.Checked = Variaveis.OperacaoEmAndamento.Controle.SonarAtivado;
|
|
|
|
InicializarComandosDirecional();
|
|
PopularInformacoesGerais();
|
|
InicializarMapa();
|
|
PopularBicos();
|
|
Variaveis.OperacaoEmAndamento.chartGraficos = chartGraficos;
|
|
|
|
tmrLeitura = new AsyncTaskTimerModel("tmrLeitura", tmrLeitura_Tick, 500, this);
|
|
tmrLeitura.Start();
|
|
|
|
if (!Variaveis.OperacaoEmAndamento.Controle.SegmentacaoSemantica && KinectService.Iniciado)
|
|
{
|
|
PictureBox picRgb = new PictureBox();
|
|
picRgb.SizeMode = PictureBoxSizeMode.StretchImage;
|
|
picRgb.Dock = DockStyle.Fill;
|
|
|
|
KinectService.picRGB = picRgb;
|
|
|
|
pnlCameraRua.Controls.Add(picRgb);
|
|
}
|
|
}
|
|
|
|
private void frmOperacaoManual_FormClosing(object sender, FormClosingEventArgs e)
|
|
{
|
|
tmrLeitura.Dispose();
|
|
Task.Run(async () => await Variaveis.OperacaoEmAndamento.FinalizarOperacao());
|
|
Variaveis.OperacaoEmAndamento.DesligarCameras();
|
|
KinectService.picRGB = null;
|
|
}
|
|
|
|
private void btnIniciarOperacao_Click(object sender, EventArgs e)
|
|
{
|
|
if (btnIniciarOperacao.Text == "Finalizar Operação")
|
|
{
|
|
// Atualiza a UI na thread principal
|
|
btnIniciarOperacao.Invoke((MethodInvoker)delegate
|
|
{
|
|
btnIniciarOperacao.Text = "Finalizando...";
|
|
btnIniciarOperacao.Enabled = false;
|
|
});
|
|
|
|
// Executa a finalização da operação
|
|
Task.Run(async () => await Variaveis.OperacaoEmAndamento.FinalizarOperacao());
|
|
|
|
// Atualiza a UI novamente na thread principal
|
|
btnIniciarOperacao.Invoke((MethodInvoker)delegate
|
|
{
|
|
btnIniciarOperacao.Text = "Iniciar Operação";
|
|
btnIniciarOperacao.Enabled = true;
|
|
});
|
|
}
|
|
else
|
|
{
|
|
// Atualiza a UI na thread principal
|
|
btnIniciarOperacao.Invoke((MethodInvoker)delegate
|
|
{
|
|
btnIniciarOperacao.Text = "Iniciando...";
|
|
btnIniciarOperacao.Enabled = false;
|
|
});
|
|
|
|
// Verifica se a operação está liberada
|
|
if (Variaveis.OperacaoEmAndamento.OperacaoLiberada)
|
|
{
|
|
// Inicia a operação de forma assíncrona
|
|
Task.Run(async () => await Variaveis.OperacaoEmAndamento.IniciarOperacao());
|
|
|
|
// Atualiza a UI após o início da operação
|
|
btnIniciarOperacao.Invoke((MethodInvoker)delegate
|
|
{
|
|
btnIniciarOperacao.Text = "Finalizar Operação";
|
|
btnIniciarOperacao.Enabled = true;
|
|
});
|
|
}
|
|
else
|
|
{
|
|
// Mostra a mensagem de erro na thread principal
|
|
btnIniciarOperacao.Invoke((MethodInvoker)delegate
|
|
{
|
|
MessageBox.Show(Variaveis.OperacaoEmAndamento.ErroOperacaoLiberada, "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
btnIniciarOperacao.Text = "Iniciar Operação";
|
|
btnIniciarOperacao.Enabled = true;
|
|
});
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
private async Task tmrLeitura_Tick()
|
|
{
|
|
this.Text = Variaveis.OperacaoEmAndamento.TextoFormOperacao("Manual");
|
|
|
|
pnlDir_DF.Invalidate();
|
|
pnlDir_DT.Invalidate();
|
|
pnlDir_EF.Invalidate();
|
|
pnlDir_ET.Invalidate();
|
|
pnlAtuadores.Invalidate();
|
|
pnlAnguloGPS.Invalidate();
|
|
pnlAnguloMagnetometro.Invalidate();
|
|
|
|
AtualizarInformacoesGerais();
|
|
|
|
var _Sensoriamento = Variaveis.OperacaoEmAndamento.Sensoriamento;
|
|
|
|
lblDistanciaEsquerda.Text = "Distancia Esq: " + _Sensoriamento.Trajetoria.DistanciaEsquerda.ToString("0.00") + " cm";
|
|
lblDistanciaDireita.Text = "Distancia Dir: " + _Sensoriamento.Trajetoria.DistanciaDireita.ToString("0.00") + " cm";
|
|
lblGPSsatelites.Text = _Sensoriamento.Gps.NumeroSatelites.ToString() + " satélites";
|
|
lblGPSFix.Text = _Sensoriamento.Gps.QualidadeFix.ToString();
|
|
lblGPSprecisao.Text = "Precisão: " + _Sensoriamento.Gps.PrecisaoCm.ToString("0.00") + " cm";
|
|
lblGPSvelocidade.Text = "Vel.: " + _Sensoriamento.Gps.Velocidade.ToString("0.00") + " km/h";
|
|
lblGPSaltitude.Text = "Altitude: " + _Sensoriamento.Gps.Altitude.ToString("0.0") + " m";
|
|
|
|
lblTensao.Text = _Sensoriamento.Bateria.TensaoInstantanea.ToString("0.00") + " v";
|
|
lblCorrente.Text = _Sensoriamento.Bateria.CorrenteInstantanea.ToString("0.00") + " A";
|
|
lblRPM.Text = _Sensoriamento.Movimentacao.RPMMedio.ToString("0") + " rpm";
|
|
lblVelocidade.Text = _Sensoriamento.Movimentacao.VelocidadeMedia.ToString("0.00");
|
|
|
|
var Sonar = _Sensoriamento.Sonar;
|
|
bool sonarAtivado = Sonar.Iniciado && Variaveis.OperacaoEmAndamento.Controle.SonarAtivado;
|
|
chbSonarDesvioAutomatico.Enabled = sonarAtivado;
|
|
chbMostrarGrade.Enabled = sonarAtivado;
|
|
if (!sonarAtivado)
|
|
{
|
|
chbSonarDesvioAutomatico.Checked = false;
|
|
chbMostrarGrade.Checked = false;
|
|
}
|
|
|
|
bool atuadorAtivado = Variaveis.OperacaoEmAndamento.DispAtu.Dados.Conectado || true;
|
|
chbPulverizador.Enabled = atuadorAtivado;
|
|
if (!atuadorAtivado)
|
|
{
|
|
chbPulverizador.Checked = false;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region Direcionais
|
|
|
|
private void InicializarComandosDirecional()
|
|
{
|
|
pnlDir_DF.Paint += pnlDir_Paint;
|
|
pnlDir_DT.Paint += pnlDir_Paint;
|
|
pnlDir_EF.Paint += pnlDir_Paint;
|
|
pnlDir_ET.Paint += pnlDir_Paint;
|
|
}
|
|
|
|
private void pnlDir_Paint(object sender, PaintEventArgs e)
|
|
{
|
|
DesenharGraficos(sender, e);
|
|
}
|
|
|
|
private void DesenharGraficos(object sender, PaintEventArgs e)
|
|
{
|
|
Panel pnl = (Panel)sender;
|
|
string ID = pnl.Name.Replace("pnlDir_", "");
|
|
|
|
var Modulo = Variaveis.OperacaoEmAndamento.DispMvd.Dados.Modulos.FirstOrDefault(m => m.Modulo_ID == ID);
|
|
double Angulo = Modulo.DirMotor.Angulo;
|
|
|
|
Label lblAngulo = pnl.Controls.OfType<Label>().FirstOrDefault(ctrl => ctrl.Name == "lblDir_" + ID);
|
|
lblAngulo.Text = ID + " " + Angulo.ToString("000") + "º";
|
|
lblAngulo.ForeColor = Modulo.DirMotor.Inicializado ? Color.Green : Color.Red;
|
|
|
|
Label lblMov = pnl.Controls.OfType<Label>().FirstOrDefault(ctrl => ctrl.Name == "lblMov_" + ID);
|
|
lblMov.Text = $"{ID} {Modulo.MovMotor.Sentido} {Modulo.MovMotor.RPM_Roda} ({Modulo.MovMotor.CodigoAlarme})";
|
|
lblMov.ForeColor = Modulo.MovMotor.Inicializado ? Color.Green : Color.Red;
|
|
|
|
// Use o objeto Graphics para desenhar a representação do motor
|
|
Graphics g = e.Graphics;
|
|
|
|
int centerX = pnl.Width / 2;
|
|
int centerY = pnl.Height / 2;
|
|
int radius = Math.Min(centerX, centerY) - 30;
|
|
|
|
// Desenhe o círculo para representar o motor
|
|
g.DrawEllipse(Pens.Black, centerX - radius, centerY - radius, 2 * radius, 2 * radius);
|
|
|
|
|
|
|
|
// Desenhe a linha externa (set point)
|
|
double setPointAngleInRadians = ((Modulo.DirMotor.Angulo_SP * Math.PI) / 180);
|
|
int setPointX = centerX + (int)((radius + 10) * Math.Sin(setPointAngleInRadians));
|
|
int setPointY = centerY - (int)((radius + 10) * Math.Cos(setPointAngleInRadians));
|
|
g.DrawLine(Pens.Green, centerX, centerY, setPointX, setPointY);
|
|
|
|
// Desenhe a seta que indica o sentido
|
|
int arrowLength = 15; // Comprimento da seta
|
|
|
|
if (Modulo.DirMotor.Sentido_SP == Sentido.Horario)
|
|
{
|
|
// Desenhe uma seta para a direita (sentido horário)
|
|
Point arrowStart = new Point(setPointX, setPointY);
|
|
Point arrowEnd = new Point(setPointX + arrowLength, setPointY);
|
|
g.DrawLine(Pens.Green, arrowStart, arrowEnd);
|
|
|
|
// Desenhe a "ponta" da seta (triângulo) para a direita
|
|
Point arrowPoint1 = new Point(setPointX + arrowLength - 5, setPointY - 5);
|
|
Point arrowPoint2 = new Point(setPointX + arrowLength - 5, setPointY + 5);
|
|
g.DrawLine(Pens.Green, arrowEnd, arrowPoint1);
|
|
g.DrawLine(Pens.Green, arrowEnd, arrowPoint2);
|
|
}
|
|
else
|
|
{
|
|
// Desenhe uma seta para a esquerda (sentido anti-horário)
|
|
Point arrowStart = new Point(setPointX, setPointY);
|
|
Point arrowEnd = new Point(setPointX - arrowLength, setPointY);
|
|
g.DrawLine(Pens.Green, arrowStart, arrowEnd);
|
|
|
|
// Desenhe a "ponta" da seta (triângulo) para a esquerda
|
|
Point arrowPoint1 = new Point(setPointX - arrowLength + 5, setPointY - 5);
|
|
Point arrowPoint2 = new Point(setPointX - arrowLength + 5, setPointY + 5);
|
|
g.DrawLine(Pens.Green, arrowEnd, arrowPoint1);
|
|
g.DrawLine(Pens.Green, arrowEnd, arrowPoint2);
|
|
}
|
|
|
|
if (Modulo.Modulo_ID.Contains("D"))
|
|
{
|
|
//Angulo *= -1;
|
|
}
|
|
|
|
// Desenhe uma linha para representar a posição do eixo do motor
|
|
double angleInRadians = (Angulo * Math.PI) / 180;
|
|
int x = centerX + (int)(radius * Math.Sin(angleInRadians));
|
|
int y = centerY - (int)(radius * Math.Cos(angleInRadians));
|
|
g.DrawLine(Pens.Red, centerX, centerY, x, y);
|
|
|
|
// Desenhe a seta que indica o sentido
|
|
if (Modulo.DirMotor.Sentido == Sentido.Horario)
|
|
{
|
|
// Desenhe uma seta para a direita (sentido horário)
|
|
Point arrowStart = new Point(x, y);
|
|
Point arrowEnd = new Point(x + arrowLength, y);
|
|
g.DrawLine(Pens.Red, arrowStart, arrowEnd);
|
|
|
|
// Desenhe a "ponta" da seta (triângulo) para a direita
|
|
Point arrowPoint1 = new Point(x + arrowLength - 5, y - 5);
|
|
Point arrowPoint2 = new Point(x + arrowLength - 5, y + 5);
|
|
g.DrawLine(Pens.Red, arrowEnd, arrowPoint1);
|
|
g.DrawLine(Pens.Red, arrowEnd, arrowPoint2);
|
|
}
|
|
else
|
|
{
|
|
// Desenhe uma seta para a esquerda (sentido anti-horário)
|
|
Point arrowStart = new Point(x, y);
|
|
Point arrowEnd = new Point(x - arrowLength, y);
|
|
g.DrawLine(Pens.Red, arrowStart, arrowEnd);
|
|
|
|
// Desenhe a "ponta" da seta (triângulo) para a esquerda
|
|
Point arrowPoint1 = new Point(x - arrowLength + 5, y - 5);
|
|
Point arrowPoint2 = new Point(x - arrowLength + 5, y + 5);
|
|
g.DrawLine(Pens.Red, arrowEnd, arrowPoint1);
|
|
g.DrawLine(Pens.Red, arrowEnd, arrowPoint2);
|
|
}
|
|
|
|
|
|
|
|
// Desenhe os pontos nos angulos fixos
|
|
int radiusCircle = 5;
|
|
var fontText = new Font(FontFamily.GenericSerif, 7);
|
|
for (int i = 0; i < 4; i++)
|
|
{
|
|
double angle = ((i * 90) * Math.PI) / 180;
|
|
int xA = centerX + (int)((radius) * Math.Sin(angle)); // Adicione 20 para afastar do círculo principal
|
|
int yA = centerY - (int)((radius) * Math.Cos(angle)); // Adicione 20 para afastar do círculo principal
|
|
|
|
Rectangle rect = new Rectangle(xA - radiusCircle, yA - radiusCircle, 2 * radiusCircle, 2 * radiusCircle);
|
|
bool Acionado = false;
|
|
Acionado =
|
|
(angle == 0 && Modulo.DirMotor.IN1_Atuado) ||
|
|
(angle == Math.PI / 2 && Modulo.DirMotor.IN2_Atuado);
|
|
using (SolidBrush brush = new SolidBrush(Acionado ? Color.Red : Color.DarkRed))
|
|
{
|
|
g.FillEllipse(brush, rect);
|
|
}
|
|
|
|
string angleText = ((i * 90).ToString() + "°");
|
|
SizeF textSize = g.MeasureString(angleText, fontText);
|
|
|
|
float textX = xA;
|
|
float textY = yA;
|
|
float textOffset = 12;
|
|
|
|
// Ajuste as coordenadas do texto com base no ângulo
|
|
if (angle == 0)
|
|
{
|
|
textX -= textSize.Width / 2;
|
|
textY -= textSize.Height - (textOffset * 2);
|
|
}
|
|
else if (angle == Math.PI / 2)
|
|
{
|
|
textX -= textSize.Width + textOffset;
|
|
textY -= textSize.Height / 2;
|
|
}
|
|
else if (angle == Math.PI)
|
|
{
|
|
textX -= textSize.Width / 2;
|
|
textY -= (textOffset * 2);
|
|
}
|
|
else if (angle == 3 * Math.PI / 2)
|
|
{
|
|
textX += textOffset;
|
|
textY -= textSize.Height / 2;
|
|
}
|
|
|
|
g.DrawString(angleText, fontText, Brushes.Black, textX, textY);
|
|
}
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Angulo orientacao Magnetica
|
|
|
|
private void pnlAnguloGPS_Paint(object sender, PaintEventArgs e)
|
|
{
|
|
try
|
|
{
|
|
double angulo = Variaveis.OperacaoEmAndamento.Sensoriamento.Gps.OrientacaoReal;
|
|
FuncoesGlobais.DesenharInclinacao((Panel)sender, e, (float)angulo, -90);
|
|
}
|
|
catch { }
|
|
}
|
|
|
|
private void pnlAnguloMagnetometro_Paint(object sender, PaintEventArgs e)
|
|
{
|
|
try
|
|
{
|
|
double angulo = Variaveis.OperacaoEmAndamento.Sensoriamento.WitMotion.AnguloCorrigido;
|
|
FuncoesGlobais.DesenharInclinacao((Panel)sender, e, (float)angulo, -270);
|
|
}
|
|
catch { }
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
#region Informacoes gerais
|
|
|
|
private void PopularInformacoesGerais()
|
|
{
|
|
gridDados.Rows.Clear();
|
|
gridDados.Columns.Clear();
|
|
gridDados.Columns.Add("clDado", "Dado");
|
|
gridDados.Columns.Add("clValor", "Valor");
|
|
gridDados.Columns.Add("clUnidade", "Un");
|
|
|
|
gridDados.Rows.Add("Tempo de Operação", "", "");
|
|
gridDados.Rows.Add("Tempo em Movimento", "", "");
|
|
gridDados.Rows.Add("Velocidade Média", "", "km/h");
|
|
gridDados.Rows.Add("Distância Percorrida", "", "m");
|
|
gridDados.Rows.Add("Nível de Bateria", "", "%");
|
|
gridDados.Rows.Add("Tensão da Bateria", "", "v");
|
|
gridDados.Rows.Add("Corrente da Bateria", "", "A");
|
|
gridDados.Rows.Add("Barramento 3V", "", "V");
|
|
gridDados.Rows.Add("Barramento 3V", "", "mA");
|
|
gridDados.Rows.Add("Barramento 5V", "", "V");
|
|
gridDados.Rows.Add("Barramento 5V", "", "mA");
|
|
gridDados.Rows.Add("Barramento 7,2V", "", "V");
|
|
gridDados.Rows.Add("Barramento 7,2V", "", "mA");
|
|
gridDados.Rows.Add("Barramento 12V", "", "V");
|
|
gridDados.Rows.Add("Barramento 12V", "", "mA");
|
|
gridDados.Rows.Add("Nível do Reservatório", "", "%");
|
|
gridDados.Rows.Add("Volume do Reservatório", "", "L");
|
|
gridDados.Rows.Add("Pressão da Linha", "", "psi");
|
|
gridDados.Rows.Add("Potência na Bomba", "", "%");
|
|
gridDados.Rows.Add("Vazão Instantanea", "", "mL/s");
|
|
gridDados.Rows.Add("Vazão Media", "", "mL/s");
|
|
gridDados.Rows.Add("Volume Vazado", "", "mL");
|
|
gridDados.Rows.Add("", "", "");
|
|
gridDados.Rows.Add("Roll", "", "");
|
|
gridDados.Rows.Add("Pitch", "", "");
|
|
gridDados.Rows.Add("Yaw", "", "");
|
|
gridDados.Rows.Add("Temperatura", "", "");
|
|
gridDados.Rows.Add("Pressao", "", "");
|
|
gridDados.Rows.Add("Altitude", "", "");
|
|
|
|
AtualizarInformacoesGerais();
|
|
}
|
|
|
|
private void AtualizarInformacoesGerais()
|
|
{
|
|
var _SensoresCorrente = Variaveis.OperacaoEmAndamento.DispSen.Dados.DadosLeitura.SensoresCorrente;
|
|
var AB3V = _SensoresCorrente.FirstOrDefault(x => x.ID == "AB3V");
|
|
var AB5V = _SensoresCorrente.FirstOrDefault(x => x.ID == "AB5V");
|
|
var AB7V2 = _SensoresCorrente.FirstOrDefault(x => x.ID == "AB7V2");
|
|
var AB12V = _SensoresCorrente.FirstOrDefault(x => x.ID == "AB12V");
|
|
var _Sensoriamento = Variaveis.OperacaoEmAndamento.Sensoriamento;
|
|
var _SensorIMU = Variaveis.OperacaoEmAndamento.DispSen.Dados.DadosLeitura.SensoresIMU.FirstOrDefault();
|
|
|
|
gridDados.Rows[0].Cells[1].Value = _Sensoriamento.TempoDecorrido.ToString("HH:mm:ss");
|
|
gridDados.Rows[1].Cells[1].Value = _Sensoriamento.Movimentacao.TempoMovimento.ToString("HH:mm:ss");
|
|
gridDados.Rows[2].Cells[1].Value = _Sensoriamento.Movimentacao.VelocidadeMedia.ToString("0.00");
|
|
gridDados.Rows[3].Cells[1].Value = _Sensoriamento.Trajetoria.DistanciaPercorrida.ToString("0.00");
|
|
gridDados.Rows[4].Cells[1].Value = (_Sensoriamento.Bateria.PorcentagemBateria.ToString("00.00"));
|
|
gridDados.Rows[5].Cells[1].Value = (_Sensoriamento.Bateria.TensaoInstantanea.ToString("0.00"));
|
|
gridDados.Rows[6].Cells[1].Value = (_Sensoriamento.Bateria.CorrenteInstantanea.ToString("0.00"));
|
|
gridDados.Rows[7].Cells[1].Value = (AB3V != null ? AB3V.BusVoltage : 0).ToString("0.00");
|
|
gridDados.Rows[8].Cells[1].Value = (AB3V != null ? (double)AB3V.Current : 0).ToString("0.00");
|
|
gridDados.Rows[9].Cells[1].Value = (AB5V != null ? AB5V.BusVoltage : 0).ToString("0.00");
|
|
gridDados.Rows[10].Cells[1].Value = (AB5V != null ? (double)AB5V.Current : 0).ToString("0.00");
|
|
gridDados.Rows[11].Cells[1].Value = (AB7V2 != null ? AB7V2.BusVoltage : 0).ToString("0.00");
|
|
gridDados.Rows[12].Cells[1].Value = (AB7V2 != null ? (double)AB7V2.Current : 0).ToString("0.00");
|
|
gridDados.Rows[13].Cells[1].Value = (AB12V != null ? AB12V.BusVoltage : 0).ToString("0.00");
|
|
gridDados.Rows[14].Cells[1].Value = (AB12V != null ? (double)AB12V.Current : 0).ToString("0.00");
|
|
gridDados.Rows[15].Cells[1].Value = _Sensoriamento.Atuador.PercentualReservatorio.ToString("00.00");
|
|
gridDados.Rows[16].Cells[1].Value = _Sensoriamento.Atuador.VolumeReservatorio.ToString("0.000");
|
|
gridDados.Rows[17].Cells[1].Value = _Sensoriamento.Atuador.PressaoLinha.ToString("0.00");
|
|
gridDados.Rows[18].Cells[1].Value = _Sensoriamento.Atuador.LeituraPotenciaBomba.ToString("0.00");
|
|
gridDados.Rows[19].Cells[1].Value = _Sensoriamento.Atuador.VazaoInstantanea.ToString("0.00");
|
|
gridDados.Rows[20].Cells[1].Value = _Sensoriamento.Atuador.VazaoMedia.ToString("0.00");
|
|
gridDados.Rows[21].Cells[1].Value = _Sensoriamento.Atuador.VolumeVazaoMl.ToString("0.00");
|
|
gridDados.Rows[22].Cells[1].Value = "";
|
|
gridDados.Rows[23].Cells[1].Value = _SensorIMU.Roll.ToString("0.00");
|
|
gridDados.Rows[24].Cells[1].Value = _SensorIMU.Pitch.ToString("0.00");
|
|
gridDados.Rows[25].Cells[1].Value = _SensorIMU.Yaw.ToString("0.00");
|
|
gridDados.Rows[26].Cells[1].Value = _SensorIMU.Temperatura.ToString("0.00");
|
|
gridDados.Rows[27].Cells[1].Value = _SensorIMU.Pressao.ToString("0.00");
|
|
gridDados.Rows[28].Cells[1].Value = _SensorIMU.Altitude.ToString("0.00");
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Mapa GPS
|
|
|
|
private void InicializarMapa()
|
|
{
|
|
Variaveis.OperacaoEmAndamento.Mapa = new MapasModel()
|
|
{
|
|
pnlMapa = pnlMapa,
|
|
};
|
|
Variaveis.OperacaoEmAndamento.Mapa.CarregarMapaGPS();
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Bicos Pulverizadores
|
|
|
|
private void PopularBicos()
|
|
{
|
|
var Atuador = Variaveis.OperacaoEmAndamento.DispAtu;
|
|
nudPressaoSP.Value = Convert.ToInt32(Variaveis.OperacaoEmAndamento.Controle.PressaoLinha);
|
|
|
|
int panelWidth = pnlAtuadores.Width;
|
|
int circleDiameter = 40; // Diâmetro dos círculos grandes
|
|
int spaceBetweenCircles = (panelWidth - (circleDiameter * Atuador.Dados.QuantidadeBicos)) / (Atuador.Dados.QuantidadeBicos + 1);
|
|
int yPosition = (pnlAtuadores.Height - circleDiameter) / 3; // Centralizado verticalmente
|
|
|
|
|
|
for (int i = 0; i < Atuador.Dados.QuantidadeBicos; i++)
|
|
{
|
|
// Calcula a posição x do círculo
|
|
int xPosition = spaceBetweenCircles + (i * (circleDiameter + spaceBetweenCircles));
|
|
// Define a string que representa o número do bico
|
|
string bicoNumero = Atuador.Dados.BicosPulverizadores[i].ID;
|
|
|
|
Button btnDesligar = new Button()
|
|
{
|
|
Name = "btn_" + bicoNumero,
|
|
Size = new Size(75, 27),
|
|
Location = new Point(xPosition + (circleDiameter - 75) / 2, circleDiameter + yPosition + 25),
|
|
Text = "Ligar"
|
|
};
|
|
btnDesligar.Click -= btn_Click;
|
|
btnDesligar.Click += btn_Click;
|
|
Label lblCmd = new Label()
|
|
{
|
|
Name = "lblCmd_" + bicoNumero,
|
|
Size = new Size(110, 15),
|
|
Location = new Point(xPosition + (circleDiameter - 110) / 2, 0),
|
|
Text = "Comando: Desligado"
|
|
};
|
|
|
|
pnlAtuadores.Controls.Add(btnDesligar);
|
|
pnlAtuadores.Controls.Add(lblCmd);
|
|
}
|
|
|
|
}
|
|
|
|
private void btn_Click(object sender, EventArgs e)
|
|
{
|
|
Button btn = (Button)sender;
|
|
string ID = btn.Name.Replace("btn_", "");
|
|
var Bico = Variaveis.OperacaoEmAndamento.DispAtu.Dados.BicosPulverizadores.FirstOrDefault(x => x.ID == ID);
|
|
if (Bico != null)
|
|
{
|
|
GeneralJoystick.EnviarComandoAtuador(S_Code.sBIC, !Bico.ComandoAtuar, Bico.ID);
|
|
|
|
pnlAtuadores.Controls.OfType<Label>().First(x => x.Name == "lblCmd_" + ID).Text = "Comando: " + (Bico.ComandoAtuar ? "Ligado" : "Desligado");
|
|
btn.Text = Bico.ComandoAtuar ? "Desligar" : "Ligar";
|
|
}
|
|
}
|
|
|
|
private void btnLigarBomba_Click(object sender, EventArgs e)
|
|
{
|
|
var Bomba = Variaveis.OperacaoEmAndamento.DispAtu.Dados.BombaPressurizadora;
|
|
GeneralJoystick.EnviarComandoAtuador(S_Code.sBMB, true, Bomba.ID);
|
|
}
|
|
|
|
private void btnDesligarBomba_Click(object sender, EventArgs e)
|
|
{
|
|
var Bomba = Variaveis.OperacaoEmAndamento.DispAtu.Dados.BombaPressurizadora;
|
|
GeneralJoystick.EnviarComandoAtuador(S_Code.sBMB, false, Bomba.ID);
|
|
}
|
|
|
|
private void nudPressaoSP_ValueChanged(object sender, EventArgs e)
|
|
{
|
|
var Bomba = Variaveis.OperacaoEmAndamento.DispAtu.Dados.BombaPressurizadora;
|
|
Variaveis.OperacaoEmAndamento.Controle.PressaoLinha = Convert.ToInt32(((NumericUpDown)sender).Value);
|
|
GeneralJoystick.EnviarComandoAtuador(S_Code.sBMB, Bomba.ComandoAtuar, Bomba.ID);
|
|
}
|
|
|
|
private void pnlAtuadores_Paint(object sender, PaintEventArgs e)
|
|
{
|
|
var Atuador = Variaveis.OperacaoEmAndamento.DispAtu.Dados;
|
|
|
|
AtuadorFuncoesGerais.DesenharAtuadores(pnlAtuadores, e, Atuador.BicosPulverizadores.Select(x => new AtuBicoSensoriamentoLogModel()
|
|
{
|
|
ID = x.ID,
|
|
Atuacoes = x.Atuacoes,
|
|
Atuado = x.ComandoAtuar,
|
|
Comandar = x.Comandar,
|
|
Inicializado = x.Inicializado,
|
|
MediaNivelFluxo = x.MediaNivelFluxo,
|
|
Posicao = x.Posicao,
|
|
StatusBico = x.LeituraStatusBico,
|
|
TempoAtuado = x.TempoAtuado,
|
|
}).ToList(), Atuador.BombaPressurizadora.LeituraEstado, Atuador.PressaoLinha, Atuador.TempoAtuado);
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
private void cmbTipoMovimento_SelectedIndexChanged(object sender, EventArgs e)
|
|
{
|
|
Variaveis.OperacaoEmAndamento.Controle.TipoMovimento = (TipoMovimentoDirecional)cmbTipoMovimento.SelectedIndex;
|
|
}
|
|
|
|
private void chbPulverizador_CheckedChanged(object sender, EventArgs e)
|
|
{
|
|
Variaveis.OperacaoEmAndamento.Controle.PulverizadorAutomatico = ((CheckBox)sender).Checked;
|
|
}
|
|
|
|
private void chbSonarAtivado_CheckedChanged(object sender, EventArgs e)
|
|
{
|
|
Variaveis.OperacaoEmAndamento.Controle.SonarAtivado = ((CheckBox)sender).Checked;
|
|
}
|
|
|
|
private void chbSonarDesvioAutomatico_CheckedChanged(object sender, EventArgs e)
|
|
{
|
|
Variaveis.OperacaoEmAndamento.Controle.SonarDesvioAutomatico = ((CheckBox)sender).Checked;
|
|
}
|
|
|
|
private void chbMostrarGrade_CheckedChanged(object sender, EventArgs e)
|
|
{
|
|
KinectService.MostrarGrade = ((CheckBox)sender).Checked;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
}
|