Project

General

Profile

Revision 697

Added by Chris Mar about 16 years ago

replaced smart_run_around with demo version from trunk. works much better now.

View differences:

smart_run_around_fsm.c
10 10

  
11 11
void run_around_init(void)
12 12
{
13
//  range_init();
14
//  analog_init();
15
//  motors_init();
16
//  orb_init();
17
//  orb_enable();
18
//  usb_init();
13
  range_init();
19 14
 
20 15
  /*Start in the default state, MOVING*/ 
21 16
  avoid_state=MOVING;
......
33 28

  
34 29
/*The main function, call this to update states as frequently as possible.*/
35 30
void run_around_FSM(void) {
36
  /*Default to moving.*/
31
  /*Default to moving.*/ 
37 32
  avoid_state=MOVING;
38 33
  
39 34
  /*The following lines ensure that undefined (-1) values
......
41 36
  int temp;
42 37
  
43 38
  temp=range_read_distance(IR1);
44
  //d1=(temp == -1) ? d1 : temp;
45
  d1 = temp;
39
  d1=(temp == -1) ? d1 : temp;
46 40
  
47 41
  temp=range_read_distance(IR2);
48
  //d2=(temp == -1) ? d2 : temp;
49
  d2 = temp;
42
  d2=(temp == -1) ? d2 : temp;
50 43
  
51 44
  temp=range_read_distance(IR3);
52
  //d3=(temp == -1) ? d3 : temp;
53
  d3 = temp;
45
  d3=(temp == -1) ? d3 : temp;
54 46
  
55 47
  temp=range_read_distance(IR4);
56
  //d4=(temp == -1) ? d4 : temp;
57
  d4 = temp;
48
  d4=(temp == -1) ? d4 : temp;
58 49
  
59 50
  temp=range_read_distance(IR5);
60
  //d5=(temp == -1) ? d5 : temp;
61
  d5 = temp;
51
  d5=(temp == -1) ? d5 : temp;
62 52
  
63
  //If the crazy count is in it's >>3 range, it acts crazy.
53
  /*If the crazy count is in it's >>3 range, it acts crazy.*/
64 54
  if(crazy_count<=(CRAZY_MAX>>3))
65 55
  {
66 56
    avoid_state=CRAZY;
......
73 63
  }
74 64
  
75 65
  //Checks the forward distance to see if it should back up, if so...state backwards.
76
  if((d2!=-1)&&(d2 < 200)){
66
  if((d2!=-1)&&(d2 < 150)){
77 67
      backup_count=BACKUP_MAX;
78 68
      avoid_state=BACKWARDS;
79 69
      evaluate_state();
80 70
      return;
81 71
  }
72
  /*
73
  if(d1 < 120 || d3 < 120) {
74
		avoid_state = BACKWARDS;
75
		backup_count = BACKUP_MAX;
76
		evaluate_state();
77
		return;
78
  }
79
  */
82 80
  if(backup_count<BACKUP_MAX){
83
    avoid_state=BACKWARDS;
81
    avoid_state=BACKWARDS; 
84 82
    if(backup_count<0)
85 83
      backup_count=BACKUP_MAX;
86 84
    evaluate_state();
87 85
    return;
88 86
  }
89 87
  
90
  //Should evaluate an expression from -255 to 255 to pass to move.
88
  /*Should evaluate an expression from -255 to 255 to pass to move.*/
91 89
  pControl= ((d3-d1) + (d4-d5)) >> TURN_CONSTANT;
92 90
  
93 91
  if(pControl>PCONTROL_CRAZY_LIMIT || pControl<-PCONTROL_CRAZY_LIMIT) crazy_count--;
94
  //i.e. if you really want to turn for an extended period of time...you're probably stuck.
92
  /*i.e. if you really want to turn for an extended period of time...you're probably stuck.*/
95 93

  
96 94
  /*Debug stuff:*/
97 95
  /*usb_puts("pControl evaluating: ");
......
120 118
      move(STRAIT_SPEED,-pControl);
121 119
      break;
122 120
    
123
    case(BACKWARDS): orb_set_color(ORANGE);
124
      move(BACK_SPEED,0);
121
    case(BACKWARDS): orb_set_color(MAGENTA);
122
      move(-STRAIT_SPEED-50,0);
125 123
      break;
126 124
      
127 125
    case(CRAZY): orb_set_color(RED);

Also available in: Unified diff