package com.zy.core.model.protocol;
|
|
import com.alibaba.fastjson.JSON;
|
import com.core.common.SpringUtils;
|
import com.zy.asrs.entity.BasShuttle;
|
import com.zy.asrs.entity.BasShuttleErr;
|
import com.zy.asrs.service.BasShuttleErrService;
|
import com.zy.asrs.service.BasShuttleService;
|
import com.zy.asrs.utils.Utils;
|
import com.zy.common.utils.NavigatePositionConvert;
|
import com.zy.core.News;
|
import com.zy.core.enums.ShuttleProtocolStatusType;
|
import com.zy.core.enums.ShuttleStatusType;
|
import com.zy.core.model.command.ShuttleAssignCommand;
|
import lombok.Data;
|
import lombok.extern.slf4j.Slf4j;
|
|
/**
|
* 牛眼四向穿梭车
|
*/
|
@Slf4j
|
@Data
|
public class NyShuttleProtocol {
|
|
/**
|
* 四向穿梭车号
|
*/
|
private Short shuttleNo;
|
|
/**
|
* 任务号
|
*/
|
private Integer taskNo = 0;
|
|
/**
|
* 任务指令
|
*/
|
private ShuttleAssignCommand assignCommand;
|
|
/**
|
* 当前小车状态(内部自我维护)
|
*/
|
private Integer protocolStatus;
|
|
/**
|
* 当前小车状态枚举
|
*/
|
private ShuttleProtocolStatusType protocolStatusType;
|
|
/**
|
* 源库位
|
*/
|
private String sourceLocNo;
|
|
/**
|
* 目标库位
|
*/
|
private String locNo;
|
|
/**
|
* 小车当前库位号
|
*/
|
private String currentLocNo;
|
|
/**
|
* 作业标记
|
*/
|
private Boolean pakMk = false;
|
|
/**
|
* 手动状态/自动状态
|
* 0/1
|
*/
|
private Integer workingMode;
|
|
/**
|
* 0:运行中1:空闲。(车自动模式下,在
|
* 静止状态下,且没有其他任务且满足发送
|
* 新任务的状态)
|
*/
|
private Integer free;
|
|
/**
|
* 当前速度,单位mm/s
|
*/
|
private Integer speed;
|
|
/**
|
* 负载状态无/有负载
|
* 0/1
|
*/
|
private Integer loadState;
|
|
/**
|
* 管制状态不在管制下/被管制中
|
* 0/1
|
*/
|
private Integer suspendState;
|
|
/**
|
* 顶升位置0-未知1-下降位置2-托举位置
|
*/
|
private Integer liftPosition;
|
|
/**
|
* 运行方向0-未知1-X向2-Y向
|
*/
|
private Integer runDir;
|
|
/**
|
* 运行方向0-未知(静止)1-X+向2-X向3-Y+向4-Y-向
|
*/
|
private Integer runDir2;
|
|
/**
|
* 充电状态0不在充电状态1充电中
|
*/
|
private Integer chargState;
|
|
/**
|
* 电池电量0%-100%
|
*/
|
private Integer powerPercent;
|
|
/**
|
* 最高电芯电压(mV)
|
*/
|
private Integer maxCellVoltage;
|
|
/**
|
* 最低电芯电压(mV),低于2900mv需要立即充电
|
*/
|
private Integer minCellVoltage;
|
|
/**
|
* 电池电压(mV)
|
*/
|
private Integer voltage;
|
|
/**
|
* 充放电循环次数
|
*/
|
private Integer chargeCycleTimes;
|
|
/**
|
* 剩余电量/10(A)
|
*/
|
private Integer surplusQuantity;
|
|
/**
|
* 总电量/10(A)
|
*/
|
private Integer countQuantity;
|
|
/**
|
* 实际库位xyz
|
*/
|
private NyShuttlePointClass point;
|
|
/**
|
* 实际坐标xyz单位mm
|
*/
|
private NyShuttlePointClass coord;
|
|
/**
|
* WCS库位xyz
|
*/
|
private NyShuttlePointClass wcsPoint;
|
|
/**
|
* 任务目的库位xyztaskId(正在动作的任务ID)lastTaskId(最后一个完成的任务ID)recentTaskId(收到的最后一个任务ID)
|
*/
|
private TaskClass task;
|
|
/**
|
* 任务状态0无任务1有任务
|
*/
|
private Integer taskState;
|
|
/**
|
* 故障状态0无故障1故障中
|
*/
|
private Integer errState;
|
|
/**
|
* 故障码
|
*/
|
private Integer errCode;
|
|
/**
|
* mileage总里程数(米),liftNumber顶升总数dropNumber下降总数reversingX换X总数reversingY换Y总数
|
*/
|
private StatusSumClass statusSum;
|
|
/**
|
* 非自动状态时间计时(S)
|
*/
|
private Integer errTime;
|
|
/**
|
* 独占令牌
|
* 未被任务占据,令牌为0
|
* 被任务占据,将任务号赋值给令牌
|
*/
|
private Integer token = 0;
|
|
/**
|
* 跑库状态
|
*/
|
private Boolean moveLoc = false;
|
|
/**
|
* 跑库类型,0:跑轨道,1:跑库位
|
*/
|
private Integer moveType = 0;
|
|
/**
|
* 跑库X起点
|
*/
|
private Integer xStart = 0;
|
|
/**
|
* 跑库X终点
|
*/
|
private Integer xTarget = 0;
|
|
/**
|
* 跑库X当前点位
|
*/
|
private Integer xCurrent = 0;
|
|
/**
|
* 跑库Y起点
|
*/
|
private Integer yStart = 0;
|
|
/**
|
* 跑库Y终点
|
*/
|
private Integer yTarget = 0;
|
|
/**
|
* 跑库Y当前点位
|
*/
|
private Integer yCurrent = 0;
|
|
//总里程数
|
@Data
|
public static class StatusSumClass {
|
private Integer mileage;//总里程数(米)
|
private Integer liftNumber;//顶升总数
|
private Integer dropNumber;//下降总数
|
private Integer reversingX;//换X总数
|
private Integer reversingY;//换Y总数
|
}
|
|
@Data
|
public static class NyShuttlePointClass{
|
private Integer x;
|
private Integer y;
|
private Integer z;
|
}
|
|
//任务目的库位
|
@Data
|
public static class TaskClass extends NyShuttlePointClass{
|
private Integer taskState;
|
private Integer taskId;//当前任务ID
|
private Integer lastTaskId;//上一次完成的任务ID
|
private Integer recentTaskId;//最后一次接收到的任务ID
|
}
|
|
public String getFree$() {
|
if (this.getFree() == null) {
|
return "";
|
}
|
return this.getFree() == 0 ? "运行中" : "空闲";
|
}
|
|
public String getWorkingMode$() {
|
if (this.getWorkingMode() == null) {
|
return "";
|
}
|
return this.getWorkingMode() == 0 ? "手动" : "自动";
|
}
|
|
public String getLoadState$() {
|
if (this.getLoadState() == null) {
|
return "";
|
}
|
return this.getLoadState() == 1 ? "有" : "无";
|
}
|
|
public String getSuspendState$() {
|
if (this.getSuspendState() == null) {
|
return "";
|
}
|
return this.getSuspendState() == 1 ? "是" : "否";
|
}
|
|
public String getPowerPercent$() {
|
if (this.getPowerPercent() == null) {
|
return "";
|
}
|
return this.getPowerPercent() + "%";
|
}
|
|
public String getLiftPosition$() {
|
if (this.getLiftPosition() == null) {
|
return "";
|
}
|
|
switch (this.getLiftPosition()) {
|
case 0:
|
return "未知";
|
case 1:
|
return "下降位置";
|
case 2:
|
return "托举位置";
|
default:
|
return this.getLiftPosition().toString();
|
}
|
}
|
|
public String getChargState$() {
|
if (this.getChargState() == null) {
|
return "";
|
}
|
return this.getChargState() == 1 ? "充电中" : "未充电";
|
}
|
|
public String getMaxCellVoltage$() {
|
if (this.getMaxCellVoltage() == null) {
|
return "";
|
}
|
return this.getMaxCellVoltage() + "mV";
|
}
|
|
public String getMinCellVoltage$() {
|
if (this.getMinCellVoltage() == null) {
|
return "";
|
}
|
return this.getMinCellVoltage() + "mV";
|
}
|
|
public String getVoltage$() {
|
if (this.getVoltage() == null) {
|
return "";
|
}
|
return this.getVoltage() + "mV";
|
}
|
|
public String getTaskState$() {
|
if (this.getTaskState() == null) {
|
return "";
|
}
|
return this.getTaskState() == 1 ? "有任务" : "无任务";
|
}
|
|
public String getErrState$() {
|
if (this.getErrState() == null) {
|
return "";
|
}
|
return this.getErrState() == 1 ? "故障中" : "无故障";
|
}
|
|
public String getRunDir$() {
|
if (this.getRunDir() == null) {
|
return "";
|
}
|
|
switch (this.getRunDir()) {
|
case 0:
|
return "未知";
|
case 1:
|
return "X向";
|
case 2:
|
return "Y向";
|
default:
|
return "未知";
|
}
|
}
|
|
public String getRunDir2$() {
|
if (this.getRunDir2() == null) {
|
return "";
|
}
|
|
switch (this.getRunDir2()) {
|
case 0:
|
return "未知";
|
case 1:
|
return "X+向";
|
case 2:
|
return "X-向";
|
case 3:
|
return "Y+向";
|
case 4:
|
return "Y-向";
|
default:
|
return "未知";
|
}
|
}
|
|
/**
|
* 设置小车状态
|
*/
|
public void setProtocolStatus(Integer status) {
|
this.protocolStatus = status;
|
this.protocolStatusType = ShuttleProtocolStatusType.get(status);
|
}
|
|
/**
|
* 设置小车状态
|
*/
|
public void setProtocolStatus(ShuttleProtocolStatusType status) {
|
this.protocolStatus = status.id;
|
this.protocolStatusType = status;
|
}
|
|
public String getProtocolStatus$() {
|
if (this.getProtocolStatus() == null) {
|
return "";
|
}
|
return ShuttleProtocolStatusType.get(this.getProtocolStatus()).desc;
|
}
|
|
public String getPakMk$() {
|
if (this.getPakMk() == null) {
|
return "";
|
}
|
return this.getPakMk() ? "Y" : "N";
|
}
|
|
public String getPoint$() {
|
if (this.getPoint() == null) {
|
return "";
|
}
|
return NavigatePositionConvert.nyXyzToLocNo(this.getPoint().getX(), this.getPoint().getY(), this.getPoint().getZ());
|
}
|
|
public String getPoint$$() {
|
if (this.getPoint() == null) {
|
return "";
|
}
|
return JSON.toJSONString(this.getPoint());
|
}
|
|
public String getCoord$() {
|
if (this.getCoord() == null) {
|
return "";
|
}
|
return JSON.toJSONString(this.getCoord());
|
}
|
|
public String getErrCode$() {
|
if (this.getErrCode() == null) {
|
return "";
|
}
|
BasShuttleErrService basShuttleErrService = SpringUtils.getBean(BasShuttleErrService.class);
|
BasShuttleErr basShuttleErr = basShuttleErrService.selectById(this.getErrCode());
|
if (basShuttleErr == null) {
|
return this.getErrCode().toString();
|
}
|
return basShuttleErr.getErrName();
|
}
|
|
public void setPoint(NyShuttlePointClass point) {
|
String locNo = NavigatePositionConvert.nyXyzToLocNo(point.getX(), point.getY(), point.getZ());
|
this.point = point;
|
this.currentLocNo = locNo;
|
NyShuttlePointClass wcsPoint = new NyShuttlePointClass();
|
wcsPoint.setX(Utils.getRow(locNo));
|
wcsPoint.setY(Utils.getBay(locNo));
|
wcsPoint.setZ(Utils.getLev(locNo));
|
this.wcsPoint = wcsPoint;
|
}
|
|
// 是否处于空闲待命状态
|
public Boolean isIdle() {
|
boolean res = this.free == ShuttleStatusType.IDLE.id
|
&& !this.pakMk
|
&& this.errState == 0
|
&& this.taskNo == 0
|
&& this.protocolStatus == ShuttleProtocolStatusType.IDLE.id
|
;
|
return res;
|
// if (!res) {
|
// return res;
|
// } else {
|
// // 电量
|
// try {
|
// Integer chargeLine = SpringUtils.getBean(BasShuttleService.class).selectById(this.shuttleNo).getChargeLine();
|
// if (chargeLine == null) {
|
// return false;
|
// }
|
// return this.getPowerPercent() >= chargeLine;
|
// } catch (Exception e) {
|
// News.error("fail", e);
|
// return false;
|
// }
|
// }
|
}
|
|
// 是否处于空闲待命状态,传入的taskNo和当前taskNo相同时允许放行
|
public Boolean isIdle(int taskNo) {
|
boolean res = this.free == ShuttleStatusType.IDLE.id
|
&& !this.pakMk
|
&& this.errState == 0
|
&& (this.taskNo == 0 || this.taskNo == taskNo)
|
&& this.protocolStatus.intValue() == ShuttleProtocolStatusType.IDLE.id
|
;
|
return res;
|
// if (!res) {
|
// return res;
|
// } else {
|
// // 电量
|
// try {
|
// Integer chargeLine = SpringUtils.getBean(BasShuttleService.class).selectById(this.shuttleNo).getChargeLine();
|
// return this.getPowerPercent() > chargeLine;
|
// } catch (Exception e) {
|
// News.error("fail", e);
|
// return false;
|
// }
|
// }
|
}
|
|
// 是否处于空闲待命状态
|
public Boolean isIdleNoCharge() {
|
boolean res = this.free == ShuttleStatusType.IDLE.id
|
&& !this.pakMk
|
&& this.errState == 0
|
&& this.taskNo == 0
|
&& this.protocolStatus == ShuttleProtocolStatusType.IDLE.id
|
;
|
return res;
|
}
|
|
// 是否处于空闲待命状态
|
public Boolean isIdleNoCharge(int taskNo) {
|
boolean res = this.free == ShuttleStatusType.IDLE.id
|
&& !this.pakMk
|
&& this.errState == 0
|
&& (this.taskNo == 0 || this.taskNo == taskNo)
|
&& this.protocolStatus == ShuttleProtocolStatusType.IDLE.id
|
;
|
return res;
|
}
|
|
// 是否满足充电状态
|
public Boolean isRequireCharge() {
|
if (this.free == null || this.pakMk == null || this.errState == null || this.taskNo == null) {
|
return false;
|
}
|
|
boolean res = this.free == ShuttleStatusType.IDLE.id
|
&& !this.pakMk
|
&& this.errState == 0
|
&& this.taskNo == 0
|
&& this.protocolStatusType.id == ShuttleProtocolStatusType.IDLE.id
|
;
|
if (!res) {
|
return res;
|
} else {
|
// 电量小于阈值或最低电芯电压小于2900mv,需要进行充电
|
try {
|
BasShuttleService shuttleService = SpringUtils.getBean(BasShuttleService.class);
|
if (shuttleService == null) {
|
return false;
|
|
}
|
BasShuttle basShuttle = shuttleService.selectById(this.shuttleNo);
|
if (basShuttle == null) {
|
return false;
|
}
|
Integer chargeLine = basShuttle.getChargeLine();
|
if (chargeLine == null) {
|
return false;
|
}
|
return this.getPowerPercent() < chargeLine;
|
} catch (Exception e) {
|
News.error("fail", e);
|
return false;
|
}
|
}
|
}
|
|
public void setShuttleNo(Short shuttleNo) {
|
if (shuttleNo != 0) {
|
this.shuttleNo = shuttleNo;
|
}
|
}
|
}
|