Show Posts
Pages: 1 ... 11 12 [13] 14
181  Using Arduino / Programming Questions / Re: looped void problem on: May 05, 2011, 08:23:18 am
what kind of debug output must i give you?


I tested the ping sensor, no problems, everything else works fine except that when it drives in one direction forward, even if there is more than 10cm in front of the ping sensor, it will stop after a couple of seconds (or 1 second) and scan again.
182  Using Arduino / Programming Questions / Re: print strings on Serial Monitor on: May 05, 2011, 08:21:27 am
and 
Code:
Serial.print("Current Time: ");
Serial.println(time);
Serial.println();
Serial.print("Current Speed: ");
Serial.println(speed);

will give:
Current time: *time here*

Current Speed: *speed here*

183  Using Arduino / Programming Questions / Re: looped void problem on: May 05, 2011, 08:17:25 am
any help?
184  Using Arduino / Programming Questions / Re: looped void problem on: May 05, 2011, 06:17:28 am
I've done some troubleshooting and find the problem, but not the cause of that problem in the code.

It turns perfectly and such, but after a second, even when the ping sensor tells it the distance is bigger than 10 it re-scans.

Can anyone check the code and look for causes of this problem?

current code:
Code:
//robot car v4.1 by Niek Blankers
//Motorshield uses digital pins 11 and 3
//Receiver uses digital pin 0 (RX)
//PING))) sensor uses digital pin 7
//ping servo right = 0 degrees middle = 85 degrees left = 171 degrees
#include <AFMotor.h>
#include <Servo.h>

Servo pingservo;  // create servo object to control a servo
AF_DCMotor M_right(1, MOTOR12_64KHZ); // driver-side motor
AF_DCMotor M_left(2, MOTOR12_64KHZ); // passenger-side motor
const int pingPin = 2;
int incomingByte = 0;
int message = 0; // This will hold one byte of the serial message
#define velocityright (66) /* how fast the wheels spin */
#define velocityleft  (80)
#define turntime (975)

unsigned long dright = 0;
unsigned long dfront = 0;
unsigned long dleft = 0;

void setup()
{
  pingservo.attach(5);
  pingservo.write(0);
  delay(400);
  pingservo.write(85);
  delay(400);
  pingservo.write(171);
  delay(400);
  pingservo.write(85);
  M_left.setSpeed(velocityleft);
  M_right.setSpeed(velocityright);
  Serial.begin(1200);  // Hardware supports up to 2400, but 1200 gives longer range
  Serial.println("Hello!");
 
  delay(500);
}

void loop()
{
// here's gonna be like: if receivednumber = 534 so on..


               
                  autosteer();
               


}

void goforward()
{
   pingservo.write(85);
  M_left.run(FORWARD);
  M_right.run(FORWARD);
 // delay(1000);
}

void turnleft()
{
   pingservo.write(85);
 M_left.run(BACKWARD);
 M_right.run(FORWARD);   
delay(turntime);
}

void turnright()
{
   M_left.run(FORWARD);
 M_right.run(BACKWARD);
 pingservo.write(85);
 delay(turntime);
}

void full_stop()
{
  M_left.run(RELEASE);
  M_right.run(RELEASE);
}

void autosteer()
{
  STEER:
  full_stop();
  pingservo.write(0);
  delay(600);
  dright = microsecondsToCentimeters(ping());

  pingservo.write(85);
  delay(400);
  dfront = microsecondsToCentimeters(ping());

  pingservo.write(171);
  delay(400);
  dleft = microsecondsToCentimeters(ping());



if ( dright < 10 && dfront < 10 && dleft < 10)
{
  //go backward
 
   M_left.run(FORWARD);
    M_right.run(BACKWARD);
     pingservo.write(85);
    delay(1950);


    goforward();
     while (microsecondsToCentimeters(ping()) > 10)
     {
     }
     
     full_stop();
 
}

if (dright > dfront && dright > dleft)
  {
   
    //go right
    turnright();
    goforward();
    while (microsecondsToCentimeters(ping()) > 10)
    {
     
    }
    full_stop();
   
  }
   
  if (dleft > dfront && dleft > dright)
  {
   
    //go left
  turnleft();
  goforward();
   while (microsecondsToCentimeters(ping()) > 10)
    {     
    }
    full_stop();
 
  }
 
  if (dfront > dright && dfront > dleft)
  {
   
    // go forward
    goforward();
    delay(400);
    while (microsecondsToCentimeters(ping()) > 10)
    {     
    }
    full_stop(); 
}

}


unsigned long ping()
{
 
  // The PING))) is triggered by a HIGH pulse of 2 or more microseconds.
  // Give a short LOW pulse beforehand to ensure a clean HIGH pulse:
  pinMode(pingPin, OUTPUT);
  digitalWrite(pingPin, LOW);
  delayMicroseconds(2);
  digitalWrite(pingPin, HIGH);
  delayMicroseconds(5);
  digitalWrite(pingPin, LOW);

  // The same pin is used to read the signal from the PING))): a HIGH
  // pulse whose duration is the time (in microseconds) from the sending
  // of the ping to the reception of its echo off of an object.
  pinMode(pingPin, INPUT);
  return pulseIn(pingPin, HIGH);


unsigned long microsecondsToCentimeters(unsigned long microseconds)
{
  // The speed of sound is 340 m/s or 29 microseconds per centimeter.
  // The ping travels out and back, so to find the distance of the
  // object we take half of the distance travelled.
  return microseconds / 29 / 2;
}
185  Using Arduino / Programming Questions / Re: looped void problem on: May 05, 2011, 05:57:40 am
debug prints? what are those?
186  Using Arduino / Programming Questions / Re: looped void problem on: May 05, 2011, 05:26:08 am
the code is just, it turns 180 degrees and then drives forward : backward


Now it still doesn't work good...
187  Using Arduino / Programming Questions / Re: looped void problem on: May 05, 2011, 05:02:35 am
it is not dangerous, because the robot platform is perfectly round and it just turns around its axis, also:

It works now, except it doesn't drive until an object comes close to it, it just drives about a second, this is the code:

Code:
//robot car v3.9 by Niek Blankers
//Motorshield uses digital pins 11 and 3
//Receiver uses digital pin 0 (RX)
//PING))) sensor uses digital pin 7
//ping servo right = 0 degrees middle = 85 degrees left = 171 degrees
#include <AFMotor.h>
#include <Servo.h>

Servo pingservo;  // create servo object to control a servo
AF_DCMotor M_right(1, MOTOR12_64KHZ); // driver-side motor
AF_DCMotor M_left(2, MOTOR12_64KHZ); // passenger-side motor
const int pingPin = 2;
int message = 0; // This will hold one byte of the serial message
#define velocityright (66) /* how fast the wheels spin */
#define velocityleft  (80)
#define turntime (975)

unsigned long dright = 0;
unsigned long dfront = 0;
unsigned long dleft = 0;

void setup()
{
  pingservo.attach(5);
  pingservo.write(0);
  delay(400);
  pingservo.write(85);
  delay(400);
  pingservo.write(171);
  delay(400);
  pingservo.write(85);
  M_left.setSpeed(velocityleft);
  M_right.setSpeed(velocityright);
  Serial.begin(1200);  // Hardware supports up to 2400, but 1200 gives longer range
  delay(500);
}

void loop()
{
// here's gonna be like: if receivednumber = 534 so on..
autosteer();
}

void goforward()
{
   pingservo.write(85);
  M_left.run(FORWARD);
  M_right.run(FORWARD);
 // delay(1000);
}

void turnleft()
{
   pingservo.write(85);
 M_left.run(BACKWARD);
 M_right.run(FORWARD);  
delay(turntime);
}

void turnright()
{
   M_left.run(FORWARD);
 M_right.run(BACKWARD);
 pingservo.write(85);
 delay(turntime);
}

void full_stop()
{
  M_left.run(RELEASE);
  M_right.run(RELEASE);
}

void autosteer()
{
  STEER:
  full_stop();
  pingservo.write(0);
  delay(600);
  dright = microsecondsToCentimeters(ping());

  pingservo.write(85);
  delay(400);
  dfront = microsecondsToCentimeters(ping());

  pingservo.write(171);
  delay(400);
  dleft = microsecondsToCentimeters(ping());



if ( dright < 10 && dfront < 10 && dleft < 10)
{
  //go backward
   M_left.run(FORWARD);
    M_right.run(BACKWARD);
     pingservo.write(85);
    delay(1950);


    goforward();
     while (microsecondsToCentimeters(ping()) > 10)
     {
     }
    
     full_stop();
 
}

if (dright > dfront && dright > dleft)
  {
    //go right
    turnright();
    goforward();
    while (microsecondsToCentimeters(ping()) > 10)
    {
      
    }
    full_stop();
    
  }
    
  if (dleft > dfront && dleft > dright)
  {
    //go left
  turnleft();
  goforward();
   while (microsecondsToCentimeters(ping()) > 10)
    {      
    }
    full_stop();
  
  }
  
  if (dfront > dright && dfront > dleft)
  {
    // go forward
    goforward();
    delay(400);
    while (microsecondsToCentimeters(ping()) > 10)
    {      
    }
    full_stop();  
}

}


unsigned long ping()
{
  // The PING))) is triggered by a HIGH pulse of 2 or more microseconds.
  // Give a short LOW pulse beforehand to ensure a clean HIGH pulse:
  pinMode(pingPin, OUTPUT);
  digitalWrite(pingPin, LOW);
  delayMicroseconds(2);
  digitalWrite(pingPin, HIGH);
  delayMicroseconds(5);
  digitalWrite(pingPin, LOW);

  // The same pin is used to read the signal from the PING))): a HIGH
  // pulse whose duration is the time (in microseconds) from the sending
  // of the ping to the reception of its echo off of an object.
  pinMode(pingPin, INPUT);
  return pulseIn(pingPin, HIGH);
}  

unsigned long microsecondsToCentimeters(unsigned long microseconds)
{
  // The speed of sound is 340 m/s or 29 microseconds per centimeter.
  // The ping travels out and back, so to find the distance of the
  // object we take half of the distance travelled.
  return microseconds / 29 / 2;
}

i'm sorry if i ask too much, but does anyone know how to solve this?
188  Using Arduino / Programming Questions / Re: looped void problem on: May 05, 2011, 04:39:12 am
Sorry, i was in bit of a rush to get this code working, thanks for all the help!
189  Using Arduino / Programming Questions / Re: looped void problem on: May 05, 2011, 04:11:35 am
hm..

now, all it does is turn right and scan and turn right and so on...
190  Using Arduino / Programming Questions / Re: looped void problem on: May 05, 2011, 04:09:43 am
aha, i forgot a bracket! compiling.
191  Using Arduino / Programming Questions / Re: looped void problem on: May 05, 2011, 03:59:25 am
Now i have:

Code:
//robot car v3.6 by Niek Blankers
//Motorshield uses digital pins 11 and 3
//Receiver uses digital pin 0 (RX)
//PING))) sensor uses digital pin 7
//ping servo right = 0 degrees middle = 85 degrees left = 171 degrees
#include <AFMotor.h>
#include <Servo.h>

Servo pingservo;  // create servo object to control a servo
AF_DCMotor M_right(1, MOTOR12_64KHZ); // driver-side motor
AF_DCMotor M_left(2, MOTOR12_64KHZ); // passenger-side motor
const int pingPin = 2;
int message = 0; // This will hold one byte of the serial message
#define velocityright (66) /* how fast the wheels spin */
#define velocityleft  (80)
#define turntime (975)

unsigned long dright = 0;
unsigned long dfront = 0;
unsigned long dleft = 0;

void setup()
{
  pingservo.attach(5);
  pingservo.write(0);
  delay(400);
  pingservo.write(85);
  delay(400);
  pingservo.write(171);
  delay(400);
  pingservo.write(85);
  M_left.setSpeed(velocityleft);
  M_right.setSpeed(velocityright);
  Serial.begin(1200);  // Hardware supports up to 2400, but 1200 gives longer range
  delay(500);
}

void loop()
{
// here's gonna be like: if receivednumber = 534 so on..
autosteer();
}

void goforward()
{
   pingservo.write(85);
  M_left.run(FORWARD);
  M_right.run(FORWARD);
 // delay(1000);
}

void turnleft()
{
   pingservo.write(85);
 M_left.run(BACKWARD);
 M_right.run(FORWARD);   
delay(turntime);
}

void turnright()
{
   M_left.run(FORWARD);
 M_right.run(BACKWARD);
 pingservo.write(85);
 delay(turntime);
}

void full_stop()
{
  M_left.run(RELEASE);
  M_right.run(RELEASE);
}

void autosteer()
{
  STEER:
  full_stop();
  pingservo.write(0);
  delay(600);
  dright = microsecondsToCentimeters(ping());

  pingservo.write(85);
  delay(400);
  dfront = microsecondsToCentimeters(ping());

  pingservo.write(171);
  delay(400);
  dleft = microsecondsToCentimeters(ping());



if ( dright < 10 && dfront < 10 && dleft < 10)
{
  //go backward
   M_left.run(FORWARD);
    M_right.run(BACKWARD);
     pingservo.write(85);
    delay(1950);


    goforward();
     while (microsecondsToCentimeters(ping()) > 10)
     {
     }
     
     full_stop();
 
}

if (dright > dfront && dleft)
  {
    //go right
    turnright();
    goforward();
    while (microsecondsToCentimeters(ping()) > 10)
    {
     
    }
    full_stop();
   
  if (dleft > dfront && dright)
  {
    //go left
  turnleft();
  goforward();
   while (microsecondsToCentimeters(ping()) > 10)
    {
     
    }
    full_stop();
 
  }
  if (dfront > dright && dleft)
  {
    // go forward
    goforward();
    delay(400);
    while (microsecondsToCentimeters(ping()) > 10)
    {
     
    }
    full_stop(); 
}



unsigned long ping()
{
  // The PING))) is triggered by a HIGH pulse of 2 or more microseconds.
  // Give a short LOW pulse beforehand to ensure a clean HIGH pulse:
  pinMode(pingPin, OUTPUT);
  digitalWrite(pingPin, LOW);
  delayMicroseconds(2);
  digitalWrite(pingPin, HIGH);
  delayMicroseconds(5);
  digitalWrite(pingPin, LOW);

  // The same pin is used to read the signal from the PING))): a HIGH
  // pulse whose duration is the time (in microseconds) from the sending
  // of the ping to the reception of its echo off of an object.
  pinMode(pingPin, INPUT);
  return pulseIn(pingPin, HIGH);


unsigned long microsecondsToCentimeters(unsigned long microseconds)
{
  // The speed of sound is 340 m/s or 29 microseconds per centimeter.
  // The ping travels out and back, so to find the distance of the
  // object we take half of the distance travelled.
  return microseconds / 29 / 2;
}

but it gives the error "function-definition is not allowed here before { token"
at  unsigned long ping()

how do i solve this?
192  Using Arduino / Programming Questions / Re: looped void problem on: May 05, 2011, 03:54:29 am
thanks! it works again!

now trying the while loop..
193  Using Arduino / Programming Questions / Re: looped void problem on: May 05, 2011, 03:48:47 am
while programming i accidentally pressed a weird key combination and now in stead of normal typing cursor i get the "low stripe" thingy and if i for example go to the middle of a sentence and type something it replaces the text after the cursor with the text i am typing.

how to fix this?
194  Using Arduino / Programming Questions / Re: looped void problem on: May 04, 2011, 02:58:11 am
Solved all of the minor issues, but how do i replace goto with "while" loops?
195  Using Arduino / Programming Questions / Re: looped void problem on: May 03, 2011, 05:52:04 am
i thought that if i used
Code:
if ( dright && dfront && dleft < 10)

that it will drive backward if all the distances are less than 10.
Pages: 1 ... 11 12 [13] 14