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 {
this.onTaskComplete = onTaskComplete
if (!this.isRunning) {
debugger
this.isRunning = true
this.executeNextTask()
}

11
src/core/manager/EntityManager.ts

@ -518,6 +518,17 @@ export default class EntityManager {
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[] {
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())
return position
}
getItemByXYZ(x: number, y: number, z: number): ItemJson | undefined {
const item = this.viewport.entityManager.findItemByLogicXYZ(x, y, z)
return item
}
dispose() {
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 {
// 创建ptr的底座
@ -323,8 +334,33 @@ export default class Cl23dObject extends THREE.Object3D {
private static ptrPillarGeometry: 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) {
super();
console.log("time", this.clock.getElapsedTime());
this.item = item;
if (!Cl23dObject.ptrPedestalGeometry) {
Cl23dObject.ptrPedestalGeometry = Cl23dObject.createPtrPedestal()
}
@ -398,7 +434,7 @@ export default class Cl23dObject extends THREE.Object3D {
client.on('message', (topic, msg) => {
console.log(`[${topic}] ${msg}`);
const a = JSON.parse(msg.toString());
const a: Cl2Task = JSON.parse(msg.toString());
this.handleMessage(a);
});
@ -409,9 +445,62 @@ export default class Cl23dObject extends THREE.Object3D {
} catch (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> {
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 toPos = new THREE.Vector3(pos.x, pos.y, pos.z)
const distance = fromPos.distanceTo(toPos)
const duration = Math.max(1.0, distance / speed)
return new Promise(resolve => {
gsap.to(this.position, {
x: toPos.x,
y: toPos.y,
z: toPos.z,
duration,
ease: 'sine.inOut',
onComplete: resolve
if (!this.travelAnimation) {
return new Promise(resolve => {
this.travelAnimation = gsap.to(this.position, {
x: toPos.x,
y: toPos.y,
z: toPos.z,
duration,
ease: 'sine.inOut',
onComplete: ()=>{
this.travelAnimation = null;
resolve()
}
})
})
})
}
handleMessage(data) {
if (data.id === 10010) {
const cl2: Cl2Entity = Model.getCl2("10") as Cl2Entity
cl2.addRobotTask(data)
this.fn(cl2)
} else {
this.travelAnimation.vars.x = toPos.x
this.travelAnimation.vars.y = toPos.y
this.travelAnimation.vars.z = toPos.z
const tt = this.travelAnimation.duration()
this.travelAnimation.duration(tt + duration)
}
}
fn = _.debounce((cl2: Cl2Entity) => {
cl2.taskStartRun()
}, 2000)
// fn = _.debounce((cl2: Cl2Entity) => {
// cl2.taskStartRun()
// }, 2000)
}

4
src/modules/cl2/Cl2Entity.ts

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

Loading…
Cancel
Save