Forráskód Böngészése

feat: 默认/自定义起终点启动仿真

HeWang 9 hónapja
szülő
commit
9078f025d1
5 módosított fájl, 129 hozzáadás és 31 törlés
  1. 16 0
      electron/main.js
  2. 4 0
      electron/preload.js
  3. 102 29
      src/views/AboutView.vue
  4. 5 1
      src/views/ReportView.vue
  5. 2 1
      vite.config.ts

+ 16 - 0
electron/main.js

@@ -212,6 +212,22 @@ ipcMain.on('start-container', (event, {zip_file_path, image_name, container_name
     }
 });
 
+ipcMain.on('run-simulation', (event, {obstacle_flag, default_start_flag, default_end_flag, start_point, end_point}) => {
+    const command = 'bash /home/cicv/work/pji_desktop/simulation/run_simulation.sh ' + obstacle_flag + ' ' + default_start_flag + ' ' + default_end_flag +
+        ' ' + start_point + ' ' + end_point;
+    console.log('command:', command);
+    exec(command, (error, stdout, stderr) => {
+        if (error) {
+            console.error(`exec error: ${error}`);
+            event.reply('run-simulation-response', { success: false, message: error.message });
+            return;
+        } else {
+            console.log(`stdout: ${stdout}`);
+            console.error(`stderr: ${stderr}`);
+            event.reply('run-simulation-response', { success: true, message: 'Run simulation successfully' });
+        }
+    });
+});
 
 ipcMain.handle('download-file', async (event, { url, fileName, savePath, overwriteFlag }) => {
     try {

+ 4 - 0
electron/preload.js

@@ -34,6 +34,10 @@ contextBridge.exposeInMainWorld('electronAPI', {
         ipcRenderer.send('docker-import', filePath, tag);
     },
     onDockerImportResponse: (callback) => ipcRenderer.on('docker-import-response', callback),
+    runSimulation: (obstacle_flag, default_start_flag, default_end_flag, start_point, end_point) => {
+        ipcRenderer.send('run-simulation', {obstacle_flag, default_start_flag, default_end_flag, start_point, end_point});
+    },
+    onRunSimulationResponse: (callback) => ipcRenderer.on('run-simulation-response', callback),
     generateWorld: (rosbag_path) => {
         // 发送事件到主进程
         ipcRenderer.send('generate-world', {rosbag_path});

+ 102 - 29
src/views/AboutView.vue

@@ -18,14 +18,15 @@
     </el-form-item>
     <el-form-item label="起点设置     :" v-if="!form.isRandom">
       <el-radio-group v-model="form.origin" @change="originChange">
-        <el-radio value="0">默认起点</el-radio>
-        <el-radio value="1">自定义起点</el-radio>
+        <el-radio :value="true">默认起点</el-radio>
+        <el-radio :value="false">自定义起点</el-radio>
+        <span >自定义起点</span>
       </el-radio-group>
     </el-form-item>
     <el-form-item label="终点设置     :" v-if="!form.isRandom">
       <el-radio-group v-model="form.destination" @change="destinationChange">
-        <el-radio value="0">默认终点</el-radio>
-        <el-radio value="1">自定义终点</el-radio>
+        <el-radio :value="true">默认终点</el-radio>
+        <el-radio :value="false">自定义终点</el-radio>
       </el-radio-group>
     </el-form-item>
     <el-form-item label="加载默认障碍物:">
@@ -36,46 +37,75 @@
     </el-form-item>
     <el-form-item label="            ">
       <!--      <el-button type="primary" @click="goToMain">开始执行</el-button>-->
-      <el-button type="primary" @click="dialogVisible = true">开始执行</el-button>
+      <el-button type="primary" @click="runSimulation">开始执行</el-button>
 
       <el-dialog
-          v-model="dialogVisible"
-          title="请输入自定义配置参数"
+          v-model="startDialogVisible"
+          title="请输入自定义起点参数"
           width="300"
           :before-close="handleClose"
           draggable
       >
         <template #footer>
           <div class="dialog-footer">
-            <el-form :model="form" label-width="auto">
+            <el-form :model="startForm" label-width="auto">
               <el-form-item style="margin-bottom: 10px" label="位置 X :">
-                <el-input v-model="form.name" />
+                <el-input v-model="startForm.X" />
               </el-form-item>
               <el-form-item style="margin-bottom: 10px" label="位置 Y :">
-                <el-input v-model="form.name" />
+                <el-input v-model="startForm.Y" />
               </el-form-item>
               <el-form-item style="margin-bottom: 10px" label="位置 Z :">
-                <el-input v-model="form.name" />
+                <el-input v-model="startForm.Z" />
               </el-form-item>
-              <el-form-item style="margin-bottom: 10px" label="姿态 X :">
-                <el-input v-model="form.name" />
+              <el-form-item style="margin-bottom: 10px" label="角度 R :">
+                <el-input v-model="startForm.R" />
               </el-form-item>
-              <el-form-item style="margin-bottom: 10px" label="姿态 Y :">
-                <el-input v-model="form.name" />
+              <el-form-item style="margin-bottom: 10px" label="角度 P :">
+                <el-input v-model="startForm.P" />
               </el-form-item>
-              <el-form-item style="margin-bottom: 10px" label="姿态 Z :">
-                <el-input v-model="form.name" />
+              <el-form-item style="margin-bottom: 10px" label="角度 H :">
+                <el-input v-model="startForm.H" />
               </el-form-item>
-              <el-form-item style="margin-bottom: 10px" label="姿态 W :">
-                <el-input v-model="form.name" />
+            </el-form>
+            <el-button type="primary" @click="startDialogVisible = false">确认</el-button>
+          </div>
+        </template>
+      </el-dialog>
+      <el-dialog
+          v-model="endDialogVisible"
+          title="请输入自定义终点参数"
+          width="300"
+          :before-close="handleClose"
+          draggable
+      >
+        <template #footer>
+          <div class="dialog-footer">
+            <el-form :model="endForm" label-width="auto">
+              <el-form-item style="margin-bottom: 10px" label="位置 X :">
+                <el-input v-model="endForm.X" />
+              </el-form-item>
+              <el-form-item style="margin-bottom: 10px" label="位置 Y :">
+                <el-input v-model="endForm.Y" />
+              </el-form-item>
+              <el-form-item style="margin-bottom: 10px" label="位置 Z :">
+                <el-input v-model="endForm.Z" />
+              </el-form-item>
+              <el-form-item style="margin-bottom: 10px" label="角度 R :">
+                <el-input v-model="endForm.R" />
+              </el-form-item>
+              <el-form-item style="margin-bottom: 10px" label="角度 P :">
+                <el-input v-model="endForm.P" />
+              </el-form-item>
+              <el-form-item style="margin-bottom: 10px" label="角度 H :">
+                <el-input v-model="endForm.H" />
               </el-form-item>
             </el-form>
-<!--            -->
-<!--            <el-button @click="dialogVisible = false">取消</el-button>-->
-            <el-button type="primary" @click="dialogVisible = false">确认</el-button>
+            <el-button type="primary" @click="endDialogVisible = false">确认</el-button>
           </div>
         </template>
       </el-dialog>
+
       <el-button style="margin-left: 10px;" type="primary" @click="goToMain">更换设置并执行</el-button>
     </el-form-item>
     <el-form-item label="            ">
@@ -93,9 +123,11 @@ import {useRouter} from 'vue-router'; // 导入 Vue Router 的 useRouter 钩子
 import {reactive} from 'vue'
 import {ref} from 'vue'
 import {ElMessageBox} from 'element-plus'
+import {ElTable, ElLoading, ElMessage} from "element-plus";
 
 
-const dialogVisible = ref(false)
+const startDialogVisible = ref(false)
+const endDialogVisible = ref(false)
 
 const handleClose = (done: () => void) => {
   done()
@@ -112,20 +144,38 @@ const form = reactive({
   resource: true,
   desc: '',
   isRandom: false,
-  origin: '0',
-  destination: '0',
+  origin: true,
+  destination: true,
   randomCount: ref(1),
 })
 
+const startForm = reactive({
+  X: '',
+  Y: '',
+  Z: '',
+  R: '',
+  P: '',
+  H: '',
+})
+
+const endForm = reactive({
+  X: '',
+  Y: '',
+  Z: '',
+  R: '',
+  P: '',
+  H: '',
+})
+
 const originChange = (value: string) => {
-  if (value == "1") {
-    dialogVisible.value = true
+  if (!value) {
+    startDialogVisible.value = true
   }
 }
 
 const destinationChange = (value: string) => {
-  if (value == "1") {
-    dialogVisible.value = true
+  if (!value) {
+    endDialogVisible.value = true
   }
 }
 
@@ -134,6 +184,29 @@ const onSubmit = () => {
 }
 const router = useRouter();
 
+const runSimulation = () => {
+  // 是否加载默认障碍物
+  let obstacle_flag = form.resource
+  let default_start_flag = form.origin
+  let default_end_flag = form.destination
+  let start_point = form.origin ? '"0 0 0 0 0 0"' : '"' +  startForm.X + ' ' + startForm.Y  + ' ' + startForm.Z + ' ' + startForm.R + ' ' + startForm.P + ' ' + startForm.H + '"'
+  let end_point = form.destination ? '"0 0 0 0 0 0"' : '"' + endForm.X + ' ' + endForm.Y  + ' ' + endForm.Z + ' ' + endForm.R + ' ' + endForm.P + ' ' + endForm.H + '"'
+
+  console.log("end_point=" + end_point)
+  // 开启仿真测试
+  window.electronAPI.runSimulation(obstacle_flag, default_start_flag, default_end_flag, start_point, end_point)
+  // 监听脚本执行状态
+  window.electronAPI.onRunSimulationResponse( (event, result) => {
+    if (result.success) { // 脚本执行成功
+      console.log('Script execution completed successfully.')
+      ElMessage.success("仿真测试成功!");
+    } else { // 脚本执行过程中发生错误
+      console.error('Script execution failed.');
+      ElMessage.error("仿真测试错误!");
+    }
+  })
+}
+
 const goToMain = () => {
   router.push('/')
 }

+ 5 - 1
src/views/ReportView.vue

@@ -196,7 +196,7 @@
             v-model="simulationDialogVisible"
             title="启动仿真测试环境"
             width="400"
-            :before-close="handleClose"
+            :before-close="handleSimulationClose"
             :close-on-click-modal="false"
         >
           <el-steps style="max-width: 600px" :active="simulation_active" finish-status="success">
@@ -286,6 +286,10 @@ const handleWorldClose = (done: () => void) => {
   world_active.value = 0
   done()
 }
+const handleSimulationClose = (done: () => void) => {
+  simulation_active.value = 0
+  done()
+}
 const handleMapClose = (done: () => void) => {
   done()
 }

+ 2 - 1
vite.config.ts

@@ -12,7 +12,8 @@ export default defineConfig({
         rewrite: (path)  => path.replace(/^\/local/,''),
       },
       '/pji': {
-        target:'http://36.110.106.156:11121',
+        // target:'http://36.110.106.156:11121', // 外网地址
+        target:'http://10.14.86.147:9081', // 内网地址
         changeOrigin: true,
         rewrite: (path)  => path.replace(/^\/pji/,''),
       },