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:
- 36:3491a7d8ffb6
- Parent:
- 35:e1cfadfe7469
- Child:
- 37:9c544f53563d
--- a/main.cpp Tue Mar 03 20:21:29 2015 +0000
+++ b/main.cpp Tue Mar 03 21:49:11 2015 +0000
@@ -5,7 +5,7 @@
#define MODERATE .48
#define CONSERVATIVE .35
#define STOP 0
-#define BLACK_THRESHOLD 64
+#define BLACK_THRESHOLD 63
#define LINE_SCAN_LENGTH 128
#define PROTECTION_THRESHOLD_UPPER .7
#define PROTECTION_THRESHOLD_LOWER -.7
@@ -103,7 +103,7 @@
current_left_motor_speed = -(AGGRESSIVE);
current_right_motor_speed = AGGRESSIVE;
}
- if (violence_level==2) {
+ else if (violence_level==2) {
current_left_motor_speed = -(MODERATE);
current_right_motor_speed = (MODERATE);
}
@@ -176,6 +176,7 @@
center_past_2= center_past_1;
center_past_1= center_now;
+ /*
for(int i = 49; i >= 0; i--)
{
if(i = 0)
@@ -186,7 +187,8 @@
{
centers_List[i] = centers_List[i-1];
}
- }
+ }
+ */
// value of center of black (single line)
//black_center_value = sum_black / black_value_count;
@@ -194,7 +196,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 = (5*center_now + 10*center_past_1 + 15*center_past_2 +30*center_past_3 +40*center_past_4)/100;
+ black_center_value = (15*center_now + 15*center_past_1 + 15*center_past_2 +25*center_past_3 +30*center_past_4)/100;
/* ******* PID ALGORITHM *******
@@ -210,6 +212,7 @@
*****************************
*/
+ /*
if (black_center_value == BLACK_THRESHOLD)
{
TFC_SetServo(0,0);
@@ -236,17 +239,20 @@
current_right_motor_speed = current_right_motor_speed + .010;
TFC_SetMotorPWM(current_left_motor_speed, current_right_motor_speed);
}
+
}
+ */
if (black_center_value < BLACK_THRESHOLD) {
- current_servo_position = float(.01875*black_center_value-(1.2));
+ //current_servo_position = float(.01875*black_center_value-(1.2));
+ current_servo_position = float(.01875*center_now-(1.2));
if(current_servo_position <= -0.4)
current_servo_position = -0.4;
TFC_SetServo(0, current_servo_position);
- bool listSame = true;
-
+ //bool listSame = true;
+ /*
int temp = 0;
int temp2 = 0;
@@ -270,7 +276,7 @@
TFC_SetMotorPWM(current_left_motor_speed, current_right_motor_speed);
}
-
+ */
/*
@@ -317,8 +323,8 @@
//current_left_motor_speed = current_left_motor_speed + float(64-black_center_value)*.0025;
//current_right_motor_speed = current_right_motor_speed + float(64-black_center_value)*.0025;
if (violence_level !=0){
- current_left_motor_speed = current_left_motor_speed + float(float(64-black_center_value)*.025);// kinda reverse this...
- current_right_motor_speed = current_right_motor_speed + float(float(64-black_center_value)*.045);// push more forwards
+ current_left_motor_speed = current_left_motor_speed + float(float(63-black_center_value)*.025);// kinda reverse this...
+ current_right_motor_speed = current_right_motor_speed + float(float(63-black_center_value)*.045);// push more forwards
}
// protection block
@@ -337,13 +343,14 @@
// need to turn right
else if (black_center_value > BLACK_THRESHOLD) {
- current_servo_position= float(.01875*black_center_value-(1.2));
- if( current_servo_position >= +0.4)
- current_servo_position = +0.4;
+ //current_servo_position= float(.01875*black_center_value-(1.2));
+ current_servo_position= float(.01875*center_now-(1.2));
+ if( current_servo_position >= 0.4)
+ current_servo_position = 0.4;
TFC_SetServo(0, current_servo_position);
- bool listSame = true;
-
+ //bool listSame = true;
+ /*
int temp = 0;
int temp2 = 0;
@@ -411,8 +418,8 @@
//current_left_motor_speed = current_left_motor_speed - float(black_center_value-64)*.0025;
//current_right_motor_speed = current_right_motor_speed - float(black_center_value-64)*.0025;
if (violence_level !=0){
- current_left_motor_speed = current_left_motor_speed - float(float(black_center_value-64)*.045);// push more forwards
- current_right_motor_speed = current_right_motor_speed - float(float(black_center_value-64)*.025);// kinda reverse this...
+ current_left_motor_speed = current_left_motor_speed - float(float(black_center_value-63)*.045);// push more forwards
+ current_right_motor_speed = current_right_motor_speed - float(float(black_center_value-63)*.025);// kinda reverse this...
}
// protection block