代码变更

This commit is contained in:
Pang_mir 2025-05-09 15:52:45 +08:00
parent 2eb6590e59
commit e03ed1cc33
3 changed files with 300 additions and 301 deletions

View File

@ -31,8 +31,10 @@ public class ShelfNetListenerComponent : MonoBehaviour,IWcsSocketDataHandle
private void Start() private void Start()
{ {
_shelfActor = GetComponent<ShelfActor>(); _shelfActor = GetComponent<ShelfActor>();
_deviceCode = _shelfActor._shelfConfig.deviceCode; _deviceCode = "DDJ01";
_deviceType = _shelfActor._shelfConfig.deviceType; // _deviceCode = _shelfActor._shelfConfig.deviceCode;
// _deviceType = _shelfActor._shelfConfig.deviceType;
_deviceType = "STACKER";
} }
public void DataHandle(object data, object other = null) public void DataHandle(object data, object other = null)

View File

@ -16,7 +16,6 @@ public class InitNetWorkProcess : IProcessState
[Autowired("WmsStorageWebsocket")] [Autowired("WmsStorageWebsocket")]
private WmsStorageWebsocket wmsStorageWebsocket; private WmsStorageWebsocket wmsStorageWebsocket;
private bool executing = false; private bool executing = false;
[Autowired] AgvTaskListData _agvTaskListData;
public string Name { get => "InitNetWorkProcess"; } public string Name { get => "InitNetWorkProcess"; }
public int Priority { get => 0; } public int Priority { get => 0; }
public bool IsExecuteProcess { get => executing; set => executing = value; } public bool IsExecuteProcess { get => executing; set => executing = value; }
@ -38,8 +37,6 @@ public class InitNetWorkProcess : IProcessState
////监听后台数据变化 ////监听后台数据变化
wmsStorageWebsocket.OnMessage(v.DataHandle); wmsStorageWebsocket.OnMessage(v.DataHandle);
}); });
//³õʼ»¯agvÈÎÎñÁбí
_agvTaskListData.Init();
netWorkComponent?.ConnectAllWebSocket(); netWorkComponent?.ConnectAllWebSocket();
} }

View File

