Link to their original design.
The code:
/*
ROV Controller Proof of Concept, created by Stephan, 20100306-01
*/
// map the inputs
#define JA 12
#define JB 9
#define JC 6
#define JD 4
// map the outputs
#define LED_LF 13
#define LED_LR 10
#define LED_RF 7
#define LED_RR 5
bool nand(bool A, bool B);
bool nand(bool A, bool B, bool C);
void logic_circuit (bool A, bool B, bool C, bool D, bool &LF, bool &LR, bool &RF, bool &RR);
int a,b,c,d;
bool LF,LR,RF,RR;
bool A = true;
bool B = true;
bool C = true;
bool D = true;
void setup() {
// setup the input pins
pinMode(JA, INPUT);
pinMode(JB, INPUT);
pinMode(JC, INPUT);
pinMode(JD, INPUT);
// assign the LED pin as an output
pinMode(LED_LF, OUTPUT);
pinMode(LED_LR, OUTPUT);
pinMode(LED_RF, OUTPUT);
pinMode(LED_RR, OUTPUT);
}
void loop() {
// read the joystick
a = (digitalRead(JA));
b = (digitalRead(JB));
c = (digitalRead(JC));
d = (digitalRead(JD));
// abstract the joystick readings
A = (a == HIGH) ? true : false;
B = (b == HIGH) ? true : false;
C = (c == HIGH) ? true : false;
D = (d == HIGH) ? true : false;
// run the logic circuit
logic_circuit(A,B,C,D,LF,LR,RF,RR);
// write to output
digitalWrite(LED_LF, LF);
digitalWrite(LED_LR, LR);
digitalWrite(LED_RF, RF);
digitalWrite(LED_RR, RR);
}
void logic_circuit (bool A, bool B, bool C, bool D, bool &LF, bool &LR, bool &RF, bool &RR) {
/*
This subroutine simulates a logic circuit created by Doug & Kay (SVSeeker@ymail.com).
The circuit was created to accept switched based joystick inputs and deliver logic signals
to activate power relays to drive a submerged ROV, according to a defined truth table.
Reference:
http://www.submarineboat.com/rov_joystick_for_props.htm#DC_Motors
Truth Table
Input from Joystick switch Output to Relay
A B C D LF LR RF RR
0 0 0 1 1 1
0 0 1 0 1 1
0 0 1 1 1
0 1 0 0 1 1
0 1 1 0 1
1 0 0 0 1 1
1 0 0 1 1
1 1 0 0 1
*/
// Left Forward
LF = nand(nand(A,!C,!D), nand(B,!C,!D));
// Right Forward
RF = nand(nand(!B,!C,D), nand(A,!B,!C));
// Left Reverse
LR = nand(nand(!A,!B,C), nand(!A,!B,D));
// Right Reverse
RR = nand(nand(!A,C,!D), nand(!A,B,!D));
}
/*
Two functions are provided to simulate the behavior of dual-input and triple-input NAND gates.
The function is overloaded based on the number of inputs two or three.
The functions accept bools as inputs and returns a bool.
The NAND gate is simulated using the ternary operator. If the operator evaluates to true,
it returns false and vice versa.
*/
bool nand (bool A, bool B) {
bool result = (A && B) ? false : true;
return (result);
}
bool nand (bool A, bool B, bool C) {
bool result = (A && B && C) ? false : true;
return (result);
}
No comments:
Post a Comment