2025.5.14第二次提交,修改完成全部编译时的报错,除部分警告之外。

This commit is contained in:
氧原子
2025-05-14 22:15:27 +08:00
parent 09b6ef759a
commit da75133de4
12 changed files with 115 additions and 151 deletions

View File

@@ -1,30 +1,20 @@
cxx_pi := gccarm cxx := g++sim
cxx_sim := g++sim
file_cpp := $(wildcard *.cpp) file_cpp := $(wildcard *.cpp)
file_o_pi := maze.x file_o := ../eyesim/all_test01/maze.x
file_o_sim := maze.x
$(file_o) : $(file_cpp)
@$(cxx) $^ -o $@
$(file_o_pi) : $(file_cpp) maze : $(file_o)
@$(cxx_pi) $^ -O $@
$(file_o_sim) : $(file_cpp)
@$(cxx_sim) $^ -O $@
mazepi : $(file_o_pi)
mazesim : $(file_o_sim)
clean : clean :
@rm -rf $(file_o_pi) @rm -rf $(file_o)
debug : debug :
@echo $(cxx_pi) @echo $(cxx)
@echo $(cxx_sim)
@echo $(file_cpp) @echo $(file_cpp)
@echo $(file_o_pi) @echo $(file_o)
@echo $(file_o_sim)
.PHONY : mazepi mazesim clean debug .PHONY : maze clean debug

View File

@@ -25,7 +25,7 @@ void flood(int *map, int *copy_map, int *copy_wall); //洪水填充算法
/*---PART4---*/ /*---PART4---*/
/*---以下为路径算法部分涉及到的函数声明---*/ /*---以下为路径算法部分涉及到的函数声明---*/
void build_path(int i, int j, int len, int *path, int *copy_wall); //路径算法 void build_path(int i, int j, int len, int *path, int *map, int *copy_wall); //路径算法
void drive_path(int len, int *path); //移动到目的地 void drive_path(int len, int *path); //移动到目的地
/*---以上为路径算法部分涉及到的函数声明---*/ /*---以上为路径算法部分涉及到的函数声明---*/
@@ -38,8 +38,8 @@ void array_copy_wall(int size_x, int size_y, int *copy_wall); //复制一份wa
/*---PART6---*/ /*---PART6---*/
/*---以下为数组打印部分涉及到的函数声明---*/ /*---以下为数组打印部分涉及到的函数声明---*/
void output_arr2D(int *arr); //打印所有二维数组数组 void output_arr2D(int size_x, int size_y, int *arr); //打印所有二维数组数组
void output_arrwall(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 *arr); //打印path数组
/*---以上为数组打印部分涉及到的函数声明---*/ /*---以上为数组打印部分涉及到的函数声明---*/

View File

@@ -2,33 +2,18 @@
#include<string> #include<string>
#include<vector> #include<vector>
#include"eyebot++.h" #include"eyebot++.h"
#include"maze_func.h"
#include"maze_parameter.h" #include"maze_parameter.h"
#include"maze_func.h"
using namespace std; using namespace std;
/*---将二维数组初始化为-1---*/
void array_negative_one(int *arr)
{
int rows = sizeof(arr) / sizeof(arr[0]); //获取X轴长度
int cols = sizeof(arr[0]) / sizeof(arr[0][0]); //获取Y轴长度
for (i = 0; i < rows; i++)
{
for (j = 0; j < cols; j++)
{
arr[i][j] = -1;
}
}
}
/*---从vector容器复制mark信息到数组函数---*/ /*---从vector容器复制mark信息到数组函数---*/
void array_copy_mark(int size_x, int size_y, int *copy_mark) void array_copy_mark(int size_x, int size_y, int *copy_mark)
{ {
for (i = 0; i < size_x; i++) for (int i = 0; i < size_x; i++)
{ {
for (j = 0; j < size_y; j++) for (int j = 0; j < size_y; j++)
{ {
copy_mark[i][j] = mark[i][j]; copy_mark[i * size_y + j] = mark[i][j];
} }
} }
} }
@@ -36,14 +21,25 @@ void array_copy_mark(int size_x, int size_y, int *copy_mark)
/*---从vector容器复制wall信息到数组函数---*/ /*---从vector容器复制wall信息到数组函数---*/
void array_copy_wall(int size_x, int size_y, int *copy_wall) void array_copy_wall(int size_x, int size_y, int *copy_wall)
{ {
for (i = 0; i <= size_x; i++) for (int i = 0; i <= size_x; i++)
{ {
for (j = 0; j <= size_y; j++) for (int j = 0; j <= size_y; j++)
{ {
for(k = 0; k < 2; k++) for(int k = 0; k < 2; k++)
{ {
copy_wall[i][j][k] = wall[i][j][k]; copy_wall[i * size_y * 2 + j * 2 + k] = wall[i][j][k];
} }
} }
} }
} }
/*---将二维数组初始化为-1---*/
void array_negative_one(int *arr)
{
int size = sizeof(arr) / sizeof(arr[0]); //获取X轴长度
for (int i = 0; i < size; i++)
{
arr[i] = -1;
}
}

