Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //camera and infared view target directly and are used to maintain tracking
- // target identification by neon non-naturally occuring color combinations
- //color combination has been left in many of the methods, in case multiple drones are implemented
- //this assumes the drone starts off seeing you in the camera
- //How can you determine distance with infared? How does neon tracking work?
- //by karl brown
- const int x_center = CENTER OF WIDTH OF PIXELS OF CAMERA;
- cont int y_center = CENTER OF HEIGHT OF PIXELS OF CAMERA;
- while(looped every X units of time)
- {
- if(!collisioncourse) //our copter isnt crashing
- {
- while(edge_of_camera(colorcombination)) //losing our target from a safe center box of the camera
- {
- reacquire(colorcombination); //method to turn to a safe distance for following
- }
- if(losing_target(colorcombination) ) //target is too far or too close
- {
- moveaccordingly(calculate_distance(colorcombination)) //simplified, we readjust before moving
- }
- }else
- {
- while(collisioncourse) //HIGHWAY TO THE DANGER ZONE
- {
- moveawayfromproblem() //up,down,left,right, front, backwards accordingly,
- turntofind(colorcombination,pixel_offset_x, pixel_offset_y) //gotta track that bad boy as we move
- ]
- }
- }
- bool collisioncourse ()
- {
- //use sensors to see if death is approaching. likely based on infared and speed
- //on fixed courses this will not be relevant
- if (infared_sensor_distance < safe_range_based_on_speed)
- {
- return true;
- }else
- {
- return false;
- }
- }
- bool edge_of_camera(colorcombination)
- {
- //There is a box that the colorcombination must stay in. Is it currently there?
- if(find_currentcenter_location_x(colorcombination) < X_BOUND_LIMIT_L || find_currentcenter_location_x(colorcombination) > X_BOUND_LIMIT_R
- || find_currentcenter_location_y(colorcombination) > Y_BOUND_LIMIT_U || find_currentcenter_location_y(colorcombination) > Y_BOUND_LIMIT_L)
- {
- return true;
- }else
- {
- return false;
- }
- }
- int find_currentcenter_location_x(colorcombination)
- {
- //find out how a camera uses neon to find targets
- //get that target, find out the most mappable location on the camera
- center_of_x = left_bound_of_target - right_bound_of_target; //use that relative to pixels of camera
- return center_of_x;
- }
- int find_currentcenter_location_y(colorcombination)
- {
- //find out how a camera uses neon to find targets
- //get that target, find out the most mappable location on the camera
- center_of_y = top_bound_of_target - bottom_bound_of_target; //use that relative to pixels of camera
- return center_of_y;
- }
- void turndrone (pixel_offset_x,pixel_offset_y)
- {
- if(pixel_offset_x<0)
- {
- while(edge_of_camera(colorcombination)) //when we arent looking properly. likely this will be adjusted to a more specific bounds
- { //as edge of camera will be more lenient to prevent constant readjustments and more following
- turnleft(ADJUSTABLEUNITS); //turn left a safe amount until reordiented
- }
- }else
- {
- while(edge_of_camera(colorcombination)) //when we arent looking properly. likely this will be adjusted to a more specific bounds
- {
- turnright(ADJUSTABLEUNITS);//turn right a safe amount until reordiented
- }
- }
- if(pixel_offset_y<0)
- {
- while(edge_of_camera(colorcombination))
- {
- moveup(ADJUSTABLEUNITS); //move up a safe amount until reordiented
- }
- }else
- {
- while(edge_of_camera(colorcombination))
- {
- movedown(ADJUSTABLEUNITS); //moveup a safe amount until reoriented
- }
- }
- }
- bool losing_target(colorcombination)
- {
- if(infared_sensor_distance_to_colorcombination > MAX_FOLLOW_RANGE || infared_sensor_distance_to_colorcombination < MIN_FOLLOW_RANGE)
- {
- return true;
- }else
- {
- return false;
- }
- }
- void moveaccordingly(calculate_distance)
- {
- for (int x =0;x<CHECKS;x++) //checks dictates how many times we make sure we arent colliding
- { //while going to target and worrying if we must reacquire
- moveforward(calculate_distance/CHECKS);
- if (edge_of_camera(colorcombination))
- {
- reacquire();
- }
- if (collisioncourse)
- {
- moveawayfromproblem()
- }
- }
- }
- double calculate_distance (colorcombination)
- {
- return INFARED_SENSOR_DISTANCE;
- }
- void moveawayfromproblem()
- {
- //use sensor data to determine where issue originates. once again, in ideal situations this isnt relevant
- while(collisioncourse)
- {
- //move opposite direction ADJUSTABLEUNITS
- reacquire()
- }
- }
- void reacquire (colorcombination)
- {
- int pixel_offset_x = x_center - find_currentcenter_location_x(colorcombination); //center - offset for x and y
- int pixel_offset_y = y_center - find_currentcenter_location_y(colorcombination); //separate lines for legibility
- turndrone(pixel_offset_x, pixel_offset_y) //adjust drone accordingly
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement