Go Down

Topic: Steering Movement Problem (Read 3 times) previous topic - next topic

cutebuddy6

here is the code that i am using
Code: [Select]
const int potPin = A0;

const int leftMotor = 10; //PWM pin to the L293
const int rightMotor = 9; //PWM pin to the L293

bool isLeft()          {
  return (analogRead(potPin)/4) < 14;
}
bool isLeftOfCenter()  {
  return (analogRead(potPin)/4) < 119;
}
bool isRightOfCenter() {
  return (analogRead(potPin)/4) > 133;
}
bool isRight()         {
  return (analogRead(potPin)/4) > 245;
}

void motorStop() {
  digitalWrite(leftMotor, LOW);
  digitalWrite(rightMotor, LOW);
}
void motorLeft() {
  digitalWrite(leftMotor, HIGH);
}
void motorRight() {
  digitalWrite(rightMotor, HIGH);
}


void setup() {
  Serial.begin(115200);
  Serial.println ("Entering setup.");
}

void loop()
{
  if (Serial.available() == 0)
    return;

  switch (toupper(Serial.read()))
  {
  case 'L':
    Serial.println("New command: L");
    if (isLeft())
      Serial.println("Already Left");
    else
    {
      Serial.println("Heading Left");
      motorLeft();
      while (!isLeft()) /* JUST WAITING */;
      motorStop();
      Serial.println("Is now Left");
    }
    break;

  case 'C':
    Serial.println("New command: C");
    if (isRightOfCenter())
    {
      Serial.println("Heading Left toward Center");
      motorLeft();
      while (isRightOfCenter()) /* JUST WAITING */;
      motorStop();
      Serial.println("Is now Centered");
    }
    else
      if (isLeftOfCenter())
      {
        Serial.println("Heading Right toward Center");
        motorRight();
        while (isLeftOfCenter()) /* JUST WAITING */;
        motorStop();
        Serial.println("Is now Centered");
      }
      else
        Serial.println("Already Centered");


    break;

  case 'R':
    Serial.println("New command: R");
    if (isRight())
      Serial.println("Already Right");
    else
    {
      Serial.println("Heading Right");
      motorRight();
      while (!isRight()) /* JUST WAITING */;
      motorStop();
      Serial.println("Is now Right");
    }

    break;

  }  // end of switch on direction

}  // end of loop

johnwasser

Well, the code looks good (possibly because I wrote it for you).

What does the output on Serial Monitor look like?
Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

cutebuddy6

well its get restarted after every two command or one command i send through serial monitor

cutebuddy6

i have Posted the schematic and what if i modify the code as
Quote
void setup() {
  Serial.begin(115200);
  Serial.println ("Entering setup.");
  pinMode(leftMotor, OUTPUT);
  pinMode(rightMotor, OUTPUT);
}

Nick Gammon


-->What will RAM do when i am Moving the code


I've been sent a personal message by CuteBuddy6 to ask for more help. Please don't.

I don't understand this sort of talk. Are you asking what the RAM will do if the buggy moves?

Oh. I see we are up to page 4.

Almost certainly the program is restarting because of electrical issues. To test disconnect the buggy and see if it restarts. The circuit you posted doesn't seem (to me) to have the Arduino in it.

You seem to be completely incapable of responding to direct questions, such as:


What does the output on Serial Monitor look like?



well its get restarted after every two command or one command i send through serial monitor


How about replying?

What Do You See In The Serial Monitor????? Copy and Paste. Don't Just Describe It.

johnwasser


What does the output on Serial Monitor look like?


Perhaps I should rephrase that. :(

cutebuddy6, please start your sketch, start the Serial Monitor, try sending the commands L, R, C, R, L,  C.  Then copy all the text from the Serial Monitor window and paste it into a reply here.
Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

cutebuddy6

Quote
New command: L
Heading Left
Is now Left
New command: R
Heading Right
Is now Right
New command: C
Heading Left toward Center
Is now Centered
Entering setup.
New command: L
Heading Left
Is now Left
New command: R
Heading Right
Is now Right
Entering setup.
New command: C
Heading Left toward Center
Is now Centered
New command: L
Heading Left
Is now Left
New command: R
Heading Right
Is now Right
Entering setup.
New command: L
Heading Left
Is now Left
New command: C
Heading Right toward Center
Is now Centered
Entering setup.

here is what i get on serial Monitor

johnwasser


New command: L - Heading Left - Is now Left
New command: R - Heading Right - Is now Right
New command: C - Heading Left toward Center - Is now Centered
Entering setup.

New command: L - Heading Left - Is now Left
New command: R - Heading Right - Is now Right
Entering setup.

New command: C - Heading Left toward Center - Is now Centered
New command: L - Heading Left - Is now Left
New command: R - Heading Right - Is now Right
Entering setup.

New command: L - Heading Left - Is now Left
New command: C - Heading Right toward Center - Is now Centered
Entering setup.


So it has nothing to do with going Left specifically because it happens randomly after L, R, or C.  It has nothing to do the motors running because it only happens AFTER the message that gets sent AFTER the motors have been stopped.

If it were a real Arduino there could be the possibility that the PC is glitching the DTR signal for some reason and the auto-reset is happening between commands.  To test for that you could jumper the Reset pin to +5 and see if the symptom goes away.  Since you have built your own Arduino-like circuit and have not shown it I don't know if you implemented auto-reset or not.
Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

cutebuddy6

It just worked
I followed the link given by the member and it just worked
http://arduino.cc/forum/index.php/topic,91456.0.html

AWOL

I'd like to refer you to reply #41
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

cutebuddy6

Thank you all of you in helping me out thanks

Go Up