2025.5.16第一次提交,彻底完成eyesim平台完整仿真,就差实机控制了。

This commit is contained in:
氧原子
2025-05-16 14:05:08 +08:00
parent a81594bf68
commit b933cdfc1b
9 changed files with 14 additions and 43 deletions

View File

@@ -20,7 +20,7 @@ void go_to(int dir); //行驶到指定单元格
/*---PART3---*/ /*---PART3---*/
/*---以下为洪水填充算法部分涉及到的函数声明---*/ /*---以下为洪水填充算法部分涉及到的函数声明---*/
void flood(int *map, int *copy_map, int *copy_wall); //洪水填充算法 void flood(int *map, int *copy_wall); //洪水填充算法
/*---以上为洪水填充算法部分涉及到的函数声明---*/ /*---以上为洪水填充算法部分涉及到的函数声明---*/
/*---PART4---*/ /*---PART4---*/
@@ -31,7 +31,7 @@ void drive_path(int len, int *path); //移动到目的地
/*---PART5---*/ /*---PART5---*/
/*---以下为数组构建部分涉及到的函数声明---*/ /*---以下为数组构建部分涉及到的函数声明---*/
void array_negative_one(int *arr); //将数组初始化为-1 void array_negative_one(int size, int *arr); //将数组初始化为-1
void array_copy_mark(int size_x, int size_y, int *copy_mark); //复制一份mark数组便于后续频繁读取提升性能 void array_copy_mark(int size_x, int size_y, int *copy_mark); //复制一份mark数组便于后续频繁读取提升性能
void array_copy_wall(int size_x, int size_y, int *copy_wall); //复制一份wall数组便于后续频繁读取提升性能 void array_copy_wall(int size_x, int size_y, int *copy_wall); //复制一份wall数组便于后续频繁读取提升性能
/*---以上为数组构建部分涉及到的函数声明---*/ /*---以上为数组构建部分涉及到的函数声明---*/
@@ -40,6 +40,6 @@ void array_copy_wall(int size_x, int size_y, int *copy_wall); //复制一份wa
/*---以下为数组打印部分涉及到的函数声明---*/ /*---以下为数组打印部分涉及到的函数声明---*/
void output_arr2D(int size_x, int size_y, int *arr); //打印所有二维数组数组 void output_arr2D(int size_x, int size_y, int *arr); //打印所有二维数组数组
void output_arrwall(int size_x, int size_y, int *arr); //打印wall数组 void output_arrwall(int size_x, int size_y, int *arr); //打印wall数组
void output_arrpath(int *arr); //打印path数组 void output_arrpath(int size, int *arr); //打印path数组
/*---以上为数组打印部分涉及到的函数声明---*/ /*---以上为数组打印部分涉及到的函数声明---*/

View File

@@ -27,17 +27,14 @@ void array_copy_wall(int size_x, int size_y, int *copy_wall)
{ {
for(int k = 0; k < 2; k++) for(int k = 0; k < 2; k++)
{ {
copy_wall[i * (size_y + 1) * 2 + j * 2 + k] = wall[i][j][k]; copy_wall[i * (size_y + 1) * 2 + j * 2 + k] = wall[i][j][k]; //注释k = 0记录的是单元格下方的数据1记录的是单元格左边的数据所以转为一维数组后i*...+j*...+k,k=1为左侧数据k=0为下方墙壁。
} }
} }
} }
} }
/*---将二维数组初始化为-1---*/ void array_negative_one(int size, int *arr) //将数组初始化为-1
void array_negative_one(int *arr)
{ {
int size = sizeof(arr) / sizeof(arr[0]); //获取X轴长度
for (int i = 0; i < size; i++) for (int i = 0; i < size; i++)
{ {
arr[i] = -1; arr[i] = -1;

View File

@@ -1,19 +1,17 @@
#include<iostream> #include<iostream>
#include<string> #include<string>
#include<vector> #include<vector>
#include<cstddef>
#include"eyebot++.h" #include"eyebot++.h"
#include"maze_parameter.h" #include"maze_parameter.h"
#include"maze_func.h" #include"maze_func.h"
using namespace std; using namespace std;
void flood(int *map, int *copy_map, int *copy_wall) void flood(int *map, int *copy_wall)
{ {
int num = 0; int num = 0;
int size_x = mark.size(); int size_x = mark.size();
int size_y = mark[0].size(); int size_y = mark[0].size();
map[0] = 0; map[0] = 0;
copy_map[0] = 0;
do do
{ {
@@ -61,13 +59,5 @@ void flood(int *map, int *copy_map, int *copy_wall)
} }
} }
} }
} while (map[((target_x - 1) * size_y) + (target_y - 1)] == -1 && num < (size_x * size_y));
// for (int i = 0; i < size_x; i++)
// {
// for (int j = 0; j < size_y; j++)
// {
// map[(i * size_y) + j] = copy_map[(i * size_y) + j];
// }
// }
} while (map[(target_x * size_y) + target_y] == -1 && num < (size_x * size_y));
} }

View File

@@ -1,6 +1,5 @@
#include<iostream> #include<iostream>
#include<string> #include<string>
#include<vector>
#include"eyebot++.h" #include"eyebot++.h"
#include"maze_parameter.h" #include"maze_parameter.h"
#include"maze_func.h" #include"maze_func.h"

