Hi, I have been working on a remote control car. I have gotten it to the remote point however forward and reverse are very jumpy. What happens is the car has spurts of speed, and wrong direction spurts. I would like to eliminate the spurts in the wrong direction and even out the correct direction spurts.
The wireless uses a basic 433 Mhz module. I bought the modules on Ebay at this site:
http://www.ebay.com/itm/261143280474?_trksid=p2060778.m2749.l2649&ssPageName=STRK%3AMEBIDX%3AIT
The motor and steering control are based off of the L293D. The motor also has an h-bridge I made to increase current capability.
The main problem is in the code, I beleive. I am currently using pulse width modulation. One pulse I send through is between 500 and 1000 micro seconds and is for forward and reverse. The other is between 1500 and 2000 micro seconds and holds the data for left and right.
It is possible, with my home made bridge to short circuit the bridge and burn up the tip120 s and tip125 s. So I made a stopCar() function to keep the bridge from getting too hot and braking. This could be part of the problem since there is a recursive call to stop car in the goForward() function.
This is the main code.
/*Stenquist
test on sending digital data with
FS1000A
09/03/2014*/
//pins
//receiver
int in1 = 3;//BusA p1
int in2 = 2;//BusA d1
//control of car
int forward1 = 7;//Bus B d1
int forward2 = 8;//Bus b d2
int forwardSpeed = 9;//Bus b p1
int reverse1 = 10; //Bus B p2
int reverse2 = 12; //bus b d3
int reverseSpeed = 11; // bus b p3
int left = 4;//bus A d2
int right = 13;//bus A d3
int amountTurned = 5;//bus a p2
//global vars
//boolean sender = true;
volatile int amountFR = -1;
volatile int amountLR = -1;
//remember volatile(changes)
volatile unsigned long signal = -1;
volatile unsigned long time1 = -1;
volatile unsigned long time2 = -1;
volatile unsigned long count = 0;
volatile boolean even = true;
volatile boolean forward = true;
volatile boolean reverse = true;
void setup()
{
Serial.begin(9600);
pinMode(forward1, OUTPUT);
pinMode(forward2, OUTPUT);
pinMode(forwardSpeed, OUTPUT);
pinMode(reverse1, OUTPUT);
pinMode(reverse2, OUTPUT);
pinMode(reverseSpeed, OUTPUT);
stopCar();
pinMode(left, OUTPUT);
pinMode(right, OUTPUT);
pinMode(amountTurned, OUTPUT);
goStraight();
pinMode(in2, INPUT);
pinMode(in1, INPUT);
//attachInterrupt(0, timing, CHANGE);
attachInterrupt(0, timing1, RISING);
attachInterrupt(1, timing2, FALLING);
}
void loop()
{
//noInterrupts();
Serial.print("received ");
Serial.println(signal);
if(signal < 2000 && signal > 1400)
{
amountLR = signal - 1000;
Serial.print("amountLR ");
Serial.println(amountLR);
}
else if(signal < 1000 && signal > 400)
{
amountFR = signal;
Serial.print("amountFR ");
Serial.println(amountFR);
}
//noInterrupts();
Serial.println();
//control speed
if(amountFR > 750)
{
goForward(1, 255);
}
else if(amountFR > 550 && amountFR < 710 )
{
stopCar();
}
else if (amountFR < 600)
{
goBack(1, 255); //needs work
}
//interrupts();
//control direction
if(amountLR > 800)
{
goRight();//0, (amountFR - 450)/250);
}
else if(amountLR > 700 && amountLR < 800 )
{
goStraight();
}
else
{
goLeft();
}
delay(1000);
}//end loop
void timing1()
{
time1 = micros();
}
void timing2()
{
time2 = micros();
signal = (time2 - time1) ;
}
This is where the functions are found.
void goForward(int time, int velocity) //velocity
{
if(reverse == false)
{
digitalWrite(forward1, LOW);
digitalWrite(forward2, HIGH);
analogWrite(forwardSpeed, velocity);
}
else
{
stopCar();
goForward(0, velocity);
}
forward = true;
delay(time);
}
void goBack(int time, int velocity)
{
if(forward == false)
{
digitalWrite(reverse1, LOW);
digitalWrite(reverse2, HIGH);
analogWrite(reverseSpeed, velocity);
}
else
{
stopCar();
goBack(0, velocity);
}
reverse = true;
delay(time);
}
void stopCar(/*int time*/)
{
digitalWrite(forward1, HIGH);
digitalWrite(forward2, LOW);
digitalWrite(reverse1, HIGH);
digitalWrite(reverse2, LOW);
forward = false;
reverse = false;
delay(10);
}
void goRight()
{
analogWrite(amountTurned, 255);
digitalWrite(left, LOW);
digitalWrite(right, HIGH);
}
void goLeft()
{
analogWrite(amountTurned, 255);
digitalWrite(right, LOW );
digitalWrite(left, HIGH);
}
void goStraight()
{
digitalWrite(right, LOW);
digitalWrite(left, LOW);
digitalWrite(amountTurned, LOW);
}
Any help with this problem would be greatly appreciated!