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@21:df5a530208eb, 2015-03-02 (annotated)
- Committer:
- bbbobbbieo
- Date:
- Mon Mar 02 17:59:55 2015 +0000
- Revision:
- 21:df5a530208eb
- Parent:
- 20:c728b8ffad97
- Child:
- 22:f097de115024
more violent... not better but different
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| bbbobbbieo | 3:c7caa058fc50 | 1 | //#include "mbed.h" |
| bbbobbbieo | 1:21d40d90b2f0 | 2 | #include "TFC.h" |
| bbbobbbieo | 0:d57117b2188d | 3 | |
| bbbobbbieo | 0:d57117b2188d | 4 | DigitalOut myled(LED1); |
| bbbobbbieo | 0:d57117b2188d | 5 | |
| bbbobbbieo | 14:f43b386b8b5d | 6 | int main() |
| bbbobbbieo | 1:21d40d90b2f0 | 7 | { |
| bbbobbbieo | 7:455e7dd338ee | 8 | //run this before anything |
| bbbobbbieo | 2:d8a51492b646 | 9 | TFC_Init(); |
| bbbobbbieo | 14:f43b386b8b5d | 10 | |
| bbbobbbieo | 7:455e7dd338ee | 11 | //variables |
| bbbobbbieo | 4:7584ff0426f1 | 12 | float current_servo_position = 0; |
| bbbobbbieo | 6:44d1079f076c | 13 | float current_left_motor_speed = 0; |
| bbbobbbieo | 6:44d1079f076c | 14 | float current_right_motor_speed = 0; |
| mperella | 17:c643b6b4a96f | 15 | |
| mperella | 17:c643b6b4a96f | 16 | float dt = 0.00001; |
| mperella | 17:c643b6b4a96f | 17 | float integral = 0; |
| mperella | 17:c643b6b4a96f | 18 | float derivative = 0; |
| mperella | 17:c643b6b4a96f | 19 | float output = 0; |
| mperella | 17:c643b6b4a96f | 20 | |
| mperella | 17:c643b6b4a96f | 21 | // gains on prop, int, der |
| mperella | 17:c643b6b4a96f | 22 | // subject to change, need to fine tune |
| mperella | 17:c643b6b4a96f | 23 | float kp = 1.8960; |
| mperella | 17:c643b6b4a96f | 24 | float ki = 0.6170; |
| mperella | 17:c643b6b4a96f | 25 | float kd = 1.5590; |
| mperella | 17:c643b6b4a96f | 26 | |
| bbbobbbieo | 6:44d1079f076c | 27 | bool rear_motor_enable_flag = true; |
| bbbobbbieo | 7:455e7dd338ee | 28 | bool linescan_ping_pong = false; |
| bbbobbbieo | 9:2b028ee421ad | 29 | bool linescan_enable = true; |
| bbbobbbieo | 14:f43b386b8b5d | 30 | |
| bbbobbbieo | 11:d65d6d7fc85e | 31 | int black_values_list[128]; |
| bbbobbbieo | 11:d65d6d7fc85e | 32 | int black_value_count = 0; |
| bbbobbbieo | 11:d65d6d7fc85e | 33 | int black_center_value = 0; |
| bbbobbbieo | 11:d65d6d7fc85e | 34 | int sum_black = 0; |
| bbbobbbieo | 14:f43b386b8b5d | 35 | int violence_level = 0; |
| bbbobbbieo | 15:830209e846d5 | 36 | |
| bbbobbbieo | 20:c728b8ffad97 | 37 | int center_now = 64; |
| bbbobbbieo | 20:c728b8ffad97 | 38 | int center_past_1 = 64; |
| bbbobbbieo | 20:c728b8ffad97 | 39 | int center_past_2 = 64; |
| bbbobbbieo | 20:c728b8ffad97 | 40 | int center_past_3 = 64; |
| bbbobbbieo | 20:c728b8ffad97 | 41 | int center_past_4 = 64; |
| bbbobbbieo | 20:c728b8ffad97 | 42 | //int best_guess_center = 64; |
| bbbobbbieo | 20:c728b8ffad97 | 43 | |
| mperella | 17:c643b6b4a96f | 44 | int set_point = 64; |
| bbbobbbieo | 19:85eb7991e2ab | 45 | int previous_error = 0; |
| mperella | 17:c643b6b4a96f | 46 | int error = 0; |
| mperella | 17:c643b6b4a96f | 47 | |
| mperella | 17:c643b6b4a96f | 48 | |
| bbbobbbieo | 9:2b028ee421ad | 49 | //uint16_t MyImage0Buffer[2][128]; |
| bbbobbbieo | 9:2b028ee421ad | 50 | //uint16_t MyImage1Buffer[2][128]; |
| bbbobbbieo | 14:f43b386b8b5d | 51 | |
| bbbobbbieo | 7:455e7dd338ee | 52 | // major loop |
| bbbobbbieo | 14:f43b386b8b5d | 53 | while(1) { |
| bbbobbbieo | 14:f43b386b8b5d | 54 | |
| bbbobbbieo | 15:830209e846d5 | 55 | // manual servo control, unused |
| bbbobbbieo | 14:f43b386b8b5d | 56 | if (TFC_ReadPushButton(0) != 0 ) { |
| bbbobbbieo | 14:f43b386b8b5d | 57 | current_servo_position = current_servo_position-.005; |
| bbbobbbieo | 14:f43b386b8b5d | 58 | if(current_servo_position <= -0.4) |
| bbbobbbieo | 14:f43b386b8b5d | 59 | current_servo_position = -0.4; |
| bbbobbbieo | 14:f43b386b8b5d | 60 | TFC_SetServo(0, current_servo_position); |
| bbbobbbieo | 14:f43b386b8b5d | 61 | }// end check button0 |
| bbbobbbieo | 14:f43b386b8b5d | 62 | |
| bbbobbbieo | 15:830209e846d5 | 63 | else {} |
| bbbobbbieo | 14:f43b386b8b5d | 64 | |
| bbbobbbieo | 15:830209e846d5 | 65 | // manual servo control, unused |
| bbbobbbieo | 14:f43b386b8b5d | 66 | if (TFC_ReadPushButton(1) != 0 ) { |
| bbbobbbieo | 14:f43b386b8b5d | 67 | current_servo_position = current_servo_position+.005; |
| bbbobbbieo | 14:f43b386b8b5d | 68 | if(current_servo_position >= 0.4) |
| bbbobbbieo | 14:f43b386b8b5d | 69 | current_servo_position = 0.4; |
| bbbobbbieo | 14:f43b386b8b5d | 70 | TFC_SetServo(0, current_servo_position); |
| bbbobbbieo | 14:f43b386b8b5d | 71 | }// end check button1 |
| bbbobbbieo | 14:f43b386b8b5d | 72 | |
| bbbobbbieo | 15:830209e846d5 | 73 | else {} |
| bbbobbbieo | 14:f43b386b8b5d | 74 | |
| bbbobbbieo | 15:830209e846d5 | 75 | // initial motor stuff |
| bbbobbbieo | 14:f43b386b8b5d | 76 | if(rear_motor_enable_flag) { |
| bbbobbbieo | 14:f43b386b8b5d | 77 | TFC_HBRIDGE_ENABLE; |
| bbbobbbieo | 14:f43b386b8b5d | 78 | |
| bbbobbbieo | 15:830209e846d5 | 79 | //current_left_motor_speed = (TFC_ReadPot(0)); |
| bbbobbbieo | 15:830209e846d5 | 80 | //current_right_motor_speed = (TFC_ReadPot(1)); |
| bbbobbbieo | 14:f43b386b8b5d | 81 | |
| bbbobbbieo | 15:830209e846d5 | 82 | // checking behavior level |
| bbbobbbieo | 14:f43b386b8b5d | 83 | violence_level = int(TFC_GetDIP_Switch()); |
| bbbobbbieo | 14:f43b386b8b5d | 84 | |
| bbbobbbieo | 15:830209e846d5 | 85 | if (violence_level==2) { |
| bbbobbbieo | 16:11ba5d6f42ba | 86 | current_left_motor_speed = -.48; |
| bbbobbbieo | 16:11ba5d6f42ba | 87 | current_right_motor_speed = .48; |
| bbbobbbieo | 15:830209e846d5 | 88 | } |
| bbbobbbieo | 15:830209e846d5 | 89 | else if (violence_level==1) { |
| bbbobbbieo | 16:11ba5d6f42ba | 90 | current_left_motor_speed = -.35; |
| bbbobbbieo | 16:11ba5d6f42ba | 91 | current_right_motor_speed = .35; |
| bbbobbbieo | 14:f43b386b8b5d | 92 | } |
| bbbobbbieo | 21:df5a530208eb | 93 | else if (violence_level==3) { |
| bbbobbbieo | 21:df5a530208eb | 94 | current_left_motor_speed = -.55; |
| bbbobbbieo | 21:df5a530208eb | 95 | current_right_motor_speed = .55; |
| bbbobbbieo | 21:df5a530208eb | 96 | } |
| bbbobbbieo | 15:830209e846d5 | 97 | else if (violence_level==0) { |
| bbbobbbieo | 15:830209e846d5 | 98 | current_left_motor_speed = 0; |
| bbbobbbieo | 15:830209e846d5 | 99 | current_right_motor_speed = 0; |
| bbbobbbieo | 15:830209e846d5 | 100 | } |
| bbbobbbieo | 15:830209e846d5 | 101 | else { |
| bbbobbbieo | 15:830209e846d5 | 102 | current_left_motor_speed = 0; |
| bbbobbbieo | 15:830209e846d5 | 103 | current_right_motor_speed = 0; |
| bbbobbbieo | 15:830209e846d5 | 104 | } |
| bbbobbbieo | 15:830209e846d5 | 105 | |
| bbbobbbieo | 14:f43b386b8b5d | 106 | |
| bbbobbbieo | 15:830209e846d5 | 107 | // protection block |
| bbbobbbieo | 21:df5a530208eb | 108 | if(current_left_motor_speed >= 0.7) |
| bbbobbbieo | 21:df5a530208eb | 109 | current_left_motor_speed= 0.7; |
| bbbobbbieo | 21:df5a530208eb | 110 | if(current_right_motor_speed >= 0.7) |
| bbbobbbieo | 21:df5a530208eb | 111 | current_right_motor_speed= 0.7; |
| bbbobbbieo | 21:df5a530208eb | 112 | if(current_left_motor_speed <= -0.7) |
| bbbobbbieo | 21:df5a530208eb | 113 | current_left_motor_speed= -0.7; |
| bbbobbbieo | 21:df5a530208eb | 114 | if(current_right_motor_speed <= -0.7) |
| bbbobbbieo | 21:df5a530208eb | 115 | current_right_motor_speed= -0.7; |
| bbbobbbieo | 14:f43b386b8b5d | 116 | |
| bbbobbbieo | 14:f43b386b8b5d | 117 | TFC_SetMotorPWM(current_left_motor_speed, current_right_motor_speed); |
| bbbobbbieo | 14:f43b386b8b5d | 118 | }// end motor enabled |
| bbbobbbieo | 14:f43b386b8b5d | 119 | else { |
| bbbobbbieo | 14:f43b386b8b5d | 120 | TFC_HBRIDGE_DISABLE; |
| bbbobbbieo | 14:f43b386b8b5d | 121 | }// end motor disabled |
| bbbobbbieo | 14:f43b386b8b5d | 122 | |
| bbbobbbieo | 15:830209e846d5 | 123 | // camera stuff |
| bbbobbbieo | 14:f43b386b8b5d | 124 | if (linescan_enable) { |
| bbbobbbieo | 14:f43b386b8b5d | 125 | if (TFC_LineScanImageReady !=0) { |
| bbbobbbieo | 14:f43b386b8b5d | 126 | |
| bbbobbbieo | 15:830209e846d5 | 127 | if (linescan_ping_pong) { |
| bbbobbbieo | 15:830209e846d5 | 128 | //checking channel 0 |
| bbbobbbieo | 15:830209e846d5 | 129 | |
| bbbobbbieo | 15:830209e846d5 | 130 | //checking center pixel, displays aprox value on leds |
| bbbobbbieo | 14:f43b386b8b5d | 131 | uint8_t shitnum = 1; |
| bbbobbbieo | 14:f43b386b8b5d | 132 | if (*(TFC_LineScanImage0+64) > 800) |
| bbbobbbieo | 14:f43b386b8b5d | 133 | shitnum = 15; |
| bbbobbbieo | 14:f43b386b8b5d | 134 | else if((*(TFC_LineScanImage0+64) > 450)) |
| bbbobbbieo | 14:f43b386b8b5d | 135 | shitnum = 7; |
| bbbobbbieo | 14:f43b386b8b5d | 136 | else if((*(TFC_LineScanImage0+64) > 400)) |
| bbbobbbieo | 14:f43b386b8b5d | 137 | shitnum = 3; |
| bbbobbbieo | 14:f43b386b8b5d | 138 | else |
| bbbobbbieo | 14:f43b386b8b5d | 139 | shitnum = 1; |
| bbbobbbieo | 14:f43b386b8b5d | 140 | TFC_SetBatteryLED(shitnum); |
| bbbobbbieo | 14:f43b386b8b5d | 141 | |
| bbbobbbieo | 15:830209e846d5 | 142 | |
| bbbobbbieo | 15:830209e846d5 | 143 | // checking for center line (single line) |
| bbbobbbieo | 14:f43b386b8b5d | 144 | for (uint16_t i=0; i<128; i++) { |
| bbbobbbieo | 21:df5a530208eb | 145 | if ((*(TFC_LineScanImage0+i) < 260)) { |
| bbbobbbieo | 14:f43b386b8b5d | 146 | black_values_list[black_value_count] = i; |
| bbbobbbieo | 14:f43b386b8b5d | 147 | black_value_count++; |
| bbbobbbieo | 14:f43b386b8b5d | 148 | } |
| bbbobbbieo | 14:f43b386b8b5d | 149 | } |
| bbbobbbieo | 14:f43b386b8b5d | 150 | |
| bbbobbbieo | 14:f43b386b8b5d | 151 | for(int i=0; i<black_value_count; i++) { |
| bbbobbbieo | 14:f43b386b8b5d | 152 | sum_black += black_values_list[i]; |
| bbbobbbieo | 14:f43b386b8b5d | 153 | } |
| bbbobbbieo | 14:f43b386b8b5d | 154 | |
| bbbobbbieo | 20:c728b8ffad97 | 155 | //update history |
| bbbobbbieo | 20:c728b8ffad97 | 156 | center_past_4= center_past_3; |
| bbbobbbieo | 20:c728b8ffad97 | 157 | center_past_3= center_past_2; |
| bbbobbbieo | 20:c728b8ffad97 | 158 | center_past_2= center_past_1; |
| bbbobbbieo | 20:c728b8ffad97 | 159 | center_past_1= center_now; |
| bbbobbbieo | 20:c728b8ffad97 | 160 | |
| bbbobbbieo | 15:830209e846d5 | 161 | // value of center of black (single line) |
| bbbobbbieo | 20:c728b8ffad97 | 162 | //black_center_value = sum_black / black_value_count; |
| bbbobbbieo | 20:c728b8ffad97 | 163 | center_now = sum_black / black_value_count; |
| bbbobbbieo | 20:c728b8ffad97 | 164 | |
| bbbobbbieo | 20:c728b8ffad97 | 165 | // best guess of center based on weighted average of history |
| bbbobbbieo | 21:df5a530208eb | 166 | black_center_value = (5*center_now + 5*center_past_1 + 10*center_past_2 +10*center_past_3 +70*center_past_4)/100; |
| bbbobbbieo | 15:830209e846d5 | 167 | |
| mperella | 17:c643b6b4a96f | 168 | /* ******* PID ALGORITHM ******* |
| mperella | 17:c643b6b4a96f | 169 | |
| mperella | 17:c643b6b4a96f | 170 | error = set_point - black_center_value; |
| mperella | 17:c643b6b4a96f | 171 | integral = integral + error*dt; |
| mperella | 17:c643b6b4a96f | 172 | derivative = (error - previous_error)/dt; |
| mperella | 17:c643b6b4a96f | 173 | output = kp*error + ki*integral + kd*derivative; |
| mperella | 17:c643b6b4a96f | 174 | previous error = error; |
| mperella | 17:c643b6b4a96f | 175 | |
| mperella | 17:c643b6b4a96f | 176 | GOTTA DO SOME TESTS/SIMULATIONS TO CALIBRATE SERVO ADJUSTMENTS |
| mperella | 17:c643b6b4a96f | 177 | |
| mperella | 17:c643b6b4a96f | 178 | |
| mperella | 17:c643b6b4a96f | 179 | ***************************** |
| mperella | 17:c643b6b4a96f | 180 | */ |
| bbbobbbieo | 14:f43b386b8b5d | 181 | |
| bbbobbbieo | 21:df5a530208eb | 182 | /*if (black_center_value == 64) { |
| bbbobbbieo | 21:df5a530208eb | 183 | |
| bbbobbbieo | 21:df5a530208eb | 184 | TFC_SetServo(0, 0.0); |
| bbbobbbieo | 21:df5a530208eb | 185 | if (violence_level !=0){ |
| bbbobbbieo | 21:df5a530208eb | 186 | current_left_motor_speed = current_left_motor_speed + violence_level*.045;// push more forwards |
| bbbobbbieo | 21:df5a530208eb | 187 | current_right_motor_speed = current_right_motor_speed + violence_level*.045;// push more forwards |
| bbbobbbieo | 21:df5a530208eb | 188 | } |
| bbbobbbieo | 21:df5a530208eb | 189 | }*/ |
| bbbobbbieo | 21:df5a530208eb | 190 | |
| bbbobbbieo | 15:830209e846d5 | 191 | // need to turn left |
| bbbobbbieo | 15:830209e846d5 | 192 | if (black_center_value < 64) { |
| bbbobbbieo | 15:830209e846d5 | 193 | |
| bbbobbbieo | 16:11ba5d6f42ba | 194 | current_servo_position= float(.01875*black_center_value-(1.2)); |
| bbbobbbieo | 14:f43b386b8b5d | 195 | if(current_servo_position <= -0.4) |
| bbbobbbieo | 14:f43b386b8b5d | 196 | current_servo_position = -0.4; |
| bbbobbbieo | 14:f43b386b8b5d | 197 | TFC_SetServo(0, current_servo_position); |
| bbbobbbieo | 15:830209e846d5 | 198 | |
| bbbobbbieo | 15:830209e846d5 | 199 | |
| bbbobbbieo | 16:11ba5d6f42ba | 200 | //current_left_motor_speed = current_left_motor_speed + float(64-black_center_value)*.0025; |
| bbbobbbieo | 16:11ba5d6f42ba | 201 | //current_right_motor_speed = current_right_motor_speed + float(64-black_center_value)*.0025; |
| bbbobbbieo | 16:11ba5d6f42ba | 202 | if (violence_level !=0){ |
| bbbobbbieo | 21:df5a530208eb | 203 | current_left_motor_speed = current_left_motor_speed + float(float(64-black_center_value)*.035);// kinda reverse this... |
| bbbobbbieo | 21:df5a530208eb | 204 | current_right_motor_speed = current_right_motor_speed + float(float(64-black_center_value)*.025);// push more forwards |
| bbbobbbieo | 16:11ba5d6f42ba | 205 | } |
| bbbobbbieo | 16:11ba5d6f42ba | 206 | |
| bbbobbbieo | 21:df5a530208eb | 207 | /*// protection block |
| bbbobbbieo | 16:11ba5d6f42ba | 208 | if(current_left_motor_speed >= 0.5) |
| bbbobbbieo | 16:11ba5d6f42ba | 209 | current_left_motor_speed= 0.5; |
| bbbobbbieo | 16:11ba5d6f42ba | 210 | if(current_right_motor_speed >= 0.5) |
| bbbobbbieo | 16:11ba5d6f42ba | 211 | current_right_motor_speed= 0.5; |
| bbbobbbieo | 16:11ba5d6f42ba | 212 | if(current_left_motor_speed <= -0.5) |
| bbbobbbieo | 16:11ba5d6f42ba | 213 | current_left_motor_speed= -0.5; |
| bbbobbbieo | 16:11ba5d6f42ba | 214 | if(current_right_motor_speed <= -0.5) |
| bbbobbbieo | 21:df5a530208eb | 215 | current_right_motor_speed= -0.5;*/ |
| bbbobbbieo | 21:df5a530208eb | 216 | |
| bbbobbbieo | 21:df5a530208eb | 217 | // protection block |
| bbbobbbieo | 21:df5a530208eb | 218 | if(current_left_motor_speed >= 0.7) |
| bbbobbbieo | 21:df5a530208eb | 219 | current_left_motor_speed= 0.7; |
| bbbobbbieo | 21:df5a530208eb | 220 | if(current_right_motor_speed >= 0.7) |
| bbbobbbieo | 21:df5a530208eb | 221 | current_right_motor_speed= 0.7; |
| bbbobbbieo | 21:df5a530208eb | 222 | if(current_left_motor_speed <= -0.7) |
| bbbobbbieo | 21:df5a530208eb | 223 | current_left_motor_speed= -0.7; |
| bbbobbbieo | 21:df5a530208eb | 224 | if(current_right_motor_speed <= -0.7) |
| bbbobbbieo | 21:df5a530208eb | 225 | current_right_motor_speed= -0.7; |
| bbbobbbieo | 16:11ba5d6f42ba | 226 | |
| bbbobbbieo | 14:f43b386b8b5d | 227 | TFC_SetMotorPWM(current_left_motor_speed, current_right_motor_speed); |
| bbbobbbieo | 14:f43b386b8b5d | 228 | |
| bbbobbbieo | 7:455e7dd338ee | 229 | } |
| bbbobbbieo | 14:f43b386b8b5d | 230 | |
| bbbobbbieo | 15:830209e846d5 | 231 | // need to turn right |
| bbbobbbieo | 14:f43b386b8b5d | 232 | if (black_center_value > 64) { |
| bbbobbbieo | 14:f43b386b8b5d | 233 | |
| bbbobbbieo | 16:11ba5d6f42ba | 234 | current_servo_position= float(.01875*black_center_value-(1.2)); |
| bbbobbbieo | 14:f43b386b8b5d | 235 | if( current_servo_position >= +0.4) |
| bbbobbbieo | 14:f43b386b8b5d | 236 | current_servo_position = +0.4; |
| bbbobbbieo | 14:f43b386b8b5d | 237 | TFC_SetServo(0, current_servo_position); |
| bbbobbbieo | 15:830209e846d5 | 238 | |
| bbbobbbieo | 16:11ba5d6f42ba | 239 | //current_left_motor_speed = current_left_motor_speed - float(black_center_value-64)*.0025; |
| bbbobbbieo | 16:11ba5d6f42ba | 240 | //current_right_motor_speed = current_right_motor_speed - float(black_center_value-64)*.0025; |
| bbbobbbieo | 16:11ba5d6f42ba | 241 | if (violence_level !=0){ |
| bbbobbbieo | 21:df5a530208eb | 242 | current_left_motor_speed = current_left_motor_speed - float(float(black_center_value-64)*.025);// push more forwards |
| bbbobbbieo | 21:df5a530208eb | 243 | current_right_motor_speed = current_right_motor_speed - float(float(black_center_value-64)*.035);// kinda reverse this... |
| bbbobbbieo | 16:11ba5d6f42ba | 244 | } |
| bbbobbbieo | 15:830209e846d5 | 245 | |
| bbbobbbieo | 21:df5a530208eb | 246 | /*// protection block |
| bbbobbbieo | 16:11ba5d6f42ba | 247 | if(current_left_motor_speed >= 0.5) |
| bbbobbbieo | 16:11ba5d6f42ba | 248 | current_left_motor_speed= 0.5; |
| bbbobbbieo | 16:11ba5d6f42ba | 249 | if(current_right_motor_speed >= 0.5) |
| bbbobbbieo | 16:11ba5d6f42ba | 250 | current_right_motor_speed= 0.5; |
| bbbobbbieo | 16:11ba5d6f42ba | 251 | if(current_left_motor_speed <= -0.5) |
| bbbobbbieo | 16:11ba5d6f42ba | 252 | current_left_motor_speed= -0.5; |
| bbbobbbieo | 16:11ba5d6f42ba | 253 | if(current_right_motor_speed <= -0.5) |
| bbbobbbieo | 21:df5a530208eb | 254 | current_right_motor_speed= -0.5;*/ |
| bbbobbbieo | 21:df5a530208eb | 255 | |
| bbbobbbieo | 21:df5a530208eb | 256 | // protection block |
| bbbobbbieo | 21:df5a530208eb | 257 | if(current_left_motor_speed >= 0.7) |
| bbbobbbieo | 21:df5a530208eb | 258 | current_left_motor_speed= 0.7; |
| bbbobbbieo | 21:df5a530208eb | 259 | if(current_right_motor_speed >= 0.7) |
| bbbobbbieo | 21:df5a530208eb | 260 | current_right_motor_speed= 0.7; |
| bbbobbbieo | 21:df5a530208eb | 261 | if(current_left_motor_speed <= -0.7) |
| bbbobbbieo | 21:df5a530208eb | 262 | current_left_motor_speed= -0.7; |
| bbbobbbieo | 21:df5a530208eb | 263 | if(current_right_motor_speed <= -0.7) |
| bbbobbbieo | 21:df5a530208eb | 264 | current_right_motor_speed= -0.7; |
| bbbobbbieo | 16:11ba5d6f42ba | 265 | |
| bbbobbbieo | 14:f43b386b8b5d | 266 | TFC_SetMotorPWM(current_left_motor_speed, current_right_motor_speed); |
| bbbobbbieo | 15:830209e846d5 | 267 | |
| bbbobbbieo | 14:f43b386b8b5d | 268 | } |
| bbbobbbieo | 14:f43b386b8b5d | 269 | |
| bbbobbbieo | 15:830209e846d5 | 270 | // clearing values for next image processing round |
| bbbobbbieo | 14:f43b386b8b5d | 271 | black_value_count = 0; |
| bbbobbbieo | 14:f43b386b8b5d | 272 | black_center_value = 0; |
| bbbobbbieo | 14:f43b386b8b5d | 273 | sum_black = 0; |
| bbbobbbieo | 14:f43b386b8b5d | 274 | |
| bbbobbbieo | 15:830209e846d5 | 275 | // end image processing |
| bbbobbbieo | 14:f43b386b8b5d | 276 | |
| bbbobbbieo | 14:f43b386b8b5d | 277 | linescan_ping_pong = false; |
| bbbobbbieo | 14:f43b386b8b5d | 278 | } // end checking channel 0 |
| bbbobbbieo | 15:830209e846d5 | 279 | |
| bbbobbbieo | 15:830209e846d5 | 280 | else { //checking channel 1 |
| bbbobbbieo | 14:f43b386b8b5d | 281 | linescan_ping_pong = true; |
| bbbobbbieo | 14:f43b386b8b5d | 282 | } |
| bbbobbbieo | 14:f43b386b8b5d | 283 | |
| bbbobbbieo | 7:455e7dd338ee | 284 | TFC_LineScanImageReady ==0; // since we used it, we reset the flag |
| bbbobbbieo | 14:f43b386b8b5d | 285 | }// end imageready |
| bbbobbbieo | 14:f43b386b8b5d | 286 | }// end linescan stuff |
| bbbobbbieo | 0:d57117b2188d | 287 | } |
| bbbobbbieo | 0:d57117b2188d | 288 | } |
| bbbobbbieo | 8:946806df7347 | 289 | |
| bbbobbbieo | 8:946806df7347 | 290 | |
| bbbobbbieo | 15:830209e846d5 | 291 | // shit code down here |