Compare commits

...

8 Commits

Author SHA1 Message Date
氧原子
c212d4add1 Merge branch 'master' of https://codehub.devcloud.cn-east-3.huaweicloud.com/2e32552ddb1a4a45b5e8c3c0e5705b48/bk_bishe_pi 2025-06-12 15:47:45 +08:00
氧原子
ed74171022 更新推送仓库地址 2025-06-12 15:46:50 +08:00
氧原子
e5fac173be 2025.5.31第二次提交 2025-05-31 23:34:28 +08:00
氧原子
0b8d29917f 2025.5.31第一次提交优化代码结构,头文件等 2025-05-31 23:28:45 +08:00
Ñõԭ×Ó
9ba913646c 25.5.29第二次提交 2025-05-29 12:11:35 +08:00
Ñõԭ×Ó
efa0d49694 2025.5.29第二次 2025-05-29 11:04:41 +08:00
氧原子
a30de465d1 2025.5.29第一次提交 2025-05-29 10:59:54 +08:00
氧原子
95c2e525c4 从别人那拿一份hdt文件。 2025-05-15 20:16:02 +08:00
14 changed files with 200 additions and 15 deletions

View File

@@ -1,8 +1,10 @@
cxx := gccarm cxx := gccarm
#~ cxx := g++sim
file_cpp := $(wildcard *.cpp) file_cpp := $(wildcard *.cpp)
file_o := /home/pi/usr/maze2.x file_o := /home/pi/usr/maze2.x
#~ file_o := ../maze2.x
$(file_o) : $(file_cpp) $(file_o) : $(file_cpp)
@$(cxx) $^ -o $@ @$(cxx) $^ -o $@

View File

@@ -45,3 +45,6 @@ void output_arrwall(int size_x, int size_y, int *arr); //打印wall数组
void output_arrpath(int size, int *arr); //打印path数组 void output_arrpath(int size, int *arr); //打印path数组
/*---以上为数组打印部分涉及到的函数声明---*/ /*---以上为数组打印部分涉及到的函数声明---*/
/*---以下为目标点输入函数声明---*/
void cin_targey(); //输入目标点
/*---以上为目标点输入函数声明---*/

View File

@@ -1,7 +1,6 @@
#include<iostream> #include<iostream>
#include<string> #include<string>
#include<vector> #include<vector>
#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;

View File

@@ -0,0 +1,26 @@
#include<iostream>
#include<string>
#include<vector>
#include"maze_parameter.h"
#include"maze_func.h"
using namespace std;
void cin_targey()
{
int size_x = mark.size();
int size_y = mark[0].size();
int num = 0;
do
{
if (!num)
{
cout << "您输入的目标点超出迷宫范围,请重新输入" << endl;
}
cout << "请输入目标点的X,Y坐标值 用空格隔开并回车" << endl;
cin >> target_x >> target_y;
cout << endl;
num++;
} while (target_x <= size_x && target_y <= size_y);
cout << endl;
}

View File

@@ -2,6 +2,7 @@
#include<string> #include<string>
#include<vector> #include<vector>
#include<cstddef> #include<cstddef>
#include<cstdlib>
#include"eyebot++.h" #include"eyebot++.h"
#include"maze_parameter.h" #include"maze_parameter.h"
#include"maze_func.h" #include"maze_func.h"
@@ -117,6 +118,7 @@ void maze_entry(int x, int y, int dir, int open)
else else
{ {
cout << "error: mark or wall empty" << endl; cout << "error: mark or wall empty" << endl;
exit(1);
} }
} }
wall[x][y+1][0] = !open; wall[x][y+1][0] = !open;
@@ -141,6 +143,7 @@ void maze_entry(int x, int y, int dir, int open)
else else
{ {
cout << "error: mark or wall empty" << endl; cout << "error: mark or wall empty" << endl;
exit(1);
} }
} }
wall[x][y][1] = !open; wall[x][y][1] = !open;
@@ -165,6 +168,7 @@ void maze_entry(int x, int y, int dir, int open)
else else
{ {
cout << "error: mark or wall empty" << endl; cout << "error: mark or wall empty" << endl;
exit(1);
} }
} }
wall[x][y][0] = !open; wall[x][y][0] = !open;
@@ -181,6 +185,7 @@ void maze_entry(int x, int y, int dir, int open)
else else
{ {
cout << "error: mark or wall empty" << endl; cout << "error: mark or wall empty" << endl;
exit(1);
} }
} }
wall[x+1][y][1] = !open; wall[x+1][y][1] = !open;

View File

@@ -1,7 +1,6 @@
#include<iostream> #include<iostream>
#include<string> #include<string>
#include<vector> #include<vector>
#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;

View File

@@ -1,6 +1,5 @@
#include<iostream> #include<iostream>
#include<string> #include<string>
#include"eyebot++.h"
#include"maze_func.h" #include"maze_func.h"
using namespace std; using namespace std;
@@ -57,5 +56,5 @@ void output_arrpath(int size, int *arr)
cout << arr[i] << " "; cout << arr[i] << " ";
} }
cout << endl; cout << endl;
cout << endl; cout << endl;
} }

