From 9fa96f85ce646aad115434fe7aa16049a4ac8637 Mon Sep 17 00:00:00 2001 From: yuliang <398780299@qq.com> Date: Sun, 22 Jun 2025 20:20:40 +0800 Subject: [PATCH] =?UTF-8?q?cl2=20=E6=8E=A5=E5=85=A5amr=E6=8C=87=E4=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/cl2/Cl23dObject.ts | 53 ++++++++++++++++++------------------------ 1 file changed, 23 insertions(+), 30 deletions(-) diff --git a/src/modules/cl2/Cl23dObject.ts b/src/modules/cl2/Cl23dObject.ts index c438521..f123577 100644 --- a/src/modules/cl2/Cl23dObject.ts +++ b/src/modules/cl2/Cl23dObject.ts @@ -5,6 +5,7 @@ import {mergeGeometries} from 'three/addons/utils/BufferGeometryUtils.js' import gsap from "gsap"; import mqtt from 'mqtt'; import {Euler} from "three/src/math/Euler"; +import Cl2Entity from "@/modules/cl2/Cl2Entity"; export interface Cl2Task { // 0:运输 1:接货 2:卸货 3:充电 4:提升移栽取货或卸货 5:滚筒取货或卸货(双向作业) 135:旋转货架 136:旋转车身 @@ -355,28 +356,31 @@ export default class Cl23dObject extends THREE.Object3D { groupPillar.add(ptrForkMesh) this.add(groupPillar) - try { - // 安全连接配置 - const client = mqtt.connect('mqtt://127.0.0.1:9001', { - path: '/mqtt', - clientId: 'virtual-' + item.id, - clean: true, - connectTimeout: 10000, - username: 'user', - password: 'user', - unixSocket: true, - keepalive: 60, - }); + // try { + // // 安全连接配置 + // const client = mqtt.connect('mqtt://127.0.0.1:9001', { + // path: '/mqtt', + // clientId: 'virtual-' + item.id, + // clean: true, + // connectTimeout: 10000, + // username: 'user', + // password: 'user', + // unixSocket: true, + // keepalive: 60, + // }); // 事件绑定 client.on('connect', () => { console.log('Connected'); - client.subscribe(['sensor/#', 'alerts'], { qos: 0 }); - client.publish('status', 'online', { retain: true }); + client.subscribe(['/wcs_server/' + item.id], { qos: 0 }); + client.publish('/agv_robot/status', 'online', { retain: true }); }); client.on('message', (topic, msg) => { console.log(`[${topic}] ${msg}`); + const a = JSON.parse(msg.toString()); + this.handleMessage(a); + }); client.on('error', (error) => { @@ -488,23 +492,12 @@ export default class Cl23dObject extends THREE.Object3D { }) } - getDirection(object: THREE.Object3D): 0 | 1 | 2 | 3 | 15 { - let ry = this.rotation.y - - while (ry > Math.PI * 2) { - ry = ry - Math.PI * 2 - } - while (ry < - Math.PI * 2) { - ry = ry + Math.PI * 2 + handleMessage(data) { + if (data.id === 10010) { + const cl2: Cl2Entity = Model.getCl2("10") as Cl2Entity + cl2.addRobotTask(data) + cl2.taskStartRun() } - if (ry < 0) { - ry = Math.PI * 2 + ry - } - if (ry >= 0 && ry < Math.PI / 2) { - return 0 - } - - return 0; } }