@ -154,301 +154,301 @@ public class ForkAgvDevice : AbstractDevice, ICar
} }
private void FixedUpdate() // private void FixedUpdate()
{ // {
//设备没初始化 // //设备没初始化
if (!initialize) // if (!initialize)
{ // {
return; // return;
} // }
//
if (!hasTask) // if (!hasTask)
{ // {
return; // return;
} // }
UpdateTask(); // UpdateTask();
//当任务状态是下发状态是,执行 // //当任务状态是下发状态是,执行
if (taskInfo.agvTaskStatus == AgvCarManage.CarTaskStatusEnum.SENT) // if (taskInfo.agvTaskStatus == AgvCarManage.CarTaskStatusEnum.SENT)
{ // {
if (currentFeedBackStatus != AgvCarManage.CarTaskStatusEnum.TAKING) // if (currentFeedBackStatus != AgvCarManage.CarTaskStatusEnum.TAKING)
{ // {
currentFeedBackStatus = AgvCarManage.CarTaskStatusEnum.TAKING; // currentFeedBackStatus = AgvCarManage.CarTaskStatusEnum.TAKING;
} // }
//多次申请 // //多次申请
FeedBackTaskStatus(currentFeedBackStatus); // FeedBackTaskStatus(currentFeedBackStatus);
} // }
//取货中 // //取货中
if (taskInfo.agvTaskStatus == AgvCarManage.CarTaskStatusEnum.TAKING) // if (taskInfo.agvTaskStatus == AgvCarManage.CarTaskStatusEnum.TAKING)
{ // {
agent.isStopped = false; // agent.isStopped = false;
//开始代理 // //开始代理
StartAgent(taskInfo.fromLocation); // StartAgent(taskInfo.fromLocation);
// 起点旋转位置 // // 起点旋转位置
if (applyTakePosition.Count > 0) // if (applyTakePosition.Count > 0)
{ // {
Vector3 applyTakeVector = LastPosition(applyTakePosition,taskInfo.fromLocation); // Vector3 applyTakeVector = LastPosition(applyTakePosition,taskInfo.fromLocation);
//抵达后,申请取货流程 // //抵达后,申请取货流程
Vector3 targetPosition = new Vector3(applyTakeVector.x, transform.position.y, applyTakeVector.z); // Vector3 targetPosition = new Vector3(applyTakeVector.x, transform.position.y, applyTakeVector.z);
if (Vector3.Distance(transform.position, targetPosition) <= 0.1f) // if (Vector3.Distance(transform.position, targetPosition) <= 0.1f)
{ // {
agent.isStopped = true; // agent.isStopped = true;
agent.updateRotation = false; // agent.updateRotation = false;
currentFeedBackStatus = AgvCarManage.CarTaskStatusEnum.APPLY_TAKE; // currentFeedBackStatus = AgvCarManage.CarTaskStatusEnum.APPLY_TAKE;
FeedBackTaskStatus(currentFeedBackStatus); // FeedBackTaskStatus(currentFeedBackStatus);
} // }
} // }
} // }
//申请取货 // //申请取货
if (taskInfo.agvTaskStatus == AgvCarManage.CarTaskStatusEnum.APPLY_TAKE) // if (taskInfo.agvTaskStatus == AgvCarManage.CarTaskStatusEnum.APPLY_TAKE)
{ // {
//抵达终点 // //抵达终点
Vector3 targetPosition = new Vector3(transform.position.x, agent.destination.y, transform.position.z); // Vector3 targetPosition = new Vector3(transform.position.x, agent.destination.y, transform.position.z);
if (Vector3.Distance(targetPosition, agent.destination) <= 0.1f) // if (Vector3.Distance(targetPosition, agent.destination) <= 0.1f)
{ // {
//获取库位容器模型,绑定到货叉上 // //获取库位容器模型,绑定到货叉上
GameObject game = deviceParseService.GameObjectByDevice(taskInfo.fromLocation); // GameObject game = deviceParseService.GameObjectByDevice(taskInfo.fromLocation);
if (game != null) // if (game != null)
{ // {
Container container = game.GetComponentInChildren<Container>(); // Container container = game.GetComponentInChildren<Container>();
if (container != null) // if (container != null)
{ // {
container.transform.parent = forkCargo.transform; // container.transform.parent = forkCargo.transform;
container.Agent.enabled = false; // container.Agent.enabled = false;
container.Agent.isStopped = true; // container.Agent.isStopped = true;
playable.Play(); // playable.Play();
} // }
} // }
//反馈取货完成 // //反馈取货完成
currentFeedBackStatus = AgvCarManage.CarTaskStatusEnum.TAKE_FINISHED; // currentFeedBackStatus = AgvCarManage.CarTaskStatusEnum.TAKE_FINISHED;
FeedBackTaskStatus(currentFeedBackStatus); // FeedBackTaskStatus(currentFeedBackStatus);
} // }
Quaternion targetRotation = RotationByDevice(taskInfo.fromDevice); // Quaternion targetRotation = RotationByDevice(taskInfo.fromDevice);
if (transform.localRotation == targetRotation) // if (transform.localRotation == targetRotation)
{ // {
//校验起点是设备,需要提升货叉到高位 // //校验起点是设备,需要提升货叉到高位
if (!IsShelf(taskInfo.fromLocation)) // if (!IsShelf(taskInfo.fromLocation))
{ // {
if(playable.time <= 1.3) // if(playable.time <= 1.3)
{ // {
playable.Play(); // playable.Play();
} // }
else // else
{ // {
playable.Pause();
}
}
if(playable.state == PlayState.Paused)
{
agent.isStopped = false;
}
}
else
{
transform.localRotation = Quaternion.RotateTowards(transform.localRotation, targetRotation, _speed * 2);
}
}
//取货完成
if (taskInfo.agvTaskStatus == AgvCarManage.CarTaskStatusEnum.TAKE_FINISHED)
{
if (HasGood)
{
//是库位取货方式
if (IsShelf(taskInfo.fromDevice))
{
if (playable.time >= 0.4)
{
OnMinFPS();
}
if (playable.state == PlayState.Paused)
{
agent.updateRotation = true;
currentFeedBackStatus = AgvCarManage.CarTaskStatusEnum.PUTTING;
FeedBackTaskStatus(currentFeedBackStatus);
}
}
else
{
//接驳点取货方式
//需要回退到指定位置做货叉下降动作
Vector3 target = LastPosition(applyTakePosition, taskInfo.fromDevice);
agent.isStopped = false;
//开始代理
StartAgent(target);
Vector3 targetPosition = new Vector3(target.x, transform.position.y, target.z);
//到位后,开始下降货叉
if (Vector3.Distance(transform.position, targetPosition) <= 0.1f)
{
if (playable.time >= 0.6)
{
playable.playableGraph.GetRootPlayable(0).SetSpeed(-1);
playable.Play();
}
else
{
playable.Pause();
agent.updateRotation = true;
currentFeedBackStatus = AgvCarManage.CarTaskStatusEnum.PUTTING;
FeedBackTaskStatus(currentFeedBackStatus);
}
}
else
{
//货叉升到满叉才执行后续动作
if (playable.time < 1.99)
{
playable.Play();
}
}
}
}
else
{
GameObject game = deviceParseService.GameObjectByDevice(taskInfo.fromLocation);
if (game != null)
{
Container container = game.GetComponentInChildren<Container>();
if (container != null)
{
container.isAwke = false;
container.transform.parent = forkCargo.transform;
playable.Play();
}
}
}
return;
}
//放货中
if (taskInfo.agvTaskStatus == AgvCarManage.CarTaskStatusEnum.PUTTING)
{
//未代理开始代理
StartAgent(taskInfo.toLocation);
// 起点旋转位置
if (applyPutPosition.Count > 0)
{
Vector3 applyPutVector = LastPosition(applyPutPosition, taskInfo.toLocation);
//抵达后,申请取货流程
Vector3 targetPosition = new Vector3(applyPutVector.x, transform.position.y, applyPutVector.z);
if (Vector3.Distance(transform.position, targetPosition) <= 0.1f)
{
agent.isStopped = true;
agent.updateRotation = false;
currentFeedBackStatus = AgvCarManage.CarTaskStatusEnum.APPLY_PUT;
FeedBackTaskStatus(currentFeedBackStatus);
}
}
}
//申请放货
if (taskInfo.agvTaskStatus == AgvCarManage.CarTaskStatusEnum.APPLY_PUT && currentFeedBackStatus == AgvCarManage.CarTaskStatusEnum.APPLY_PUT)
{
//抵达终点
if (Vector3.Distance(transform.position, agent.destination) <= 0.1f)
{
currentFeedBackStatus = AgvCarManage.CarTaskStatusEnum.PUT_FINISHED;
}
Quaternion targetRotation = RotationByDevice(taskInfo.toDevice);
if (transform.localRotation == targetRotation)
{
//启用代理
agent.isStopped = false;
//如果是设备将货叉提升完
if(!IsShelf(taskInfo.toLocation))
{
playable.Play();
}
}
else
{
transform.localRotation = Quaternion.RotateTowards(transform.localRotation, targetRotation, _speed * 2);
}
}
if (currentFeedBackStatus == AgvCarManage.CarTaskStatusEnum.PUT_FINISHED)
{
if (HasGood)
{
//校验是库位还是设备
if(IsShelf(taskInfo.toLocation))
{
Debug.LogWarning("放货持续");
if (playable.time > 0)
{
playable.playableGraph.GetRootPlayable(0).SetSpeed(-1);
playable.Play();
}
else
{
//暂停播放
// playable.Pause(); // playable.Pause();
////解绑容器 // }
//Container container = forkCargo.transform.GetComponentInChildren<Container>(); // }
//container.transform.parent = null; // if(playable.state == PlayState.Paused)
OnMaxFPS(); // {
} // agent.isStopped = false;
} // }
else // }
{ // else
if (playable.time > 1.5f) // {
{ // transform.localRotation = Quaternion.RotateTowards(transform.localRotation, targetRotation, _speed * 2);
playable.playableGraph.GetRootPlayable(0).SetSpeed(-1); // }
playable.Play(); // }
} //
else //
{ // //取货完成
OnMaxFPS(); // if (taskInfo.agvTaskStatus == AgvCarManage.CarTaskStatusEnum.TAKE_FINISHED)
} // {
} // if (HasGood)
// {
} // //是库位取货方式
else // if (IsShelf(taskInfo.fromDevice))
{ // {
if(!IsShelf(taskInfo.toLocation)) // if (playable.time >= 0.4)
{ // {
//当后退完成后最终下降完货叉并重置agv状态 // OnMinFPS();
Vector3 position = LastPosition(applyPutPosition, taskInfo.toLocation); // }
Vector3 targetPosition = new Vector3(position.x, transform.position.y, position.z); // if (playable.state == PlayState.Paused)
// {
if (Vector3.Distance(transform.position, targetPosition) <= 0.1f) // agent.updateRotation = true;
{ // currentFeedBackStatus = AgvCarManage.CarTaskStatusEnum.PUTTING;
if(playable.time > 0) // FeedBackTaskStatus(currentFeedBackStatus);
{ // }
playable.Play(); // }
} // else
else // {
{ // //接驳点取货方式
playable.Pause(); // //需要回退到指定位置做货叉下降动作
FeedBackTaskStatus(currentFeedBackStatus); // Vector3 target = LastPosition(applyTakePosition, taskInfo.fromDevice);
Rest(); // agent.isStopped = false;
} // //开始代理
} // StartAgent(target);
} // Vector3 targetPosition = new Vector3(target.x, transform.position.y, target.z);
else // //到位后,开始下降货叉
{ // if (Vector3.Distance(transform.position, targetPosition) <= 0.1f)
Vector3 position = LastPosition(applyPutPosition, taskInfo.toLocation); // {
Vector3 targetPosition = new Vector3(position.x, transform.position.y, position.z); // if (playable.time >= 0.6)
if (Vector3.Distance(transform.position, targetPosition) <= 0.1f) // {
{ // playable.playableGraph.GetRootPlayable(0).SetSpeed(-1);
GameObject game = deviceParseService.GameObjectByDevice(taskInfo.toLocation); // playable.Play();
Container container = containersManage.GetContainerByCode(taskInfo.containerCode); // }
container.transform.parent = game.transform; // else
container.transform.localPosition = new Vector3(0, -0.2472343f, 0.0006999969f); // {
container.Agent.enabled = true; // playable.Pause();
FeedBackTaskStatus(currentFeedBackStatus); // agent.updateRotation = true;
Rest(); // currentFeedBackStatus = AgvCarManage.CarTaskStatusEnum.PUTTING;
} // FeedBackTaskStatus(currentFeedBackStatus);
} // }
} // }
} // else
} // {
// //货叉升到满叉才执行后续动作
// if (playable.time < 1.99)
// {
// playable.Play();
// }
// }
//
// }
//
// }
// else
// {
// GameObject game = deviceParseService.GameObjectByDevice(taskInfo.fromLocation);
// if (game != null)
// {
// Container container = game.GetComponentInChildren<Container>();
//
// if (container != null)
// {
// container.isAwke = false;
// container.transform.parent = forkCargo.transform;
// playable.Play();
// }
// }
// }
// return;
// }
// //放货中
// if (taskInfo.agvTaskStatus == AgvCarManage.CarTaskStatusEnum.PUTTING)
// {
// //未代理开始代理
// StartAgent(taskInfo.toLocation);
//
// // 起点旋转位置
// if (applyPutPosition.Count > 0)
// {
// Vector3 applyPutVector = LastPosition(applyPutPosition, taskInfo.toLocation);
// //抵达后,申请取货流程
// Vector3 targetPosition = new Vector3(applyPutVector.x, transform.position.y, applyPutVector.z);
// if (Vector3.Distance(transform.position, targetPosition) <= 0.1f)
// {
// agent.isStopped = true;
// agent.updateRotation = false;
// currentFeedBackStatus = AgvCarManage.CarTaskStatusEnum.APPLY_PUT;
// FeedBackTaskStatus(currentFeedBackStatus);
// }
//
// }
//
// }
// //申请放货
// if (taskInfo.agvTaskStatus == AgvCarManage.CarTaskStatusEnum.APPLY_PUT && currentFeedBackStatus == AgvCarManage.CarTaskStatusEnum.APPLY_PUT)
// {
// //抵达终点
// if (Vector3.Distance(transform.position, agent.destination) <= 0.1f)
// {
// currentFeedBackStatus = AgvCarManage.CarTaskStatusEnum.PUT_FINISHED;
//
// }
// Quaternion targetRotation = RotationByDevice(taskInfo.toDevice);
// if (transform.localRotation == targetRotation)
// {
// //启用代理
// agent.isStopped = false;
// //如果是设备将货叉提升完
// if(!IsShelf(taskInfo.toLocation))
// {
// playable.Play();
// }
// }
// else
// {
// transform.localRotation = Quaternion.RotateTowards(transform.localRotation, targetRotation, _speed * 2);
// }
// }
//
// if (currentFeedBackStatus == AgvCarManage.CarTaskStatusEnum.PUT_FINISHED)
// {
// if (HasGood)
// {
// //校验是库位还是设备
//
// if(IsShelf(taskInfo.toLocation))
// {
// Debug.LogWarning("放货持续");
// if (playable.time > 0)
// {
// playable.playableGraph.GetRootPlayable(0).SetSpeed(-1);
// playable.Play();
// }
// else
// {
// //暂停播放
// //playable.Pause();
// ////解绑容器
// //Container container = forkCargo.transform.GetComponentInChildren<Container>();
// //container.transform.parent = null;
// OnMaxFPS();
// }
// }
// else
// {
// if (playable.time > 1.5f)
// {
// playable.playableGraph.GetRootPlayable(0).SetSpeed(-1);
// playable.Play();
// }
// else
// {
// OnMaxFPS();
// }
// }
//
// }
// else
// {
// if(!IsShelf(taskInfo.toLocation))
// {
// //当后退完成后最终下降完货叉并重置agv状态
// Vector3 position = LastPosition(applyPutPosition, taskInfo.toLocation);
// Vector3 targetPosition = new Vector3(position.x, transform.position.y, position.z);
//
// if (Vector3.Distance(transform.position, targetPosition) <= 0.1f)
// {
// if(playable.time > 0)
// {
// playable.Play();
// }
// else
// {
// playable.Pause();
// FeedBackTaskStatus(currentFeedBackStatus);
// Rest();
// }
// }
// }
// else
// {
// Vector3 position = LastPosition(applyPutPosition, taskInfo.toLocation);
// Vector3 targetPosition = new Vector3(position.x, transform.position.y, position.z);
// if (Vector3.Distance(transform.position, targetPosition) <= 0.1f)
// {
// GameObject game = deviceParseService.GameObjectByDevice(taskInfo.toLocation);
// Container container = containersManage.GetContainerByCode(taskInfo.containerCode);
// container.transform.parent = game.transform;
// container.transform.localPosition = new Vector3(0, -0.2472343f, 0.0006999969f);
// container.Agent.enabled = true;
// FeedBackTaskStatus(currentFeedBackStatus);
// Rest();
// }
// }
// }
// }
// }
/// <summary> /// <summary>
/// 重置设备状态 /// 重置设备状态
/// </summary> /// </summary>
@ -473,7 +473,7 @@ public class ForkAgvDevice : AbstractDevice, ICar
{ {
if(debugFeedBack) if(debugFeedBack)
{ {
taskInfo.agvTaskStatus = status; // taskInfo.agvTaskStatus = status;
} }
FeedBackEntity feedBackDTO = new FeedBackEntity(); FeedBackEntity feedBackDTO = new FeedBackEntity();
feedBackDTO.feedbackStatus = status.ToString(); feedBackDTO.feedbackStatus = status.ToString();