Project

General

Profile

Statistics
| Revision:

root / trunk / code / behaviors / hunter_prey / joystickPlayer / robot / hunter_prey.c @ 1785

History | View | Annotate | Download (1011 Bytes)

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

    
4
#define TAG_TIME 3
5
#define TAG_RANGE 250
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 either value is -1, just return */
23
  if(max_bom == -1 || frontRange == -1) {
24
    return 0;
25
  }
26

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

    
46
  return 0;
47

    
48
}