Browse Source

cl2 基于设备状态和任务状态分步生成设备任务消息

master
yuliang 6 months ago
parent
commit
eee916d616
  1. 2
      src/core/manager/EnvManager.ts
  2. 42
      src/modules/amr/ptr/PtrObject.ts
  3. 4
      src/modules/amr/ptr/cl2/Cl23dObject.ts
  4. 5
      src/modules/amr/ptr/clx/Clx3dObject.ts

2
src/core/manager/EnvManager.ts

@ -17,7 +17,7 @@ export default class EnvManager {
} }
onMqttMessage = (topic: string, payload: Buffer, packet: IPublishPacket) => { onMqttMessage = (topic: string, payload: Buffer, packet: IPublishPacket) => {
console.log(`[${topic}]-> ${payload.toString()}`) // console.log(`[${topic}]-> ${payload.toString()}`)
if (topic.startsWith('/wcs_server/')) { if (topic.startsWith('/wcs_server/')) {
const message: AmrMsg<any> = JSON.parse(payload.toString()) const message: AmrMsg<any> = JSON.parse(payload.toString())
this.amrMessageManager.handleMessage(topic, message) this.amrMessageManager.handleMessage(topic, message)

42
src/modules/amr/ptr/PtrObject.ts

@ -62,7 +62,12 @@ export default class PtrObject extends THREE.Object3D {
private runningStepTask: StepTask = null private runningStepTask: StepTask = null
public runningStepTaskList: StepTask[] = [] public runningStepTaskList: StepTask[] = []
// 移动动画
public travelAnimation: core.Tween = null public travelAnimation: core.Tween = null
// 旋转动画
public rotationAnimation: core.Tween = null
// 动作动画
public actionAnimation: core.Tween = null
// 心跳间隔 UInt32 单位: s // 心跳间隔 UInt32 单位: s
private heartBeatInterval: number = 0 private heartBeatInterval: number = 0
@ -345,7 +350,7 @@ export default class PtrObject extends THREE.Object3D {
if (!worldModel.state.runState.isVirtual) { if (!worldModel.state.runState.isVirtual) {
return return
} }
console.log('send message:', JSON.stringify(msg)) // console.log('send message:', JSON.stringify(msg))
if (this.sendMessageQueue.indexOf(msg) < 0) { if (this.sendMessageQueue.indexOf(msg) < 0) {
this.sendMessageQueue.push(msg) this.sendMessageQueue.push(msg)
} }
@ -428,17 +433,17 @@ export default class PtrObject extends THREE.Object3D {
while (ra < 0) { while (ra < 0) {
ra += Math.PI * 2 ra += Math.PI * 2
} }
const ddra = Math.PI / 8 const ddra = Math.PI / 180
if (ra >= ddra * 7 || ra < ddra) { if (ra >= Math.PI * 2 - ddra || ra <= ddra) {
this.currentDirection = 0; 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; this.currentDirection = 3;
} else if (ra >= ddra * 3 && ra < ddra * 5) { } else if (ra >= Math.PI - ddra && ra <= Math.PI + ddra) {
this.currentDirection = 2; 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; this.currentDirection = 1;
} else { } else {
this.currentDirection = 15; this.currentDirection = 15;
@ -477,11 +482,13 @@ export default class PtrObject extends THREE.Object3D {
} }
let endDirection = currentStepTask.EndDirection 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++) { for (let i = 0; i < data.Link.length; i++) {
const link = data.Link[i] const link = data.Link[i]
if ((currentStepTask.X == link.X && currentStepTask.Y == link.Y) if ((currentStepTask.X == link.X && currentStepTask.Y == link.Y)
|| (currentStepTask.X != link.X && currentStepTask.Y != link.Y)) { || (currentStepTask.X != link.X && currentStepTask.Y != link.Y)) {
debugger
continue continue
} else if (currentStepTask.X < link.X) { } else if (currentStepTask.X < link.X) {
if (link.Speed > 0) { if (link.Speed > 0) {
@ -547,6 +554,9 @@ 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) { if (data.OperationType == 0 && data.EndDirection >= 0 && data.EndDirection <= 3) {
endDirection = data.EndDirection; endDirection = data.EndDirection;
@ -615,6 +625,10 @@ export default class PtrObject extends THREE.Object3D {
} else { } else {
} }
}
console.log(JSON.stringify(this.currentStepTaskList))
} }
@ -624,6 +638,7 @@ export default class PtrObject extends THREE.Object3D {
const stepTask = this.currentStepTaskList[0] const stepTask = this.currentStepTaskList[0]
if (this.runningStepTask) { 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.EndDirection == this.runningStepTask.EndDirection
&& (stepTask.Speed > 0) == (this.runningStepTask.Speed > 0)) { && (stepTask.Speed > 0) == (this.runningStepTask.Speed > 0)) {
this.runningStepTask = stepTask this.runningStepTask = stepTask
@ -693,12 +708,13 @@ export default class PtrObject extends THREE.Object3D {
const duration = time const duration = time
return new Promise(resolve => { return new Promise(resolve => {
gsap.to(this.rotation, { this.rotationAnimation = gsap.to(this.rotation, {
y: tr, y: tr,
duration, duration,
ease: 'none', ease: 'none',
onComplete: ()=>{ onComplete: ()=>{
resolve() resolve()
this.rotationAnimation = null
this.onActionCompleted() this.onActionCompleted()
} }
}) })
@ -718,11 +734,7 @@ export default class PtrObject extends THREE.Object3D {
if (!this.travelAnimation) { if (!this.travelAnimation) {
return new Promise(resolve => { return new Promise(resolve => {
this.travelAnimation = gsap.fromTo(this.position, { this.travelAnimation = gsap.to(this.position, {
x: fromPos.x,
y: fromPos.y,
z: fromPos.z,
}, {
x: toPos.x, x: toPos.x,
y: toPos.y, y: toPos.y,
z: toPos.z, z: toPos.z,
@ -776,6 +788,7 @@ export default class PtrObject extends THREE.Object3D {
()=>this.animationUpFork(height + 0.2).then( ()=>this.animationUpFork(height + 0.2).then(
()=>this.animationHideFork().then( ()=>this.animationHideFork().then(
()=>this.animationDownFork().then(()=>{ ()=>this.animationDownFork().then(()=>{
this.actionAnimation = null
this.onActionCompleted() this.onActionCompleted()
}) })
) )
@ -792,6 +805,7 @@ export default class PtrObject extends THREE.Object3D {
()=>this.animationUpFork(height).then( ()=>this.animationUpFork(height).then(
()=>this.animationHideFork().then( ()=>this.animationHideFork().then(
()=>this.animationDownFork().then(()=>{ ()=>this.animationDownFork().then(()=>{
this.actionAnimation = null
this.onActionCompleted() this.onActionCompleted()
}) })
) )
@ -815,13 +829,13 @@ export default class PtrObject extends THREE.Object3D {
//获取ptr的角度朝向 //获取ptr的角度朝向
getAmrOrientation(radY: number) { getAmrOrientation(radY: number) {
radY = radY + Math.PI
while (radY < 0) { while (radY < 0) {
radY += Math.PI * 2 radY += Math.PI * 2
} }
while (radY > Math.PI * 2) { while (radY > Math.PI * 2) {
radY -= Math.PI * 2 radY -= Math.PI * 2
} }
radY = (Math.PI * 2 - radY)%(Math.PI * 2)
return THREE.MathUtils.radToDeg(radY) return THREE.MathUtils.radToDeg(radY)
} }

4
src/modules/amr/ptr/cl2/Cl23dObject.ts

@ -83,7 +83,7 @@ export default class Cl23dObject extends PtrObject {
const ptrPillar = this.getObjectByName('ptrPillar') const ptrPillar = this.getObjectByName('ptrPillar')
const time = 3 const time = 3
return new Promise(resolve => { return new Promise(resolve => {
gsap.to(ptrPillar.position, { this.actionAnimation = gsap.to(ptrPillar.position, {
z: -z, z: -z,
duration: time, duration: time,
repeat: 0, repeat: 0,
@ -106,7 +106,7 @@ export default class Cl23dObject extends PtrObject {
const bh = 0.22 const bh = 0.22
const children = ptrFork.children const children = ptrFork.children
gsap.to(ptrFork.position, { this.actionAnimation = gsap.to(ptrFork.position, {
y: y, y: y,
duration: time, duration: time,
repeat: 0, repeat: 0,

5
src/modules/amr/ptr/clx/Clx3dObject.ts

@ -184,7 +184,7 @@ export default class Clx3dObject extends PtrObject {
}) })
return new Promise(resolve => { return new Promise(resolve => {
gsap.to(clxFork.position, { this.actionAnimation = gsap.to(clxFork.position, {
z: -z, z: -z,
duration: time, duration: time,
repeat: 0, repeat: 0,
@ -243,7 +243,7 @@ export default class Clx3dObject extends PtrObject {
const bh = 0.22 const bh = 0.22
const children = clxFork.children const children = clxFork.children
gsap.to(clxFork.position, { this.actionAnimation = gsap.to(clxFork.position, {
y: y, y: y,
duration: time, duration: time,
repeat: 0, repeat: 0,
@ -252,7 +252,6 @@ export default class Clx3dObject extends PtrObject {
onUpdate: function() { onUpdate: function() {
const a = this.targets()[0] const a = this.targets()[0]
if (a.y < bh) { if (a.y < bh) {
console.log(a.z)
if (a.z > -1) { if (a.z > -1) {
for (let i = 0; i < children.length; i++) { for (let i = 0; i < children.length; i++) {
const child = children[i] const child = children[i]

Loading…
Cancel
Save