Hello, I'm doing a waypoint RC robot project. It's a university project.
Right now I can only do the RC system, I want to add a waypoint system to the car using the GY-NEO6MV2 module and the HMC5883L compass.
by purchasing equipment and studying by following the link
But my robot doesn't use Bluetooth.
where my robot scope set is
That is, I want to estimate that I teach the robot first.
Assuming that we force our hands with the RC system, when we reach the point we want, press the button to record the GPS coordinates as the starting point, which is point A.
and driven by RC again to the desired destination. and press the save button to record as the destination point is point B
Then when we are going to use it, take the car to point A, turn on the GPS mode, let it drive forward to point B.
At point B, it stops working.
Now I only have RC control system with following code.
int motorLR = 4; // Dir_L
int motorLS = 5; // PWM_L
int motorRR = 6; // Dir_R
int motorRS = 7; // PWM_R
int pump = 2;
int channel1 = A0; // move left and right
int channel2 = A1; // forward backwards
int channel3 = A2; // adjust speed
int channel4 = A3; // move left and right
int channel5 = A4; // forward backwards
int channel6 = A5; // water pump
int channel7 = A6; // save GPS point A coordinates
int channel8 = A7; // save GPS point B coordinates
int channel9 = A8; // clear GPS coordinates
int channel10 = A9; // Driven by GPS
int ch1; // left right
int ch2; // forward backwards
int ch3; // adjust speed
int ch6; // water pump
int ch7; // save GPS coordinates
int ch8; // clear GPS coordinates
int ch9; //
int Speed ;
////////////////////////////////////////////////// ///////////////////////
///////////////////////// RC CONTROL /////////////////// // //////////
////////////////////////////////////////////////// ///////////////////////
void setup(){
pinMode (pump, OUTPUT);
pinMode (motorRR, OUTPUT);
pinMode (motorRS, OUTPUT);
pinMode(channel2, INPUT);
pinMode(channel3, INPUT);
pinMode(channel6,INPUT);
pinMode (channel7, INPUT);
pinMode(channel8, INPUT);
pinMode (channel9, INPUT);
Serial. begin(9600);
}
void loop(){
ch1 = (pulseIn (channel1, HIGH));
Serial.println(ch1);
ch2 = (pulseIn (channel2, HIGH));
Serial.println(ch2);
ch3 = (pulseIn (channel3, HIGH));
Serial.println(ch3);
ch6 = (pulseIn (channel6, HIGH));
Serial.println(ch6);
ch7 = (pulseIn (channel7, HIGH));
Serial.println(ch7);
ch8 = (pulseIn (channel8, HIGH));
Serial.println(ch8);
ch9 = (pulseIn (channel9, HIGH));
Serial.println(ch9);
analogWrite(pump, map(pulseIn(channel6,HIGH),1000,2000,0,100)); //_______________ water pump
delay(20);
int Speed = map(ch3,1000,2000,0,255);
if(ch1 > 1300 && ch1 < 1600 && ch2 > 1300 && ch2 < 1600)
{
analogWrite(motorLS, 0);
analogWrite(motorRS, 0);
digitalWrite(motorLR, HIGH);
digitalWrite(motorRR, LOW);
delay(200);
}
if (ch1 < 1300 && ch2 < 1300) // ___________________Left
{ analogWrite(motorLS, Speed);
analogWrite(motorRS, Speed);
digitalWrite(motorLR, LOW);
digitalWrite(motorRR, LOW);
delay(200);
}
else if (ch1 > 1600 && ch2 <1300) //________________back diagonally right
{
analogWrite(motorLS, Speed);
analogWrite(motorRS, Speed);
digitalWrite(motorLR, HIGH);
digitalWrite(motorRR, HIGH);
delay(200);
}
else if (ch1 < 1300 && ch2 > 1600)//_________________Left diagonal forward
{
analogWrite(motorLS, Speed);
analogWrite(motorRS, Speed);
digitalWrite(motorLR, LOW);
digitalWrite(motorRR, LOW);
delay(200);
}
else if (ch1 > 1600 && ch2 >1600) //_________________Right
{
analogWrite(motorLS, Speed);
analogWrite(motorRR, Speed);
digitalWrite(motorLR, HIGH);
digitalWrite(motorRR, HIGH);
delay(200);
}
else if (ch2 < 1400) //___________________backward
{
analogWrite(motorLS, Speed);
analogWrite(motorRS, Speed);
digitalWrite(motorLR, LOW);
digitalWrite(motorRR, HIGH);
delay(200);
}
else if (ch2 > 1600) // _____________________Forward
{
analogWrite(motorLS, Speed);
analogWrite(motorRS, Speed);
digitalWrite(motorLR, HIGH);
digitalWrite(motorRR, LOW);
delay(200);
}
}
I should code my GPS with Compass, how is it good, any suggestions? Thanks.