Båtprojekt

Elektronisk växel och gasreglage

Jag har börjat på ett projekt att göra om gas/växel elektroniskt styrd.

Det är än så länge i startskedet. Det kommer att styras av en Arduino, med linjära servon för reglering på motorn.

Material

  • Arduino nano
  • linjär 10 Kohm marint kapslad potentiometer
  • 4 st linjära sevo
    • Slaglängd: 10cm
    • Kraft ca: 15-20 Kg
    • Hastighet: 4-10 cm/

Jag kommer att lägga upp ändringar och mer beskrivning på installation.


Programkod:

/* Electronic Servocontrolled Throttle and Gear for boatmotors

Roger Caballero Jonsson
2017-03-20

Version 1.3

For use in marin environment it´s prefered to use Linear servo (PWM 5 Volt)or actuator with feedback.
– Speed : 40-100 mm/sec
– Force : 15-20 Kg
– Stroke: 100 mm

Potentiometer for marin environment
– Value : 10Kohm, linear
*/

#include <LiquidCrystal.h>
#include <Servo.h>

// SETUP LCD DISPLAY
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

// SETUP SERVO
Servo throttleservo; // Create Servo objekt for THROTLE servo1
Servo gearservo; // Create Servo objekt for GEAR servo2
// SET VARIABLES
int potpin = 0; // REGLAGE Potentiometer input from analog port (A0)

int iControlPos; // (A0) Potentiometer input value (position)
int iControlGearValue; // Trottle servo value
int iControlThrottleValue; // Gear servo value
int StopMotor = 7; // Motor OFF (Emergency) Digital Pin 7

// DECLARE USER CHANGABLE VARABLES
int ZeroThrottle = 0;
int NeutralGear = 90;
int GearForward = 1;
int GearReverse = 180;
int WaitForServoDelay = 0; // Set ’WaitForServoDelay’ to 0 ms

void setup()
{
lcd.begin(16, 2); // 16 caracter, 2 row LCD display
throttleservo.attach(8); // Connect Gear servo to pin 6
gearservo.attach(9); // Connect Throttle servo to pin 10
pinMode(StopMotor, OUTPUT); // sets the digital pin as output
Serial.begin(9600);
lcd.setCursor(0, 0);
lcd.print(”Startup sequence ”);// Open Serial comunicaton (to Serial Monitor)
delay(1000);
lcd.setCursor(0, 0);
lcd.print(” ”);
}

// ——————————————————-
void loop()
{

iControlPos = analogRead(potpin); // Read the value from controll potentiometer (value between 0 och 1023
iControlThrottleValue = map(iControlPos, 0, 511, 180, 0); // Scale iControlThrottleValue (0 – 180)
iControlGearValue = map(iControlPos, 0, 1023, 0, 180); // Scale iControlGearValue (0 – 180)
iControlPos = map(iControlPos, 0, 1023, 0, 180); // Scale iControlPos Value (0 – 180)
// Output to LCD display
if (WaitForServoDelay > 500) {
lcd.setCursor(0, 0);
lcd.print(” NEUTRAL ”);
lcd.setCursor(0, 1);
lcd.print(” Wait for servo ”);
}

// Set Throttle to off, and then set Gear to neutral.
throttleservo.write(ZeroThrottle); // Set Throttle to off
delay(WaitForServoDelay); // Wait for Throttle servo to reach Throttle off (0)
gearservo.write(NeutralGear); // Set Gear to Neutral
delay(WaitForServoDelay); // Wait for Gear servo to reach NEUTRAL (90)

if (iControlPos>=80 and iControlPos<=100){ // If The controll is in neutral position GO to NEUTRAL function
GoNeutral();}
else if(iControlPos>=0 and iControlPos<80){ // If The controll is in forward position Go to FORWARE function
GoForward();}
else if(iControlPos>100 and iControlPos<=180){ // If The controll is in rewerse position Go to REVERSE function
GoReverse();}
{
}
}
// End loop ————————————————-
// NEUTRAL
void GoNeutral()
{
while(iControlPos>=80 and iControlPos<=100)
{
// Read Position of Control Hendle
iControlPos = analogRead(potpin); // Read the value from controll potentiometer (value between 0 och 1023
iControlPos = map(iControlPos, 0, 1023, 0, 180); // Scale iControlPos Value (0 – 180)

// Output to LCD display
lcd.setCursor(1, 0);
lcd.print(” NEUTRAL ”);
lcd.setCursor(0, 1);
lcd.print(” Ready ”);

iControlThrottleValue = ZeroThrottle; // Set Throttle to off
iControlGearValue = NeutralGear; // Set Gear to Neutral

// Debug output to Serial Monitor
Serial.println(”NEUTRAL ”);
lcd.setCursor(0, 1);
Serial.print(iControlThrottleValue);
Serial.print(”,”);
Serial.print(iControlGearValue);
Serial.print(”,”);
Serial.println(iControlPos);

//Set Throttle and Gear
gearservo.write(iControlGearValue); // Send position to Gear servo
delay(200); // Wait 70ms for servo to get position
throttleservo.write(iControlThrottleValue); // Send position to Throttle servo
delay(70); // Wait 70ms for servo to get position
}
WaitForServoDelay = (0); // Set ’WaitForServoDelay’ to 0ms
}

