diff --git a/src/core/manager/EnvManager.ts b/src/core/manager/EnvManager.ts index bbb2703..fbfa78b 100644 --- a/src/core/manager/EnvManager.ts +++ b/src/core/manager/EnvManager.ts @@ -17,7 +17,7 @@ export default class EnvManager { } onMqttMessage = (topic: string, payload: Buffer, packet: IPublishPacket) => { - console.log(`[${topic}]-> ${payload.toString()}`) + // console.log(`[${topic}]-> ${payload.toString()}`) if (topic.startsWith('/wcs_server/')) { const message: AmrMsg = JSON.parse(payload.toString()) this.amrMessageManager.handleMessage(topic, message) diff --git a/src/modules/amr/ptr/PtrObject.ts b/src/modules/amr/ptr/PtrObject.ts index 59a90c6..51488d9 100644 --- a/src/modules/amr/ptr/PtrObject.ts +++ b/src/modules/amr/ptr/PtrObject.ts @@ -62,7 +62,12 @@ export default class PtrObject extends THREE.Object3D { private runningStepTask: StepTask = null public runningStepTaskList: StepTask[] = [] + // 移动动画 public travelAnimation: core.Tween = null + // 旋转动画 + public rotationAnimation: core.Tween = null + // 动作动画 + public actionAnimation: core.Tween = null // 心跳间隔 UInt32 单位: s private heartBeatInterval: number = 0 @@ -345,7 +350,7 @@ export default class PtrObject extends THREE.Object3D { if (!worldModel.state.runState.isVirtual) { return } - console.log('send message:', JSON.stringify(msg)) + // console.log('send message:', JSON.stringify(msg)) if (this.sendMessageQueue.indexOf(msg) < 0) { this.sendMessageQueue.push(msg) } @@ -428,17 +433,17 @@ export default class PtrObject extends THREE.Object3D { while (ra < 0) { ra += Math.PI * 2 } - const ddra = Math.PI / 8 - if (ra >= ddra * 7 || ra < ddra) { + const ddra = Math.PI / 180 + if (ra >= Math.PI * 2 - ddra || ra <= ddra) { this.currentDirection = 0; - } else if (ra >= ddra && ra < ddra * 3) { + } else if (ra >= Math.PI/2 - ddra && ra <= Math.PI/2 + ddra) { this.currentDirection = 3; - } else if (ra >= ddra * 3 && ra < ddra * 5) { + } else if (ra >= Math.PI - ddra && ra <= Math.PI + ddra) { this.currentDirection = 2; - } else if (ra >= ddra * 5 && ra < ddra * 7) { + } else if (ra >= Math.PI/2*3 - ddra && ra <= Math.PI/2*3 + ddra) { this.currentDirection = 1; } else { this.currentDirection = 15; @@ -477,11 +482,13 @@ export default class PtrObject extends THREE.Object3D { } let endDirection = currentStepTask.EndDirection - if (data.Link.length > 0) { + const linkCount = data.Link?.length || 0 + if (linkCount > 0) { for (let i = 0; i < data.Link.length; i++) { const link = data.Link[i] if ((currentStepTask.X == link.X && currentStepTask.Y == link.Y) || (currentStepTask.X != link.X && currentStepTask.Y != link.Y)) { + debugger continue } else if (currentStepTask.X < link.X) { if (link.Speed > 0) { @@ -547,75 +554,82 @@ export default class PtrObject extends THREE.Object3D { } } + // 如果没有link 或者当前link的XY是任务结束点位 + if (linkCount <= 0 + || (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; - } 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) { - if (data.GoodsSlotDirection == 0) { - endDirection = 3 - } else { - endDirection = (data.GoodsSlotDirection - 1) as LogicDirection + if (data.OperationType == 0 && data.EndDirection >= 0 && data.EndDirection <= 3) { + 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) { + if (data.GoodsSlotDirection == 0) { + endDirection = 3 + } else { + endDirection = (data.GoodsSlotDirection - 1) as LogicDirection + } } - } - if (endDirection != currentStepTask.EndDirection) { - const stepTask: StepTask = { - SeqNo: data.SeqNo, - StepTaskType: "ROTATION", - OperationType: 0, - PickMode: 0, - X: data.EndX, - Y: data.EndY, - Speed: currentStepTask.Speed, - EndDirection: endDirection, - ChargeLocation: data.ChargeLocation, - GoodsSlotHeight: data.GoodsSlotHeight, - position: Model.getPositionByLogicXY(data.EndX, data.EndY) as THREE.Vector3, - isCompleted: false + if (endDirection != currentStepTask.EndDirection) { + const stepTask: StepTask = { + SeqNo: data.SeqNo, + StepTaskType: "ROTATION", + OperationType: 0, + PickMode: 0, + X: data.EndX, + Y: data.EndY, + Speed: currentStepTask.Speed, + EndDirection: endDirection, + ChargeLocation: data.ChargeLocation, + GoodsSlotHeight: data.GoodsSlotHeight, + position: Model.getPositionByLogicXY(data.EndX, data.EndY) as THREE.Vector3, + isCompleted: false + } + this.currentStepTaskList.push(stepTask) } - this.currentStepTaskList.push(stepTask) - } - if (data.OperationType == 3) { + if (data.OperationType == 3) { - const stepTask: StepTask = { - SeqNo: data.SeqNo, - StepTaskType: "CHARGE", - OperationType: 3, - PickMode: 0, - X: data.EndX, - Y: data.EndY, - Speed: currentStepTask.Speed, - EndDirection: endDirection, - ChargeLocation: data.ChargeLocation, - GoodsSlotHeight: data.GoodsSlotHeight, - position: Model.getPositionByLogicXY(data.EndX, data.EndY) as THREE.Vector3, - isCompleted: false - } - this.currentStepTaskList.push(stepTask) - - } else if (data.OperationType == 4) { - - const stepTask: StepTask = { - SeqNo: data.SeqNo, - StepTaskType: data.PickMode == 1 ? "LOAD" : "UNLOAD", - OperationType: 4, - PickMode: data.PickMode, - X: data.EndX, - Y: data.EndY, - Speed: currentStepTask.Speed, - EndDirection: endDirection, - ChargeLocation: data.ChargeLocation, - GoodsSlotHeight: data.GoodsSlotHeight, - position: Model.getPositionByLogicXY(data.EndX, data.EndY) as THREE.Vector3, - isCompleted: false - } - this.currentStepTaskList.push(stepTask) + const stepTask: StepTask = { + SeqNo: data.SeqNo, + StepTaskType: "CHARGE", + OperationType: 3, + PickMode: 0, + X: data.EndX, + Y: data.EndY, + Speed: currentStepTask.Speed, + EndDirection: endDirection, + ChargeLocation: data.ChargeLocation, + GoodsSlotHeight: data.GoodsSlotHeight, + position: Model.getPositionByLogicXY(data.EndX, data.EndY) as THREE.Vector3, + isCompleted: false + } + this.currentStepTaskList.push(stepTask) - } else { + } else if (data.OperationType == 4) { + + const stepTask: StepTask = { + SeqNo: data.SeqNo, + StepTaskType: data.PickMode == 1 ? "LOAD" : "UNLOAD", + OperationType: 4, + PickMode: data.PickMode, + X: data.EndX, + Y: data.EndY, + Speed: currentStepTask.Speed, + EndDirection: endDirection, + ChargeLocation: data.ChargeLocation, + GoodsSlotHeight: data.GoodsSlotHeight, + position: Model.getPositionByLogicXY(data.EndX, data.EndY) as THREE.Vector3, + isCompleted: false + } + this.currentStepTaskList.push(stepTask) + } else { + + } } + + console.log(JSON.stringify(this.currentStepTaskList)) + } executeTask() { @@ -624,6 +638,7 @@ export default class PtrObject extends THREE.Object3D { const stepTask = this.currentStepTaskList[0] if (this.runningStepTask) { 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)) { this.runningStepTask = stepTask @@ -693,12 +708,13 @@ export default class PtrObject extends THREE.Object3D { const duration = time return new Promise(resolve => { - gsap.to(this.rotation, { + this.rotationAnimation = gsap.to(this.rotation, { y: tr, duration, ease: 'none', onComplete: ()=>{ resolve() + this.rotationAnimation = null this.onActionCompleted() } }) @@ -718,11 +734,7 @@ export default class PtrObject extends THREE.Object3D { if (!this.travelAnimation) { return new Promise(resolve => { - this.travelAnimation = gsap.fromTo(this.position, { - x: fromPos.x, - y: fromPos.y, - z: fromPos.z, - }, { + this.travelAnimation = gsap.to(this.position, { x: toPos.x, y: toPos.y, z: toPos.z, @@ -776,6 +788,7 @@ export default class PtrObject extends THREE.Object3D { ()=>this.animationUpFork(height + 0.2).then( ()=>this.animationHideFork().then( ()=>this.animationDownFork().then(()=>{ + this.actionAnimation = null this.onActionCompleted() }) ) @@ -792,6 +805,7 @@ export default class PtrObject extends THREE.Object3D { ()=>this.animationUpFork(height).then( ()=>this.animationHideFork().then( ()=>this.animationDownFork().then(()=>{ + this.actionAnimation = null this.onActionCompleted() }) ) @@ -815,13 +829,13 @@ export default class PtrObject extends THREE.Object3D { //获取ptr的角度朝向 getAmrOrientation(radY: number) { - radY = radY + Math.PI while (radY < 0) { radY += Math.PI * 2 } while (radY > Math.PI * 2) { radY -= Math.PI * 2 } + radY = (Math.PI * 2 - radY)%(Math.PI * 2) return THREE.MathUtils.radToDeg(radY) } diff --git a/src/modules/amr/ptr/cl2/Cl23dObject.ts b/src/modules/amr/ptr/cl2/Cl23dObject.ts index 1ca81c4..affaecf 100644 --- a/src/modules/amr/ptr/cl2/Cl23dObject.ts +++ b/src/modules/amr/ptr/cl2/Cl23dObject.ts @@ -83,7 +83,7 @@ export default class Cl23dObject extends PtrObject { const ptrPillar = this.getObjectByName('ptrPillar') const time = 3 return new Promise(resolve => { - gsap.to(ptrPillar.position, { + this.actionAnimation = gsap.to(ptrPillar.position, { z: -z, duration: time, repeat: 0, @@ -106,7 +106,7 @@ export default class Cl23dObject extends PtrObject { const bh = 0.22 const children = ptrFork.children - gsap.to(ptrFork.position, { + this.actionAnimation = gsap.to(ptrFork.position, { y: y, duration: time, repeat: 0, diff --git a/src/modules/amr/ptr/clx/Clx3dObject.ts b/src/modules/amr/ptr/clx/Clx3dObject.ts index f1be300..ee8ed1a 100644 --- a/src/modules/amr/ptr/clx/Clx3dObject.ts +++ b/src/modules/amr/ptr/clx/Clx3dObject.ts @@ -184,7 +184,7 @@ export default class Clx3dObject extends PtrObject { }) return new Promise(resolve => { - gsap.to(clxFork.position, { + this.actionAnimation = gsap.to(clxFork.position, { z: -z, duration: time, repeat: 0, @@ -243,7 +243,7 @@ export default class Clx3dObject extends PtrObject { const bh = 0.22 const children = clxFork.children - gsap.to(clxFork.position, { + this.actionAnimation = gsap.to(clxFork.position, { y: y, duration: time, repeat: 0, @@ -252,7 +252,6 @@ export default class Clx3dObject extends PtrObject { onUpdate: function() { const a = this.targets()[0] if (a.y < bh) { - console.log(a.z) if (a.z > -1) { for (let i = 0; i < children.length; i++) { const child = children[i]