Statistics
| Revision:

root / demos / hunter_prey / src / hunter_prey.c @ 1828

History | View | Annotate | Download (905 Bytes)

1
#include "hunter_prey.h"
2
#include <dragonfly_lib.h>
3

    
4
#define TAG_TIME 3
5
#define TAG_RANGE 150
6

    
7
/**** This file should not be edited! ****/
8

    
9

    
10
/*
11
 * The criteria for tagging are the following:
12
 *   * The max bom is betweed 1 and 7
13
 *   * The front rangefinder reads less than TAG_RANGE
14
 *   * -1 values from the rangefinder are ignored
15
 *   * These conditions are met across TAG_TIME calls to this function
16
 */
17

    
18
unsigned char hunter_prey_tagged(int max_bom, int frontRange) {
19

    
20
  static int onTarget = 0;
21

    
22
  if(max_bom < 7 && max_bom > 1 && frontRange > 0 && frontRange < TAG_RANGE) {
23
    if(onTarget == 0) {
24
      onTarget = TAG_TIME;
25
      usb_puts("On target!\n");
26
    }
27
    else {
28
      if(--onTarget <= 0) {
29
        onTarget = 0;
30
        usb_puts("TAG!\n");
31
        return 1;
32
      }
33
    }
34
  }
35
  else{
36
    //don't reset onTarget because the robot got too close
37
    if(frontRange > 0)
38
      onTarget = 0;
39
  }
40

    
41
  return 0;
42

    
43
}