Commit 4198ca5c authored by wanghao's avatar wanghao

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

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