View File

@@ -2,8 +2,8 @@
#include<string> #include<string>
#include<vector> #include<vector>
#include"eyebot++.h" #include"eyebot++.h"
#include"maze_func.h"
#include"maze_parameter.h" #include"maze_parameter.h"
#include"maze_func.h"
using namespace std; using namespace std;
@@ -21,7 +21,7 @@ bool check_mark()
bool S_mark; bool S_mark;
bool E_mark; bool E_mark;
if (x>0 && y>0) //情况1 if (x>0 && y>0) //情况1
{ {
if (y == size_y - 1) //N if (y == size_y - 1) //N
{ {
@@ -42,7 +42,7 @@ bool check_mark()
E_mark = mark[x+1][y]; E_mark = mark[x+1][y];
} }
} }
else if (x==0 && y>0) //情况2 else if (x==0 && y>0) //情况2
{ {
if (y == size_y - 1) //N if (y == size_y - 1) //N
{ {
@@ -63,7 +63,7 @@ bool check_mark()
E_mark = mark[x+1][y]; E_mark = mark[x+1][y];
} }
} }
else if (x>0 && y==0) //情况3 else if (x>0 && y==0) //情况3
{ {
if (y == size_y - 1) //N if (y == size_y - 1) //N
{ {
@@ -84,7 +84,7 @@ bool check_mark()
E_mark = mark[x+1][y]; E_mark = mark[x+1][y];
} }
} }
else //(x==0 && y==0) else //(x==0 && y==0)
{ {
if (y == size_y - 1) //N if (y == size_y - 1) //N
{ {
@@ -106,12 +106,12 @@ bool check_mark()
} }
} }
bool N_road = (! wall[x][y+1][0] && N_mark); bool N_road = (!wall[x][y+1][0] && N_mark);
bool W_road = (! wall[x][y][1] && W_mark); bool W_road = (!wall[x][y][1] && W_mark);
bool S_road = (! wall[x][y][0] && S_mark); bool S_road = (!wall[x][y][0] && S_mark);
bool E_road = (! wall[x+1][y][1] && E_mark); bool E_road = (!wall[x+1][y][1] && E_mark);
if (N_road && W_road && S_road && E_road) if (N_road && W_road && S_road && E_road)
{ {
check = true; check = true;
} }
@@ -126,51 +126,51 @@ void maze_entry(int x, int y, int dir, int open)
switch (maze_dir) switch (maze_dir)
{ {
case 0: //0表示北(上),表示(xy+1)坐标单元格的下方墙壁信息 case 0: //0表示北(上),表示(xy+1)坐标单元格的下方墙壁信息
if (y == mark[0].size() - 1 && open) //检测是否超出容器范围,如果超出,则扩大容器:对每一个内层尾插数据 if (y == mark[0].size() - 1 && open) //检测是否超出容器范围,如果超出,则扩大容器:对每一个内层尾插数据
{ {
for (i = 0; i < mark.size() - 1; i++) for (int i = 0; i < mark.size() - 1; i++)
{ {
mark[i].emplace_back(0); mark[i].emplace_back(0);
} }
for (i = 0; i < wall.size() - 1; i++) for (int i = 0; i < wall.size() - 1; i++)
{ {
wall[i].emplace_back(vector<int>(2,0)); wall[i].emplace_back(vector<int>(2,0));
} }
} }
wall[x][y+1][0] = ! open; wall[x][y+1][0] = !open;
break; break;
case 1: //1表示西(左),表示(xy)坐标单元格的左侧墙壁信息 case 1: //1表示西(左),表示(xy)坐标单元格的左侧墙壁信息
if (x == 0 && open) //检测是否超出容器范围,如果超出,则扩大容器:头插一个内层 if (x == 0 && open) //检测是否超出容器范围,如果超出,则扩大容器:头插一个内层
{ {
mark.emplace(mark.begin(), mark[0].size(), 0); mark.emplace(mark.begin(), mark[0].size(), 0);
wall.emplace(wall.begin(), wall[0].size(), vector<int>(2,0)); wall.emplace(wall.begin(), wall[0].size(), vector<int>(2,0));
} }
wall[x][y][1] = ! open; wall[x][y][1] = !open;
break; break;
case 2: //2表示南(下),表示(xy)坐标单元格的下侧墙壁信息 case 2: //2表示南(下),表示(xy)坐标单元格的下侧墙壁信息
if (y == 0 && open) //检测是否超出容器范围,如果超出,则扩大容器:对每一个内层头插数据 if (y == 0 && open) //检测是否超出容器范围,如果超出,则扩大容器:对每一个内层头插数据
{ {
for (i = 0; i < mark.size() - 1; i++) for (int i = 0; i < mark.size() - 1; i++)
{ {
mark[i].emplace(mark[i].begin(), 0); mark[i].emplace(mark[i].begin(), 0);
} }
for (i = 0; i < wall.size() - 1; i++) for (int i = 0; i < wall.size() - 1; i++)
{ {
wall[i].emplace(wall[i].begin(), vector<int>(2,0)); wall[i].emplace(wall[i].begin(), vector<int>(2,0));
} }
} }
wall[x][y][0] = ! open; wall[x][y][0] = !open;
break; break;
case 3: //3表示东(右),表示(x+1y)坐标单元格的左侧墙壁信息 case 3: //3表示东(右),表示(x+1y)坐标单元格的左侧墙壁信息
if (x == mark.size() - 1 && open) //检测是否超出容器范围,如果超出,则扩大容器:尾插一个内层 if (x == (mark.size() - 1) && open) //检测是否超出容器范围,如果超出,则扩大容器:尾插一个内层
{ {
mark.emplace_back(mark[0].size(), 0); mark.emplace_back(mark[0].size(), 0);
wall.emplace_back(wall[0].size(), vector<int>(2,0)); wall.emplace_back(wall[0].size(), vector<int>(2,0));
} }
wall[x+1][y][1] = ! open; wall[x+1][y][1] = !open;
break; break;
} }
} }
@@ -246,21 +246,21 @@ void explore()
} }
old_dir = rob_dir; old_dir = rob_dir;
if (F_open && unmarked(rob_x, rob_y, old_dir)) //如果前方有通路且前方单元格未被探索 if (F_open && unmarked(rob_x, rob_y, old_dir)) //如果前方有通路且前方单元格未被探索
{ {
go_to(old_dir); //向前移动一格 go_to(old_dir); //向前移动一格
explore(); //进行递归在完成所有可到达单元格的访问前一直循环在explore中 explore(); //进行递归在完成所有可到达单元格的访问前一直循环在explore中
go_to(old_dir + 2); //返回到移动前的单元格 go_to(old_dir + 2); //返回到移动前的单元格
} }
if (L_open && unmarked(rob_x, rob_y, old_dir + 1)) //如果左侧有通路且前方单元格未被探索 if (L_open && unmarked(rob_x, rob_y, old_dir + 1)) //如果左侧有通路且前方单元格未被探索
{ {
go_to(old_dir + 1); //向左移动一格 go_to(old_dir + 1); //向左移动一格
explore(); //进行递归在完成所有可到达单元格的访问前一直循环在explore中 explore(); //进行递归在完成所有可到达单元格的访问前一直循环在explore中
go_to(old_dir - 1); //返回到移动前的单元格 go_to(old_dir - 1); //返回到移动前的单元格
} }
if (R_open && unmarked(rob_x, rob_y, old_dir - 1)) //如果右侧有通路且前方单元格未被探索 if (R_open && unmarked(rob_x, rob_y, old_dir - 1)) //如果右侧有通路且前方单元格未被探索
{ {
go_to(old_dir - 1); //向右移动一格 go_to(old_dir - 1); //向右移动一格
explore(); //进行递归在完成所有可到达单元格的访问前一直循环在explore中 explore(); //进行递归在完成所有可到达单元格的访问前一直循环在explore中

View File

@@ -2,8 +2,8 @@
#include<string> #include<string>
#include<vector> #include<vector>
#include"eyebot++.h" #include"eyebot++.h"
#include"maze_func.h"
#include"maze_parameter.h" #include"maze_parameter.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_map, int *copy_wall)
@@ -11,49 +11,49 @@ void flood(int *map, int *copy_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] = 0; map[0] = 0;
copy_map[0][0] = 0; copy_map[0] = 0;
do do
{ {
for (i = 0; i < size_x; i++) for (int i = 0; i < size_x; i++)
{ {
for (j = 0; j < size_y; j++) for (int j = 0; j < size_y; j++)
{ {
if (! map[i][j] == -1) if (map[(i * size_y) + j] != -1)
{ {
if (i > 0) if (i > 0)
{ {
if (! copy_wall[i][j][1] && map[i-1][j] = -1) //左边格子 if (!copy_wall[(i * size_y * 2) + (j * 2) + 1] && map[((i-1) * size_y) + j] == -1) //左边格子
{ {
copy_map[i-1][j] = map[i][j] + 1; copy_map[((i-1) * size_y) + j] = map[(i * size_y) + j] + 1;
num++; num++;
} }
} }
if (i < size_x - 1) if (i < size_x - 1)
{ {
if (! copy_wall[i+1][j][1] && map[i+1][j] = -1) //右边格子 if (!copy_wall[((i+1) * size_y * 2) + (j * 2) + 1] && map[((i+1) * size_y) + j] == -1) //右边格子
{ {
copy_map[i+1][j] = map[i][j] + 1; copy_map[((i+1) * size_y) + j] = map[(i * size_y) + j] + 1;
num++; num++;
} }
} }
if (j > 0) if (j > 0)
{ {
if (! copy_wall[i][j][0] && map[i][j-1] = -1) if (!copy_wall[(i * size_y * 2) + (j * 2) + 0] && map[(i *size_y) + (j-1)] == -1)
{ {
copy_map[i][j-1] = map[i][j] + 1; copy_map[(i * size_y) + (j-1)] = map[(i * size_y) + j] + 1;
num++; num++;
} }
} }
if (j < size_y - 1) if (j < size_y - 1)
{ {
if (! copy_wall[i][j+1][0] && map[i][j+1] = -1) if (!copy_wall[(i * size_y * 2) + ((j+1) * 2) + 0] && map[(i * size_y) + (j+1)] == -1)
{ {
copy_map[i][j+1] = map[i][j] + 1; copy_map[(i * size_y) + (j+1)] = map[(i * size_y) + j] + 1;
num++; num++;
} }
} }
@@ -61,12 +61,12 @@ void flood(int *map, int *copy_map, int *copy_wall)
} }
} }
for (i = 0; i < size_x; i++) for (int i = 0; i < size_x; i++)
{ {
for (j = 0; j < size_y; j++) for (int j = 0; j < size_y; j++)
{ {
map[i][j] = copy_map[i][j]; map[(i * size_y) + j] = copy_map[(i * size_y) + j];
} }
} }
} while (map[target_x][target_y] == -1 && num < (size_x * size_y)) } while (map[(target_x * size_y) + target_y] == -1 && num < (size_x * size_y));
} }

View File

@@ -2,8 +2,8 @@
#include<string> #include<string>
#include<vector> #include<vector>
#include"eyebot++.h" #include"eyebot++.h"
#include"maze_func.h"
#include"maze_parameter.h" #include"maze_parameter.h"
#include"maze_func.h"
using namespace std; using namespace std;
/*---X坐标更新---*/ /*---X坐标更新---*/

View File

@@ -2,39 +2,35 @@
#include<string> #include<string>
#include<vector> #include<vector>
#include"eyebot++.h" #include"eyebot++.h"
#include"maze_func.h"
#include"maze_parameter.h" #include"maze_parameter.h"
#include"maze_func.h"
using namespace std; using namespace std;
/*---打印数组检查错误---*/ /*---打印数组检查错误---*/
/*---打印数组mark,map,copy_map等二维数组所用的函数---*/ /*---打印数组mark,map,copy_map等二维数组所用的函数---*/
void output_arr2D(int *arr) void output_arr2D(int size_x, int size_y, int *arr)
{ {
int rows = sizeof(arr) / sizeof(arr[0]);
int cols = sizeof(arr[0]) / sizeof(arr[0][0]);
for (int i = cols - 1; i >= 0; i--) for (int i = size_y - 1; i >= 0; i--)
{ {
for (int j = 0; j < rows; j++) for (int j = 0; j < size_x; j++)
{ {
cout << arr[j][i] << " "; cout << arr[(j * size_y) + i] << " ";
} }
cout << endl; cout << endl;
} }
} }
/*---打印数组wall---*/ /*---打印数组wall---*/
void output_arrwall(int *arr) void output_arrwall(int size_x, int size_y, int *arr)
{ {
int rows = sizeof(arr) / sizeof(arr[0]);
int cols = sizeof(arr[0]) / sizeof(arr[0][0]);
for (int i = cols - 1; i >= 0; i--) for (int i = size_y - 1; i >= 0; i--)
{ {
for (int j = 0; j < rows; j++) for (int j = 0; j < size_x; j++)
{ {
if (arr[j][i][1] == 1) if (arr[(j * size_y * 2) + (i * 2) + 1] == 1)
{ {
cout << "|" ; cout << "|" ;
} }
@@ -43,7 +39,7 @@ void output_arrwall(int *arr)
cout << " " ; cout << " " ;
} }
if (arr[j][i][0] == 1) if (arr[(j * size_y * 2) + (i * 2) + 0] == 1)
{ {
cout << "_" ; cout << "_" ;
} }
@@ -61,7 +57,7 @@ void output_arrpath(int *arr)
{ {
int size = sizeof(arr) / sizeof(arr[0]); int size = sizeof(arr) / sizeof(arr[0]);
for (i = 0; i < size; i++) for (int i = 0; i < size; i++)
{ {
cout << arr[i] << " "; cout << arr[i] << " ";
} }

View File

@@ -2,35 +2,34 @@
#include<string> #include<string>
#include<vector> #include<vector>
#include"eyebot++.h" #include"eyebot++.h"
#include"maze_func.h"
#include"maze_parameter.h" #include"maze_parameter.h"
#include"maze_func.h"
using namespace std; using namespace std;
/*---解迷宫路径到path数组函数---*/ /*---解迷宫路径到path数组函数---*/
void build_path(int i, int j, int len, int *path, int *copy_wall) void build_path(int i, int j, int len, int *path, int *map, int *copy_wall)
{ {
int k;
int size_x = mark.size(); int size_x = mark.size();
int size_y = mark[0].size(); int size_y = mark[0].size();
for (k = len -1; k >= 0; k--) for (int k = len -1; k >= 0; k--)
{ {
if (i > 0 && ! copy_wall[i][j][1] && map[i-1][j] == k) //前一个单位的东面是当前格,即当前格子的左侧为上一个格子 if (i > 0 && !copy_wall[(i * size_y * 2) + (j * 2) + 1] && map[((i-1) * size_y) + j] == k) //前一个单位的东面是当前格,即当前格子的左侧为上一个格子
{ {
i--; i--;
path[k] = 3; path[k] = 3;
} }
else if (i < size_x - 1 && ! copy_wall[i+1][j][1] && map[i+1][j] == k) //前一个单位的西面是当前格,即当前格子的右侧为上一个格子 else if (i < size_x - 1 && !copy_wall[((i+1) * size_y * 2) + (j * 2) + 1] && map[((i+1) * size_y) + j] == k) //前一个单位的西面是当前格,即当前格子的右侧为上一个格子
{ {
i++; i++;
path[k] = 1; path[k] = 1;
} }
else if(j > 0 && ! copy_wall[i][j][0] && map[i][j-1] == k) //前一个单位的北面是当前格,即当前格子的下侧为上一个格子 else if(j > 0 && !copy_wall[(i * size_y * 2) + (j * 2) + 0] && map[(i * size_y) + (j-1)] == k) //前一个单位的北面是当前格,即当前格子的下侧为上一个格子
{ {
j--; j--;
path[k] = 0; path[k] = 0;
} }
else if (j < size_y - 1 && ! copy_wall[i][j+1][0] && map[i][j+1] == k) //前一个单位的南面是当前格,即当前格子的上侧为上一个格子 else if (j < size_y - 1 && !copy_wall[(i * size_y * 2) + ((j+1) * 2) + 0] && map[(i * size_y) + (j+1)] == k) //前一个单位的南面是当前格,即当前格子的上侧为上一个格子
{ {
j++; j++;
path[k] = 2; path[k] = 2;
@@ -45,7 +44,7 @@ void build_path(int i, int j, int len, int *path, int *copy_wall)
/*---通过path数组移动到目标点函数---*/ /*---通过path数组移动到目标点函数---*/
void drive_path(int len, int *path) void drive_path(int len, int *path)
{ {
for(i = 0; i < len; i++) for(int i = 0; i < len; i++)
{ {
go_to(path[i]); go_to(path[i]);
} }

View File

@@ -2,8 +2,8 @@
#include<string> #include<string>
#include<vector> #include<vector>
#include"eyebot++.h" #include"eyebot++.h"
#include"maze_func.h"
#include"maze_parameter.h" #include"maze_parameter.h"
#include"maze_func.h"
using namespace std; using namespace std;

View File

@@ -2,8 +2,8 @@
#include<string> #include<string>
#include<vector> #include<vector>
#include"eyebot++.h" #include"eyebot++.h"
#include"maze_func.h"
#include"maze_parameter.h" #include"maze_parameter.h"
#include"maze_func.h"
using namespace std; using namespace std;
@@ -15,29 +15,29 @@ int main()
const int mazesize_x = mark.size(); //获取探索结束之后的迷宫的X轴长度 const int mazesize_x = mark.size(); //获取探索结束之后的迷宫的X轴长度
const int mazesize_y = mark[0].size(); //获取探索结束之后的迷宫的Y轴长度 const int mazesize_y = mark[0].size(); //获取探索结束之后的迷宫的Y轴长度
int copy_mark[mazesize_x][mazesize_y] = {}; //复制一份mark数组便于后续频繁读取提升性能并初始化为0 int copy_mark[mazesize_x * mazesize_y] = {}; //复制一份mark数组并转换为一维数组,便于后续频繁读取提升性能并初始化为0
int copy_wall[mazesize_x + 1][mazesize_y + 1] = {}; //复制一份wall数组便于后续频繁读取提升性能并初始化为0 int copy_wall[(mazesize_x + 1) * (mazesize_y + 1) * 2] = {}; //复制一份wall数组并转换为一维数组,便于后续频繁读取提升性能并初始化为0
array_copy_wall(mazesize_x, mazesize_y, copy_mark); //复制一份mark数组便于后续频繁读取提升性能 array_copy_mark(mazesize_x, mazesize_y, copy_mark); //复制一份mark数组并转换为一维数组,便于后续频繁读取提升性能
array_copy_wall(mazesize_x, mazesize_y, copy_wall); //复制一份wall数组便于后续频繁读取提升性能 array_copy_wall(mazesize_x, mazesize_y, copy_wall); //复制一份wall数组并转换为一维数组,便于后续频繁读取提升性能
output_arr2D(copy_mark); //打印地图mark信息 output_arr2D(mazesize_x, mazesize_y, copy_mark); //打印地图mark信息
output_arrwall(copy_wall); //打印墙壁wall信息 output_arrwall(mazesize_x + 1, mazesize_y + 1, 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 int copy_map[mazesize_x * mazesize_y] = {}; //创建copy复制地图并初始化为0
array_negative_one(map); //将map数组初始化为-1 array_negative_one(map); //将map数组初始化为-1
array_negative_one(copy_map); //将copy_map数组初始化为-1 array_negative_one(copy_map); //将copy_map数组初始化为-1
flood(map, copy_map, copy_mark, copy_wall); //洪水填充算法 flood(map, copy_map, copy_wall); //洪水填充算法
output_arr2D(map); //打印map的数组信息 output_arr2D(mazesize_x, mazesize_y, map); //打印map的数组信息
const int len = map[target_x][target_y]; //迷宫的终点(人为确定) const int len = map[(target_x * mazesize_y) + target_y]; //迷宫的终点(人为确定)
int path[len] = {}; //创建最短路径结果地图并初始化为0 int path[len] = {}; //创建最短路径结果地图并初始化为0
build_path(target_x, target_y, len, path, copy_wall); //构建出最短路径path数组 build_path(target_x, target_y, len, path, map, copy_wall); //构建出最短路径path数组
drive_path(len, path); //移动到指定目标点 drive_path(len, path); //移动到指定目标点
output_arrpath(path); //打印path数组信息及小车每一步的行驶方向 output_arrpath(path); //打印path数组信息及小车每一步的行驶方向

View File

@@ -2,8 +2,8 @@
#include<string> #include<string>
#include<vector> #include<vector>
#include"eyebot++.h" #include"eyebot++.h"
#include"maze_func.h"
#include"maze_parameter.h" #include"maze_parameter.h"
#include"maze_func.h"
using namespace std; using namespace std;
/*---定义数据---*/ /*---定义数据---*/
@@ -16,19 +16,6 @@ const int DIST_wall = 130 ; //与墙壁的距离
vector<vector<int>> mark(1,vector<int>(1,0)); //定义mark容器二维容器容器初始为1行1列 1=为已访问 vector<vector<int>> mark(1,vector<int>(1,0)); //定义mark容器二维容器容器初始为1行1列 1=为已访问
vector<vector<vector<int>>> wall(1,vector<vector<int>>(1,vector<int>(2,0))); //定义wall容器三维容器容器初始为1行1列且每个格子内带有2个墙壁信息 1=墙壁0=通路 vector<vector<vector<int>>> wall(1,vector<vector<int>>(1,vector<int>(2,0))); //定义wall容器三维容器容器初始为1行1列且每个格子内带有2个墙壁信息 1=墙壁0=通路
/*---数组类---*/
// int mark[4][4] = {}; //1=为已访问
// int wall[5][5][2] = {}; //1=墙壁0=通路
// int map[4][4] = {}; //最短路径求解地图
// int copy_map[4][4] = {}; //copy复制地图
// int path[4][4] = {}; //最短路径结果地图
// int mark[mazesize_x][mazesize_y] = {}; //1=为已访问
// int wall[mazesize_x + 1][mazesize_y + 1][2] = {}; //1=墙壁0=通路
// wall[1][1][0] = 1; //定义迷宫的初始小车背后为墙
// int map[mazesize_x][mazesize_y]; //最短路径求解地图
// int copy_map[mazesize_x][mazesize_y]; //copy复制地图
// int path[mazesize_x][mazesize_y]; //最短路径结果地图
/*---机器人坐标---*/ /*---机器人坐标---*/
int rob_x0 = 0; //机器人起点X坐标 int rob_x0 = 0; //机器人起点X坐标
int rob_y0 = 0; //机器人起点Y坐标 int rob_y0 = 0; //机器人起点Y坐标
@@ -42,8 +29,10 @@ int rob_dir = 0; //机器人当前的朝向初始为0
/*---PID算法---*/ /*---PID算法---*/
const float Kp = 1, Ki = 0, Kd = 0.5; //定义PID的参数 const float Kp = 1, Ki = 0, Kd = 0.5; //定义PID的参数
float Kpid; //定义PID计算后输出的倍率 float Kpid; //定义PID计算后输出的倍率
float Kpid_speed;
const int Kpid_base = 2, speed = 24; //定义基本角速度和速度 const int Kpid_base = 2, speed = 24; //定义基本角速度和速度
const int speed2 = 0.75*speed; //快到目的地时减速 const int speed2 = 0.75*speed; //快到目的地时减速
int speed1;
int err, err_old, err_sum, err_diff; //定义误差,上一次误差,积分误差,微分误差 int err, err_old, err_sum, err_diff; //定义误差,上一次误差,积分误差,微分误差
const int eI_max = 20; //定义积分限幅 const int eI_max = 20; //定义积分限幅

View File

@@ -9,15 +9,8 @@ extern const int DIST_wall; //与墙壁的距离
/*---声明全局变量---*/ /*---声明全局变量---*/
/*---声明全局容器---*/ /*---声明全局容器---*/
extern vector<vector<int>> mark; //声明mark容器二维容器 extern std::vector<std::vector<int>> mark; //声明mark容器二维容器
extern vector<vector<vector<int>>> wall; //声明wall容器三维容器 extern std::vector<std::vector<std::vector<int>>> wall; //声明wall容器三维容器
/*---声明数组类---*/
// extern int mark[6][6]; //迷宫单元格是否访问数组
// extern int wall[7][7][2]; //迷宫墙壁信息数组
// extern int map[6][6]; //迷宫地图数组
// extern int copy_map[6][6]; //迷宫地图复制数组
// extern int path[6][6]; //迷宫路径数组
/*---声明机器人坐标---*/ /*---声明机器人坐标---*/
extern int rob_x0; //机器人起点X坐标 extern int rob_x0; //机器人起点X坐标
@@ -35,7 +28,8 @@ extern const float Kp, Ki, Kd; //声明PID的参数
extern float Kpid; //定义PID计算后输出的倍率 extern float Kpid; //定义PID计算后输出的倍率
extern float Kpid_speed; //定义计算后的速度 extern float Kpid_speed; //定义计算后的速度
extern const int Kpid_base, speed; //定义基本角速度和速度 extern const int Kpid_base, speed; //定义基本角速度和速度
extern const int speed1,speed2; //快到目的地时减速 extern const int speed2; //快到目的地时减速
extern int speed1;
extern int err, err_old, err_sum, err_diff; //定义误差,上一次误差,积分误差,微分误差 extern int err, err_old, err_sum, err_diff; //定义误差,上一次误差,积分误差,微分误差
extern const int eI_max; //定义积分限幅 extern const int eI_max; //定义积分限幅