Advertisement
Guest User

Untitled

a guest
Oct 31st, 2014
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.71 KB | None | 0 0
  1. //camera and infared view target directly and are used to maintain tracking
  2. // target identification by neon non-naturally occuring color combinations
  3. //color combination has been left in many of the methods, in case multiple drones are implemented
  4. //this assumes the drone starts off seeing you in the camera
  5. //How can you determine distance with infared? How does neon tracking work?
  6. //by karl brown
  7. const int x_center = CENTER OF WIDTH OF PIXELS OF CAMERA;
  8. cont int y_center = CENTER OF HEIGHT OF PIXELS OF CAMERA;
  9. while(looped every X units of time)
  10. {
  11.     if(!collisioncourse) //our copter isnt crashing
  12.     {
  13.         while(edge_of_camera(colorcombination)) //losing our target from a safe center box of the camera
  14.         {
  15.         reacquire(colorcombination); //method to turn to a safe distance for following
  16.         }
  17.         if(losing_target(colorcombination) ) //target is too far or too close
  18.         {
  19.             moveaccordingly(calculate_distance(colorcombination)) //simplified, we readjust before moving
  20.         }
  21.     }else
  22.     {
  23.         while(collisioncourse) //HIGHWAY TO THE DANGER ZONE
  24.         {
  25.             moveawayfromproblem() //up,down,left,right, front, backwards accordingly,
  26.             turntofind(colorcombination,pixel_offset_x, pixel_offset_y)  //gotta track that bad boy as we move
  27.         ]      
  28.     }
  29. }
  30.  
  31. bool collisioncourse ()
  32. {
  33.     //use sensors to see if death is approaching. likely based on infared and speed
  34.     //on fixed courses this will not be relevant
  35.     if (infared_sensor_distance < safe_range_based_on_speed)
  36.     {
  37.         return true;
  38.     }else
  39.     {
  40.         return false;
  41.     }
  42. }
  43. bool edge_of_camera(colorcombination)
  44. {
  45.     //There is a box that the colorcombination must stay in. Is it currently there?
  46.     if(find_currentcenter_location_x(colorcombination) < X_BOUND_LIMIT_L || find_currentcenter_location_x(colorcombination) > X_BOUND_LIMIT_R
  47.     || find_currentcenter_location_y(colorcombination) > Y_BOUND_LIMIT_U || find_currentcenter_location_y(colorcombination) > Y_BOUND_LIMIT_L)
  48.     {
  49.         return true;
  50.     }else
  51.     {
  52.         return false;
  53.     }
  54. }
  55. int find_currentcenter_location_x(colorcombination)
  56. {
  57.     //find out how a camera uses neon to find targets
  58.     //get that target, find out the most mappable location on the camera
  59.     center_of_x = left_bound_of_target - right_bound_of_target; //use that relative to pixels of camera
  60.     return center_of_x;
  61. }
  62. int find_currentcenter_location_y(colorcombination)
  63. {
  64.     //find out how a camera uses neon to find targets
  65.     //get that target, find out the most mappable location on the camera
  66.     center_of_y = top_bound_of_target - bottom_bound_of_target; //use that relative to pixels of camera
  67.     return center_of_y;
  68. }
  69. void turndrone (pixel_offset_x,pixel_offset_y)
  70. {
  71.     if(pixel_offset_x<0)
  72.     {
  73.         while(edge_of_camera(colorcombination)) //when we arent looking properly. likely this will be adjusted to a more specific bounds
  74.         {                                       //as edge of camera will be more lenient to prevent constant readjustments and more following
  75.         turnleft(ADJUSTABLEUNITS); //turn left a safe amount until reordiented
  76.         }
  77.     }else
  78.     {
  79.         while(edge_of_camera(colorcombination)) //when we arent looking properly. likely this will be adjusted to a more specific bounds
  80.         {
  81.         turnright(ADJUSTABLEUNITS);//turn right a safe amount until reordiented
  82.         }
  83.     }
  84.     if(pixel_offset_y<0)
  85.     {
  86.         while(edge_of_camera(colorcombination))
  87.         {                                      
  88.         moveup(ADJUSTABLEUNITS); //move up a safe amount until reordiented
  89.         }
  90.     }else
  91.     {
  92.         while(edge_of_camera(colorcombination))
  93.         {
  94.         movedown(ADJUSTABLEUNITS); //moveup a safe amount until reoriented
  95.         }
  96.     }
  97. }  
  98. bool losing_target(colorcombination)
  99. {
  100.     if(infared_sensor_distance_to_colorcombination > MAX_FOLLOW_RANGE || infared_sensor_distance_to_colorcombination < MIN_FOLLOW_RANGE)
  101.     {
  102.         return true;
  103.     }else
  104.     {
  105.         return false;
  106.     }
  107. }
  108. void moveaccordingly(calculate_distance)
  109. {
  110.     for (int x =0;x<CHECKS;x++) //checks dictates how many times we make sure we arent colliding  
  111.     {                           //while going to target and worrying if we must reacquire
  112.         moveforward(calculate_distance/CHECKS);
  113.         if (edge_of_camera(colorcombination))
  114.         {
  115.             reacquire();
  116.         }
  117.         if (collisioncourse)
  118.         {
  119.         moveawayfromproblem()
  120.         }
  121.     }
  122. }
  123. double calculate_distance (colorcombination)
  124. {
  125.     return INFARED_SENSOR_DISTANCE;
  126. }
  127. void moveawayfromproblem()
  128. {
  129.     //use sensor data to determine where issue originates. once again, in ideal situations this isnt relevant
  130.     while(collisioncourse)
  131.     {
  132.     //move opposite direction ADJUSTABLEUNITS
  133.     reacquire()
  134.     }
  135. }
  136.  
  137. void reacquire (colorcombination)
  138. {
  139.         int pixel_offset_x = x_center - find_currentcenter_location_x(colorcombination); //center - offset for x and y
  140.         int pixel_offset_y = y_center - find_currentcenter_location_y(colorcombination); //separate lines for legibility
  141.         turndrone(pixel_offset_x, pixel_offset_y) //adjust drone accordingly
  142. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement