diff --git a/src/node.cpp b/src/node.cpp old mode 100644 new mode 100755 index 9117cdb..8f93a3f --- a/src/node.cpp +++ b/src/node.cpp @@ -8,6 +8,7 @@ #include #include #include +#include const int BALL_AT_CORNER_THRESH = 20; const int HALF_FIELD_MAXX = 3000; @@ -22,34 +23,299 @@ ros::Subscriber vision_sub; ros::Publisher pub; queue > velQ; + + void PRINT(const krssg_ssl_msgs::BeliefState bs) + { + cout<<"isteamyellow: "<(6, 0); + filterd_msg.homeDetected = vector(6, 0); + filterd_msg.awayPos = vector(6, Pose2D()); + filterd_msg.homePos = vector(6, Pose2D()); + + filterd_msg=set_message(vmsg); + + + static int count = 0, t_count=0; + static deque vec_homepos_x[6], vec_awaypos_x[6], vec_ballpos_x; + static deque vec_homepos_y[6], vec_awaypos_y[6], vec_ballpos_y; + + deque temp_vec_homepos_x[6], temp_vec_awaypos_x[6], temp_vec_ballpos_x; + deque temp_vec_homepos_y[6], temp_vec_awaypos_y[6], temp_vec_ballpos_y; + + // double arr[5] = {0.086, -0.143, -0.086, 0.257, 0.886}; + double arr[5] = {0.886, 0.257, -0.086, -0.143, 0.086}; + if(count < 5){ + ++count; + + + for (int i = 0; i < 6; ++i) + { + vec_homepos_x[i].push_back(vmsg.homePos[i].x); + vec_awaypos_x[i].push_back(vmsg.awayPos[i].x); + + vec_homepos_y[i].push_back(vmsg.homePos[i].y); + vec_awaypos_y[i].push_back(vmsg.awayPos[i].y); + } + vec_ballpos_x.push_back(vmsg.ballPos.x); + vec_ballpos_y.push_back(vmsg.ballPos.y); + + for (int i = 0; i < count; ++i) + { + for (int j = 0; j < 6; ++j) + { + temp_vec_homepos_x[j][i] = vec_homepos_x[j][i] * arr[i]; + temp_vec_awaypos_x[j][i] = vec_awaypos_x[j][i] * arr[i]; + + temp_vec_homepos_y[j][i] = vec_homepos_y[j][i] * arr[i]; + temp_vec_awaypos_y[j][i] = vec_awaypos_y[j][i] * arr[i]; + } + + temp_vec_ballpos_x[i] = vec_ballpos_x[i] * arr[i]; + temp_vec_ballpos_y[i] = vec_ballpos_y[i] * arr[i]; + } + + // average + float sum_homepos_x[6], sum_awaypos_x[6], sum_ballpos_x=0; + float sum_homepos_y[6], sum_awaypos_y[6], sum_ballpos_y=0; + + for(int i=0;i<6;i++) + sum_homepos_x[i]=sum_homepos_y[i]=sum_awaypos_x[i]=sum_awaypos_y[i]=0; + + for (int j = 0; j < 6; ++j) + { + for (int i = 0; i < count; ++i) + { + sum_homepos_x[j] += temp_vec_homepos_x[j][i]; + sum_awaypos_x[j] += temp_vec_awaypos_x[j][i]; + + sum_homepos_y[j] += temp_vec_homepos_y[j][i]; + sum_awaypos_y[j] += temp_vec_awaypos_y[j][i]; + } + + } + + for(int i=0;irobots_yellow.size()==0 && vmsg->robots_blue.size()==0)) + { + cout<<"bad frame bot!!!!!!!!!!!!!!!!!!! "<frame_number+1; + } + else + { + cout<<"proceeding"<frame_number; + vmsg_temp.t_capture=vmsg->t_capture; + vmsg_temp.t_sent=vmsg->t_sent; + vmsg_temp.camera_id=vmsg->camera_id; + vmsg_temp.robots_yellow=vmsg->robots_yellow; + vmsg_temp.robots_blue=vmsg->robots_blue; + if(vmsg->balls.size()==0) + { + cout<<"bad frame ball!!!!!!!!!!!!!!!!!!! "<balls; + } + } + + + + //printf("got a vmsg1!\n"); using namespace krssg_ssl_msgs; using geometry_msgs::Pose2D; using geometry_msgs::Point32; krssg_ssl_msgs::BeliefState msg; - msg.frame_number = vmsg->frame_number; - msg.t_capture = vmsg->t_capture; - msg.t_sent = vmsg->t_sent; + msg.frame_number = vmsg_temp.frame_number; + msg.t_capture = vmsg_temp.t_capture; + msg.t_sent = vmsg_temp.t_sent; msg.isteamyellow = is_team_yellow; - if (vmsg->balls.size() > 0) { + + vector homePos, awayPos; + if (is_team_yellow) { + homePos = vmsg_temp.robots_yellow; + awayPos = vmsg_temp.robots_blue; + } else { + homePos = vmsg_temp.robots_blue; + awayPos = vmsg_temp.robots_yellow; + } + + + + + if (vmsg_temp.balls.size() > 0) { assert(velQ.size() != 0); Pose2D oldPos = velQ.front().first; ros::Time oldTime = velQ.front().second; velQ.pop(); ros::Time curTime = ros::Time::now(); msg.ballDetected = true; - msg.ballPos.x = vmsg->balls[0].x; - msg.ballPos.y = vmsg->balls[0].y; + msg.ballPos.x = vmsg_temp.balls[0].x; + msg.ballPos.y = vmsg_temp.balls[0].y; - if(vmsg->balls[0].x <= 0 ) + //printf("got a vmsg2!\n"); + if(vmsg_temp.balls[0].x <= 0 ) msg.ball_in_our_half = true; else msg.ball_in_our_half = false; - if(fabs(vmsg->balls[0].x) > (HALF_FIELD_MAXX - BALL_AT_CORNER_THRESH) && fabs(vmsg->balls[0].y) > (HALF_FIELD_MAXY - BALL_AT_CORNER_THRESH)) + if(fabs(vmsg_temp.balls[0].x) > (HALF_FIELD_MAXX - BALL_AT_CORNER_THRESH) && fabs(vmsg_temp.balls[0].y) > (HALF_FIELD_MAXY - BALL_AT_CORNER_THRESH)) msg.ball_at_corners = true; else msg.ball_at_corners = false; @@ -60,20 +326,16 @@ void Callback(const krssg_ssl_msgs::SSL_DetectionFrame::ConstPtr& vmsg) } else { msg.ballDetected = 0; } - vector homePos, awayPos; - if (is_team_yellow) { - homePos = vmsg->robots_yellow; - awayPos = vmsg->robots_blue; - } else { - homePos = vmsg->robots_blue; - awayPos = vmsg->robots_yellow; - } + + //printf("got a vmsg3!\n"); // assuming 6 robots per side! msg.awayDetected = vector(6, 0); msg.homeDetected = vector(6, 0); + // cout<<"away Detected: "<(6, Pose2D()); msg.homePos = vector(6, Pose2D()); + //printf("got a vmsg4!\n"); float distance_from_ball = 999999,dist,temp=10; msg.ball_in_our_possession = false; @@ -84,7 +346,7 @@ void Callback(const krssg_ssl_msgs::SSL_DetectionFrame::ConstPtr& vmsg) msg.homePos[bot_id].x = homePos[i].x; msg.homePos[bot_id].y = homePos[i].y; - dist = sqrt(pow((homePos[i].x - vmsg->balls[0].x),2) - pow((homePos[i].y - vmsg->balls[0].y) , 2)); + dist = sqrt(pow((homePos[i].x - msg.ballPos.x),2) + pow((homePos[i].y - msg.ballPos.y) , 2)); if(dist < distance_from_ball){ distance_from_ball = dist; msg.our_bot_closest_to_ball = i; @@ -105,37 +367,66 @@ void Callback(const krssg_ssl_msgs::SSL_DetectionFrame::ConstPtr& vmsg) } } msg.our_goalie = temp; + // temp = 10; temp = 10; distance_from_ball = 999999; + // printf("got a vmsg41! %d\n",awayPos.size()); + // cout<balls[0].x),2) - pow((awayPos[i].y - vmsg->balls[0].y) , 2)); +// cout< (HALF_FIELD_MAXX - DBOX_WIDTH) && fabs(homePos[i].y) < DBOX_HEIGHT){ + if(awayPos[i].x > (HALF_FIELD_MAXX - DBOX_WIDTH) && fabs(awayPos[i].y) < DBOX_HEIGHT){ if(temp = 10) temp = i; - else if(fabs(homePos[temp].orientation) > 1.54 && fabs(homePos[i].orientation) < 1.54) + else if(fabs(awayPos[temp].orientation) > 1.54 && fabs(awayPos[i].orientation) < 1.54) temp = i; } } msg.opp_goalie = temp; + // cout<("/belief_state", 1000); + vision_sub = n.subscribe("/vision", 10000, Callback); + pub = n.advertise("/belief_state", 10000); ros::spin(); return 0;