//inside main loop int main() { ////////////////////////////// ///Skipping Unmodified Codes// ////////////////////////////// //Around Line 80 ColorFinder* green_finder = new ColorFinder(120, 45, 35, 0, 0.3, 40.0); ColorFinder* blue_finder = new ColorFinder(225, 15, 45, 0, 0.3, 50.0); //created 2 new ColorFinder objects to find color green and blue BallTracker marker_tracker = BallTracker(); //created a new BallTracker object to use camera tracking BallFollower marker_follower = BallFollower(); //created a new BallFollower object to follow target/marker int _marker_found = 0; //created a flag for marker ////////////////////////////// ///Skipping Unmodified Codes// ////////////////////////////// //inside while loop while(1) { int greenCount = 0, blueCount = 0; //created 2 int to store filtered pixel counts Point2D green, blue, center; //created 3 objects of Point2D class else if(StatusCheck::m_cur_mode == SPRINT) //under a new mode called Sprint { green = green_finder->GetPosition(LinuxCamera::GetInstance()->fbuffer->m_HSVFrame, greenCount); //using the modified GetPosition function that also return filtered pixel counts blue = blue_finder->GetPosition(LinuxCamera::GetInstance()->fbuffer->m_HSVFrame, blueCount); //store position of green and blue color if(green.X < 0 || blue.X < 0) center.X = -1; else center.X = (green.X + blue.X)/2; if(green.Y < 0 || blue.Y < 0) center.Y = -1; else center.Y = (green.Y + blue.Y)/2; //calculate center of blue and green _marker_found = marker_tracker.SearchAndTracking(center); //use camera tracking and raise the flag if marker is found } ////////////////////////////// ///Skipping Unmodified Codes// ////////////////////////////// //around Line 350 Add case SPRINT: //implement new codes here to execute after pressing start button if(Action::GetInstance()->IsRunning() == 0) { Head::GetInstance()->m_Joint.SetEnableHeadOnly(true, true); Walking::GetInstance()->m_Joint.SetEnableBodyWithoutHead(true, true); //Initialize walking module and head joints if(Walking::GetInstance()->IsRunning() == false && _ball_found != 1){ Walking::GetInstance()->X_MOVE_AMPLITUDE = 30.0; //Set forward and back step length to 30cm Walking::GetInstance()->A_MOVE_AMPLITUDE = 0.0; //Set yaw step length to 0 Walking::GetInstance()->Start(); } if(_marker_found == 1) { marker_follower.Process(marker_tracker.ball_position); //use BallFollower object to start following marker if(greenCount >= 10500 || blueCount >= 10500) //pixel count can be used to approximate distance, but in this case, //this stop condition is sufficient { Walking::GetInstance()->Stop(); fprintf(stderr, "stop\n"); while(Walking::GetInstance()->IsRunning() == true) usleep(1000000); } } else { Walking::GetInstance()->X_MOVE_AMPLITUDE = 30.0; Walking::GetInstance()->A_MOVE_AMPLITUDE = 0.0; } }