diff --git a/servo/src/main/java/com/galaxis/rcs/RcsRootController.java b/servo/src/main/java/com/galaxis/rcs/RcsRootController.java index 8262f84..e8389f5 100644 --- a/servo/src/main/java/com/galaxis/rcs/RcsRootController.java +++ b/servo/src/main/java/com/galaxis/rcs/RcsRootController.java @@ -1,12 +1,22 @@ package com.galaxis.rcs; +import com.galaxis.rcs.communication.amrCommunication.MqttService; +import org.eclipse.paho.mqttv5.common.MqttException; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; @RestController public class RcsRootController { + + @Autowired + private MqttService mqttService; + @GetMapping("/ok") - public String ok() { + public String ok() throws MqttException { + mqttService.subscribe("/agv_robot/status"); +// mqttService.publish("rcs/root/ok", "OK"); return "OK"; } + } diff --git a/servo/src/main/java/com/galaxis/rcs/communication/amrCommunication/MqttConfig.java b/servo/src/main/java/com/galaxis/rcs/communication/amrCommunication/MqttConfig.java new file mode 100644 index 0000000..3b2ef9e --- /dev/null +++ b/servo/src/main/java/com/galaxis/rcs/communication/amrCommunication/MqttConfig.java @@ -0,0 +1,43 @@ +package com.galaxis.rcs.communication.amrCommunication; + +import org.eclipse.paho.mqttv5.client.MqttClient; +import org.eclipse.paho.mqttv5.client.MqttConnectionOptions; +import org.eclipse.paho.mqttv5.common.MqttException; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + + +@Configuration +public class MqttConfig { + @Value("${mqtt.broker-url}") + private String brokerUrl; + + @Value("${mqtt.client-id}") + private String clientId; + + @Value("${mqtt.username}") + private String username; + + @Value("${mqtt.password}") + private String password; + + @Bean + public MqttConnectionOptions mqttConnectOptions() { + MqttConnectionOptions options = new MqttConnectionOptions(); + options.setServerURIs(new String[]{brokerUrl}); + options.setAutomaticReconnect(true); // 启用自动重连 + options.setUserName(username); + options.setPassword(password.getBytes()); + return options; + } + + @Bean(destroyMethod = "disconnect") + public MqttClient mqttClient() throws MqttException { + MqttClient client = new MqttClient(brokerUrl, clientId); + client.connect(mqttConnectOptions()); + return client; + } +} + + diff --git a/servo/src/main/java/com/galaxis/rcs/communication/amrCommunication/MqttService.java b/servo/src/main/java/com/galaxis/rcs/communication/amrCommunication/MqttService.java new file mode 100644 index 0000000..c784e3a --- /dev/null +++ b/servo/src/main/java/com/galaxis/rcs/communication/amrCommunication/MqttService.java @@ -0,0 +1,27 @@ +package com.galaxis.rcs.communication.amrCommunication; + +import org.eclipse.paho.mqttv5.client.IMqttMessageListener; +import org.eclipse.paho.mqttv5.client.MqttClient; +import org.eclipse.paho.mqttv5.common.MqttException; +import org.eclipse.paho.mqttv5.common.MqttMessage; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +@Service +public class MqttService implements IMqttMessageListener { + @Autowired + private MqttClient mqttClient; + + public void subscribe(String topic) throws MqttException { + mqttClient.subscribe(topic, 0, this); + } + + public void publish(String topic, String payload) throws MqttException { + mqttClient.publish(topic, new MqttMessage(payload.getBytes())); + } + + @Override + public void messageArrived(String topic, MqttMessage message) throws Exception { + System.out.println("Received message: " + message.toString() + " from topic: " + topic); + } +} diff --git a/servo/src/main/java/com/galaxis/rcs/connector/cl2/Cl2TaskManger.java b/servo/src/main/java/com/galaxis/rcs/connector/cl2/Cl2TaskManger.java new file mode 100644 index 0000000..55a1a7f --- /dev/null +++ b/servo/src/main/java/com/galaxis/rcs/connector/cl2/Cl2TaskManger.java @@ -0,0 +1,4 @@ +package com.galaxis.rcs.connector.cl2; + +public class Cl2TaskManger { +} diff --git a/servo/src/main/java/com/galaxis/rcs/connector/cl2/receiveEntity/AmrMessage.java b/servo/src/main/java/com/galaxis/rcs/connector/cl2/receiveEntity/AmrMessage.java new file mode 100644 index 0000000..ab314d2 --- /dev/null +++ b/servo/src/main/java/com/galaxis/rcs/connector/cl2/receiveEntity/AmrMessage.java @@ -0,0 +1,16 @@ +package com.galaxis.rcs.connector.cl2.receiveEntity; + +// RCS 接收 AMR的消息 +public class AmrMessage { + // 作业序号 UInt32 从1开始,0作为超级序号使用,不参与序号规则判断 + public long SeqNo; + // AMR编号 UInt16 + public int VehicleId; + // 消息创建时间 UInt64 毫秒级时间戳 + public long CreateTime; + // 消息创建时主机的开机时长 UInt64 毫秒级时间戳 + public long CreateMonoTime; + // 发送消息的时间 UInt64 毫秒级时间戳 + public long SendTime; + +} diff --git a/servo/src/main/java/com/galaxis/rcs/connector/cl2/sendEntity/Cmd10010.java b/servo/src/main/java/com/galaxis/rcs/connector/cl2/sendEntity/Cmd10010.java index 582c255..065518a 100644 --- a/servo/src/main/java/com/galaxis/rcs/connector/cl2/sendEntity/Cmd10010.java +++ b/servo/src/main/java/com/galaxis/rcs/connector/cl2/sendEntity/Cmd10010.java @@ -47,6 +47,30 @@ public class Cmd10010 { public byte Roll1Motion; // 滚筒2 运动操作 对于左右滚动的双滚筒机型,此滚筒为靠近车尾的滚筒。 对于前后滚动的双滚筒机型,此滚筒为车身右侧的滚筒。 对于单滚筒机型,此参数无意义。 UInt8 0:不控制(无动作) 1:从货架上取货 2:将货物放到货架上 3:仅调整托盘高度(不进行取放货操作) 4:调整车身货物(仅供调试,RCS勿发送此命令) 5:仅调整载货台到取货高度,但是不动作 6:仅调整载货台到放货高度,但是不动作 public byte Roll2Motion; + // 与滚筒1对接的站台朝向 UInt8 0: X轴正向 1: Y轴正向 2: X轴负向 3: Y轴负向 + public byte Roll1StationDirection; + // 与滚筒2对接的站台朝向 对于单滚筒机型,此参数无意义。 UInt8 0: X轴正向 1: Y轴正向 2: X轴负向 3: Y轴负向 + public byte Roll2StationDirection; + // 滚筒1目标货物长度 UInt16 单位:mm + public int Roll1GoodsLength; + // 滚筒2目标货物长度 对于单滚筒机型,此参数无意义。UInt16 单位:mm + public int Roll2GoodsLength; + // 滚筒1目标货物数量 UInt16 1~N + public int Roll1GoodsQuantity; + // 滚筒2目标货物数量 对于单滚筒机型,此参数无意义。 UInt16 1~N + public int Roll2GoodsQuantity; + // 多滚筒运动模式 UInt8[6] 数组形式,0:不控制(无动作) 1:从货架上取货 2:将货物放到货架上 3:仅调整托盘高度(不进行取放货操作) 4:调整车身货物(仅供调试,RCS勿发送此命令) 5:仅调整载货台到取货高度,但是不动作 6:仅调整载货台到放货高度,但是不动作 + public byte[] MRollMotion; + // 多滚筒对接的站台朝向 UInt8[6] 0: X轴正向 1: Y轴正向 2: X轴负向 3: Y轴负向 + public byte[] MRollStationDirection; + // 多滚筒目标货物数量 UInt16[6] 数组形式,意义同"RollGoodsQuantity" + public int[] MRollGoodsQuantity; + // 是否仅执行任务的准备部分 bool 默认为false,仅执行该动作的准备部分,如仅进行导航,调整托盘高度等,但不进行取放货操作 + public boolean Preparing; + // 货架标识 uint32 车根据货架类型查询尺寸进行避障 + public long RackTypeId; + // 终点自适应 bool 默认为false,为true时,会根据任务和对应器件的位置,自动调整停止点 + public boolean EndSelfAdaption; static class Link { //该段目标点X坐标 UInt16 逻辑单位,乘以一定系数才是物理距离 diff --git a/servo/src/main/resources/application-dev.yml b/servo/src/main/resources/application-dev.yml index e763216..8f4dc6b 100644 --- a/servo/src/main/resources/application-dev.yml +++ b/servo/src/main/resources/application-dev.yml @@ -37,6 +37,11 @@ redis: database: 0 password: 'yxt123456' +mqtt: + broker-url: 'tcp://10.10.8.31:1883' + client-id: 'yvan-rcs-dev' + username: 'admin' + password: 'admin' web: resources: enable: true diff --git a/servo/src/main/resources/application.yml b/servo/src/main/resources/application.yml index 5d319da..ad026f2 100644 --- a/servo/src/main/resources/application.yml +++ b/servo/src/main/resources/application.yml @@ -141,6 +141,7 @@ web: read-only: false security: ignore-paths: + - '/ok' - '/favicon.ico' - '/dist/**' - '/static/**' @@ -160,7 +161,7 @@ web: - '/**/*.woff2' - '/**/.git' - '/ok' - ignore-auth-paths: [ ] + ignore-auth-paths: ['/ok'] ignore-auth-failed-paths: [ ] current-user-path: '/api/current_user' login: