Permalink
Browse files

turned bot around, swapped pulsewidth #defines

  • Loading branch information...
1 parent 549ef2c commit 7c137a0758aa43f14fe4ab957859c05defda8c39 @g4lvanix committed Apr 13, 2012
Showing with 10 additions and 14 deletions.
  1. +10 −14 main.c
View
@@ -9,11 +9,11 @@
#define right_fwd 500
#define right_bwd 1000
-#define left_fwd 1000
+#define left_fwd 830
#define left_bwd 500
-#define right_stop 696
-#define left_stop 680
+#define right_stop 680
+#define left_stop 696
/* define pulsewidth register for each motor */
#define m_right OCR1A
@@ -76,6 +76,8 @@ uint16_t read_sharp(void){
int main(void){
+ uint16_t distL, distR;
+
// add a delay to compensate for missing on/off switch
_delay_ms(3000);
@@ -89,11 +91,12 @@ int main(void){
// go straight while distance is greater than 10cm
while(read_sharp() > 10);
+
while(read_sharp() < 20){
m_right = right_bwd;
m_left = left_fwd;
_delay_ms(5); // wait until next reading of sharp
- };
+ }
/*
// turn right and measure distance
@@ -106,7 +109,7 @@ int main(void){
// give it some time to settle
_delay_ms(100);
- uint16_t distR = read_sharp();
+ distR = read_sharp();
// turn left and measure distance
m_right = right_fwd;
@@ -118,26 +121,19 @@ int main(void){
// give it some time to settle
_delay_ms(100);
- uint16_t distL = read_sharp();
+ distL = read_sharp();
if(distR > distL){ // if there is more space on the right, turn right
while(read_sharp() < 20){ // until distance >= 20cm
m_right = right_bwd;
m_left = left_fwd;
}
}
- else if(distL > distR){ // if there is more space on the left, turn left
+ else{ // if there is more space on the left, turn left
while(read_sharp() < 20){ // until distance >= 20cm
m_right = right_fwd;
m_left = left_bwd;
}
- }
- else{
- while(read_sharp() < 20){ // turn right as long as read_sharp() < 20cm
- m_right = right_bwd;
- m_left = left_fwd;
- }
}*/
-
}
}

0 comments on commit 7c137a0

Please sign in to comment.