Commit 4198ca5c authored by wanghao's avatar wanghao

1 机械臂 可以 实时设置 有指令时是否执行的操作。

2 下料 时 柜子断电 导致 指令不执行 调整,把 断电的的柜子的 指令 设置成 断电失败的状态,等柜子修好后继续。
parent 81db12e6
......@@ -138,6 +138,27 @@ public class RobotArmCommandController extends BaseController
return toAjax(robotArmCommandService.updateInstructionExecutionPriority(priority));
}
/**
* 控制机械臂
* @param action
* @return
*/
@GetMapping("/updateAnimationState/{action}")
public AjaxResult updateAnimationState(@PathVariable("action") String action) {
return toAjax(robotArmCommandService.updateAnimationState(action));
}
/**
* 短电已修复
* @param robotArmCommandId r
* @return r
*/
@GetMapping("/powerFailureResolved/{robotArmCommandId}")
public AjaxResult powerFailureResolved(@PathVariable("robotArmCommandId") Long robotArmCommandId) {
return robotArmCommandService.powerFailureResolved(robotArmCommandId);
}
/**
* 删除机械臂指令
*/
......
......@@ -8,7 +8,7 @@ spring:
master:
url: jdbc:mysql://localhost:3306/zh-mes-device-db?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&allowMultiQueries=true
username: root
password: zh@123456
password: Zh@123456
# 从库数据源
slave:
# 从数据源开关/默认关闭
......@@ -102,4 +102,4 @@ robot:
arm:
udp:
ip: 127.0.0.1
port: 6000
\ No newline at end of file
port: 6000
......@@ -25,8 +25,8 @@ spring:
messages:
# 国际化资源文件路径
basename: i18n/messages
profiles:
active: test
profiles:
active: dev
# 文件上传
servlet:
multipart:
......@@ -48,7 +48,7 @@ token:
secret: abcdefghijklmnopqrstuvwxyz
# 令牌有效期(默认30分钟)
expireTime: 3000000
# MyBatis配置
mybatis:
# 搜索指定包别名
......@@ -59,11 +59,11 @@ mybatis:
configLocation: classpath:mybatis/mybatis-config.xml
# PageHelper分页插件
pagehelper:
pagehelper:
helperDialect: mysql
reasonable: true
supportMethodsArguments: true
params: count=countSql
params: count=countSql
# Swagger配置
swagger:
......@@ -73,7 +73,7 @@ swagger:
pathMapping: /dev-api
# 防止XSS攻击
xss:
xss:
# 过滤开关
enabled: true
# 排除链接(多个用逗号分隔)
......
......@@ -36,7 +36,7 @@ public class RobotArmCommand extends BaseEntity
private String type;
/** 状态:0-待执行;1-执行中;2-执行结束(上料就是绑定托盘,下料就是解绑托盘) */
@Excel(name = "状态:0-待分配位置,1-待执行;2-执行中;3-未上电;4-执行结束(上料就是绑定托盘,下料就是解绑托盘)")
@Excel(name = "状态:0-待分配位置,1-待执行;2-执行中;3-未上电;4-执行结束(上料就是绑定托盘,下料就是解绑托盘): 5-断电失败")
private String status;
/** 指令开始执行时间 */
......
......@@ -43,6 +43,8 @@ public interface RobotArmCommandMapper
public List<RobotArmCommand> selectIsRunningCommandByTrayCode(String trayCode);
public void updateStatusPowerOffFailed(String storeyCode);
/**
* 新增机械臂指令
*
......
......@@ -241,7 +241,9 @@ public class NettyUdpServerHandler extends SimpleChannelInboundHandler<DatagramP
// 完成指令
robotArmCommandService.completeCommand(commandIdToComplete);
log.info("指令完成: {}", commandIdToComplete);
} catch (Exception e) {
log.error("指令完成失败: {}", commandIdToComplete, e);
} finally {
// 清空当前指令
currentCommandId = null;
......@@ -252,9 +254,6 @@ public class NettyUdpServerHandler extends SimpleChannelInboundHandler<DatagramP
synchronized (this) {
handleFullyIdleState();
}
} catch (Exception e) {
log.error("指令完成失败: {}", commandIdToComplete, e);
commandState.set(CommandState.ERROR);
}
}
}
......
......@@ -69,6 +69,10 @@ public interface IRobotArmCommandService
public int updateInstructionExecutionPriority(String priority);
public int updateAnimationState(String action);
public AjaxResult powerFailureResolved(Long robotArmCommandId);
/**
* 批量删除机械臂指令
*
......
......@@ -105,52 +105,62 @@ public class RobotArmCommandServiceImpl implements IRobotArmCommandService
if (cacheObject != null) {
priority = (String) cacheObject;
}
// 合并查询:同时获取上料、下料各1条待执行指令
List<RobotArmCommand> pendingCommands = robotArmCommandMapper.selectPendingLoadUnloadCommands();
String feedConveyorIpAndPort = iConveyorBeltIpMaintainService.selectConfigByKey(Constants.FEED_CONVEYOR_IP_AND_PORT);
String feedIp ;
int feedPort ;
String outLetBeltIpAndPort = iConveyorBeltIpMaintainService.selectConfigByKey(Constants.OUT_LET_BELT_IP_AND_PORT);
String outLetBeltIp;
int outLetBeltPort;
// 区分上料、下料指令(根据f_type)
RobotArmCommand loadingCommand = null;
RobotArmCommand unloadingCommand = null;
for (RobotArmCommand command : pendingCommands) {
if ("0".equals(command.getType())) { // 上料指令(type=0)
loadingCommand = command;
} else if ("1".equals(command.getType())) { // 下料指令(type=1)
unloadingCommand = command;
}
Object cacheObject1 = redisCache.getCacheObject("sys_config:robotAction");
String action = "start";
if (cacheObject1 != null) {
action = (String) cacheObject1;
}
if(StringUtils.isNotBlank(feedConveyorIpAndPort) && StringUtils.isNotBlank(outLetBeltIpAndPort)) {
String[] splitFeed = feedConveyorIpAndPort.split(":");
feedIp = splitFeed[0];
feedPort = Integer.parseInt(splitFeed[1]);
if("start".equals(action)) {
// 合并查询:同时获取上料、下料各1条待执行指令
List<RobotArmCommand> pendingCommands = robotArmCommandMapper.selectPendingLoadUnloadCommands();
String feedConveyorIpAndPort = iConveyorBeltIpMaintainService.selectConfigByKey(Constants.FEED_CONVEYOR_IP_AND_PORT);
String feedIp ;
int feedPort ;
String outLetBeltIpAndPort = iConveyorBeltIpMaintainService.selectConfigByKey(Constants.OUT_LET_BELT_IP_AND_PORT);
String outLetBeltIp;
int outLetBeltPort;
// 区分上料、下料指令(根据f_type)
RobotArmCommand loadingCommand = null;
RobotArmCommand unloadingCommand = null;
for (RobotArmCommand command : pendingCommands) {
if ("0".equals(command.getType())) { // 上料指令(type=0)
loadingCommand = command;
} else if ("1".equals(command.getType())) { // 下料指令(type=1)
unloadingCommand = command;
}
}
if(StringUtils.isNotBlank(feedConveyorIpAndPort) && StringUtils.isNotBlank(outLetBeltIpAndPort)) {
String[] splitOut = outLetBeltIpAndPort.split(":");
outLetBeltIp = splitOut[0];
outLetBeltPort = Integer.parseInt(splitOut[1]);
String[] splitFeed = feedConveyorIpAndPort.split(":");
feedIp = splitFeed[0];
feedPort = Integer.parseInt(splitFeed[1]);
if((loadingCommand != null && "loading".equals(priority)) ||
(unloadingCommand == null && loadingCommand != null && "unloading".equals(priority))) {
// 传送带检测先去掉
boolean[] roboticArmEntryConveyorData = Modbus4jUtils.getRoboticArmExitConveyorData(feedIp,feedPort);
String[] splitOut = outLetBeltIpAndPort.split(":");
outLetBeltIp = splitOut[0];
outLetBeltPort = Integer.parseInt(splitOut[1]);
log.info("机械臂入口 conveyor 0状态: " + roboticArmEntryConveyorData[0]);
log.info("机械臂入口 conveyor 1状态: " + roboticArmEntryConveyorData[1]);
if(roboticArmEntryConveyorData[1]) {
sendCommand(loadingCommand, "LOAD");
}
} else if(unloadingCommand != null) {
boolean[] roboticArmExitConveyorData = Modbus4jUtils.getRoboticArmExitConveyorData(outLetBeltIp,outLetBeltPort);
log.info("机械臂出口 conveyor 0状态: " + roboticArmExitConveyorData[0]);
log.info("机械臂出口 conveyor 1状态: " + roboticArmExitConveyorData[1]);
if(!roboticArmExitConveyorData[0]) {
log.info("开始处理下料指令: {}", unloadingCommand);
sendCommand(unloadingCommand, "UNLOAD");
if((loadingCommand != null && "loading".equals(priority)) ||
(unloadingCommand == null && loadingCommand != null && "unloading".equals(priority))) {
// 传送带检测先去掉
boolean[] roboticArmEntryConveyorData = Modbus4jUtils.getRoboticArmExitConveyorData(feedIp,feedPort);
log.info("机械臂入口 conveyor 0状态: " + roboticArmEntryConveyorData[0]);
log.info("机械臂入口 conveyor 1状态: " + roboticArmEntryConveyorData[1]);
if(roboticArmEntryConveyorData[1]) {
sendCommand(loadingCommand, "LOAD");
}
} else if(unloadingCommand != null) {
boolean[] roboticArmExitConveyorData = Modbus4jUtils.getRoboticArmExitConveyorData(outLetBeltIp,outLetBeltPort);
log.info("机械臂出口 conveyor 0状态: " + roboticArmExitConveyorData[0]);
log.info("机械臂出口 conveyor 1状态: " + roboticArmExitConveyorData[1]);
if(!roboticArmExitConveyorData[0]) {
log.info("开始处理下料指令: {}", unloadingCommand);
sendCommand(unloadingCommand, "UNLOAD");
}
}
}
}
......@@ -659,6 +669,41 @@ public class RobotArmCommandServiceImpl implements IRobotArmCommandService
return 1;
}
/**
* 修改动画状态
*
* @param action 动作
* @return 结果
*/
@Override
public int updateAnimationState(String action) {
redisCache.setCacheObject("sys_config:robotAction", action);
return 1;
}
/**
* 恢复电源故障
*
* @param robotArmCommandId r
* @return r
*/
@Override
public AjaxResult powerFailureResolved(Long robotArmCommandId) {
if(robotArmCommandId == null) {
return AjaxResult.error("参数错误");
}
RobotArmCommand robotArmCommand = new RobotArmCommand();
robotArmCommand.setRobotArmCommandId(robotArmCommandId);
robotArmCommand.setStatus("1");
robotArmCommandMapper.updateRobotArmCommand(robotArmCommand);
notifyCommandsUpdate();
return AjaxResult.success();
}
/**
* 批量删除机械臂指令
*
......
......@@ -9,13 +9,12 @@ import com.zehong.system.domain.SysConfig;
import com.zehong.system.domain.TEquipmentAlarmData;
import com.zehong.system.domain.TStoreyInfo;
import com.zehong.system.domain.TTrayInfo;
import com.zehong.system.mapper.RobotArmCommandMapper;
import com.zehong.system.mapper.TStoreyInfoMapper;
import com.zehong.system.mapper.TTrayInfoMapper;
import com.zehong.system.modbus.util.Modbus4jUtils;
import com.zehong.system.service.ISysConfigService;
import com.zehong.system.service.ITEquipmentAlarmDataService;
import com.zehong.system.service.ITStoreyInfoService;
import com.zehong.system.service.ITTrayInfoService;
import com.zehong.system.service.*;
import com.zehong.system.service.websocket.RobotArmWebSocketHandler;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -54,6 +53,11 @@ public class AllCommandHandler {
@Autowired
private ISysConfigService configService;
@Resource
private RobotArmCommandMapper robotArmCommandMapper;
@Resource
private RobotArmWebSocketHandler robotArmWebSocketHandler;
// 使用常量定义索引,避免魔法数字
private static final int AGING_STAGE_INDEX = 3;
private static final int DEFAULT_HOURS = 72;
......@@ -140,8 +144,8 @@ public class AllCommandHandler {
@Async // 异步执行
@EventListener(PowerOffCommandEvent.class)
public void handlePowerOffCommand(PowerOffCommandEvent event) {
String storeyCode = event.getDeviceCode() + "-" + event.getLayer();
try {
String storeyCode = event.getDeviceCode() + "-" + event.getLayer();
String ip = event.getIp();
int port = event.getPort();
int registerOffset = event.getRegisterOffset();
......@@ -169,6 +173,11 @@ public class AllCommandHandler {
} catch (ModbusInitException | ModbusTransportException e) {
log.error("断电指令执行失败 - 设备:{} 层:{}", event.getDeviceCode(), event.getLayer(), e);
//把这个指令状态 改成 断电失败,不影响下面的指令执行
robotArmCommandMapper.updateStatusPowerOffFailed(storeyCode);
// 通过WebSocket广播更新
robotArmWebSocketHandler.broadcastCommandUpdate();
// 记录异常
TEquipmentAlarmData alarmData = new TEquipmentAlarmData();
alarmData.setfAlarmType("03"); // 老化层
......
......@@ -37,6 +37,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<include refid="selectRobotArmCommandVo"/>
where f_tray_code = #{trayCode} and f_status != '4'
</select>
<update id="updateStatusPowerOffFailed" parameterType="string">
update t_robot_arm_command
set f_status = '5'
where f_storey_code = #{storeyCode} and f_status = '2'
</update>
<select id="selectRobotArmCommandList" parameterType="RobotArmCommand" resultMap="RobotArmCommandResult">
<include refid="selectRobotArmCommandVo"/>
......
......@@ -112,6 +112,14 @@ export function delCommand(robotArmCommandId) {
})
}
export function powerFailureResolved(robotArmCommandId) {
return request({
url: '/robotArm/command/powerFailureResolved/' + robotArmCommandId,
method: 'get'
})
}
// 导出机械臂指令
export function exportCommand(query) {
return request({
......@@ -120,3 +128,10 @@ export function exportCommand(query) {
params: query
})
}
export function updateAnimationState(action) {
return request({
url: '/robotArm/command/updateAnimationState/' + action,
method: 'get'
})
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment