Browse Source

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

master
yuliang 6 months ago
parent
commit
4c903aad42
  1. 1
      src/core/base/TaskQueue.ts
  2. 11
      src/core/manager/EntityManager.ts
  3. 4
      src/core/script/ModelManager.ts
  4. 138
      src/modules/cl2/Cl23dObject.ts
  5. 4
      src/modules/cl2/Cl2Entity.ts

1
src/core/base/TaskQueue.ts

@ -70,6 +70,7 @@ export default class TaskQueue {
start(onTaskComplete?: (task: Task) => void): void { start(onTaskComplete?: (task: Task) => void): void {
this.onTaskComplete = onTaskComplete this.onTaskComplete = onTaskComplete
if (!this.isRunning) { if (!this.isRunning) {
debugger
this.isRunning = true this.isRunning = true
this.executeNextTask() this.executeNextTask()
} }

11
src/core/manager/EntityManager.ts

@ -518,6 +518,17 @@ export default class EntityManager {
return item return item
} }
findItemByLogicXYZ(x: number, y: number, z: number): ItemJson | undefined {
let item: ItemJson | undefined = undefined
this.___entityMap.forEach((value) => {
if (value.tf[0][0] === x && /*value.tf[0][1] === y &&*/ value.tf[0][2] === z && value.logicX) {
item = value
return
}
})
return item
}
getObjectByCanvasMouse(event: MouseEvent): Object3DLike[] { getObjectByCanvasMouse(event: MouseEvent): Object3DLike[] {
const _domElement = this.viewport.renderer.domElement const _domElement = this.viewport.renderer.domElement

4
src/core/script/ModelManager.ts

@ -88,6 +88,10 @@ export default class ModelManager implements IControls, Model {
matrix.decompose(position, new THREE.Quaternion(), new THREE.Vector3()) matrix.decompose(position, new THREE.Quaternion(), new THREE.Vector3())
return position return position
} }
getItemByXYZ(x: number, y: number, z: number): ItemJson | undefined {
const item = this.viewport.entityManager.findItemByLogicXYZ(x, y, z)
return item
}
dispose() { dispose() {
this.viewport = null as any this.viewport = null as any

138
src/modules/cl2/Cl23dObject.ts

@ -33,6 +33,17 @@ export interface Cl2Task {
} }
} }
interface Task {
SeqNo: number;
OperationType: 0 | 1 | 2 | 3 | 4 | 5 | 135 | 136;
PickMode: 0 | 1 | 2 | 3 | 4 | 5 | 6;
GoodsSlotHeight: number;
GoodsSlotDirection: 0 | 1 | 2 | 3 | 15;
X: number;
Y: number;
Speed: number;
}
export default class Cl23dObject extends THREE.Object3D { export default class Cl23dObject extends THREE.Object3D {
// 创建ptr的底座 // 创建ptr的底座
@ -323,8 +334,33 @@ export default class Cl23dObject extends THREE.Object3D {
private static ptrPillarGeometry: THREE.BufferGeometry = null; private static ptrPillarGeometry: THREE.BufferGeometry = null;
private static ptrForkGeometry: THREE.BufferGeometry = null; private static ptrForkGeometry: THREE.BufferGeometry = null;
private item: ItemJson;
private _cl2Entity: Cl2Entity = null;
private taskList: Task[] = [];
private executingTask: Task[] = [];
private travelAnimation: core.Tween = null
private rotationAnimation: core.Tween = null;
private riseAnimation: core.Tween = null;
private stretchAnimation: core.Tween = null;
public get cl2Entity(): Cl2Entity {
if (!this._cl2Entity) {
const cl2: Cl2Entity = Model.getCl2(this.item.id) as Cl2Entity
this._cl2Entity = cl2
}
return this._cl2Entity
}
private clock = new THREE.Clock();
constructor(item: ItemJson, option?: RendererCudOption) { constructor(item: ItemJson, option?: RendererCudOption) {
super(); super();
console.log("time", this.clock.getElapsedTime());
this.item = item;
if (!Cl23dObject.ptrPedestalGeometry) { if (!Cl23dObject.ptrPedestalGeometry) {
Cl23dObject.ptrPedestalGeometry = Cl23dObject.createPtrPedestal() Cl23dObject.ptrPedestalGeometry = Cl23dObject.createPtrPedestal()
} }
@ -398,7 +434,7 @@ export default class Cl23dObject extends THREE.Object3D {
client.on('message', (topic, msg) => { client.on('message', (topic, msg) => {
console.log(`[${topic}] ${msg}`); console.log(`[${topic}] ${msg}`);
const a = JSON.parse(msg.toString()); const a: Cl2Task = JSON.parse(msg.toString());
this.handleMessage(a); this.handleMessage(a);
}); });
@ -409,9 +445,62 @@ export default class Cl23dObject extends THREE.Object3D {
} catch (e) { } catch (e) {
console.error(e) console.error(e)
} }
}
/*==========消息处理============*/
handleMessage(data: Cl2Task) {
if (data.id === 10010) {
if (this.taskList.length <= 0) {
//当队列为空时,检查当前车辆所在位置
const pointItem = Model.getItemByXYZ(this.position.x, this.position.y, this.position.z)
if (!pointItem || data.content.StartX != pointItem.logicX || data.content.StartY != pointItem.logicY) {
throw new Error('当前车辆所在位置未找到')
}
}
for (const item of data.content.Link) {
// 添加到队列
this.taskList.push({
SeqNo: data.content.SeqNo,
OperationType: data.content.OperationType,
PickMode: data.content.PickMode,
GoodsSlotHeight: data.content.GoodsSlotHeight,
GoodsSlotDirection: data.content.GoodsSlotDirection,
X: item.X,
Y: item.Y,
Speed: item.Speed,
})
}
console.log("time", this.clock.getElapsedTime());
this.executeTask()
return
this.cl2Entity.addRobotTask(data)
if (!this.cl2Entity.taskIsRunning) {
this.cl2Entity.taskStartRun()
}
}
} }
executeTask() {
while (this.taskList.length > 0) {
const task = this.taskList.shift()
this.addTravel(task.X, task.Y, task.Speed/1000)
this.executingTask.push(task)
}
}
/*==========动画处理============*/
animationShowFork(z: number): Promise<void> { animationShowFork(z: number): Promise<void> {
const ptrPillar = this.getObjectByName('ptrPillar') const ptrPillar = this.getObjectByName('ptrPillar')
@ -493,35 +582,42 @@ export default class Cl23dObject extends THREE.Object3D {
} }
// 走 // 走
addTravel(pos: Vector3IF | string, speed : number = 1): Promise<void> { addTravel(logicX: number, logicY: number, speed : number = 1): Promise<void> {
const pos = Model.getPositionByLogicXY(logicX, logicY)
const fromPos = this.position const fromPos = this.position
const toPos = new THREE.Vector3(pos.x, pos.y, pos.z) const toPos = new THREE.Vector3(pos.x, pos.y, pos.z)
const distance = fromPos.distanceTo(toPos) const distance = fromPos.distanceTo(toPos)
const duration = Math.max(1.0, distance / speed) const duration = Math.max(1.0, distance / speed)
return new Promise(resolve => { if (!this.travelAnimation) {
gsap.to(this.position, { return new Promise(resolve => {
x: toPos.x, this.travelAnimation = gsap.to(this.position, {
y: toPos.y, x: toPos.x,
z: toPos.z, y: toPos.y,
duration, z: toPos.z,
ease: 'sine.inOut', duration,
onComplete: resolve ease: 'sine.inOut',
onComplete: ()=>{
this.travelAnimation = null;
resolve()
}
})
}) })
}) } else {
} this.travelAnimation.vars.x = toPos.x
this.travelAnimation.vars.y = toPos.y
handleMessage(data) { this.travelAnimation.vars.z = toPos.z
if (data.id === 10010) { const tt = this.travelAnimation.duration()
const cl2: Cl2Entity = Model.getCl2("10") as Cl2Entity this.travelAnimation.duration(tt + duration)
cl2.addRobotTask(data)
this.fn(cl2)
} }
} }
fn = _.debounce((cl2: Cl2Entity) => { // fn = _.debounce((cl2: Cl2Entity) => {
cl2.taskStartRun() // cl2.taskStartRun()
}, 2000) // }, 2000)
} }

4
src/modules/cl2/Cl2Entity.ts

@ -32,9 +32,9 @@ export default class Cl2Entity extends BaseEntity {
throw new Error('Invalid task'); throw new Error('Invalid task');
} else if (startX === link.X) { } else if (startX === link.X) {
if (startY < link.Y && link.Speed > 0 || startY > link.Y && link.Speed < 0) { if (startY < link.Y && link.Speed > 0 || startY > link.Y && link.Speed < 0) {
moveDirection = 1
} else {
moveDirection = 3 moveDirection = 3
} else {
moveDirection = 1
} }
} else { } else {
if (startX > link.X && link.Speed > 0 || startX < link.X && link.Speed < 0) { if (startX > link.X && link.Speed > 0 || startX < link.X && link.Speed < 0) {

Loading…
Cancel
Save