seabass2020
Jet Boat Lover
- Messages
- 68
- Reaction score
- 32
- Points
- 67
- Boat Make
- Yamaha
- Year
- 2017
- Boat Model
- AR
- Boat Length
- 21
And in case anyone is interested, here is my arduino sketch:
#include <TinyGPS++.h>
#include <SoftwareSerial.h>
#include <PID_v1.h>
static const int RXPin = 10, TXPin = 11, CruiseUp1 = 5, CruiseUp2 = 6, CruiseDown1 = 3, CruiseDown2 = 4, ButtonPin = 7;
static const uint32_t GPSBaud = 9600;
double TargetSpeed;
double CurrentSpeed;
double DeadZone = 1.1; //amount of space where no adjustment made
TinyGPSPlus gps;
SoftwareSerial ss(RXPin, TXPin);
void setup()
{
Serial.begin(57600);
ss.begin(GPSBaud);
Serial.println("Firing it up");
pinMode(CruiseUp1, OUTPUT); //two cruise ups and down because of the chip i'm using to trip the switch
pinMode(CruiseUp2, OUTPUT);
pinMode(CruiseDown1, OUTPUT);
pinMode(CruiseDown2, OUTPUT);
pinMode(ButtonPin, INPUT);
//CurrentSpeed = 20;
}
void loop()
{
if (digitalRead(ButtonPin) == HIGH) {
TargetSpeed = CurrentSpeed;
Serial.println("Got Button Press");
Serial.print("Target speed is now: ");
Serial.println(TargetSpeed);
}
while (ss.available() > 0)
if (gps.encode(ss.read()) && gps.speed.mph() > 0){
//CurrentSpeed = gps.speed.mph();
}
//else Serial.println("GPS Not Ready");
if (millis() > 7000 && gps.charsProcessed() < 10)
{
Serial.println(F("No GPS detected: check wiring."));
while(true);
}
if (TargetSpeed > 0) DoCruiseCheck();
if (CurrentSpeed < 10) {
TargetSpeed = 0;
Serial.println("Current Speed less than 10 MPH, setting Target Speed to 0.");
}
ReadInputString(); //check if there is a serial monitor input string
DisplayInfo();
}
void DoCruiseCheck(){
if ( abs((TargetSpeed * 100) - (CurrentSpeed * 100)) > DeadZone * 100){ //if delta is greater than deadzone, take action
if (CurrentSpeed > TargetSpeed) CruiseButtonDown();
else CruiseButtonUp();
}
}
void CruiseButtonUp(){
digitalWrite(CruiseUp1, HIGH);
Serial.println("Simulating Cruise Up - One Second Delay.....");
delay(1000);
digitalWrite(CruiseUp1, LOW);
}
void CruiseButtonDown(){
digitalWrite(CruiseDown1, HIGH);
Serial.println("Simulating Cruise Down - One Second Delay.....");
delay(1000);
digitalWrite(CruiseDown1, LOW);
}
void ReadInputString(){
String readString;
while (Serial.available()) {
char c = Serial.read(); //gets one byte from serial buffer
readString += c; //makes the string readString
delay(2); //slow looping to allow buffer to fill with next character
}
if (readString.length() >0) {
CurrentSpeed = readString.toDouble(); //convert readString into a number
}
}
void DisplayInfo(){
Serial.println("GPS INFO:-------");
Serial.print("GPS Coordinates:");
Serial.print(gps.location.lat(), 6); // Latitude in degrees (double)
Serial.print(", ");
Serial.println(gps.location.lng(), 6); // Longitude in degrees (double)
//Serial.println("---------------------------------------");
Serial.println();
Serial.print("Current MPH: ");
Serial.println(CurrentSpeed);
Serial.print("Target MPH: ");
Serial.println(TargetSpeed);
}
#include <TinyGPS++.h>
#include <SoftwareSerial.h>
#include <PID_v1.h>
static const int RXPin = 10, TXPin = 11, CruiseUp1 = 5, CruiseUp2 = 6, CruiseDown1 = 3, CruiseDown2 = 4, ButtonPin = 7;
static const uint32_t GPSBaud = 9600;
double TargetSpeed;
double CurrentSpeed;
double DeadZone = 1.1; //amount of space where no adjustment made
TinyGPSPlus gps;
SoftwareSerial ss(RXPin, TXPin);
void setup()
{
Serial.begin(57600);
ss.begin(GPSBaud);
Serial.println("Firing it up");
pinMode(CruiseUp1, OUTPUT); //two cruise ups and down because of the chip i'm using to trip the switch
pinMode(CruiseUp2, OUTPUT);
pinMode(CruiseDown1, OUTPUT);
pinMode(CruiseDown2, OUTPUT);
pinMode(ButtonPin, INPUT);
//CurrentSpeed = 20;
}
void loop()
{
if (digitalRead(ButtonPin) == HIGH) {
TargetSpeed = CurrentSpeed;
Serial.println("Got Button Press");
Serial.print("Target speed is now: ");
Serial.println(TargetSpeed);
}
while (ss.available() > 0)
if (gps.encode(ss.read()) && gps.speed.mph() > 0){
//CurrentSpeed = gps.speed.mph();
}
//else Serial.println("GPS Not Ready");
if (millis() > 7000 && gps.charsProcessed() < 10)
{
Serial.println(F("No GPS detected: check wiring."));
while(true);
}
if (TargetSpeed > 0) DoCruiseCheck();
if (CurrentSpeed < 10) {
TargetSpeed = 0;
Serial.println("Current Speed less than 10 MPH, setting Target Speed to 0.");
}
ReadInputString(); //check if there is a serial monitor input string
DisplayInfo();
}
void DoCruiseCheck(){
if ( abs((TargetSpeed * 100) - (CurrentSpeed * 100)) > DeadZone * 100){ //if delta is greater than deadzone, take action
if (CurrentSpeed > TargetSpeed) CruiseButtonDown();
else CruiseButtonUp();
}
}
void CruiseButtonUp(){
digitalWrite(CruiseUp1, HIGH);
Serial.println("Simulating Cruise Up - One Second Delay.....");
delay(1000);
digitalWrite(CruiseUp1, LOW);
}
void CruiseButtonDown(){
digitalWrite(CruiseDown1, HIGH);
Serial.println("Simulating Cruise Down - One Second Delay.....");
delay(1000);
digitalWrite(CruiseDown1, LOW);
}
void ReadInputString(){
String readString;
while (Serial.available()) {
char c = Serial.read(); //gets one byte from serial buffer
readString += c; //makes the string readString
delay(2); //slow looping to allow buffer to fill with next character
}
if (readString.length() >0) {
CurrentSpeed = readString.toDouble(); //convert readString into a number
}
}
void DisplayInfo(){
Serial.println("GPS INFO:-------");
Serial.print("GPS Coordinates:");
Serial.print(gps.location.lat(), 6); // Latitude in degrees (double)
Serial.print(", ");
Serial.println(gps.location.lng(), 6); // Longitude in degrees (double)
//Serial.println("---------------------------------------");
Serial.println();
Serial.print("Current MPH: ");
Serial.println(CurrentSpeed);
Serial.print("Target MPH: ");
Serial.println(TargetSpeed);
}