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

master
SoulStar 3 months ago
parent 09aaa1e752
commit 4c39b28fe7

@ -1,11 +1,16 @@
using Microsoft.Extensions.Logging;
using SlnMesnac.Config;
using SlnMesnac.Model.AirportApiEntity;
using SlnMesnac.Model.domain;
using SlnMesnac.Repository;
using SlnMesnac.Repository.service;
using SlnMesnac.TouchSocket;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace SlnMesnac.Business.@base
{
@ -16,24 +21,34 @@ namespace SlnMesnac.Business.@base
{
private ILogger<BaseAGVBusiness> _logger;
private static BaseAGVBusiness instance;
private AppConfig _appConfig;
private AirPorthttpClient _airPorthttpClient;
private IAGVStateService _AGVStateService;
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;
_airPorthttpClient = airPorthttpClient;
_AGVStateService = AGVStateService;
_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)
{
instance = new BaseAGVBusiness(logger, airPorthttpClient, AGVStateService, aGVMapPointService);
instance = new BaseAGVBusiness(logger, airPorthttpClient, AGVStateService, aGVMapPointService, appConfig);
}
return instance;
}
@ -85,7 +100,7 @@ namespace SlnMesnac.Business.@base
/// <summary>
/// 发送封装的任务类
/// </summary>
/// <returns></returns>
/// <returns>任务ID</returns>
public string DownloadTask(string AGVGUID, string JobGUID, string PointGUID, string ParamName, string TaskName = "AGVCTask", string RobotType = "S800")
{
try
@ -115,40 +130,48 @@ namespace SlnMesnac.Business.@base
/// <returns></returns>
public bool EndAGVTask(string AGVGUID)
{
var agvState = _AGVStateService.GetAGVState(AGVGUID);
if(agvState == null)
{
return false;
}
if(agvState.agvworkstate != "待机")
try
{
var response = _airPorthttpClient.AGVOperationalTaskRequest(new AGVRequestOperationalTaskEntity()
AGVState agvState = _AGVStateService.GetAGVState(AGVGUID);
if (agvState == null)
{
taskid = agvState.taskno,
state = 0,
operatingSource = "agvc",
operatingUser = "agvc",
remark = "agvcEnd"
});
if (response.code == 0)
return false;
}
if (agvState.agvworkstate != "待机")
{
var response = _airPorthttpClient.AGVOperationalTaskRequest(new AGVRequestOperationalTaskEntity()
{
taskid = agvState.taskno,
state = 0,
operatingSource = "agvc",
operatingUser = "agvc",
remark = "agvcEnd"
});
if (response.code == 0)
{
_logger.LogInformation($"AGV {agvState.agvno} 任务 {agvState.taskno} 结束成功");
return true;
}
else
{
_logger.LogError($"AGV {agvState.agvno} 任务 {agvState.taskno} 结束失败 ERROR:{response.message}");
return false;
}
}
else if (agvState.agvworkstate == "待机")
{
_logger.LogInformation($"AGV {agvState.agvno} 任务 {agvState.taskno} 结束成功");
return true;
_logger.LogError($"AGV {agvState.agvno} 现在无任务");
return false;
}
else
{
_logger.LogError($"AGV {agvState.agvno} 任务 {agvState.taskno} 结束失败 ERROR:{response.message}");
_logger.LogError($"AGV {agvState.agvno} 终止任务失败!");
return false;
}
}
else if(agvState.agvworkstate == "待机")
{
_logger.LogError($"AGV {agvState.agvno} 现在无任务");
return false;
}
else
catch (Exception ex)
{
_logger.LogError($"AGV {agvState.agvno} 终止任务失败!");
_logger.LogError($"AGV任务结束失败 ERROR{ex.Message}");
return false;
}
}
@ -208,6 +231,92 @@ namespace SlnMesnac.Business.@base
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>
/// AGV任务状态代码匹配
/// </summary>

@ -35,6 +35,11 @@
<TextBox Name="AirNo" Width="188" Height="36"/>
</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">
<Button x:Name="btn_ok" Content="确认" Width="145" Click="btn_ok_Click" />

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

@ -117,7 +117,7 @@ namespace SlnMesnac.WPF.ViewModel
_tcpServer = App.ServiceProvider.GetService<TcpServer>();
_airPorthttpClient = App.ServiceProvider.GetService<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);
_baseStateRefreshBusiness = BaseStateRefreshBusiness.GetInstance(_StateRefreshBusinessLogger, _AGVStateService, _airPorthttpClient, _AGVSettingService);
ControlOnClickCommand = new RelayCommand<object>(obj => ControlOnClick(obj));
@ -190,75 +190,30 @@ namespace SlnMesnac.WPF.ViewModel
_visionBusiness.RequestVisionReplace(_tcpServer.VID);
break;
case "TestButton3":
//终止小车当前任务
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
);
_baseAGVBusiness.EndTaskAndClearErrorAndDownloadTask("S800-B", "800小车进入位置任务pause");
break;
case "TestButton4":
//终止小车当前任务
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
);
_baseAGVBusiness.EndTaskAndClearErrorAndDownloadTask("S800-B", "800小车入库任务pause");
break;
case "TestButton8":
//终止小车当前任务
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
);
_baseAGVBusiness.EndTaskAndClearErrorAndDownloadTask("S1000-A", "1000小车进入位置任务pause");
break;
case "TestButton9":
//终止小车当前任务
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
);
_baseAGVBusiness.EndTaskAndClearErrorAndDownloadTask("S1000-A", "1000小车入库任务pause");
break;
case "TestButton10":
//终止小车当前任务
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
);
_baseAGVBusiness.EndTaskAndClearErrorAndDownloadTask("S1000-A", "1000校正模板");
break;
case "TestButton5":
//手动停止任务
StopTaskAndClearError("S800-B");
_baseAGVBusiness.EndTaskAndClearError("S800-B");
break;
case "TestButton6":
//手动清除报警
ClaerError("S800-B");
_baseAGVBusiness.ClaerError("S800-B");
break;
case "TestButton7":
BusinessShow();
_baseAGVBusiness.EndTaskAndClearError("S1000-A");
break;
default:
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>

Loading…
Cancel
Save