energy changed(8/7game PID test)

This commit is contained in:
sun
2019-08-07 03:38:31 +08:00
parent 0257b87720
commit f93f5911ff
9 changed files with 45 additions and 22 deletions

View File

@@ -26,8 +26,16 @@ void Energy::clearAll() {
void Energy::initImage(cv::Mat &src) {
// imagePreprocess(src);
// if(show_process)imshow("img_preprocess", src);
systime cur_time;
getsystime(cur_time);
float interval = getTimeIntervalms(cur_time, time_start_energy);
if (src.type() == CV_8UC3)cvtColor(src, src, COLOR_BGR2GRAY);
threshold(src, src, energy_part_param_.GRAY_THRESH, 255, THRESH_BINARY);
if(interval > 3000 && !is_find_target){
threshold(src, src, energy_part_param_.SUB_GRAY_THRESH, 255, THRESH_BINARY);
}else{
threshold(src, src, energy_part_param_.GRAY_THRESH, 255, THRESH_BINARY);
}
if (show_process)imshow("bin", src);
if (show_energy)waitKey(1);
}

View File

@@ -17,6 +17,7 @@ void Energy::initEnergy() {
is_mark = false;
is_guessing = false;
is_predicting = true;
is_find_target = false;
energy_mode_init = true;
energy_rotation_init = true;
manual_mark = false;
@@ -71,7 +72,7 @@ void Energy::initEnergy() {
target_armors.clear();
flow_strips.clear();
all_target_armor_centers.clear();
while(!recent_target_armor_centers.empty())recent_target_armor_centers.pop();
while (!recent_target_armor_centers.empty())recent_target_armor_centers.pop();
}
@@ -82,7 +83,8 @@ void Energy::initEnergy() {
void Energy::initEnergyPartParam() {
// gimbal_energy_part_param_.GRAY_THRESH = 120;//home
// gimbal_energy_part_param_.GRAY_THRESH = 200;//official
gimbal_energy_part_param_.GRAY_THRESH =180;//game
gimbal_energy_part_param_.GRAY_THRESH = 180;//game
gimbal_energy_part_param_.SUB_GRAY_THRESH = 100;
gimbal_energy_part_param_.SPLIT_GRAY_THRESH = 180;
gimbal_energy_part_param_.FAN_GRAY_THRESH = 75;
gimbal_energy_part_param_.ARMOR_GRAY_THRESH = 80;
@@ -157,7 +159,6 @@ void Energy::initEnergyPartParam() {
gimbal_energy_part_param_.STRIP_ARMOR_DISTANCE_MAX = 52;
chassis_energy_part_param_.GRAY_THRESH = 120;//home
// chassis_energy_part_param_.GRAY_THRESH = 200;//official
// chassis_energy_part_param_.GRAY_THRESH = 225;

View File

@@ -53,6 +53,8 @@ void Energy::setBigEnergyInit() {
initEnergy();
initEnergyPartParam();
getsystime(time_start_energy);
is_big = true;
is_small = false;
is_gimbal = true;

View File

@@ -85,6 +85,7 @@ void Energy::runBig(cv::Mat &gimbal_src) {
if (!findTargetInFlowStripFan()) return;
if (!findFlowStrip(gimbal_src))return;
}
is_find_target = true;
if (!findCenterROI(gimbal_src))return;
if (show_energy)showFlowStrip("strip", gimbal_src);
if (!findCenterR(gimbal_src))return;

View File

@@ -24,20 +24,30 @@ void Energy::sendEnergy() {
} else if (ROBOT_ID == 7) {
float yaw_I_component = BIG_YAW_AIM_KI * sum_yaw;
float pitch_I_component = BIG_PITCH_AIM_KI * sum_pitch;
MINMAX(yaw_I_component, -3, 3);
MINMAX(pitch_I_component, -3, 3);
// MINMAX(yaw_I_component, -2, 2);
// MINMAX(pitch_I_component, -2, 2);
// MINMAX(yaw_I_component, -3, 3);
// MINMAX(pitch_I_component, -3, 3);
MINMAX(yaw_I_component, -2, 2);
MINMAX(pitch_I_component, -2, 2);
}
double tmp_yaw = yaw_rotation;
double tmp_pitch = pitch_rotation;
yaw_rotation = BIG_YAW_AIM_KP * yaw_rotation + BIG_YAW_AIM_KI * sum_yaw +
BIG_YAW_AIM_KD * (yaw_rotation - last_yaw);
pitch_rotation = BIG_PITCH_AIM_KP * pitch_rotation + BIG_PITCH_AIM_KI * sum_pitch +
BIG_PITCH_AIM_KD * (pitch_rotation - last_pitch);
// cout << BIG_YAW_AIM_KP * yaw_rotation << '\t' << BIG_YAW_AIM_KI * sum_yaw << '\t'
if(mcu_data.mark == 1){
yaw_rotation = TRY_BIG_YAW_AIM_KP * yaw_rotation + TRY_BIG_YAW_AIM_KI * sum_yaw +
TRY_BIG_YAW_AIM_KD * (yaw_rotation - last_yaw);
pitch_rotation = TRY_BIG_PITCH_AIM_KP * pitch_rotation + TRY_BIG_PITCH_AIM_KI * sum_pitch +
TRY_BIG_PITCH_AIM_KD * (pitch_rotation - last_pitch);
} else {
yaw_rotation = BIG_YAW_AIM_KP * yaw_rotation + BIG_YAW_AIM_KI * sum_yaw +
BIG_YAW_AIM_KD * (yaw_rotation - last_yaw);
pitch_rotation = BIG_PITCH_AIM_KP * pitch_rotation + BIG_PITCH_AIM_KI * sum_pitch +
BIG_PITCH_AIM_KD * (pitch_rotation - last_pitch);
}
// cout << "yaw: "<<BIG_YAW_AIM_KP * yaw_rotation << '\t' << BIG_YAW_AIM_KI * sum_yaw << '\t'
// << BIG_YAW_AIM_KD * (yaw_rotation - last_yaw) << endl;
// cout << "pitch: "<<BIG_PITCH_AIM_KP * pitch_rotation << '\t' << BIG_PITCH_AIM_KI * sum_pitch << '\t'
// << BIG_PITCH_AIM_KD * (pitch_rotation - last_pitch) << endl;
last_yaw = tmp_yaw;
last_pitch = tmp_pitch;
if (ROBOT_ID == 7) {