// FORWARD
void GoForward()
{
while(iControlPos<80)
{
// Set Gear
iControlGearValue = GearForward; // Set Gear to Forward position
// Input controll if Gear is in Forward position

// Read Position of Control Hendle
iControlPos = analogRead(potpin);
iControlPos = constrain(iControlPos,0,511); //
iControlThrottleValue = map(iControlPos, 0, 511, 180, 0);
iControlPos = map(iControlPos, 0, 1023, 0, 180); // Scale to Servo use (0 – 180)

// Output to LCD display
lcd.setCursor(1, 0);
lcd.print(” Forward ”);
lcd.setCursor(0, 0);
lcd.print(”<”);
lcd.setCursor(0, 1);
lcd.print(” ”);

// Debug output to Serial Monitor
Serial.println(”Forward ”);
Serial.print(iControlThrottleValue);
Serial.print(”,”);
Serial.print(iControlGearValue);
Serial.print(”,”);
Serial.println(iControlPos);

//Set Throttle and Gear
gearservo.write(iControlGearValue); // Send position to Gear servo
delay(300); // Wait 300ms for servo to get position
throttleservo.write(iControlThrottleValue); // Send position to Throttle servo
delay(70); // Wait 70ms for servo to get position
}
WaitForServoDelay = (1000); // Set ’WaitForServoDelay’ to 1000ms
}

//REVERSE
void GoReverse()
{
while(iControlPos>100)
{

// Set Gear
iControlGearValue = GearReverse; // Set Gear to Forward position
// Input controll if Gear is in Forward position

// Read Position of Control Hendle
iControlPos = analogRead(potpin);
iControlThrottleValue = map(iControlPos, 0, 1023, 0, 180);
iControlPos = map(iControlPos, 0, 1023, 0, 180); // Scale to Servo use (0 – 180)

// Output to LCD display
lcd.setCursor(1, 0);
lcd.print(” Reverse ”);
lcd.setCursor(15, 0);
lcd.print(”>”);
lcd.setCursor(0, 1);
lcd.print(” ”);

// Debug output to Serial Monitor
Serial.println(”Reverse ”);
Serial.print(iControlThrottleValue);
Serial.print(”,”);
Serial.print(iControlGearValue);
Serial.print(”,”);
Serial.println(iControlPos);

//Set Throttle and Gear
gearservo.write(iControlGearValue); // Set Gear to Revers position
delay(300); // Wait 300ms for servo to get position
throttleservo.write(iControlThrottleValue); // Send position to Throttle servo
delay(70); // Wait 70ms for servo to get position
}
WaitForServoDelay = (1000);
}

// Error handling
void Error()
{
// Input error handling
digitalWrite(StopMotor, HIGH); // Raise the relay to stop motor (emergensy stop of motor. Iff more then one motor, stop all)
}