mirror of
https://gitee.com/yyz_o/bk_bishe_pi.git
synced 2025-09-07 23:21:26 +00:00
Compare commits
8 Commits
14b3d14170
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c212d4add1 | ||
|
|
ed74171022 | ||
|
|
e5fac173be | ||
|
|
0b8d29917f | ||
|
|
9ba913646c | ||
|
|
efa0d49694 | ||
|
|
a30de465d1 | ||
|
|
95c2e525c4 |
@@ -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 $@
|
||||||
|
|||||||
@@ -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(); //输入目标点
|
||||||
|
/*---以上为目标点输入函数声明---*/
|
||||||
@@ -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;
|
||||||
|
|||||||
26
bot_code_turn/maze_func_cin.cpp
Normal file
26
bot_code_turn/maze_func_cin.cpp
Normal 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;
|
||||||
|
}
|
||||||
@@ -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;
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|
||||||
|
|||||||
@@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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); //移动到指定目标点
|
||||||
|
|||||||
@@ -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
Executable file
BIN
文件/maze2.x
Executable file
Binary file not shown.
147
文件/老师的函数.txt
Normal file
147
文件/老师的函数.txt
Normal 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user