Browse Source

Logs 推送问题

master
修宁 5 months ago
parent
commit
8b9e594c42
  1. 7
      src/components/YvSrcEditorInner.vue
  2. 7
      src/core/manager/BackendMessageReceiver.ts
  3. 4
      src/core/script/ModelManager.ts
  4. 48
      src/editor/widgets/logger/LoggerView.vue
  5. 21
      src/editor/widgets/monitor/MonitorView.vue
  6. 14
      src/editor/widgets/server/ServerView.vue
  7. 98
      src/modules/amr/ptr/PtrObject.ts
  8. 9
      src/types/Model.d.ts

7
src/components/YvSrcEditorInner.vue

@ -150,6 +150,13 @@ export default {
() => null () => null
) )
}, },
clear(){
if (this.editor) {
this.editor.setValue('')
this.$emit('update:modelValue', '')
this.$emit('change', '')
}
},
init() { init() {
// this.editor.updateOptions(option); // this.editor.updateOptions(option);
this.editor.setValue(this.modelValue ?? '') this.editor.setValue(this.modelValue ?? '')

7
src/core/manager/BackendMessageReceiver.ts

@ -349,7 +349,7 @@ export default class BackendMessageReceiver {
private handleDeviceAlive(message: MqttMessage, handler: BackendMessageHandler) { private handleDeviceAlive(message: MqttMessage, handler: BackendMessageHandler) {
try { try {
const data = JSON.parse(message.payload.toString()) const data = JSON.parse(message.payload.toString())
handler('DeviceAlive', message.topic, _.cloneDeep(data)) handler('DeviceAlive', message.topic, data)
// 处理设备存活状态 // 处理设备存活状态
} catch (error) { } catch (error) {
@ -359,8 +359,7 @@ export default class BackendMessageReceiver {
private handleLogMonitor(message: MqttMessage, handler: BackendMessageHandler) { private handleLogMonitor(message: MqttMessage, handler: BackendMessageHandler) {
try { try {
const data = JSON.parse(message.payload.toString()) handler('Logs', message.topic, message.payload.toString())
handler('Logs', message.topic, _.cloneDeep(data))
// 处理日志更新 // 处理日志更新
} catch (error) { } catch (error) {
@ -371,7 +370,7 @@ export default class BackendMessageReceiver {
private handleAlarmMonitor(message: MqttMessage, handler: BackendMessageHandler) { private handleAlarmMonitor(message: MqttMessage, handler: BackendMessageHandler) {
try { try {
const data = JSON.parse(message.payload.toString()) const data = JSON.parse(message.payload.toString())
handler('Alarm', message.topic, _.cloneDeep(data)) handler('Alarm', message.topic, data)
} catch (error) { } catch (error) {
console.error('Error parsing alarm data:', error) console.error('Error parsing alarm data:', error)

4
src/core/script/ModelManager.ts

@ -77,6 +77,10 @@ export default class ModelManager implements IControls, Model {
return item return item
} }
find3D(id: string): any {
return this.viewport.entityManager.findObjectById(id)
}
getPositionByEntityId(entityId: string): THREE.Vector3 { getPositionByEntityId(entityId: string): THREE.Vector3 {
const item = this.viewport.entityManager.findItemById(entityId) const item = this.viewport.entityManager.findItemById(entityId)
const matrix = getMatrixFromTf(item.tf) const matrix = getMatrixFromTf(item.tf)

48
src/editor/widgets/logger/LoggerView.vue

@ -11,12 +11,13 @@
</span> </span>
</div> </div>
<div class="calc-bottom-panel"> <div class="calc-bottom-panel">
<YvSrcEditor ref="jsEditor" language="typescript" v-model="currentLog" /> <YvSrcEditor ref="jsEditor" language="typescript" />
</div> </div>
</template> </template>
<script> <script>
import IWidgets from '../IWidgets.js' import IWidgets from '../IWidgets.js'
import YvSrcEditor from '@/components/YvSrcEditor.vue' import YvSrcEditor from '@/components/YvSrcEditor.vue'
import { worldModel } from '@/core/manager/WorldModel.js'
export default { export default {
name: 'LoggerView', name: 'LoggerView',
@ -24,8 +25,53 @@ export default {
mixins: [IWidgets], mixins: [IWidgets],
data() { data() {
return { return {
stopSubscribe: [],
searchKeyword: '' searchKeyword: ''
} }
},
mounted() {
window['LoggerView'] = this
},
unmounted() {
window['LoggerView'] = null
this.undescribe()
},
methods: {
onServerLogMessage() {
},
async refreshData() {
this.$refs.jsEditor.clear()
},
async subscribe() {
await this.refreshData()
//
this.stopSubscribe.push(
worldModel.backendMessageReceiver.subscribe('Logs', this.onServerLogMessage.bind(this))
)
},
undescribe() {
//
for (const stopFn of this.stopSubscribe) {
stopFn()
}
this.stopSubscribe = []
}
},
watch: {
isActivated: {
handler(value) {
if (value) {
this.subscribe()
}
//
// else {
// this.undescribe()
// }
},
immediate: true
}
} }
} }
</script> </script>

21
src/editor/widgets/monitor/MonitorView.vue

@ -4,12 +4,16 @@
<el-button size="small" :icon="renderIcon('Refresh')" @click="refreshData" <el-button size="small" :icon="renderIcon('Refresh')" @click="refreshData"
style="margin-left: 5px;" style="margin-left: 5px;"
/> />
<el-button size="small" :icon="renderIcon('fa Simplybuilt')" @click="simBootAll"
style="margin-left: 2px;" link
v-if="worldModelState.runState.isRunning && worldModelState.runState.isVirtual"
>全上线
</el-button>
<el-input v-model="searchKeyword" size="small" style="width: 240px" placeholder="Search"> <el-input v-model="searchKeyword" size="small" style="width: 240px" placeholder="Search">
<template #prefix> <template #prefix>
<component :is="renderIcon('element Search')"></component> <component :is="renderIcon('element Search')"></component>
</template> </template>
</el-input> </el-input>
<span class="close" @click="closeMe"> <span class="close" @click="closeMe">
<component :is="renderIcon('element Close')" /> <component :is="renderIcon('element Close')" />
</span> </span>
@ -93,6 +97,18 @@ export default {
this.undescribe() this.undescribe()
}, },
methods: { 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) { copyDeviceId(deviceInfo) {
navigator.clipboard.writeText(deviceInfo.id).then(() => { navigator.clipboard.writeText(deviceInfo.id).then(() => {
system.msg('设备ID已复制到剪贴板', 'success') system.msg('设备ID已复制到剪贴板', 'success')
@ -234,6 +250,9 @@ export default {
}, },
idle() { idle() {
return this.deviceList.filter(device => device.mode === 'AMR_FREE_MODE').length return this.deviceList.filter(device => device.mode === 'AMR_FREE_MODE').length
},
worldModelState() {
return worldModel.state
} }
}, },
watch: { watch: {

14
src/editor/widgets/server/ServerView.vue

@ -108,6 +108,13 @@ export default {
worldModel.backendMessageReceiver.subscribe('ServerState', this.onServerStateMessage.bind(this)) worldModel.backendMessageReceiver.subscribe('ServerState', this.onServerStateMessage.bind(this))
) )
}, },
undescribe() {
//
for (const stopFn of this.stopSubscribe) {
stopFn()
}
this.stopSubscribe = []
},
async refreshData() { async refreshData() {
this.serverList = [] this.serverList = []
this.isLoading = true this.isLoading = true
@ -123,13 +130,6 @@ export default {
this.isLoading = false this.isLoading = false
} }
}, },
undescribe() {
//
for (const stopFn of this.stopSubscribe) {
stopFn()
}
this.stopSubscribe = []
},
// //
getSystemTagClass(system) { getSystemTagClass(system) {

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

@ -1,4 +1,4 @@
import * as THREE from "three"; import * as THREE from 'three'
import { import {
AmrErrorCode, AmrErrorCode,
AmrMsg, AmrMsg10010, AmrMsg10050, AmrMsg10060, AmrMsg10110, AmrMsg10120, AmrMsg20010, AmrMsg, AmrMsg10010, AmrMsg10050, AmrMsg10060, AmrMsg10110, AmrMsg10120, AmrMsg20010,
@ -14,14 +14,14 @@ import {
TaskModeChangeData, TaskModeChangeData,
TaskStatusChangeData, TaskStatusChangeData,
TaskTypeChangeData TaskTypeChangeData
} from "@/core/manager/amr/AmrMessageDefine"; } from '@/core/manager/amr/AmrMessageDefine'
import {worldModel} from "@/core/manager/WorldModel"; import { worldModel } from '@/core/manager/WorldModel'
import Viewport from "@/core/engine/Viewport"; import Viewport from '@/core/engine/Viewport'
import {Euler} from "three/src/math/Euler"; import { Euler } from 'three/src/math/Euler'
import gsap from "gsap"; 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 { export interface StepTask {
SeqNo: number; SeqNo: number;
@ -55,8 +55,8 @@ export default class PtrObject extends THREE.Object3D {
public clock = new THREE.Clock() public clock = new THREE.Clock()
override AGVModel = "" override AGVModel = ''
override AGVFnModel = "" override AGVFnModel = ''
private boxBody: any = null private boxBody: any = null
private __toPos: THREE.Vector3 = null private __toPos: THREE.Vector3 = null
@ -159,7 +159,7 @@ export default class PtrObject extends THREE.Object3D {
private mqRetryTimeCount: number = 0 private mqRetryTimeCount: number = 0
constructor(item: ItemJson, viewport: Viewport) { constructor(item: ItemJson, viewport: Viewport) {
super(); super()
this.viewport = viewport this.viewport = viewport
this.item = item this.item = item
this.vehicleId = parseInt(item.id) this.vehicleId = parseInt(item.id)
@ -194,23 +194,23 @@ export default class PtrObject extends THREE.Object3D {
// 开机 // 开机
boot() { boot() {
this.bootTime = Date.now(); this.bootTime = Date.now()
this.computeLogicXYAndDirection(); 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 mass = 10
const localInertia = new this.viewport.ammoModel.btVector3(0, 0, 0) const localInertia = new this.viewport.ammoModel.btVector3(0, 0, 0)
boxShape.calculateLocalInertia(mass, localInertia) boxShape.calculateLocalInertia(mass, localInertia)
const boxTransform = new this.viewport.ammoModel.btTransform(); const boxTransform = new this.viewport.ammoModel.btTransform()
boxTransform.setIdentity(); boxTransform.setIdentity()
boxTransform.setOrigin(new this.viewport.ammoModel.btVector3(this.position.x, this.position.y, this.position.z)); 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) const rbInfo = new this.viewport.ammoModel.btRigidBodyConstructionInfo(mass, boxMotionState, boxShape, localInertia)
this.boxBody = new this.viewport.ammoModel.btRigidBody(rbInfo); this.boxBody = new this.viewport.ammoModel.btRigidBody(rbInfo)
this.viewport.physicsWorld.addRigidBody(this.boxBody); this.viewport.physicsWorld.addRigidBody(this.boxBody)
if (!worldModel.state.runState.isVirtual) { if (!worldModel.state.runState.isVirtual) {
return return
@ -321,7 +321,7 @@ export default class PtrObject extends THREE.Object3D {
ActuatorsData: [ ActuatorsData: [
{ {
MechNo: 1, MechNo: 1,
Name: "Mech1", Name: 'Mech1',
PickMode: this.PickMode PickMode: this.PickMode
} }
] ]
@ -349,10 +349,10 @@ export default class PtrObject extends THREE.Object3D {
content.CurLogicX = this.currentLogicX content.CurLogicX = this.currentLogicX
content.CurLogicY = this.currentLogicY content.CurLogicY = this.currentLogicY
content.CurOrientation = this.currentOrientation content.CurOrientation = this.currentOrientation
content.CurX = this.position.x; content.CurX = this.position.x
content.CurY = this.position.z; content.CurY = this.position.z
content.X = this.position.x; content.X = this.position.x
content.Y = this.position.z; content.Y = this.position.z
const m20060 = new AmrMsg<AmrMsg20060>(content) const m20060 = new AmrMsg<AmrMsg20060>(content)
this.sendMessage(m20060) this.sendMessage(m20060)
} }
@ -460,27 +460,27 @@ export default class PtrObject extends THREE.Object3D {
} }
const ddra = Math.PI / 180 const ddra = Math.PI / 180
if (ra >= Math.PI * 2 - ddra || ra <= ddra) { 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) { } 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) { } 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) { } 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
} }
const pointItem = Model.getItemByXYZ(this.position.x, this.position.y, this.position.z) const pointItem = Model.getItemByXYZ(this.position.x, this.position.y, this.position.z)
if (!pointItem || !pointItem.logicX || !pointItem.logicY) { if (!pointItem || !pointItem.logicX || !pointItem.logicY) {
this.currentLogicX = -1; this.currentLogicX = -1
this.currentLogicY = -1; this.currentLogicY = -1
} else { } else {
this.currentLogicX = pointItem.logicX; this.currentLogicX = pointItem.logicX
this.currentLogicY = pointItem.logicY; this.currentLogicY = pointItem.logicY
} }
this.currentOrientation = this.getAmrOrientation(this.rotation.y) this.currentOrientation = this.getAmrOrientation(this.rotation.y)
} }
@ -494,7 +494,7 @@ export default class PtrObject extends THREE.Object3D {
} else { } else {
currentStepTask = { currentStepTask = {
SeqNo: 0, SeqNo: 0,
StepTaskType: "MOVE", StepTaskType: 'MOVE',
OperationType: 0, OperationType: 0,
PickMode: 0, PickMode: 0,
X: this.currentLogicX, X: this.currentLogicX,
@ -549,7 +549,7 @@ export default class PtrObject extends THREE.Object3D {
if (endDirection != currentStepTask.EndDirection) { if (endDirection != currentStepTask.EndDirection) {
const stepTask: StepTask = { const stepTask: StepTask = {
SeqNo: data.SeqNo, SeqNo: data.SeqNo,
StepTaskType: "ROTATION", StepTaskType: 'ROTATION',
OperationType: 0, OperationType: 0,
PickMode: 0, PickMode: 0,
X: prevLink.X, X: prevLink.X,
@ -567,7 +567,7 @@ export default class PtrObject extends THREE.Object3D {
const stepTask: StepTask = { const stepTask: StepTask = {
SeqNo: data.SeqNo, SeqNo: data.SeqNo,
StepTaskType: link.Speed > 0 ? "MOVE" : "MOVE_BACKWARD", StepTaskType: link.Speed > 0 ? 'MOVE' : 'MOVE_BACKWARD',
OperationType: 0, OperationType: 0,
PickMode: 0, PickMode: 0,
X: link.X, 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)) { || (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
} else if (data.OperationType == 3 && data.ChargeDirection >= 0 && data.ChargeDirection <= 3) { } else if (data.OperationType == 3 && data.ChargeDirection >= 0 && data.ChargeDirection <= 3) {
endDirection = data.ChargeDirection endDirection = data.ChargeDirection
} else if (data.OperationType == 4 && data.GoodsSlotDirection >= 0 && data.GoodsSlotDirection <= 3) { } 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 = { const stepTask: StepTask = {
SeqNo: data.SeqNo, SeqNo: data.SeqNo,
StepTaskType: "ROTATION", StepTaskType: 'ROTATION',
OperationType: 0, OperationType: 0,
PickMode: 0, PickMode: 0,
X: data.EndX, X: data.EndX,
@ -629,7 +629,7 @@ export default class PtrObject extends THREE.Object3D {
const stepTask: StepTask = { const stepTask: StepTask = {
SeqNo: data.SeqNo, SeqNo: data.SeqNo,
StepTaskType: "CHARGE", StepTaskType: 'CHARGE',
OperationType: 3, OperationType: 3,
PickMode: 0, PickMode: 0,
X: data.EndX, X: data.EndX,
@ -647,7 +647,7 @@ export default class PtrObject extends THREE.Object3D {
const stepTask: StepTask = { const stepTask: StepTask = {
SeqNo: data.SeqNo, SeqNo: data.SeqNo,
StepTaskType: data.PickMode == 1 ? "LOAD" : "UNLOAD", StepTaskType: data.PickMode == 1 ? 'LOAD' : 'UNLOAD',
OperationType: 4, OperationType: 4,
PickMode: data.PickMode, PickMode: data.PickMode,
X: data.EndX, X: data.EndX,
@ -676,7 +676,7 @@ export default class PtrObject extends THREE.Object3D {
while (this.currentStepTaskList.length > 0) { while (this.currentStepTaskList.length > 0) {
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 && 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)) {
@ -693,13 +693,13 @@ export default class PtrObject extends THREE.Object3D {
this.runningStepTask = stepTask this.runningStepTask = stepTask
this.currentStepTaskList.shift() this.currentStepTaskList.shift()
this.runningStepTaskList.push(stepTask) 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) this.addTravel(stepTask.X, stepTask.Y, stepTask.Speed / 1000)
} else if (stepTask.StepTaskType == "ROTATION") { } else if (stepTask.StepTaskType == 'ROTATION') {
this.addRotation(stepTask.EndDirection) this.addRotation(stepTask.EndDirection)
} else if (stepTask.StepTaskType == "LOAD") { } else if (stepTask.StepTaskType == 'LOAD') {
this.addLoad(stepTask.GoodsSlotHeight / 1000) this.addLoad(stepTask.GoodsSlotHeight / 1000)
} else if (stepTask.StepTaskType == "UNLOAD") { } else if (stepTask.StepTaskType == 'UNLOAD') {
this.addUnload(stepTask.GoodsSlotHeight / 1000) 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<void> { addTravel(logicX: number, logicY: number, speed: number = 1): Promise<void> {
this.OperationType = 0 this.OperationType = 0
this.PickMode = 0 this.PickMode = 0
const pos = Model.getPositionByLogicXY(logicX, logicY) const pos = Model.getPositionByLogicXY(logicX, logicY)
@ -791,13 +790,13 @@ export default class PtrObject extends THREE.Object3D {
// 运动参数 // 运动参数
const accelForce = speed > 0 ? 4 : (-4) const accelForce = speed > 0 ? 4 : (-4)
let currentPhase = 'accelerate'; let currentPhase = 'accelerate'
if (this.viewport.registerPhysicsUpdateCallBack.has(this.item.id)) { if (this.viewport.registerPhysicsUpdateCallBack.has(this.item.id)) {
return null return null
} }
this.travelAnimation = "asd" this.travelAnimation = 'asd'
const force = new this.viewport.ammoModel.btVector3(accelForce, 0, 0) const force = new this.viewport.ammoModel.btVector3(accelForce, 0, 0)
this.viewport.registerPhysicsUpdateCallBack.set(this.item.id, () => { this.viewport.registerPhysicsUpdateCallBack.set(this.item.id, () => {
@ -826,7 +825,8 @@ export default class PtrObject extends THREE.Object3D {
this.travelAnimation = null this.travelAnimation = null
this.onActionCompleted() this.onActionCompleted()
} if (distance <= stopDistance) { }
if (distance <= stopDistance) {
currentPhase = 'decelerate' currentPhase = 'decelerate'
} }
// 运动阶段控制 // 运动阶段控制

9
src/types/Model.d.ts

@ -3,12 +3,18 @@
*/ */
declare interface Model { declare interface Model {
/** /**
* ID * ID
* @param entityId ID * @param entityId ID
*/ */
find(entityId: string): ItemJson find(entityId: string): ItemJson
/** /**
* ID
* @param id
*/
find3D(id: string): any
/**
* ID * ID
*/ */
getPositionByEntityId(entityId: string): Vector3IF getPositionByEntityId(entityId: string): Vector3IF
@ -87,6 +93,7 @@ declare interface Model {
*/ */
multiSelectedEntityIds: string[] multiSelectedEntityIds: string[]
} }
/** /**

Loading…
Cancel
Save