Ajustes no freio e controle joystick

This commit is contained in:
Diego Freitas 2026-03-20 12:30:20 -03:00
parent 51c9f51f4f
commit fc89b3a90e
6 changed files with 36 additions and 20 deletions

View File

@ -706,14 +706,18 @@ namespace AgroBase
{
Comando.Dispositivo = T_Code.Mov;
DirecaoAtual = tipoControle?.UltimaDirecao ?? Direcao.Parado;
_Controle.PercentualVelocidadeSP++;
int s = Math.Sign(_Controle.PercentualVelocidadeSP);
var p = (Math.Abs(_Controle.PercentualVelocidadeSP) + 1) * s;
_Controle.PercentualVelocidadeSP = p;
Pressionado = true;
}
else if (Comando.Comando == Keys.Subtract)
{
Comando.Dispositivo = T_Code.Mov;
DirecaoAtual = tipoControle?.UltimaDirecao ?? Direcao.Parado;
_Controle.PercentualVelocidadeSP--;
int s = Math.Sign(_Controle.PercentualVelocidadeSP);
var p = (Math.Abs(_Controle.PercentualVelocidadeSP) - 1) * s;
_Controle.PercentualVelocidadeSP = p;
Pressionado = true;
}
// Controle Direcao dos Motores BLDC (MOV)

View File

@ -65,6 +65,7 @@ namespace AgroBase.Models.Modules
public int NumeroPolos { get; set; } = 10;
public int Rampa { get; set; } = 0;
public int CorrenteTorqueMaximo { get; set; } = 40;
public int CorrenteFreio { get; set; } = 5;
public double OffsetLeitura { get; set; } = 1.0;
private DateTime UltimoAlarmeComando { get; set; } = DateTime.MinValue;
public bool AlarmeComando
@ -436,16 +437,24 @@ namespace AgroBase.Models.Modules
ComandoLigado ? OidFuncCode.ComandoVelocidade :
OidFuncCode.ComandoCorrente;
if (EnviaComando) // && !Freado
if (EnviaComando)
{
int mx =
float setPoint = 0;
if (modoControle == OidFuncCode.ComandoCorrenteFreio)
{
setPoint = (float)CorrenteFreio;
}
else {
int mx =
Sentido_SP == Sentido.Horario ? 1 :
Sentido_SP == Sentido.Antihorario ? -1 :
0;
float velocidade = RPM_SP * mx;
setPoint = RPM_SP * mx;
}
//velocidade = (Mod_ID.Contains("T") ? velocidade : velocidade * 0.7f);
OIDCanService.ComandoControle(_EnderecoCAN_Tx, _EnderecoCAN_Rx, modoControle, velocidade);
OIDCanService.ComandoControle(_EnderecoCAN_Tx, _EnderecoCAN_Rx, modoControle, setPoint);
LeituraRPM = RPM_SP;
}

View File

