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.
Diff: main.cpp
- Revision:
- 28:06cefc8dd15e
- Parent:
- 27:3dd1460365d3
- Child:
- 29:91bda3a63f17
--- a/main.cpp Tue Mar 03 18:55:17 2015 +0000
+++ b/main.cpp Tue Mar 03 19:48:45 2015 +0000
@@ -43,19 +43,21 @@
int accelList[3];
int lastAccessed = 0;
- int centers_List[100];
+ int centers_List[50];
- int center_now = 64;
- int center_past_1 = 64;
- int center_past_2 = 64;
- int center_past_3 = 64;
- int center_past_4 = 64;
+ int center_now = 63;
+ int center_past_1 = 63;
+ int center_past_2 = 63;
+ int center_past_3 = 63;
+ int center_past_4 = 63;
//int best_guess_center = 64;
- int set_point = 64;
+ int set_point = 63;
int previous_error = 0;
int error = 0;
+ for(int i = 0; i < 50; i++)
+ centers_List[i] = 63;
//uint16_t MyImage0Buffer[2][128];
//uint16_t MyImage1Buffer[2][128];
@@ -72,6 +74,7 @@
}// end check button0
else {}
+
// manual servo control, unused
if (TFC_ReadPushButton(1) != 0 ) {
@@ -169,9 +172,7 @@
center_past_2= center_past_1;
center_past_1= center_now;
- /*
-
- for(int i = 99; i >= 0; i--)
+ for(int i = 49; i >= 0; i--)
{
if(i = 0)
{
@@ -181,10 +182,7 @@
{
centers_List[i] = centers_List[i-1];
}
- }
-
- */
-
+ }
// value of center of black (single line)
//black_center_value = sum_black / black_value_count;
@@ -192,7 +190,7 @@
// best guess of center based on weighted average of history
//black_center_value = (5*center_now + 10*center_past_1 + 15*center_past_2 +30*center_past_3 +40*center_past_4)/100;
- black_center_value = (30*center_now + 10*center_past_1 + 15*center_past_2 +5*center_past_3 +40*center_past_4)/100;
+ black_center_value = (5*center_now + 10*center_past_1 + 15*center_past_2 +30*center_past_3 +40*center_past_4)/100;
/* ******* PID ALGORITHM *******
@@ -209,6 +207,35 @@
*/
// need to turn left
+
+ if (black_center_value == BLACK_THRESHOLD)
+ {
+ TFC_SetServo(0,0);
+
+ temp = 0;
+ temp2 = 0;
+
+ for(int i = 20; i < 30; i++)
+ {
+ temp = centers_List[i] + temp;
+ }
+
+ for(int i = 30; i < 40; i++)
+ {
+ temp2 = centers_List[i] + temp2;
+ }
+
+ temp = temp/10;
+ temp2 = temp/10;
+
+ if(temp < 70 && temp > 60 && temp2 < 70 && temp2 > 60)
+ {
+ current_left_motor_speed = current_left_motor_speed + .010;
+ current_right_motor_speed = current_right_motor_speed + .010;
+ TFC_SetMotorPWM(current_left_motor_speed, current_right_motor_speed);
+ }
+ }
+
if (black_center_value < 64) {
current_servo_position= float(.01875*black_center_value-(1.2));
@@ -218,6 +245,32 @@
boolean listSame = true;
+ temp = 0;
+ temp2 = 0;
+
+ for(int i = 20; i < 30; i++)
+ {
+ temp = centers_List[i] + temp;
+ }
+
+ for(int i = 30; i < 40; i++)
+ {
+ temp2 = centers_List[i] + temp2;
+ }
+
+ temp = temp/10;
+ temp2 = temp/10;
+
+ if(temp < 70 && temp > 60 && temp2 < 70 && temp2 > 60)
+ {
+ current_left_motor_speed = current_left_motor_speed + .010;
+ current_right_motor_speed = current_right_motor_speed + .010;
+ TFC_SetMotorPWM(current_left_motor_speed, current_right_motor_speed);
+ }
+
+
+
+
/*
if(center_now + 5 < center_past_4 && center_now - 5 > center_past_4)
{
@@ -290,6 +343,29 @@
boolean listSame = true;
+ temp = 0;
+ temp2 = 0;
+
+ for(int i = 20; i < 30; i++)
+ {
+ temp = centers_List[i] + temp;
+ }
+
+ for(int i = 30; i < 40; i++)
+ {
+ temp2 = centers_List[i] + temp2;
+ }
+
+ temp = temp/10;
+ temp2 = temp/10;
+
+ if(temp < 70 && temp > 60 && temp2 < 70 && temp2 > 60)
+ {
+ current_left_motor_speed = current_left_motor_speed + .010;
+ current_right_motor_speed = current_right_motor_speed + .010;
+ TFC_SetMotorPWM(current_left_motor_speed, current_right_motor_speed);
+ }
+
/*
if(center_now + 5 < center_past_4 && center_now - 5 > center_past_4)
{