更新反陀螺和分类器参数。
This commit is contained in:
@@ -108,7 +108,7 @@ private:
|
||||
Serial &serial; // 串口对象,引用外部变量,用于和能量机关共享同一个变量
|
||||
const uint8_t &use_classifier; // 标记是否启用CNN分类器,引用外部变量,自动变化
|
||||
ArmorBox::BoxOrientation last_orient; // 上一帧目标装甲板方向,用于反陀螺
|
||||
timeval last_switch_time; // 上一次发生装甲板方向切换的时间
|
||||
timeval last_front_time; // 上一次发生装甲板方向切换的时间
|
||||
int anti_top_cnt; // 满足条件的装甲板方向切换持续次数,用于反陀螺
|
||||
AntiTopState anti_top_state; // 当前是否识别到陀螺
|
||||
|
||||
|
||||
@@ -3,12 +3,15 @@
|
||||
//
|
||||
|
||||
#include <armor_finder/armor_finder.h>
|
||||
#include <log.h>
|
||||
|
||||
static double getTimeIntervalms(const timeval& now, const timeval &last){
|
||||
return (now.tv_sec-last.tv_sec)*1000.0 + (now.tv_usec-last.tv_usec)/1000.0;
|
||||
}
|
||||
|
||||
void ArmorFinder::antiTop() {
|
||||
double top_periodms = 0;
|
||||
timeval curr_time;
|
||||
if(anti_top_state == ANTI_TOP){
|
||||
cout << "anti top" << endl;
|
||||
}else if(anti_top_state == NORMAL){
|
||||
@@ -23,23 +26,26 @@ void ArmorFinder::antiTop() {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if(orientation!=last_orient){
|
||||
timeval curr_time;
|
||||
if(orientation != last_orient){
|
||||
gettimeofday(&curr_time, nullptr);
|
||||
auto interval = getTimeIntervalms(curr_time, last_switch_time);
|
||||
cout << interval << endl;
|
||||
if(50 < interval && interval < 700){
|
||||
anti_top_cnt++;
|
||||
}else{
|
||||
auto interval = getTimeIntervalms(curr_time, last_front_time);
|
||||
if(interval > 700){
|
||||
anti_top_cnt = 0;
|
||||
}
|
||||
last_switch_time = curr_time;
|
||||
}else{
|
||||
timeval curr_time;
|
||||
gettimeofday(&curr_time, nullptr);
|
||||
if(getTimeIntervalms(curr_time, last_switch_time) > 700) {
|
||||
anti_top_state = NORMAL;
|
||||
if(orientation == ArmorBox::FRONT){
|
||||
last_front_time = curr_time;
|
||||
}
|
||||
}else if(interval > 150){
|
||||
if(orientation == ArmorBox::FRONT){
|
||||
anti_top_cnt++;
|
||||
if(anti_top_state == ANTI_TOP){
|
||||
top_periodms = interval;
|
||||
LOGM(STR_CTR(WORD_LIGHT_GREEN, "top period: %.1lf ms"), top_periodms);
|
||||
}
|
||||
last_front_time = curr_time;
|
||||
}
|
||||
}
|
||||
last_orient = orientation;
|
||||
}
|
||||
if(anti_top_cnt > 4){
|
||||
anti_top_state = ANTI_TOP;
|
||||
|
||||
@@ -53,9 +53,11 @@ ArmorBox::BoxOrientation ArmorBox::getOrientation() const{
|
||||
switch (id) {
|
||||
case R1:
|
||||
case R7:
|
||||
case R8:
|
||||
case B1:
|
||||
case B7:
|
||||
if(lengthDistanceRatio() < 0.3){
|
||||
case B8:
|
||||
if(lengthDistanceRatio() < 0.30){
|
||||
return FRONT;
|
||||
}else{
|
||||
return SIDE;
|
||||
@@ -68,7 +70,7 @@ ArmorBox::BoxOrientation ArmorBox::getOrientation() const{
|
||||
case B3:
|
||||
case B4:
|
||||
case B5:
|
||||
if (lengthDistanceRatio() < 0.43) {
|
||||
if (lengthDistanceRatio() < 0.45) {
|
||||
return FRONT;
|
||||
}else{
|
||||
return SIDE;
|
||||
|
||||
@@ -35,6 +35,7 @@ static bool sendTarget(Serial &serial, double x, double y, double z) {
|
||||
}
|
||||
|
||||
bool ArmorFinder::sendBoxPosition() {
|
||||
if(armor_box.rect == cv::Rect2d()) return false;
|
||||
auto rect = armor_box.rect;
|
||||
double dx = rect.x + rect.width / 2 - 320;
|
||||
double dy = rect.y + rect.height / 2 - 240 - 20;
|
||||
|
||||
Reference in New Issue
Block a user