Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp@0:bf39986ebff7, 2015-03-24 (annotated)
- Committer:
- bbbobbbieo
- Date:
- Tue Mar 24 19:28:03 2015 +0000
- Revision:
- 0:bf39986ebff7
- Child:
- 1:e561f697985b
shit;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
bbbobbbieo | 0:bf39986ebff7 | 1 | //#include "mbed.h" |
bbbobbbieo | 0:bf39986ebff7 | 2 | #include "TFC.h" |
bbbobbbieo | 0:bf39986ebff7 | 3 | #include <iostream> |
bbbobbbieo | 0:bf39986ebff7 | 4 | #include <stdio.h> |
bbbobbbieo | 0:bf39986ebff7 | 5 | //#include "serialib.h" |
bbbobbbieo | 0:bf39986ebff7 | 6 | |
bbbobbbieo | 0:bf39986ebff7 | 7 | const float AGGRESSIVE = .55; |
bbbobbbieo | 0:bf39986ebff7 | 8 | const float MODERATE =.48; |
bbbobbbieo | 0:bf39986ebff7 | 9 | const float CONSERVATIVE =.35; |
bbbobbbieo | 0:bf39986ebff7 | 10 | const float STOP =0; |
bbbobbbieo | 0:bf39986ebff7 | 11 | const float PROTECTION_THRESHOLD_UPPER =.7; |
bbbobbbieo | 0:bf39986ebff7 | 12 | const float PROTECTION_THRESHOLD_LOWER =-.7; |
bbbobbbieo | 0:bf39986ebff7 | 13 | const float TURN_FORWARD_ACCEL =0.045; |
bbbobbbieo | 0:bf39986ebff7 | 14 | const float TURN_BACKWARD_ACCEL =0.025; |
bbbobbbieo | 0:bf39986ebff7 | 15 | const float SERVO_CAN_MOVE_IN_ONE_FRAME =0.1; |
bbbobbbieo | 0:bf39986ebff7 | 16 | const float SERVO_MAX =.5; |
bbbobbbieo | 0:bf39986ebff7 | 17 | |
bbbobbbieo | 0:bf39986ebff7 | 18 | const int BLACK_THRESHOLD =63; |
bbbobbbieo | 0:bf39986ebff7 | 19 | const int LINE_SCAN_LENGTH =128; |
bbbobbbieo | 0:bf39986ebff7 | 20 | |
bbbobbbieo | 0:bf39986ebff7 | 21 | |
bbbobbbieo | 0:bf39986ebff7 | 22 | DigitalOut myled(LED1); |
bbbobbbieo | 0:bf39986ebff7 | 23 | |
bbbobbbieo | 0:bf39986ebff7 | 24 | int main() |
bbbobbbieo | 0:bf39986ebff7 | 25 | { |
bbbobbbieo | 0:bf39986ebff7 | 26 | //run this before anything |
bbbobbbieo | 0:bf39986ebff7 | 27 | TFC_Init(); |
bbbobbbieo | 0:bf39986ebff7 | 28 | |
bbbobbbieo | 0:bf39986ebff7 | 29 | //variables |
bbbobbbieo | 0:bf39986ebff7 | 30 | float current_servo_position = 0; |
bbbobbbieo | 0:bf39986ebff7 | 31 | float previous_servo_position = 0; |
bbbobbbieo | 0:bf39986ebff7 | 32 | float current_left_motor_speed = 0; |
bbbobbbieo | 0:bf39986ebff7 | 33 | float current_right_motor_speed = 0; |
bbbobbbieo | 0:bf39986ebff7 | 34 | |
bbbobbbieo | 0:bf39986ebff7 | 35 | float proportional = 0; |
bbbobbbieo | 0:bf39986ebff7 | 36 | float last_proportional = 0; |
bbbobbbieo | 0:bf39986ebff7 | 37 | float integral = 0; |
bbbobbbieo | 0:bf39986ebff7 | 38 | float derivative = 0; |
bbbobbbieo | 0:bf39986ebff7 | 39 | float output = 0; |
bbbobbbieo | 0:bf39986ebff7 | 40 | |
bbbobbbieo | 0:bf39986ebff7 | 41 | // gains on prop, int, der |
bbbobbbieo | 0:bf39986ebff7 | 42 | // subject to change, need to fine tune |
bbbobbbieo | 0:bf39986ebff7 | 43 | float kp = 1.8960; |
bbbobbbieo | 0:bf39986ebff7 | 44 | float ki = 0.6170; |
bbbobbbieo | 0:bf39986ebff7 | 45 | float kd = 1.5590; |
bbbobbbieo | 0:bf39986ebff7 | 46 | |
bbbobbbieo | 0:bf39986ebff7 | 47 | bool rear_motor_enable_flag = true; |
bbbobbbieo | 0:bf39986ebff7 | 48 | bool linescan_ping_pong = false; |
bbbobbbieo | 0:bf39986ebff7 | 49 | bool linescan_enable = true; |
bbbobbbieo | 0:bf39986ebff7 | 50 | |
bbbobbbieo | 0:bf39986ebff7 | 51 | int black_values_list[LINE_SCAN_LENGTH]; |
bbbobbbieo | 0:bf39986ebff7 | 52 | int black_value_count = 0; |
bbbobbbieo | 0:bf39986ebff7 | 53 | int black_center_value = 0; |
bbbobbbieo | 0:bf39986ebff7 | 54 | int sum_black = 0; |
bbbobbbieo | 0:bf39986ebff7 | 55 | int violence_level = 0; |
bbbobbbieo | 0:bf39986ebff7 | 56 | |
bbbobbbieo | 0:bf39986ebff7 | 57 | int accelList[3]; |
bbbobbbieo | 0:bf39986ebff7 | 58 | int lastAccessed = 0; |
bbbobbbieo | 0:bf39986ebff7 | 59 | |
bbbobbbieo | 0:bf39986ebff7 | 60 | int centers_List[50]; |
bbbobbbieo | 0:bf39986ebff7 | 61 | |
bbbobbbieo | 0:bf39986ebff7 | 62 | int center_now = 63; |
bbbobbbieo | 0:bf39986ebff7 | 63 | int center_past_1 = 63; |
bbbobbbieo | 0:bf39986ebff7 | 64 | int center_past_2 = 63; |
bbbobbbieo | 0:bf39986ebff7 | 65 | int center_past_3 = 63; |
bbbobbbieo | 0:bf39986ebff7 | 66 | int center_past_4 = 63; |
bbbobbbieo | 0:bf39986ebff7 | 67 | //int best_guess_center = 64; |
bbbobbbieo | 0:bf39986ebff7 | 68 | |
bbbobbbieo | 0:bf39986ebff7 | 69 | int position = 0; |
bbbobbbieo | 0:bf39986ebff7 | 70 | int set_point = 63; |
bbbobbbieo | 0:bf39986ebff7 | 71 | int previous_error = 0; |
bbbobbbieo | 0:bf39986ebff7 | 72 | int error = 0; |
bbbobbbieo | 0:bf39986ebff7 | 73 | |
bbbobbbieo | 0:bf39986ebff7 | 74 | for(int i = 0; i < 50; i++) |
bbbobbbieo | 0:bf39986ebff7 | 75 | centers_List[i] = 63; |
bbbobbbieo | 0:bf39986ebff7 | 76 | |
bbbobbbieo | 0:bf39986ebff7 | 77 | float left_counter =0; |
bbbobbbieo | 0:bf39986ebff7 | 78 | float right_counter =0; |
bbbobbbieo | 0:bf39986ebff7 | 79 | bool turn_left=false; |
bbbobbbieo | 0:bf39986ebff7 | 80 | bool turn_right=false; |
bbbobbbieo | 0:bf39986ebff7 | 81 | |
bbbobbbieo | 0:bf39986ebff7 | 82 | |
bbbobbbieo | 0:bf39986ebff7 | 83 | // major loop |
bbbobbbieo | 0:bf39986ebff7 | 84 | while(1) { |
bbbobbbieo | 0:bf39986ebff7 | 85 | |
bbbobbbieo | 0:bf39986ebff7 | 86 | // manual servo control, unused |
bbbobbbieo | 0:bf39986ebff7 | 87 | if (TFC_ReadPushButton(0) != 0 ) { |
bbbobbbieo | 0:bf39986ebff7 | 88 | current_servo_position = current_servo_position-.005; |
bbbobbbieo | 0:bf39986ebff7 | 89 | if(current_servo_position <= -0.4) |
bbbobbbieo | 0:bf39986ebff7 | 90 | current_servo_position = -0.4; |
bbbobbbieo | 0:bf39986ebff7 | 91 | TFC_SetServo(0, current_servo_position); |
bbbobbbieo | 0:bf39986ebff7 | 92 | }// end check button0 |
bbbobbbieo | 0:bf39986ebff7 | 93 | |
bbbobbbieo | 0:bf39986ebff7 | 94 | else {} |
bbbobbbieo | 0:bf39986ebff7 | 95 | |
bbbobbbieo | 0:bf39986ebff7 | 96 | |
bbbobbbieo | 0:bf39986ebff7 | 97 | // manual servo control, unused |
bbbobbbieo | 0:bf39986ebff7 | 98 | if (TFC_ReadPushButton(1) != 0 ) { |
bbbobbbieo | 0:bf39986ebff7 | 99 | current_servo_position = current_servo_position+.005; |
bbbobbbieo | 0:bf39986ebff7 | 100 | if(current_servo_position >= 0.4) |
bbbobbbieo | 0:bf39986ebff7 | 101 | current_servo_position = 0.4; |
bbbobbbieo | 0:bf39986ebff7 | 102 | TFC_SetServo(0, current_servo_position); |
bbbobbbieo | 0:bf39986ebff7 | 103 | }// end check button1 |
bbbobbbieo | 0:bf39986ebff7 | 104 | |
bbbobbbieo | 0:bf39986ebff7 | 105 | else {} |
bbbobbbieo | 0:bf39986ebff7 | 106 | |
bbbobbbieo | 0:bf39986ebff7 | 107 | // initial motor stuff |
bbbobbbieo | 0:bf39986ebff7 | 108 | if(rear_motor_enable_flag) { |
bbbobbbieo | 0:bf39986ebff7 | 109 | TFC_HBRIDGE_ENABLE; |
bbbobbbieo | 0:bf39986ebff7 | 110 | |
bbbobbbieo | 0:bf39986ebff7 | 111 | |
bbbobbbieo | 0:bf39986ebff7 | 112 | |
bbbobbbieo | 0:bf39986ebff7 | 113 | // checking behavior level |
bbbobbbieo | 0:bf39986ebff7 | 114 | violence_level = int(TFC_GetDIP_Switch()); |
bbbobbbieo | 0:bf39986ebff7 | 115 | |
bbbobbbieo | 0:bf39986ebff7 | 116 | if (violence_level==3) { |
bbbobbbieo | 0:bf39986ebff7 | 117 | current_left_motor_speed = -(AGGRESSIVE); |
bbbobbbieo | 0:bf39986ebff7 | 118 | current_right_motor_speed = AGGRESSIVE; |
bbbobbbieo | 0:bf39986ebff7 | 119 | } |
bbbobbbieo | 0:bf39986ebff7 | 120 | else if (violence_level==2) { |
bbbobbbieo | 0:bf39986ebff7 | 121 | current_left_motor_speed = -(MODERATE); |
bbbobbbieo | 0:bf39986ebff7 | 122 | current_right_motor_speed = (MODERATE); |
bbbobbbieo | 0:bf39986ebff7 | 123 | } |
bbbobbbieo | 0:bf39986ebff7 | 124 | else if (violence_level==1) { |
bbbobbbieo | 0:bf39986ebff7 | 125 | current_left_motor_speed = -(CONSERVATIVE); |
bbbobbbieo | 0:bf39986ebff7 | 126 | current_right_motor_speed = CONSERVATIVE; |
bbbobbbieo | 0:bf39986ebff7 | 127 | } |
bbbobbbieo | 0:bf39986ebff7 | 128 | else if (violence_level==0) { |
bbbobbbieo | 0:bf39986ebff7 | 129 | current_left_motor_speed = STOP; |
bbbobbbieo | 0:bf39986ebff7 | 130 | current_right_motor_speed = STOP; |
bbbobbbieo | 0:bf39986ebff7 | 131 | } |
bbbobbbieo | 0:bf39986ebff7 | 132 | else { |
bbbobbbieo | 0:bf39986ebff7 | 133 | current_left_motor_speed = STOP; |
bbbobbbieo | 0:bf39986ebff7 | 134 | current_right_motor_speed = STOP; |
bbbobbbieo | 0:bf39986ebff7 | 135 | } |
bbbobbbieo | 0:bf39986ebff7 | 136 | |
bbbobbbieo | 0:bf39986ebff7 | 137 | |
bbbobbbieo | 0:bf39986ebff7 | 138 | // protection block |
bbbobbbieo | 0:bf39986ebff7 | 139 | if(current_left_motor_speed >= PROTECTION_THRESHOLD_UPPER) |
bbbobbbieo | 0:bf39986ebff7 | 140 | current_left_motor_speed= PROTECTION_THRESHOLD_UPPER; |
bbbobbbieo | 0:bf39986ebff7 | 141 | if(current_right_motor_speed >= PROTECTION_THRESHOLD_UPPER) |
bbbobbbieo | 0:bf39986ebff7 | 142 | current_right_motor_speed = PROTECTION_THRESHOLD_UPPER; |
bbbobbbieo | 0:bf39986ebff7 | 143 | if(current_left_motor_speed <= PROTECTION_THRESHOLD_LOWER) |
bbbobbbieo | 0:bf39986ebff7 | 144 | current_left_motor_speed = PROTECTION_THRESHOLD_LOWER; |
bbbobbbieo | 0:bf39986ebff7 | 145 | if(current_right_motor_speed <= PROTECTION_THRESHOLD_LOWER) |
bbbobbbieo | 0:bf39986ebff7 | 146 | current_right_motor_speed = PROTECTION_THRESHOLD_LOWER; |
bbbobbbieo | 0:bf39986ebff7 | 147 | |
bbbobbbieo | 0:bf39986ebff7 | 148 | TFC_SetMotorPWM(current_left_motor_speed, current_right_motor_speed); |
bbbobbbieo | 0:bf39986ebff7 | 149 | }// end motor enabled |
bbbobbbieo | 0:bf39986ebff7 | 150 | else { |
bbbobbbieo | 0:bf39986ebff7 | 151 | TFC_HBRIDGE_DISABLE; |
bbbobbbieo | 0:bf39986ebff7 | 152 | }// end motor disabled |
bbbobbbieo | 0:bf39986ebff7 | 153 | |
bbbobbbieo | 0:bf39986ebff7 | 154 | // camera stuff |
bbbobbbieo | 0:bf39986ebff7 | 155 | if (linescan_enable) { |
bbbobbbieo | 0:bf39986ebff7 | 156 | if (TFC_LineScanImageReady !=0) { |
bbbobbbieo | 0:bf39986ebff7 | 157 | |
bbbobbbieo | 0:bf39986ebff7 | 158 | if (linescan_ping_pong) { |
bbbobbbieo | 0:bf39986ebff7 | 159 | //checking channel 0 |
bbbobbbieo | 0:bf39986ebff7 | 160 | |
bbbobbbieo | 0:bf39986ebff7 | 161 | //checking center pixel, displays aprox value on leds |
bbbobbbieo | 0:bf39986ebff7 | 162 | uint8_t shitnum = 1; |
bbbobbbieo | 0:bf39986ebff7 | 163 | |
bbbobbbieo | 0:bf39986ebff7 | 164 | |
bbbobbbieo | 0:bf39986ebff7 | 165 | // checking for center line (single line) |
bbbobbbieo | 0:bf39986ebff7 | 166 | for (uint16_t i=15; i<113; i++) { |
bbbobbbieo | 0:bf39986ebff7 | 167 | if ((*(TFC_LineScanImage0+i) < 450)) { |
bbbobbbieo | 0:bf39986ebff7 | 168 | black_values_list[black_value_count] = i; |
bbbobbbieo | 0:bf39986ebff7 | 169 | black_value_count++; |
bbbobbbieo | 0:bf39986ebff7 | 170 | } |
bbbobbbieo | 0:bf39986ebff7 | 171 | } |
bbbobbbieo | 0:bf39986ebff7 | 172 | |
bbbobbbieo | 0:bf39986ebff7 | 173 | for(int i=0; i<black_value_count; i++) { |
bbbobbbieo | 0:bf39986ebff7 | 174 | sum_black += black_values_list[i]; |
bbbobbbieo | 0:bf39986ebff7 | 175 | } |
bbbobbbieo | 0:bf39986ebff7 | 176 | |
bbbobbbieo | 0:bf39986ebff7 | 177 | //update history |
bbbobbbieo | 0:bf39986ebff7 | 178 | center_past_4= center_past_3; |
bbbobbbieo | 0:bf39986ebff7 | 179 | center_past_3= center_past_2; |
bbbobbbieo | 0:bf39986ebff7 | 180 | center_past_2= center_past_1; |
bbbobbbieo | 0:bf39986ebff7 | 181 | center_past_1= center_now; |
bbbobbbieo | 0:bf39986ebff7 | 182 | |
bbbobbbieo | 0:bf39986ebff7 | 183 | |
bbbobbbieo | 0:bf39986ebff7 | 184 | //if (black_value_count>2) |
bbbobbbieo | 0:bf39986ebff7 | 185 | center_now = sum_black / black_value_count; |
bbbobbbieo | 0:bf39986ebff7 | 186 | |
bbbobbbieo | 0:bf39986ebff7 | 187 | uint8_t num = 0; |
bbbobbbieo | 0:bf39986ebff7 | 188 | |
bbbobbbieo | 0:bf39986ebff7 | 189 | if(center_now > 15 && center_now < 27) |
bbbobbbieo | 0:bf39986ebff7 | 190 | num = 1; |
bbbobbbieo | 0:bf39986ebff7 | 191 | else if(center_now >= 27 && center_now < 54) |
bbbobbbieo | 0:bf39986ebff7 | 192 | num = 2; |
bbbobbbieo | 0:bf39986ebff7 | 193 | else if(center_now > 60 && center_now < 70) |
bbbobbbieo | 0:bf39986ebff7 | 194 | num = 15; |
bbbobbbieo | 0:bf39986ebff7 | 195 | else if(center_now >= 54 && center_now < 81) |
bbbobbbieo | 0:bf39986ebff7 | 196 | num = 4; |
bbbobbbieo | 0:bf39986ebff7 | 197 | else if(center_now >= 81 && center_now < 113) |
bbbobbbieo | 0:bf39986ebff7 | 198 | num = 8; |
bbbobbbieo | 0:bf39986ebff7 | 199 | |
bbbobbbieo | 0:bf39986ebff7 | 200 | else |
bbbobbbieo | 0:bf39986ebff7 | 201 | num = 0; |
bbbobbbieo | 0:bf39986ebff7 | 202 | |
bbbobbbieo | 0:bf39986ebff7 | 203 | TFC_SetBatteryLED(num); |
bbbobbbieo | 0:bf39986ebff7 | 204 | |
bbbobbbieo | 0:bf39986ebff7 | 205 | // best guess of center based on weighted average of history |
bbbobbbieo | 0:bf39986ebff7 | 206 | //black_center_value = (5*center_now + 10*center_past_1 + 15*center_past_2 +30*center_past_3 +40*center_past_4)/100; |
bbbobbbieo | 0:bf39986ebff7 | 207 | //black_center_value = (15*center_now + 15*center_past_1 + 15*center_past_2 +25*center_past_3 +30*center_past_4)/100; |
bbbobbbieo | 0:bf39986ebff7 | 208 | black_center_value = center_now; |
bbbobbbieo | 0:bf39986ebff7 | 209 | |
bbbobbbieo | 0:bf39986ebff7 | 210 | |
bbbobbbieo | 0:bf39986ebff7 | 211 | // turn left |
bbbobbbieo | 0:bf39986ebff7 | 212 | //if (black_center_value > BLACK_THRESHOLD+30) { |
bbbobbbieo | 0:bf39986ebff7 | 213 | if (num==8) |
bbbobbbieo | 0:bf39986ebff7 | 214 | { |
bbbobbbieo | 0:bf39986ebff7 | 215 | //left_counter += (128-black_center_value); |
bbbobbbieo | 0:bf39986ebff7 | 216 | //left_counter+=20; |
bbbobbbieo | 0:bf39986ebff7 | 217 | left_counter=-0.4; |
bbbobbbieo | 0:bf39986ebff7 | 218 | turn_left=true; |
bbbobbbieo | 0:bf39986ebff7 | 219 | turn_right=false; |
bbbobbbieo | 0:bf39986ebff7 | 220 | |
bbbobbbieo | 0:bf39986ebff7 | 221 | } |
bbbobbbieo | 0:bf39986ebff7 | 222 | if (num==4) |
bbbobbbieo | 0:bf39986ebff7 | 223 | { |
bbbobbbieo | 0:bf39986ebff7 | 224 | //left_counter += (128-black_center_value); |
bbbobbbieo | 0:bf39986ebff7 | 225 | //left_counter+=20; |
bbbobbbieo | 0:bf39986ebff7 | 226 | left_counter=-0.6; |
bbbobbbieo | 0:bf39986ebff7 | 227 | turn_left=true; |
bbbobbbieo | 0:bf39986ebff7 | 228 | turn_right=false; |
bbbobbbieo | 0:bf39986ebff7 | 229 | |
bbbobbbieo | 0:bf39986ebff7 | 230 | } |
bbbobbbieo | 0:bf39986ebff7 | 231 | |
bbbobbbieo | 0:bf39986ebff7 | 232 | // need to turn right |
bbbobbbieo | 0:bf39986ebff7 | 233 | //else if (black_center_value < BLACK_THRESHOLD-30) { |
bbbobbbieo | 0:bf39986ebff7 | 234 | else if (num==1) |
bbbobbbieo | 0:bf39986ebff7 | 235 | { |
bbbobbbieo | 0:bf39986ebff7 | 236 | //right_counter += black_center_value; |
bbbobbbieo | 0:bf39986ebff7 | 237 | |
bbbobbbieo | 0:bf39986ebff7 | 238 | //right_counter +=20; |
bbbobbbieo | 0:bf39986ebff7 | 239 | right_counter =.4; |
bbbobbbieo | 0:bf39986ebff7 | 240 | turn_left=false; |
bbbobbbieo | 0:bf39986ebff7 | 241 | turn_right=true; |
bbbobbbieo | 0:bf39986ebff7 | 242 | |
bbbobbbieo | 0:bf39986ebff7 | 243 | } |
bbbobbbieo | 0:bf39986ebff7 | 244 | else if (num==2) |
bbbobbbieo | 0:bf39986ebff7 | 245 | { |
bbbobbbieo | 0:bf39986ebff7 | 246 | //right_counter += black_center_value; |
bbbobbbieo | 0:bf39986ebff7 | 247 | //right_counter +=20; |
bbbobbbieo | 0:bf39986ebff7 | 248 | right_counter =.6; |
bbbobbbieo | 0:bf39986ebff7 | 249 | turn_left=false; |
bbbobbbieo | 0:bf39986ebff7 | 250 | turn_right=true; |
bbbobbbieo | 0:bf39986ebff7 | 251 | |
bbbobbbieo | 0:bf39986ebff7 | 252 | } |
bbbobbbieo | 0:bf39986ebff7 | 253 | //else if (black_value_count < 2) |
bbbobbbieo | 0:bf39986ebff7 | 254 | // { |
bbbobbbieo | 0:bf39986ebff7 | 255 | // turn_right=false; |
bbbobbbieo | 0:bf39986ebff7 | 256 | //// turn_left=false; |
bbbobbbieo | 0:bf39986ebff7 | 257 | // TFC_SetServo(0,0.0); |
bbbobbbieo | 0:bf39986ebff7 | 258 | // } |
bbbobbbieo | 0:bf39986ebff7 | 259 | else |
bbbobbbieo | 0:bf39986ebff7 | 260 | { |
bbbobbbieo | 0:bf39986ebff7 | 261 | turn_right=false; |
bbbobbbieo | 0:bf39986ebff7 | 262 | turn_left=false; |
bbbobbbieo | 0:bf39986ebff7 | 263 | TFC_SetServo(0,0.0); |
bbbobbbieo | 0:bf39986ebff7 | 264 | } |
bbbobbbieo | 0:bf39986ebff7 | 265 | |
bbbobbbieo | 0:bf39986ebff7 | 266 | //dealwiththeshit |
bbbobbbieo | 0:bf39986ebff7 | 267 | if(turn_left) |
bbbobbbieo | 0:bf39986ebff7 | 268 | { |
bbbobbbieo | 0:bf39986ebff7 | 269 | turn_right = false; |
bbbobbbieo | 0:bf39986ebff7 | 270 | //TFC_SetServo(0, ((left_counter)*(-.05))); |
bbbobbbieo | 0:bf39986ebff7 | 271 | TFC_SetServo(0,left_counter); |
bbbobbbieo | 0:bf39986ebff7 | 272 | left_counter -= 1; |
bbbobbbieo | 0:bf39986ebff7 | 273 | //if (left_counter < 10) |
bbbobbbieo | 0:bf39986ebff7 | 274 | // turn_left =false; |
bbbobbbieo | 0:bf39986ebff7 | 275 | } |
bbbobbbieo | 0:bf39986ebff7 | 276 | |
bbbobbbieo | 0:bf39986ebff7 | 277 | if(turn_right) |
bbbobbbieo | 0:bf39986ebff7 | 278 | { |
bbbobbbieo | 0:bf39986ebff7 | 279 | turn_left =false; |
bbbobbbieo | 0:bf39986ebff7 | 280 | //TFC_SetServo(0, ((right_counter)*(.05))); |
bbbobbbieo | 0:bf39986ebff7 | 281 | TFC_SetServo(0,right_counter); |
bbbobbbieo | 0:bf39986ebff7 | 282 | right_counter -= 1; |
bbbobbbieo | 0:bf39986ebff7 | 283 | // if (right_counter < 10) |
bbbobbbieo | 0:bf39986ebff7 | 284 | // turn_right =false; |
bbbobbbieo | 0:bf39986ebff7 | 285 | } |
bbbobbbieo | 0:bf39986ebff7 | 286 | |
bbbobbbieo | 0:bf39986ebff7 | 287 | // clearing values for next image processing round |
bbbobbbieo | 0:bf39986ebff7 | 288 | black_value_count = 0; |
bbbobbbieo | 0:bf39986ebff7 | 289 | //black_center_value = 0; |
bbbobbbieo | 0:bf39986ebff7 | 290 | sum_black = 0; |
bbbobbbieo | 0:bf39986ebff7 | 291 | |
bbbobbbieo | 0:bf39986ebff7 | 292 | // end image processing |
bbbobbbieo | 0:bf39986ebff7 | 293 | |
bbbobbbieo | 0:bf39986ebff7 | 294 | linescan_ping_pong = false; |
bbbobbbieo | 0:bf39986ebff7 | 295 | } // end checking channel 0 |
bbbobbbieo | 0:bf39986ebff7 | 296 | |
bbbobbbieo | 0:bf39986ebff7 | 297 | else { //checking channel 1 |
bbbobbbieo | 0:bf39986ebff7 | 298 | linescan_ping_pong = true; |
bbbobbbieo | 0:bf39986ebff7 | 299 | } |
bbbobbbieo | 0:bf39986ebff7 | 300 | |
bbbobbbieo | 0:bf39986ebff7 | 301 | TFC_LineScanImageReady = 0; // since we used it, we reset the flag |
bbbobbbieo | 0:bf39986ebff7 | 302 | }// end imageready |
bbbobbbieo | 0:bf39986ebff7 | 303 | }// end linescan stuff |
bbbobbbieo | 0:bf39986ebff7 | 304 | } |
bbbobbbieo | 0:bf39986ebff7 | 305 | } |
bbbobbbieo | 0:bf39986ebff7 | 306 | |
bbbobbbieo | 0:bf39986ebff7 | 307 | // shit code down here |
bbbobbbieo | 0:bf39986ebff7 | 308 |