2025.5.18第一次提交,包括17号和今天上午对实机的调试

This commit is contained in:
Ñõԭ×Ó
2025-05-18 11:35:02 +08:00
parent 47a4473330
commit df42d6ce7f
14 changed files with 232 additions and 103 deletions

View File

@@ -4,26 +4,21 @@
#include"PID.h"
using namespace std;
float Kp = 0.79, Ki = 0.009, Kd = 0.14; //定义PID的参数
float Kp = 0.815, Ki = 0.0083, Kd = 0.167; //定义PID的参数
float Kpid;
int Kpid_speed;
const int speed_l = 17;
const int speed_l = 18;
const int speed_r = speed_l - 2;
const int speed_err = 2;
const float Kpid_base = 1;
// const int speed2 = 0.75*speed;
// int speed1;
//int speed2 = speed;
/*---定义全局变量---*/
int err, err_old, err_sum, err_diff; //定义误差,上一次误差,积分误差,微分误差
const int eI_max = 200;
/*---定义全局常量---*/
/*---定义全局常量---*/
// const int DIST_cell = 300 ;
// const int DIST_wall = 100 ;
const int DIST_cell = 310;
const int DIST_wall_f = 120;
const int DIST_wall_f = 75;
const int DIST_wall_rl = 90;
/*---全局各种变量与常量定义完成---*/
@@ -126,7 +121,7 @@ void PIDStraight()
/*---打印输出PSD数值---*/
cout << "PSD L:" << L_PSD << " R:" << R_PSD << " F:" << F_PSD << " " ;
/*---打印结束---*/
if (20<L_PSD && L_PSD<180 && 50<R_PSD && R_PSD<180) //如果两侧都有墙的情况
if (20<L_PSD && L_PSD<180 && 20<R_PSD && R_PSD<180) //如果两侧都有墙的情况
{
err = L_PSD - R_PSD;
PID_AL();

View File

@@ -7,8 +7,8 @@ using namespace std;
/*---定义全局常量---*/
// const int DIST_cell = 300 ;
// const int DIST_wall = 100 ;
const int DIST_cell = 300;
const int DIST_wall_f = 120;
const int DIST_cell = 310;
const int DIST_wall_f = 75;
const int DIST_wall_rl = 90;
/*---全局各种变量与常量定义完成---*/

View File

@@ -1,14 +1,16 @@
cxx := gccarm
#~ cxx := gpparm
#~ file_cpp := $(wildcard *.cpp)
file_cpp := ./test_turn.cpp
#~ file_cpp := ./test_turn.cpp
#~ file_cpp := ./test_turn2.cpp
#~ file_cpp := ./test_run.cpp
#~ file_cpp := ./test_psd.cpp
file_cpp := ./test_psd.cpp
#~ file_o := /home/pi/usr/move.x
file_o := /home/pi/usr/turn.x
#~ file_o := /home/pi/usr/psd.x
#~ file_o := /home/pi/usr/turn.x
file_o := /home/pi/usr/psd.x
$(file_o) : $(file_cpp)
@$(cxx) $^ -o $@

View File

@@ -11,8 +11,8 @@ int main()
LCDMenu("","","","END");
do
{
Fwall = PSDGetRaw(1); //检测前面侧是否有墙
Lwall = PSDGetRaw(2); //检测左面
Fwall = PSDGetRaw(1)-2; //检测前面侧是否有墙
Lwall = PSDGetRaw(2)-16; //检测左面
Rwall = PSDGetRaw(3); //检测右面
bwall = PSDGetRaw(4); //
cout << "PSD L:" << Lwall << " R:" << Rwall << " F:" << Fwall << " b:" << bwall << endl; ;

View File

@@ -7,10 +7,8 @@ using namespace std;
int main()
{
//~ int f_wall, r_wall, l_wall, b_wall;
//~ int old_f_wall, old_r_wall, old_l_wall, old_b_wall;
int b_wall;
int old_b_wall;
int f_wall, b_wall;
int old_f_wall, old_b_wall;
int turn_check;
LCDMenu("","","","END");
int num;
@@ -65,6 +63,34 @@ int main()
OSWait(50);
} while (turn_check < -3 || b_wall > 130);
}
else if (num == 2)
{
b_wall = PSDGetRaw(4) - 2;
f_wall = PSDGetRaw(1) - 2;
do
{
old_b_wall = b_wall;
old_f_wall = f_wall;
MOTORDriveRaw(1,19);
MOTORDriveRaw(2,-17);
//~ MOTORDriveRaw(1,24);
//~ MOTORDriveRaw(2,-22);
OSWait(1000);
//~ OSWait(1980);
MOTORDriveRaw(1,0);
MOTORDriveRaw(2,0);
b_wall = (PSDGetRaw(4) - 2) * 0.7 + old_b_wall * 0.3; //减小突变
f_wall = (PSDGetRaw(1) - 2) * 0.7 + old_f_wall * 0.3; //减小突变
//~ b_wall = PSDGetRaw(4) - 2;
//~ f_wall = PSDGetRaw(1) - 2;
turn_check = b_wall - old_b_wall;
/*---打印输出PSD数值---*/
//~ cout << "PSD L:" << L_PSD << " R:" << R_PSD << " F:" << F_PSD << " " ;
cout << "f_wall: " << f_wall << "\t" << "b_wall: " << b_wall << "\t" << "check: " << turn_check << endl;
/*---打印结束---*/
OSWait(50);
} while (f_wall < 200 || turn_check < -4 || b_wall > 130);
}
//~ if(num == 1)
//~ {
//~ MOTORDriveRaw(1,19);

View File

@@ -0,0 +1,79 @@
#include<iostream>
#include<string>
#include<cmath>
//~ #include"eyebot++.h"
#include"/home/pi/eyebot/include/eyebot++.h"
using namespace std;
int main()
{
LCDMenu("","","","END");
int num;
//~ int pwm1, pwm2;
do
{
cin>>num;
if (num == 1)
{
ENCODERReset(1);
ENCODERReset(2);
do
{
MOTORDriveRaw(1,21);
MOTORDriveRaw(2,-19);
} while (abs(ENCODERRead(2)) < 217);
MOTORDriveRaw(1,0);
MOTORDriveRaw(2,0);
}
else if (num == 2)
{
ENCODERReset(1);
ENCODERReset(2);
do
{
MOTORDriveRaw(1,21);
MOTORDriveRaw(2,-19);
} while (abs(ENCODERRead(2)) < 500);
MOTORDriveRaw(1,0);
MOTORDriveRaw(2,0);
}
else if (num == 3)
{
ENCODERReset(1);
ENCODERReset(2);
do
{
MOTORDriveRaw(1,-21);
MOTORDriveRaw(2,19);
} while (abs(ENCODERRead(2)) < 242);
MOTORDriveRaw(1,0);
MOTORDriveRaw(2,0);
}
else if (num == 4)
{
ENCODERReset(1);
ENCODERReset(2);
do
{
MOTORDriveRaw(1,-21);
} while (abs(ENCODERRead(1)) < 285);
MOTORDriveRaw(1,0);
do
{
MOTORDriveRaw(2,19);
} while (abs(ENCODERRead(2)) < 285);
MOTORDriveRaw(2,0);
}
else
{
cout << " num error " << endl;
}
} while (KEYRead() != KEY4);
}