View File

@@ -1,8 +1,6 @@
#include<iostream> #include<iostream>
#include<string> #include<string>
#include<vector>
#include"eyebot++.h" #include"eyebot++.h"
#include"maze_parameter.h"
#include"maze_func.h" #include"maze_func.h"
using namespace std; using namespace std;
@@ -11,7 +9,6 @@ using namespace std;
/*---打印数组mark,map,copy_map等二维数组所用的函数---*/ /*---打印数组mark,map,copy_map等二维数组所用的函数---*/
void output_arr2D(int size_x, int size_y, int *arr) void output_arr2D(int size_x, int size_y, int *arr)
{ {
for (int i = size_y - 1; i >= 0; i--) for (int i = size_y - 1; i >= 0; i--)
{ {
for (int j = 0; j < size_x; j++) for (int j = 0; j < size_x; j++)
@@ -25,7 +22,6 @@ void output_arr2D(int size_x, int size_y, int *arr)
/*---打印数组wall---*/ /*---打印数组wall---*/
void output_arrwall(int size_x, int size_y, int *arr) void output_arrwall(int size_x, int size_y, int *arr)
{ {
for (int i = size_y; i >= 0; i--) for (int i = size_y; i >= 0; i--)
{ {
for (int j = 0; j <= size_x; j++) for (int j = 0; j <= size_x; j++)
@@ -52,11 +48,8 @@ void output_arrwall(int size_x, int size_y, int *arr)
} }
} }
/*---打印数组path---*/ void output_arrpath(int size, int *arr)
void output_arrpath(int *arr)
{ {
int size = sizeof(arr) / sizeof(arr[0]);
for (int i = 0; i < size; i++) for (int i = 0; i < size; i++)
{ {
cout << arr[i] << " "; cout << arr[i] << " ";

View File

@@ -1,7 +1,6 @@
#include<iostream> #include<iostream>
#include<string> #include<string>
#include<vector> #include<vector>
#include<cstddef>
#include"eyebot++.h" #include"eyebot++.h"
#include"maze_parameter.h" #include"maze_parameter.h"
#include"maze_func.h" #include"maze_func.h"

View File

@@ -1,6 +1,5 @@
#include<iostream> #include<iostream>
#include<string> #include<string>
#include<vector>
#include"eyebot++.h" #include"eyebot++.h"
#include"maze_parameter.h" #include"maze_parameter.h"
#include"maze_func.h" #include"maze_func.h"

View File

@@ -1,7 +1,6 @@
#include<iostream> #include<iostream>
#include<string> #include<string>
#include<vector> #include<vector>
#include<cstddef>
#include"eyebot++.h" #include"eyebot++.h"
#include"maze_parameter.h" #include"maze_parameter.h"
#include"maze_func.h" #include"maze_func.h"
@@ -27,21 +26,17 @@ int main()
output_arrwall(mazesize_x, mazesize_y, copy_wall); //打印墙壁wall信息 output_arrwall(mazesize_x, mazesize_y, copy_wall); //打印墙壁wall信息
int map[mazesize_x * mazesize_y] = {}; //创建最短路径求解地图并初始化为0 int map[mazesize_x * mazesize_y] = {}; //创建最短路径求解地图并初始化为0
int copy_map[mazesize_x * mazesize_y] = {}; //创建copy复制地图并初始化为0 array_negative_one(mazesize_x * mazesize_y, map); //将map数组初始化为-1
array_negative_one(map); //将map数组初始化为-1
array_negative_one(copy_map); //将copy_map数组初始化为-1
flood(map, copy_map, copy_wall); //洪水填充算法
flood(map, copy_wall); //洪水填充算法
output_arr2D(mazesize_x, mazesize_y, map); //打印map的数组信息 output_arr2D(mazesize_x, mazesize_y, map); //打印map的数组信息
const int len = map[(target_x * mazesize_y) + target_y]; //迷宫的终点(人为确定) const int len = map[((target_x - 1) * mazesize_y) + (target_y -1)]; //迷宫的终点(人为确定)
int path[len] = {}; //创建最短路径结果地图并初始化为0 int path[len] = {}; //创建最短路径结果地图并初始化为0
build_path(target_x, target_y, len, path, map, copy_wall); //构建出最短路径path数组 build_path(target_x - 1, target_y - 1, len, path, map, copy_wall); //构建出最短路径path数组
drive_path(len, path); //移动到指定目标点 drive_path(len, path); //移动到指定目标点
output_arrpath(path); //打印path数组信息及小车每一步的行驶方向 output_arrpath(len, path); //打印path数组信息及小车每一步的行驶方向
} }

View File

@@ -1,10 +1,9 @@
#include<iostream> #include<iostream>
#include<string> #include<string>
#include<vector> #include<vector>
#include<cstddef>
#include"eyebot++.h" #include"eyebot++.h"
#include"maze_parameter.h" #include"maze_parameter.h"
#include"maze_func.h" // #include"maze_func.h"
using namespace std; using namespace std;
/*---定义数据---*/ /*---定义数据---*/