diff --git a/src/components/YvSrcEditorInner.vue b/src/components/YvSrcEditorInner.vue index f8444c7..d46035e 100644 --- a/src/components/YvSrcEditorInner.vue +++ b/src/components/YvSrcEditorInner.vue @@ -150,6 +150,13 @@ export default { () => null ) }, + clear(){ + if (this.editor) { + this.editor.setValue('') + this.$emit('update:modelValue', '') + this.$emit('change', '') + } + }, init() { // this.editor.updateOptions(option); this.editor.setValue(this.modelValue ?? '') diff --git a/src/core/manager/BackendMessageReceiver.ts b/src/core/manager/BackendMessageReceiver.ts index c3abe11..c6cd985 100644 --- a/src/core/manager/BackendMessageReceiver.ts +++ b/src/core/manager/BackendMessageReceiver.ts @@ -349,7 +349,7 @@ export default class BackendMessageReceiver { private handleDeviceAlive(message: MqttMessage, handler: BackendMessageHandler) { try { const data = JSON.parse(message.payload.toString()) - handler('DeviceAlive', message.topic, _.cloneDeep(data)) + handler('DeviceAlive', message.topic, data) // 处理设备存活状态 } catch (error) { @@ -359,8 +359,7 @@ export default class BackendMessageReceiver { private handleLogMonitor(message: MqttMessage, handler: BackendMessageHandler) { try { - const data = JSON.parse(message.payload.toString()) - handler('Logs', message.topic, _.cloneDeep(data)) + handler('Logs', message.topic, message.payload.toString()) // 处理日志更新 } catch (error) { @@ -371,7 +370,7 @@ export default class BackendMessageReceiver { private handleAlarmMonitor(message: MqttMessage, handler: BackendMessageHandler) { try { const data = JSON.parse(message.payload.toString()) - handler('Alarm', message.topic, _.cloneDeep(data)) + handler('Alarm', message.topic, data) } catch (error) { console.error('Error parsing alarm data:', error) diff --git a/src/core/script/ModelManager.ts b/src/core/script/ModelManager.ts index 120eb9e..778402e 100644 --- a/src/core/script/ModelManager.ts +++ b/src/core/script/ModelManager.ts @@ -77,6 +77,10 @@ export default class ModelManager implements IControls, Model { return item } + find3D(id: string): any { + return this.viewport.entityManager.findObjectById(id) + } + getPositionByEntityId(entityId: string): THREE.Vector3 { const item = this.viewport.entityManager.findItemById(entityId) const matrix = getMatrixFromTf(item.tf) diff --git a/src/editor/widgets/logger/LoggerView.vue b/src/editor/widgets/logger/LoggerView.vue index 236b637..65a5421 100644 --- a/src/editor/widgets/logger/LoggerView.vue +++ b/src/editor/widgets/logger/LoggerView.vue @@ -11,12 +11,13 @@
- +
diff --git a/src/editor/widgets/monitor/MonitorView.vue b/src/editor/widgets/monitor/MonitorView.vue index 405b984..869be24 100644 --- a/src/editor/widgets/monitor/MonitorView.vue +++ b/src/editor/widgets/monitor/MonitorView.vue @@ -4,12 +4,16 @@ + 全上线 + - @@ -93,6 +97,18 @@ export default { this.undescribe() }, methods: { + simBootAll() { + const viewport = window['viewport'] + for (const deviceInfo of this.deviceList) { + if (deviceInfo.isOnline) { + continue + } + const view3DObject = Model.find3D(deviceInfo.id) + if (typeof view3DObject.boot === 'function') { + view3DObject.boot() + } + } + }, copyDeviceId(deviceInfo) { navigator.clipboard.writeText(deviceInfo.id).then(() => { system.msg('设备ID已复制到剪贴板', 'success') @@ -154,7 +170,7 @@ export default { worldModel.backendMessageReceiver.subscribe('DeviceStatus', this.onDeviceStatusMessage.bind(this)) ) }, - async refreshData(){ + async refreshData() { this.deviceList = [] const res = await LCC.queryDeviceInfoList() if (!res.success) { @@ -234,6 +250,9 @@ export default { }, idle() { return this.deviceList.filter(device => device.mode === 'AMR_FREE_MODE').length + }, + worldModelState() { + return worldModel.state } }, watch: { diff --git a/src/editor/widgets/server/ServerView.vue b/src/editor/widgets/server/ServerView.vue index c5e4252..e6ffbae 100644 --- a/src/editor/widgets/server/ServerView.vue +++ b/src/editor/widgets/server/ServerView.vue @@ -108,6 +108,13 @@ export default { worldModel.backendMessageReceiver.subscribe('ServerState', this.onServerStateMessage.bind(this)) ) }, + undescribe() { + // 取消订阅设备状态消息 + for (const stopFn of this.stopSubscribe) { + stopFn() + } + this.stopSubscribe = [] + }, async refreshData() { this.serverList = [] this.isLoading = true @@ -123,13 +130,6 @@ export default { this.isLoading = false } }, - undescribe() { - // 取消订阅设备状态消息 - for (const stopFn of this.stopSubscribe) { - stopFn() - } - this.stopSubscribe = [] - }, // 获取系统标签的样式类 getSystemTagClass(system) { diff --git a/src/modules/amr/ptr/PtrObject.ts b/src/modules/amr/ptr/PtrObject.ts index ac8623e..facf6cc 100644 --- a/src/modules/amr/ptr/PtrObject.ts +++ b/src/modules/amr/ptr/PtrObject.ts @@ -1,4 +1,4 @@ -import * as THREE from "three"; +import * as THREE from 'three' import { AmrErrorCode, AmrMsg, AmrMsg10010, AmrMsg10050, AmrMsg10060, AmrMsg10110, AmrMsg10120, AmrMsg20010, @@ -14,14 +14,14 @@ import { TaskModeChangeData, TaskStatusChangeData, TaskTypeChangeData -} from "@/core/manager/amr/AmrMessageDefine"; -import {worldModel} from "@/core/manager/WorldModel"; -import Viewport from "@/core/engine/Viewport"; -import {Euler} from "three/src/math/Euler"; -import gsap from "gsap"; +} from '@/core/manager/amr/AmrMessageDefine' +import { worldModel } from '@/core/manager/WorldModel' +import Viewport from '@/core/engine/Viewport' +import { Euler } from 'three/src/math/Euler' +import gsap from 'gsap' -type CStepTaskType = "MOVE" | "MOVE_BACKWARD" | "ROTATION" | "LOAD" | "UNLOAD" | "CHARGE" +type CStepTaskType = 'MOVE' | 'MOVE_BACKWARD' | 'ROTATION' | 'LOAD' | 'UNLOAD' | 'CHARGE' export interface StepTask { SeqNo: number; @@ -55,8 +55,8 @@ export default class PtrObject extends THREE.Object3D { public clock = new THREE.Clock() - override AGVModel = "" - override AGVFnModel = "" + override AGVModel = '' + override AGVFnModel = '' private boxBody: any = null private __toPos: THREE.Vector3 = null @@ -159,7 +159,7 @@ export default class PtrObject extends THREE.Object3D { private mqRetryTimeCount: number = 0 constructor(item: ItemJson, viewport: Viewport) { - super(); + super() this.viewport = viewport this.item = item this.vehicleId = parseInt(item.id) @@ -194,23 +194,23 @@ export default class PtrObject extends THREE.Object3D { // 开机 boot() { - this.bootTime = Date.now(); - this.computeLogicXYAndDirection(); + this.bootTime = Date.now() + this.computeLogicXYAndDirection() - const boxShape = new this.viewport.ammoModel.btBoxShape(new Ammo.btVector3(0.5, 0.5, 0.5)); + const boxShape = new this.viewport.ammoModel.btBoxShape(new Ammo.btVector3(0.5, 0.5, 0.5)) const mass = 10 const localInertia = new this.viewport.ammoModel.btVector3(0, 0, 0) boxShape.calculateLocalInertia(mass, localInertia) - const boxTransform = new this.viewport.ammoModel.btTransform(); - boxTransform.setIdentity(); - boxTransform.setOrigin(new this.viewport.ammoModel.btVector3(this.position.x, this.position.y, this.position.z)); + const boxTransform = new this.viewport.ammoModel.btTransform() + boxTransform.setIdentity() + boxTransform.setOrigin(new this.viewport.ammoModel.btVector3(this.position.x, this.position.y, this.position.z)) - const boxMotionState = new this.viewport.ammoModel.btDefaultMotionState(boxTransform); + const boxMotionState = new this.viewport.ammoModel.btDefaultMotionState(boxTransform) const rbInfo = new this.viewport.ammoModel.btRigidBodyConstructionInfo(mass, boxMotionState, boxShape, localInertia) - this.boxBody = new this.viewport.ammoModel.btRigidBody(rbInfo); - this.viewport.physicsWorld.addRigidBody(this.boxBody); + this.boxBody = new this.viewport.ammoModel.btRigidBody(rbInfo) + this.viewport.physicsWorld.addRigidBody(this.boxBody) if (!worldModel.state.runState.isVirtual) { return @@ -321,7 +321,7 @@ export default class PtrObject extends THREE.Object3D { ActuatorsData: [ { MechNo: 1, - Name: "Mech1", + Name: 'Mech1', PickMode: this.PickMode } ] @@ -349,10 +349,10 @@ export default class PtrObject extends THREE.Object3D { content.CurLogicX = this.currentLogicX content.CurLogicY = this.currentLogicY content.CurOrientation = this.currentOrientation - content.CurX = this.position.x; - content.CurY = this.position.z; - content.X = this.position.x; - content.Y = this.position.z; + content.CurX = this.position.x + content.CurY = this.position.z + content.X = this.position.x + content.Y = this.position.z const m20060 = new AmrMsg(content) this.sendMessage(m20060) } @@ -362,7 +362,7 @@ export default class PtrObject extends THREE.Object3D { } subscribeMessage(topic: string) { - worldModel.envManager.client.subscribe(topic, {qos: 0}) + worldModel.envManager.client.subscribe(topic, { qos: 0 }) } sendMessage(msg: AmrMsg) { @@ -385,7 +385,7 @@ export default class PtrObject extends THREE.Object3D { return } const content = new AmrMsg20100(this.vehicleId) - content.Temperature = {Battery: this.Battery} + content.Temperature = { Battery: this.Battery } const m20100 = new AmrMsg(content) worldModel.envManager.client.publish('/agv_robot/status', JSON.stringify(m20100)) } @@ -460,27 +460,27 @@ export default class PtrObject extends THREE.Object3D { } const ddra = Math.PI / 180 if (ra >= Math.PI * 2 - ddra || ra <= ddra) { - this.currentDirection = 0; + this.currentDirection = 0 } else if (ra >= Math.PI / 2 - ddra && ra <= Math.PI / 2 + ddra) { - this.currentDirection = 3; + this.currentDirection = 3 } else if (ra >= Math.PI - ddra && ra <= Math.PI + ddra) { - this.currentDirection = 2; + this.currentDirection = 2 } else if (ra >= Math.PI / 2 * 3 - ddra && ra <= Math.PI / 2 * 3 + ddra) { - this.currentDirection = 1; + this.currentDirection = 1 } else { - this.currentDirection = 15; + this.currentDirection = 15 } const pointItem = Model.getItemByXYZ(this.position.x, this.position.y, this.position.z) if (!pointItem || !pointItem.logicX || !pointItem.logicY) { - this.currentLogicX = -1; - this.currentLogicY = -1; + this.currentLogicX = -1 + this.currentLogicY = -1 } else { - this.currentLogicX = pointItem.logicX; - this.currentLogicY = pointItem.logicY; + this.currentLogicX = pointItem.logicX + this.currentLogicY = pointItem.logicY } this.currentOrientation = this.getAmrOrientation(this.rotation.y) } @@ -494,7 +494,7 @@ export default class PtrObject extends THREE.Object3D { } else { currentStepTask = { SeqNo: 0, - StepTaskType: "MOVE", + StepTaskType: 'MOVE', OperationType: 0, PickMode: 0, X: this.currentLogicX, @@ -513,7 +513,7 @@ export default class PtrObject extends THREE.Object3D { const linkCount = data.Link?.length || 0 if (linkCount > 0) { - let prevLink = {X: data.StartX, Y: data.StartY, Speed: 1000} + let prevLink = { X: data.StartX, Y: data.StartY, Speed: 1000 } for (let i = 0; i < data.Link.length; i++) { const link = data.Link[i] if ((currentStepTask.X == link.X && currentStepTask.Y == link.Y) @@ -549,7 +549,7 @@ export default class PtrObject extends THREE.Object3D { if (endDirection != currentStepTask.EndDirection) { const stepTask: StepTask = { SeqNo: data.SeqNo, - StepTaskType: "ROTATION", + StepTaskType: 'ROTATION', OperationType: 0, PickMode: 0, X: prevLink.X, @@ -567,7 +567,7 @@ export default class PtrObject extends THREE.Object3D { const stepTask: StepTask = { SeqNo: data.SeqNo, - StepTaskType: link.Speed > 0 ? "MOVE" : "MOVE_BACKWARD", + StepTaskType: link.Speed > 0 ? 'MOVE' : 'MOVE_BACKWARD', OperationType: 0, PickMode: 0, X: link.X, @@ -590,7 +590,7 @@ export default class PtrObject extends THREE.Object3D { || (linkCount > 0 && data.Link[linkCount - 1].X == data.EndX && data.Link[linkCount - 1].Y == data.EndY)) { if (data.OperationType == 0 && data.EndDirection >= 0 && data.EndDirection <= 3) { - endDirection = data.EndDirection; + endDirection = data.EndDirection } else if (data.OperationType == 3 && data.ChargeDirection >= 0 && data.ChargeDirection <= 3) { endDirection = data.ChargeDirection } else if (data.OperationType == 4 && data.GoodsSlotDirection >= 0 && data.GoodsSlotDirection <= 3) { @@ -610,7 +610,7 @@ export default class PtrObject extends THREE.Object3D { } const stepTask: StepTask = { SeqNo: data.SeqNo, - StepTaskType: "ROTATION", + StepTaskType: 'ROTATION', OperationType: 0, PickMode: 0, X: data.EndX, @@ -629,7 +629,7 @@ export default class PtrObject extends THREE.Object3D { const stepTask: StepTask = { SeqNo: data.SeqNo, - StepTaskType: "CHARGE", + StepTaskType: 'CHARGE', OperationType: 3, PickMode: 0, X: data.EndX, @@ -647,7 +647,7 @@ export default class PtrObject extends THREE.Object3D { const stepTask: StepTask = { SeqNo: data.SeqNo, - StepTaskType: data.PickMode == 1 ? "LOAD" : "UNLOAD", + StepTaskType: data.PickMode == 1 ? 'LOAD' : 'UNLOAD', OperationType: 4, PickMode: data.PickMode, X: data.EndX, @@ -676,7 +676,7 @@ export default class PtrObject extends THREE.Object3D { while (this.currentStepTaskList.length > 0) { const stepTask = this.currentStepTaskList[0] if (this.runningStepTask) { - if ((stepTask.StepTaskType == "MOVE" || stepTask.StepTaskType == "MOVE_BACKWARD") + if ((stepTask.StepTaskType == 'MOVE' || stepTask.StepTaskType == 'MOVE_BACKWARD') && this.rotationAnimation == null && this.actionAnimation == null && stepTask.EndDirection == this.runningStepTask.EndDirection && (stepTask.Speed > 0) == (this.runningStepTask.Speed > 0)) { @@ -693,13 +693,13 @@ export default class PtrObject extends THREE.Object3D { this.runningStepTask = stepTask this.currentStepTaskList.shift() this.runningStepTaskList.push(stepTask) - if (stepTask.StepTaskType == "MOVE" || stepTask.StepTaskType == "MOVE_BACKWARD") { + if (stepTask.StepTaskType == 'MOVE' || stepTask.StepTaskType == 'MOVE_BACKWARD') { this.addTravel(stepTask.X, stepTask.Y, stepTask.Speed / 1000) - } else if (stepTask.StepTaskType == "ROTATION") { + } else if (stepTask.StepTaskType == 'ROTATION') { this.addRotation(stepTask.EndDirection) - } else if (stepTask.StepTaskType == "LOAD") { + } else if (stepTask.StepTaskType == 'LOAD') { this.addLoad(stepTask.GoodsSlotHeight / 1000) - } else if (stepTask.StepTaskType == "UNLOAD") { + } else if (stepTask.StepTaskType == 'UNLOAD') { this.addUnload(stepTask.GoodsSlotHeight / 1000) } } @@ -775,7 +775,6 @@ export default class PtrObject extends THREE.Object3D { addTravel(logicX: number, logicY: number, speed: number = 1): Promise { - this.OperationType = 0 this.PickMode = 0 const pos = Model.getPositionByLogicXY(logicX, logicY) @@ -790,14 +789,14 @@ export default class PtrObject extends THREE.Object3D { } // 运动参数 - const accelForce = speed > 0 ? 4 : (-4 ) - let currentPhase = 'accelerate'; + const accelForce = speed > 0 ? 4 : (-4) + let currentPhase = 'accelerate' if (this.viewport.registerPhysicsUpdateCallBack.has(this.item.id)) { return null } - this.travelAnimation = "asd" + this.travelAnimation = 'asd' const force = new this.viewport.ammoModel.btVector3(accelForce, 0, 0) this.viewport.registerPhysicsUpdateCallBack.set(this.item.id, () => { @@ -826,7 +825,8 @@ export default class PtrObject extends THREE.Object3D { this.travelAnimation = null this.onActionCompleted() - } if (distance <= stopDistance) { + } + if (distance <= stopDistance) { currentPhase = 'decelerate' } // 运动阶段控制 diff --git a/src/types/Model.d.ts b/src/types/Model.d.ts index a34e868..dcdd001 100644 --- a/src/types/Model.d.ts +++ b/src/types/Model.d.ts @@ -3,12 +3,18 @@ */ declare interface Model { /** - * 根据实体 ID 查找模型实体 + * 根据实体 ID 查找数据实体 * @param entityId 实体 ID */ find(entityId: string): ItemJson /** + * 根据实体 ID 查找模型实体 + * @param id + */ + find3D(id: string): any + + /** * 根据实体 ID 获取位置 */ getPositionByEntityId(entityId: string): Vector3IF @@ -87,6 +93,7 @@ declare interface Model { */ multiSelectedEntityIds: string[] + } /**