Go Down

Topic: Passing Obstacle Arduino Car (Read 226 times) previous topic - next topic

HalilSenn

Hi. I'm forth year student in Turkey and i have final project. I try to make a car that can pass the obstacle but unfortunately my car's not even go straight. I need some help, im not good at coding. I am searching the codes and trying to change it appropriately.
My project will be like this (actually same with this);
https://www.youtube.com/watch?v=ZllwboOxNFE&feature=youtu.be
Can someone help me?

vinceherman

Yes, we can help you.
Help us.

Tell us what hardware you are using.
It looks to me like that video uses 2 motors and has encoders on the wheels.
Do you have that?

HalilSenn

Yes, we can help you.
Help us.

Tell us what hardware you are using.
It looks to me like that video uses 2 motors and has encoders on the wheels.
Do you have that?
I am using 2 motors, L298N motor driver, encoders, ultrasonic sensor, arduino uno and compass sensor.
Here is my code to go straight (it is not going straight);

const byte MOTOR_SAG = 3;
const byte MOTOR_SOL = 2;

const float stepcount = 20.00;
const float wheeldiameter = 60.00;

volatile int counter_A = 0;
volatile int counter_B = 0;

//Motor sağ
int enA = 10;
int in1 = 9;
int in2 = 8;

//Motor sol
int enB = 5;
int in3 = 7;
int in4 = 6;

//Motor sağ pulse counter
void ISR_countA()
{
  counter_A++;
}
 //Motor sol pulse counter
void ISR_countB()
{
  counter_B++;
}

int CMtoSteps(float cm)
{
  int result;
  float circumference = (wheeldiameter * 3.14) / 10;
  float cm_step = circumference / stepcount;

  float f_result = cm / cm_step;
  result = (int) f_result;
  return result;
}

void MoveForward(int steps, int mspeed)
{
  counter_A = 0; //reset counter A to zero
  counter_B = 0; //reset counter B to zero

  //Motor sağ ileri
  digitalWrite(in1, HIGH);
  digitalWrite(in2, LOW);
  //Motor sol ileri
  digitalWrite(in3, HIGH);
  digitalWrite(in4, LOW);

  //Sayılan sayı bitene kadar ilerle
  while (steps > counter_A || steps > counter_B)
  { if(counter_B >= counter_A)
  { analogWrite(enA, mspeed);}
  else
  { analogWrite(enA, 0); }
  if (counter_A >= counter_B)
  { analogWrite(enB, mspeed); }
  else
  {analogWrite(enB, 0);}
}

// Bittiğinde durdur
analogWrite(enA, 0);
analogWrite(enB, 0);
//Sprint();
counter_A = 0;
counter_B = 0;
}
void setup() {
  attachInterrupt(digitalPinToInterrupt (MOTOR_SAG), ISR_countA, RISING);
  attachInterrupt(digitalPinToInterrupt (MOTOR_SOL), ISR_countB, RISING);

  //cm sonra durdurur
  MoveForward(CMtoSteps(1000),200);
  delay(1000);

}

void loop() {
  // put your main code here, to run repeatedly:

}

(Motor_SAG is right motor and motor_SOL is left motor in Turkish)

AWOL

Get your code to tell you how it is working by adding some debug prints.
Just make sure you don't put any in interrupt context.

HalilSenn

https://www.youtube.com/watch?v=ZllwboOxNFE
My project will be this. But im not good at coding. Please help me :(
I look the GitHub but almost all of the codes are obstacle avoiding projects. How can i stop the car when the obstacle is moving?

Go Up