View File

@@ -1,7 +1,7 @@
#include<iostream> #include<iostream>
#include<string> #include<string>
#include<vector> #include<vector>
#include"eyebot++.h" #include<cstdlib>
#include"maze_parameter.h" #include"maze_parameter.h"
#include"maze_func.h" #include"maze_func.h"
using namespace std; using namespace std;
@@ -36,7 +36,8 @@ void build_path(int i, int j, int len, int *path, int *map, int *copy_wall)
} }
else else
{ {
LCDPrintf("ERROR"); cout << "error" << endl;
exit(1);
} }
} }
} }

View File

@@ -16,7 +16,7 @@ void BOTturn(int turn)
{ {
MOTORDriveRaw(1,20); MOTORDriveRaw(1,20);
MOTORDriveRaw(2,-18); MOTORDriveRaw(2,-18);
} while (abs(ENCODERRead(2)) < 250); } while (abs(ENCODERRead(2)) < 240);
MOTORDriveRaw(1,0); MOTORDriveRaw(1,0);
MOTORDriveRaw(2,0); MOTORDriveRaw(2,0);
} }
@@ -28,7 +28,7 @@ void BOTturn(int turn)
{ {
MOTORDriveRaw(1,-20); MOTORDriveRaw(1,-20);
MOTORDriveRaw(2,18); MOTORDriveRaw(2,18);
} while (abs(ENCODERRead(2)) < 250); } while (abs(ENCODERRead(2)) < 240);
MOTORDriveRaw(1,0); MOTORDriveRaw(1,0);
MOTORDriveRaw(2,0); MOTORDriveRaw(2,0);
} }
@@ -41,7 +41,7 @@ void BOTturn(int turn)
MOTORDriveRaw(1,20); MOTORDriveRaw(1,20);
MOTORDriveRaw(2,-18); MOTORDriveRaw(2,-18);
} while (abs(ENCODERRead(2)) < 580); } while (abs(ENCODERRead(2)) < 570);
MOTORDriveRaw(1,0); MOTORDriveRaw(1,0);
MOTORDriveRaw(2,0); MOTORDriveRaw(2,0);
} }

View File

@@ -1,6 +1,7 @@
#include<iostream> #include<iostream>
#include<string> #include<string>
#include<vector> #include<vector>
#include<cstdlib>
#include"eyebot++.h" #include"eyebot++.h"
#include"maze_parameter.h" #include"maze_parameter.h"
#include"maze_func.h" #include"maze_func.h"
@@ -26,19 +27,20 @@ int main()
array_copy_wall(mazesize_x, mazesize_y, copy_wall); //复制一份wall数组并转换为一维数组便于后续频繁读取提升性能 array_copy_wall(mazesize_x, mazesize_y, copy_wall); //复制一份wall数组并转换为一维数组便于后续频繁读取提升性能
cout << "访问数组打印:" << endl; cout << "访问数组打印:" << endl;
cout << endl;
output_arr2D(mazesize_x, mazesize_y, copy_mark); //打印地图mark信息 output_arr2D(mazesize_x, mazesize_y, copy_mark); //打印地图mark信息
cout << "地图打印:" << endl; cout << "地图打印:" << endl;
cout << endl;
output_arrwall(mazesize_x, mazesize_y, copy_wall); //打印墙壁wall信息 output_arrwall(mazesize_x, mazesize_y, copy_wall); //打印墙壁wall信息
cout << "请输入目标点的X,Y坐标值 用空格隔开并回车" << endl; cin_targey(); //输入目标点,带超界检测
cin >> target_x >> target_y;
cout << endl;
int map[mazesize_x * mazesize_y] = {}; //创建最短路径求解地图并初始化为0 int map[mazesize_x * mazesize_y] = {}; //创建最短路径求解地图并初始化为0
array_negative_one(mazesize_x * mazesize_y, map); //将map数组初始化为-1 array_negative_one(mazesize_x * mazesize_y, map); //将map数组初始化为-1
flood(map, copy_wall); //洪水填充算法 flood(map, copy_wall); //洪水填充算法
cout << "路径打印:" << endl; cout << "路径打印:" << endl;
cout << endl;
output_arr2D(mazesize_x, mazesize_y, map); //打印map的数组信息 output_arr2D(mazesize_x, mazesize_y, map); //打印map的数组信息
const int len = map[((target_x - 1) * mazesize_y) + (target_y -1)]; //迷宫的终点(人为确定) const int len = map[((target_x - 1) * mazesize_y) + (target_y -1)]; //迷宫的终点(人为确定)
@@ -47,6 +49,7 @@ int main()
build_path(target_x - 1, target_y - 1, len, path, map, copy_wall); //构建出最短路径path数组 build_path(target_x - 1, target_y - 1, len, path, map, copy_wall); //构建出最短路径path数组
cout << "移动指令打印:" << endl; cout << "移动指令打印:" << endl;
cout << endl;
output_arrpath(len, path); //打印path数组信息及小车每一步的行驶方向 output_arrpath(len, path); //打印path数组信息及小车每一步的行驶方向
drive_path(len, path); //移动到指定目标点 drive_path(len, path); //移动到指定目标点

View File

@@ -1,7 +1,6 @@
#include<iostream> #include<iostream>
#include<string> #include<string>
#include<vector> #include<vector>
#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;
@@ -9,8 +8,10 @@ using namespace std;
/*---定义数据---*/ /*---定义数据---*/
/*---定义全局常量---*/ /*---定义全局常量---*/
const int DIST_cell = 240; //单元格长度 const int DIST_cell = 240; //单元格长度
const int DIST_move = 330; //移动的单元格距离 const int DIST_move = 320; //移动的单元格距离
const int DIST_wall_F = 95; //与墙壁的距离 //~ const int DIST_move = 330; //移动的单元格距离
const int DIST_wall_F = 100; //与墙壁的距离
//~ const int DIST_wall_F = 95; //与墙壁的距离
//~ const int DIST_wall_RL = 90; //与左右墙壁的距离 1 //~ const int DIST_wall_RL = 90; //与左右墙壁的距离 1
const int DIST_wall_RL = 87; //与左右墙壁的距离 const int DIST_wall_RL = 87; //与左右墙壁的距离

BIN
maze2.x Normal file

Binary file not shown.

BIN
文件/maze2.x Executable file

Binary file not shown.

147
文件/老师的函数.txt Normal file
View File

@@ -0,0 +1,147 @@
#include "eyebot.h"
#define SAFE 200
static int v_des1,v_des2;
float Kp=0.25;
float Ki=0.06;
float Klink=0.05;
TIMER t1;
void picontroller()
{
int enc_new1,v_act1,r_mot1,e_func1;
int enc_new2,v_act2,r_mot2,e_func2;
static int enc_old1,enc_old2;
static int r_old1=0,e_old1=0;
static int r_old2=0,e_old2=0;
enc_new1=ENCODERRead(1);
enc_new2=ENCODERRead(2);
v_act1=enc_new1-enc_old1;
v_act2=enc_new2-enc_old2;
e_func1=v_des1-v_act1;
e_func2=v_des2-v_act2;
r_mot1=r_old1+Kp*(e_func1-e_old1)+Ki*(e_func1+e_old1)/2+Klink*(abs(enc_new1)-abs(enc_new2));
r_mot2=r_old2+Kp*(e_func2-e_old2)+Ki*(e_func2+e_old2)/2-Klink*(abs(enc_new1)-abs(enc_new2));
if(v_des1>0&&v_des2>0)
{
if(r_mot1>35)r_mot1=35;
else if(r_mot1<0) r_mot1=0;
if(r_mot2>35)r_mot2=35;
else if(r_mot2<0) r_mot2=0;
}
else if(v_des1>0&&v_des2<0)
{
if(r_mot1>35)r_mot1=35;
else if(r_mot1<0) r_mot1=0;
if(r_mot2>0)r_mot2=0;
else if(r_mot2<-35) r_mot2=-35;
}
else if(v_des1<0&&v_des2>0)
{
if(r_mot1>0)r_mot1=0;
else if(r_mot1<-35) r_mot1=-35;
if(r_mot2>35)r_mot2=35;
else if(r_mot2<0) r_mot2=0;
}
else if(v_des1==0&&v_des2==0)
{
r_mot1=0;
r_mot2=0;
v_act1=0;
v_act2=0;
enc_old1=0;
r_old1=0;
enc_old2=0;
r_old2=0;
e_func1=0;
e_func2=0;
ENCODERReset(1);
ENCODERReset(2);
}
MOTORDrive(1,r_mot1);
MOTORDrive(2,r_mot2);
enc_old1=enc_new1;
r_old1=r_mot1;
e_old1=e_func1;
enc_old2=enc_new2;
r_old2=r_mot2;
e_old2=e_func2;
printf("%d %d %d %d\n",r_mot1,r_mot2,enc_old1,enc_old2);
}
void VWSpeed(int v1,int v2)
{
v_des1=v1;
v_des2=v2;
}
void drive()
{
do
{
if(PSDGetRaw(PSD_LEFT)<SAFE)
VWSpeed(100,90);
else VWSpeed(90,100);
OSWait(80);
}while(PSDGetRaw(PSD_FRONT)>SAFE);
VWSpeed(0,0);
OSWait(1000);
}
void turn()
{
VWSpeed(50,-50);
while(PSDGetRaw(PSD_FRONT)<400) OSWait(80);
VWSpeed(0,0);
OSWait(1000);
}
int main()
{
LCDMenu("STOP","2","3","END");
ENCODERReset(1);
ENCODERReset(2);
PSDGetRaw(PSD_FRONT);
PSDGetRaw(PSD_LEFT);
t1=OSAttachTimer(100,picontroller);
while(KEYRead()!=KEY1)
{ drive();
turn();
}
OSDetachTimer(t1);
AUBeep();
while(KEYRead()!=KEY4)
{
MOTORDrive(1,0);
MOTORDrive(2,0);
}
return(0);
}