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:
- 22:539311b65796
- Parent:
- 21:4c7fcbf3718c
- Child:
- 23:a141ca857b8f
--- a/main.cpp Fri Mar 27 18:47:04 2015 +0000
+++ b/main.cpp Fri Mar 27 18:53:23 2015 +0000
@@ -64,7 +64,6 @@
int center_past_2 = 63;
int center_past_3 = 63;
int center_past_4 = 63;
- //int best_guess_center = 64;
int position = 0;
int set_point = 63;
@@ -127,7 +126,6 @@
TFC_SetMotorPWM(current_left_motor_speed, current_right_motor_speed);
}
-
// protection block
if(current_left_motor_speed >= PROTECTION_THRESHOLD_UPPER)
current_left_motor_speed= PROTECTION_THRESHOLD_UPPER;
@@ -138,7 +136,6 @@
if(current_right_motor_speed <= PROTECTION_THRESHOLD_LOWER)
current_right_motor_speed = PROTECTION_THRESHOLD_LOWER;
- //TFC_SetMotorPWM(current_left_motor_speed, current_right_motor_speed);
}// end motor enabled
else {
TFC_HBRIDGE_DISABLE;
@@ -154,18 +151,16 @@
//checking center pixel, displays aprox value on leds
uint8_t shitnum = 1;
-
// checking for center line (single line)
for (uint16_t i=10; i<118; i++) {
- if ((*(TFC_LineScanImage0+i) < 400)) {
+ if ((*(TFC_LineScanImage0+i) < 425)) {
black_values_list[black_value_count] = i;
black_value_count++;
}
}
- for(int i=0; i<black_value_count; i++) {
+ for(int i=0; i<black_value_count; i++)
sum_black += black_values_list[i];
- }
//update history
center_past_4= center_past_3;
@@ -173,8 +168,6 @@
center_past_2= center_past_1;
center_past_1= center_now;
-
- //if (black_value_count>2)
center_now = sum_black / black_value_count;
uint8_t num = 0;
@@ -212,25 +205,21 @@
// turn left
// hit wall a little bit on the right
if (num==8 and right_counter <.2 ) // only if we arent turning right
- //if(center_now >= 110 && center_now < 118 and right_counter <.2)
{
//turn away a little bit for each frame that is wall
if (left_counter >-.45)
{
- //left_counter -=.05;
- //left_counter -=.03;
- //left_counter -= (.001428571*(128-center_now));
- //left_counter -= (.002*(128-center_now));
if (center_now>100)
- left_counter -=.03;
+ //left_counter -=.03;
+ left_counter -=.027;
else
- left_counter -=.05;
+ //left_counter -=.05;
+ left_counter -=.044;
}
if (left_counter <-.46)
{
num_of_left =0;
- //need_decel=true;
}
@@ -254,7 +243,6 @@
// wall is close to center on left
else if (num==2 and left_counter >-.2)// only if we arent turning left
{
-
right_counter =.54;
turn_left=false;
turn_right=true;
@@ -267,15 +255,10 @@
// turn right
// hit wall a little bit on the left
else if (num==1 and left_counter >-.2) // only if we arent turning left
- //else if ( center_now > 15 && center_now < 27 and left_counter >-.2) // only if we arent turning left
{
//turn away a little bit for each frame that is wall
if (right_counter <.45)
{
- //right_counter +=.05;
- //right_counter +=.03;
- //right_counter +=(.001428571*center_now);
- //right_counter +=(.002*center_now);
if (center_now<28)
right_counter +=.03;
else
@@ -285,7 +268,6 @@
if (right_counter >.46)
{
num_of_right =0;
- //need_decel=true;
}
turn_left=false;
@@ -323,10 +305,9 @@
// normalize to center each frame
// left turning is - servo
if(left_counter > -.2) // small turn, normalize quickly
- //left_counter += .015;
- left_counter += .010;
+ left_counter += .009;
else // hard turn, normalize slowly
- left_counter += .009;
+ left_counter += .008;
// no longer turning boolean
if (left_counter > (0+ bullshit_offset))