Hey guys,
I'm currently working on project that involves controlling a boat autonomously and whilst that is going on collect GPS coordinates of the path the boat is travelling and send it to a log file. So far i have been able to write the program to control the movement of the boat autonomously works perfectly fine on its own, the same goes the GPS code, its also works on its own. But the minute i try to combine the two programs together, the boat goes out of control and the servos start turning uncontrollably, its just doesn't work. Any ideas on how i can achieve this. Thanks alot
Code for boat movement
#include <Servo.h>
Servo Rudders;
Servo fThrust1;
//Servo fThrust2;
Servo rThrust;
/
int minPulse = 850;
int maxPulse = 2250;
int pos = 0;
int counter = 0;
boolean ok = false;
boolean ready = false;
void setup()
{
Serial.begin(9600);
void loop()
{
if(!ready)
{
First();
}
if(!ok)
{
Move();
}
}
void Move(){ //Beginning of move function..
fThrust1.write(30);
// fThrust2.write(180);
rThrust.write(30);
delay(5000);
for(pos = 90; pos<=140; pos+=1) // goes from 180 degrees to 0 degrees
{
Rudders.write(pos); // tell servo to go to position in variable 'pos'
delay(30); // waits 15ms for the servo to reach the position
}
delay(2000);
for(pos = 140; pos>=90; pos -= 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
Rudders.write(pos); // tell servo to go to position in variable 'pos'
delay(30); // waits 15ms for the servo to reach the position
}
// counter += 1;
//Serial.print("Counter is :");
//Serial.println(counter);
delay(5000); //wait for a bit before turning again ...
for(pos = 90; pos<=140; pos+=1) // goes from 180 degrees to 0 degrees
{
Rudders.write(pos); // tell servo to go to position in variable 'pos'
delay(30); // waits 15ms for the servo to reach the position
}
delay(2000);
for(pos = 140; pos>=90; pos -= 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
Rudders.write(pos); // tell servo to go to position in variable 'pos'
delay(30); // waits 15ms for the servo to reach the position
}
//counter += 1;
//Serial.print("\nCounter is :");
//Serial.println(counter);
delay(5000); //wait for a bit before turning again ...
for(pos = 90; pos<=140; pos+=1) // goes from 180 degrees to 0 degrees
{
Rudders.write(pos); // tell servo to go to position in variable 'pos'
delay(30); // waits 15ms for the servo to reach the position
}
delay(2000);
for(pos = 140; pos>=90; pos -= 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
Rudders.write(pos); // tell servo to go to position in variable 'pos'
delay(30); // waits 15ms for the servo to reach the position
}
delay(2000);
//counter += 1;
//Serial.print("\nCounter is :");
//Serial.println(counter);
delay(5000); //wait for a bit before turning again ...
fThrust1.write(0);
ok = true;
}// End of Move function....
void First(){ // Function to arm the thrusters ...
// Attach each Servo object to a digital pin
Rudders.attach(9, minPulse, maxPulse);
fThrust1.attach(10, minPulse, maxPulse);
//fThrust2.attach(10, minPulse, maxPulse);
rThrust.attach(11, minPulse, maxPulse);
fThrust1.write(0);
// fThrust2.write(0);
rThrust.write(0);
delay(2000);
fThrust1.write(180);
//fThrust2.write(180);
rThrust.write(180);
delay(2000);
fThrust1.write(0);
//fThrust2.write(0);
rThrust.write(0);
delay(2000);
ready = true;
}
P.S the codes for the GPS and the final output i attached to this post.. Pls check them and let me what you think ..
gpsCode.ino (8.25 KB)
finalCode.ino (11.9 KB)