@ -1369,7 +1369,7 @@ namespace AgroBase.Models
}
var modsAtualizar = Variaveis.OperacaoEmAndamento.DispMvd.Dados.Modulos.Where(Mod => Mod.MovMotor.NovoRPMNecessario).Select(x => x.Modulo_ID).ToList();
bool envioNecessario = ForcarEnvio || _Controle.RPM_SP != _ControleAnterior.RPM_SP;
bool envioNecessario = ForcarEnvio || _Controle.RPM_SP != _ControleAnterior.RPM_SP || _Controle.EmFreio != _ControleAnterior.EmFreio;
if (envioNecessario || modsAtualizar.Any())
{
foreach (var Mod in Variaveis.OperacaoEmAndamento.DispMvd.Dados.Modulos.Where(x => envioNecessario ? true : modsAtualizar.Contains(x.Modulo_ID)))

View File

@ -169,11 +169,11 @@ namespace AgroBase.Services
{
if (ReleCoolerEntrada != null && CoolerEntradaEstadoRele != CoolerEntradaEstado)
{
GeneralJoystick.EnviarComandoSensoriamento(ReleCoolerEntrada.Componente, ReleCoolerEntrada.ID, CoolerEntradaEstado);
GeneralJoystick.EnviarComandoSensoriamento(ReleCoolerEntrada.Componente, ReleCoolerEntrada.ID, CoolerEntradaEstado, true);
}
if (ReleCoolerSaida != null && CoolerSaidaEstadoRele != CoolerSaidaEstado)
{
GeneralJoystick.EnviarComandoSensoriamento(ReleCoolerSaida.Componente, ReleCoolerSaida.ID, CoolerSaidaEstado);
GeneralJoystick.EnviarComandoSensoriamento(ReleCoolerSaida.Componente, ReleCoolerSaida.ID, CoolerSaidaEstado, true);
}
}

View File

@ -123,11 +123,15 @@ namespace AgroBase.Services
switch (funcCode)
{
case OidFuncCode.ComandoCorrente:
case OidFuncCode.ComandoCorrenteFreio:
case OidFuncCode.AjusteCorrenteMaxima:
short corrente_10mA = (short)(setPoint * 100);
setPointBytes = BitConverter.GetBytes(corrente_10mA).Reverse().ToArray();
DadosLeitura.FirstOrDefault(x => x.EnderecoTx == idTx).ModoControle = OIDModoControle.Corrente;
break;
case OidFuncCode.ComandoCorrenteFreio:
{
short corrente_10mA = (short)(setPoint * 100);
setPointBytes = BitConverter.GetBytes(corrente_10mA).Reverse().ToArray();
short corrente_10mA_f = (short)(setPoint * 100);
setPointBytes = BitConverter.GetBytes(corrente_10mA_f).Reverse().ToArray();
DadosLeitura.FirstOrDefault(x => x.EnderecoTx == idTx).ModoControle = OIDModoControle.Freio;
break;
}
@ -142,6 +146,7 @@ namespace AgroBase.Services
{
short duty = (short)(Math.Max(-100, Math.Min(setPoint, 100)) * 10);
setPointBytes = BitConverter.GetBytes(duty).Reverse().ToArray();
DadosLeitura.FirstOrDefault(x => x.EnderecoTx == idTx).ModoControle = OIDModoControle.CicloTrabalho;
break;
}
case OidFuncCode.AjusteAceleracaoVelocidade:
@ -182,7 +187,7 @@ namespace AgroBase.Services
byte addrTx = Modulo._EnderecoCAN_Tx;
byte addrRx = Modulo._EnderecoCAN_Rx;
ComandoControle(addrTx, addrRx, OidFuncCode.ComandoCorrenteFreio, 3.0);
//ComandoControle(addrTx, addrRx, OidFuncCode.ComandoCorrenteFreio, 3.0);
ComandoControle(addrTx, addrRx, OidFuncCode.ComandoVelocidade, 0.0);
ComandoControle(addrTx, addrRx, OidFuncCode.AjusteCorrenteMaxima, Modulo.CorrenteTorqueMaximo);
ComandoControle(addrTx, addrRx, OidFuncCode.AjusteAceleracaoVelocidade, Modulo.Rampa);

View File

@ -306,6 +306,8 @@ class IMUCamera(ModuloDiagnosticoBase):
self.last_publish_ts = time.time()
self.last_redis_ts = t_pub
ts_imu = (time.time() * 1000)
ContextoGlobalRedis.atualizar_ctx_dict(
ContextoGlobalRedis.ModKey(T_Code.Imu),
roll=round(-roll, 2),
@ -319,7 +321,7 @@ class IMUCamera(ModuloDiagnosticoBase):
rugosidade_idx=round(self.rugosidade_idx, 1),
impacto_idx=round(self.impacto_idx, 1),
estabilidade_idx=round(self.estabilidade_idx, 1),
timestamp=(time.time() * 1000),
timestamp=ts_imu,
last_packet_ts=self.last_packet_ts,
last_publish_ts=self.last_publish_ts,
ultimo_erro_ts=self.ultimo_erro_ts,
@ -347,17 +349,14 @@ class IMUCamera(ModuloDiagnosticoBase):
try:
agora = time.time()
modulo = ContextoGlobalRedis.get_modulo(T_Code.Imu) or {}
mod_ts = modulo.get("timestamp")
if mod_ts is None or mod_ts == 0:
return
mod_ts = modulo.get("last_packet_ts")
FREQ_BASE = self.freq
FREQ_MIN = FREQ_BASE * 0.5
SAUDE_MIN_ALERTA = 80
SAUDE_MIN_FALHA = 45
tempo_sem_dados = ((time.time() * 1000) - mod_ts) / 1000.0
tempo_sem_dados = (time.time() - (mod_ts or 0))
conectado = tempo_sem_dados < 10
freq_hz = float(modulo.get("frequencia", 0.0) or 0.0)
@ -375,7 +374,6 @@ class IMUCamera(ModuloDiagnosticoBase):
motivos = []
if not conectado:
print(f"Thread da IMU não está viva à {tempo_sem_dados:.2f} s, mod_ts: {mod_ts}")
motivos.append(f"Thread da IMU não está viva à {tempo_sem_dados:.2f} s")
saude = 0
else: