Pages: 1 2 3 [4]   Go Down
Author Topic: Steering Movement Problem  (Read 2559 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Full Member
***
Karma: 0
Posts: 196
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

here is the code that i am using
Code:
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
Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 178
Posts: 8064
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

What does the output on Serial Monitor look like?
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Offline Offline
Full Member
***
Karma: 0
Posts: 196
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Offline Offline
Full Member
***
Karma: 0
Posts: 196
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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);
}
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 452
Posts: 18694
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

-->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.
Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 178
Posts: 8064
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

What does the output on Serial Monitor look like?

Perhaps I should rephrase that. smiley-sad

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.
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Offline Offline
Full Member
***
Karma: 0
Posts: 196
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 178
Posts: 8064
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Offline Offline
Full Member
***
Karma: 0
Posts: 196
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 238
Posts: 24318
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'd like to refer you to reply #41
Logged

"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.

Offline Offline
Full Member
***
Karma: 0
Posts: 196
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thank you all of you in helping me out thanks
Logged

Pages: 1 2 3 [4]   Go Up
Jump to: