add - 添加空筐数量设定,添加AGV任务控制类

master
SoulStar 3 months ago
parent 09aaa1e752
commit 4c39b28fe7

@ -1,11 +1,16 @@
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using SlnMesnac.Config;
using SlnMesnac.Model.AirportApiEntity; using SlnMesnac.Model.AirportApiEntity;
using SlnMesnac.Model.domain; using SlnMesnac.Model.domain;
using SlnMesnac.Repository;
using SlnMesnac.Repository.service; using SlnMesnac.Repository.service;
using SlnMesnac.TouchSocket; using SlnMesnac.TouchSocket;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using System.Text; using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace SlnMesnac.Business.@base namespace SlnMesnac.Business.@base
{ {
@ -16,24 +21,34 @@ namespace SlnMesnac.Business.@base
{ {
private ILogger<BaseAGVBusiness> _logger; private ILogger<BaseAGVBusiness> _logger;
private static BaseAGVBusiness instance; private static BaseAGVBusiness instance;
private AppConfig _appConfig;
private AirPorthttpClient _airPorthttpClient; private AirPorthttpClient _airPorthttpClient;
private IAGVStateService _AGVStateService; private IAGVStateService _AGVStateService;
private IAGVMapPointService _AGVMapPointService; private IAGVMapPointService _AGVMapPointService;
public BaseAGVBusiness(ILogger<BaseAGVBusiness> logger, AirPorthttpClient airPorthttpClient, IAGVStateService AGVStateService, IAGVMapPointService aGVMapPointService) public BaseAGVBusiness(ILogger<BaseAGVBusiness> logger,
AirPorthttpClient airPorthttpClient,
IAGVStateService AGVStateService,
IAGVMapPointService aGVMapPointService,
AppConfig appConfig)
{ {
_logger = logger; _logger = logger;
_airPorthttpClient = airPorthttpClient; _airPorthttpClient = airPorthttpClient;
_AGVStateService = AGVStateService; _AGVStateService = AGVStateService;
_AGVMapPointService = aGVMapPointService; _AGVMapPointService = aGVMapPointService;
_appConfig = appConfig;
} }
public static BaseAGVBusiness GetInstance(ILogger<BaseAGVBusiness> logger, AirPorthttpClient airPorthttpClient, IAGVStateService AGVStateService, IAGVMapPointService aGVMapPointService) public static BaseAGVBusiness GetInstance(ILogger<BaseAGVBusiness> logger,
AirPorthttpClient airPorthttpClient,
IAGVStateService AGVStateService,
IAGVMapPointService aGVMapPointService,
AppConfig appConfig)
{ {
if (instance == null) if (instance == null)
{ {
instance = new BaseAGVBusiness(logger, airPorthttpClient, AGVStateService, aGVMapPointService); instance = new BaseAGVBusiness(logger, airPorthttpClient, AGVStateService, aGVMapPointService, appConfig);
} }
return instance; return instance;
} }
@ -85,7 +100,7 @@ namespace SlnMesnac.Business.@base
/// <summary> /// <summary>
/// 发送封装的任务类 /// 发送封装的任务类
/// </summary> /// </summary>
/// <returns></returns> /// <returns>任务ID</returns>
public string DownloadTask(string AGVGUID, string JobGUID, string PointGUID, string ParamName, string TaskName = "AGVCTask", string RobotType = "S800") public string DownloadTask(string AGVGUID, string JobGUID, string PointGUID, string ParamName, string TaskName = "AGVCTask", string RobotType = "S800")
{ {
try try
@ -115,12 +130,14 @@ namespace SlnMesnac.Business.@base
/// <returns></returns> /// <returns></returns>
public bool EndAGVTask(string AGVGUID) public bool EndAGVTask(string AGVGUID)
{ {
var agvState = _AGVStateService.GetAGVState(AGVGUID); try
if(agvState == null) {
AGVState agvState = _AGVStateService.GetAGVState(AGVGUID);
if (agvState == null)
{ {
return false; return false;
} }
if(agvState.agvworkstate != "待机") if (agvState.agvworkstate != "待机")
{ {
var response = _airPorthttpClient.AGVOperationalTaskRequest(new AGVRequestOperationalTaskEntity() var response = _airPorthttpClient.AGVOperationalTaskRequest(new AGVRequestOperationalTaskEntity()
{ {
@ -141,7 +158,7 @@ namespace SlnMesnac.Business.@base
return false; return false;
} }
} }
else if(agvState.agvworkstate == "待机") else if (agvState.agvworkstate == "待机")
{ {
_logger.LogError($"AGV {agvState.agvno} 现在无任务"); _logger.LogError($"AGV {agvState.agvno} 现在无任务");
return false; return false;
@ -152,6 +169,12 @@ namespace SlnMesnac.Business.@base
return false; return false;
} }
} }
catch (Exception ex)
{
_logger.LogError($"AGV任务结束失败 ERROR{ex.Message}");
return false;
}
}
/// <summary> /// <summary>
/// 获取活跃地图的点位更新到数据库 /// 获取活跃地图的点位更新到数据库
@ -208,6 +231,92 @@ namespace SlnMesnac.Business.@base
return _AGVMapPointService.DeleteAndAddAgvMapPoint(list); return _AGVMapPointService.DeleteAndAddAgvMapPoint(list);
} }
/// <summary>
/// 结束当前任务 清除报警 下发任务
/// </summary>
/// <param name="agvName"></param>
/// <param name="jobName"></param>
/// <returns>新任务GUID</returns>
public string EndTaskAndClearErrorAndDownloadTask(string agvName, string jobName)
{
bool result = false;
try
{
//终止小车当前任务
result = EndTaskAndClearError(agvName);
var param = _appConfig.JobConfig.Where(x => x.JobName == jobName).First();
//调用小车到抓取位置
return DownloadTask(_appConfig.AGVConfig.Where(x => x.AGVName == agvName).First().AGVGUID, param.JobGUID, param.PointGUID, param.PointParamName);
}
catch (Exception ex)
{
return string.Empty;
}
}
/// <summary>
/// 结束任务并清除报警 延迟1s
/// </summary>
public bool EndTaskAndClearError(string agvName)
{
bool result1 = false, result2 = false;
try
{
Task.Run(() =>
{
result1 = EndAGVTask(_appConfig.AGVConfig.Where(x => x.AGVName == agvName).First().AGVGUID);
Thread.Sleep(500);
result2 = ClaerError(_appConfig.AGVConfig.Where(x => x.AGVName == agvName).First().AGVIp);
});
return result1 && result2;
}
catch (Exception ex)
{
_logger.LogError("结束任务并清除报警发生异常 " + ex);
return false;
}
}
/// <summary>
/// 清除报警 延迟500ms
/// </summary>
public bool ClaerError(string agvName)
{
bool result = false;
try
{
Task.Run(() =>
{
var response = _airPorthttpClient.AGVErrorClear(_appConfig.AGVConfig.Where(x => x.AGVName == agvName).First().AGVIp);
Thread.Sleep(500);
if (response == null)
{
_logger.LogError("清除报警返回空数据");
result = false;
return false;
}
if(response.code == 0)
{
_logger.LogError("清除报警成功");
result = true;
return true;
}
else
{
_logger.LogError("清除报警失败 message:" + response.message);
result = false;
return false;
}
});
return result;
}
catch (Exception ex)
{
_logger.LogError("清除报警发生异常 " + ex);
return false;
}
}
/// <summary> /// <summary>
/// AGV任务状态代码匹配 /// AGV任务状态代码匹配
/// </summary> /// </summary>

@ -35,6 +35,11 @@
<TextBox Name="AirNo" Width="188" Height="36"/> <TextBox Name="AirNo" Width="188" Height="36"/>
</StackPanel> </StackPanel>
<StackPanel Grid.Row="3" Orientation="Horizontal">
<Label Content="空筐数量" Width="64" VerticalAlignment="Center"/>
<TextBox Name="BoxNo" Width="188" Height="36"/>
</StackPanel>
<StackPanel Grid.Row="5" Orientation="Horizontal"> <StackPanel Grid.Row="5" Orientation="Horizontal">
<Button x:Name="btn_ok" Content="确认" Width="145" Click="btn_ok_Click" /> <Button x:Name="btn_ok" Content="确认" Width="145" Click="btn_ok_Click" />

@ -80,6 +80,7 @@ namespace SlnMesnac.WPF.Page.IndexPage
taskno = taskNo.Text, taskno = taskNo.Text,
conveyorno = AreaNo.SelectedValue.ToString(), conveyorno = AreaNo.SelectedValue.ToString(),
flightno = AirNo.Text, flightno = AirNo.Text,
totalcount = Convert.ToInt32(BoxNo.Text),
taskstate = "等待", taskstate = "等待",
starttime = DateTime.Now starttime = DateTime.Now
}; };

@ -117,7 +117,7 @@ namespace SlnMesnac.WPF.ViewModel
_tcpServer = App.ServiceProvider.GetService<TcpServer>(); _tcpServer = App.ServiceProvider.GetService<TcpServer>();
_airPorthttpClient = App.ServiceProvider.GetService<AirPorthttpClient>(); _airPorthttpClient = App.ServiceProvider.GetService<AirPorthttpClient>();
_baseTaskInfoBusiness = BaseTaskInfoBusiness.GetInstance(_BaseTaskInfoBusinesslogger, _Taskservice, _AGVStateService, _tcpServer, _airPorthttpClient); _baseTaskInfoBusiness = BaseTaskInfoBusiness.GetInstance(_BaseTaskInfoBusinesslogger, _Taskservice, _AGVStateService, _tcpServer, _airPorthttpClient);
_baseAGVBusiness = BaseAGVBusiness.GetInstance(_baseAGVBusinessLogger, _airPorthttpClient, _AGVStateService, _AGVMapPointService); _baseAGVBusiness = BaseAGVBusiness.GetInstance(_baseAGVBusinessLogger, _airPorthttpClient, _AGVStateService, _AGVMapPointService, _appConfig);
_visionBusiness = VisionBusiness.GetInstance(_VisionBusinessLogger, _tcpServer); _visionBusiness = VisionBusiness.GetInstance(_VisionBusinessLogger, _tcpServer);
_baseStateRefreshBusiness = BaseStateRefreshBusiness.GetInstance(_StateRefreshBusinessLogger, _AGVStateService, _airPorthttpClient, _AGVSettingService); _baseStateRefreshBusiness = BaseStateRefreshBusiness.GetInstance(_StateRefreshBusinessLogger, _AGVStateService, _airPorthttpClient, _AGVSettingService);
ControlOnClickCommand = new RelayCommand<object>(obj => ControlOnClick(obj)); ControlOnClickCommand = new RelayCommand<object>(obj => ControlOnClick(obj));
@ -190,75 +190,30 @@ namespace SlnMesnac.WPF.ViewModel
_visionBusiness.RequestVisionReplace(_tcpServer.VID); _visionBusiness.RequestVisionReplace(_tcpServer.VID);
break; break;
case "TestButton3": case "TestButton3":
//终止小车当前任务 _baseAGVBusiness.EndTaskAndClearErrorAndDownloadTask("S800-B", "800小车进入位置任务pause");
StopTaskAndClearError("S800-B");
var param = _appConfig.JobConfig.Where(x => x.JobName == "800小车进入位置任务pause").First();
//调用小车到抓取位置
_baseAGVBusiness.DownloadTask(
_appConfig.AGVConfig.Where(x => x.AGVName == "S800-B").First().AGVGUID,
param.JobGUID,
param.PointGUID,
param.PointParamName
);
break; break;
case "TestButton4": case "TestButton4":
//终止小车当前任务 _baseAGVBusiness.EndTaskAndClearErrorAndDownloadTask("S800-B", "800小车入库任务pause");
StopTaskAndClearError("S800-B");
var param1 = _appConfig.JobConfig.Where(x => x.JobName == "800小车入库任务pause").First();
//调用小车到库位
_baseAGVBusiness.DownloadTask(
_appConfig.AGVConfig.Where(x => x.AGVName == "S800-B").First().AGVGUID,
param1.JobGUID,
param1.PointGUID,
param1.PointParamName
);
break; break;
case "TestButton8": case "TestButton8":
//终止小车当前任务 _baseAGVBusiness.EndTaskAndClearErrorAndDownloadTask("S1000-A", "1000小车进入位置任务pause");
StopTaskAndClearError("S1000-A");
var param2 = _appConfig.JobConfig.Where(x => x.JobName == "1000小车进入位置任务pause").First();
//调用小车到抓取位置
_baseAGVBusiness.DownloadTask(
_appConfig.AGVConfig.Where(x => x.AGVName == "S1000-A").First().AGVGUID,
param2.JobGUID,
param2.PointGUID,
param2.PointParamName
);
break; break;
case "TestButton9": case "TestButton9":
//终止小车当前任务 _baseAGVBusiness.EndTaskAndClearErrorAndDownloadTask("S1000-A", "1000小车入库任务pause");
StopTaskAndClearError("S1000-A");
var param3 = _appConfig.JobConfig.Where(x => x.JobName == "1000小车入库任务pause").First();
//调用小车到库位
_baseAGVBusiness.DownloadTask(
_appConfig.AGVConfig.Where(x => x.AGVName == "S1000-A").First().AGVGUID,
param3.JobGUID,
param3.PointGUID,
param3.PointParamName
);
break; break;
case "TestButton10": case "TestButton10":
//终止小车当前任务 _baseAGVBusiness.EndTaskAndClearErrorAndDownloadTask("S1000-A", "1000校正模板");
StopTaskAndClearError("S1000-A");
var param4 = _appConfig.JobConfig.Where(x => x.JobName == "1000校正模板").First();
//调用小车到库位
_baseAGVBusiness.DownloadTask(
_appConfig.AGVConfig.Where(x => x.AGVName == "S1000-A").First().AGVGUID,
param4.JobGUID,
param4.PointGUID,
param4.PointParamName
);
break; break;
case "TestButton5": case "TestButton5":
//手动停止任务 //手动停止任务
StopTaskAndClearError("S800-B"); _baseAGVBusiness.EndTaskAndClearError("S800-B");
break; break;
case "TestButton6": case "TestButton6":
//手动清除报警 //手动清除报警
ClaerError("S800-B"); _baseAGVBusiness.ClaerError("S800-B");
break; break;
case "TestButton7": case "TestButton7":
BusinessShow(); _baseAGVBusiness.EndTaskAndClearError("S1000-A");
break; break;
default: default:
break; break;
@ -270,72 +225,6 @@ namespace SlnMesnac.WPF.ViewModel
} }
} }
/// <summary>
/// 演示程序
/// </summary>
private void BusinessShow()
{
try
{
//Task.Run(() =>
//{
// while (true)
// {
// Thread.Sleep(1000);
// List<AGVState> lists = _AGVStateService.GetAllAGVState();
// }
//});
//手动停止任务
StopTaskAndClearError("S1000-A");
}
catch(Exception ex)
{
_logger.LogError($"发生错误{ex.Message}");
}
}
/// <summary>
/// 结束任务并清除报警
/// </summary>
private void StopTaskAndClearError(string agvName)
{
try
{
Task.Run(() =>
{
_baseAGVBusiness.EndAGVTask(_appConfig.AGVConfig.Where(x => x.AGVName == agvName).First().AGVGUID);
Thread.Sleep(500);
_airPorthttpClient.AGVErrorClear(_appConfig.AGVConfig.Where(x => x.AGVName == agvName).First().AGVIp);
Thread.Sleep(500);
});
}
catch (Exception ex)
{
_logger.LogError("结束任务并清除报警发生异常 " + ex);
}
}
/// <summary>
/// 清除报警
/// </summary>
private void ClaerError(string agvName)
{
try
{
Task.Run(() =>
{
_airPorthttpClient.AGVErrorClear(_appConfig.AGVConfig.Where(x => x.AGVName == agvName).First().AGVIp);
Thread.Sleep(500);
});
}
catch(Exception ex)
{
_logger.LogError("清除报警发生异常 " + ex);
}
}
/// <summary> /// <summary>
/// 界面跳转 /// 界面跳转
/// </summary> /// </summary>

Loading…
Cancel
Save