The Arduino code will be the same as I ran in the Catamaran I may add differential thrust with steering angle as its a twin
#include
int ch1 = 4;
int ch2 = 5;
unsigned long ch1v;
unsigned long ch2v;
unsigned long RightLeft = 0;
unsigned long UpDown = 0;
long Trim = 0;
long Throttle = 0;
long Cooling = 0;
long PumpSpeed = 0;
Servo Servo1;
Servo Servo2;
Servo Servo3;
Servo Servo4;
#define MAX_CHAN 8
int AnIn[MAX_CHAN] = {0, };
unsigned long PPMtout = 20000;
char buf[300] = {0, };
long mS = 0;
void setup() {
Serial.begin(115200);
pinMode(ch1, INPUT);
pinMode(ch2, INPUT);
Servo1.attach(8);
Servo2.attach(9);
Servo3.attach(10);
Servo4.attach(11);
}
void loop() {
AnIn[0] = analogRead(A0);
AnIn[1] = analogRead(A1);
AnIn[2] = analogRead(A2);
AnIn[3] = analogRead(A3);
AnIn[4] = analogRead(A4);
AnIn[5] = analogRead(A5);
AnIn[6] = analogRead(A6);
AnIn[7] = analogRead(A7);
/* RAZU-2 Six turn
This device has a gain of 55mV per amp giving a 36 Amp working range,
and a resolution of 11.3777 mA per bit with the maximum output at 5 volts
which is 1024 bits in the Arduino. By the way I should point out that
these devices on a 5 volt rail will sit around 2.5 volts with no current
flowing, so at a 2 Volt delta the out put should be around 4.5 V
*/
mS = micros();
//Get PPM from each RX channel
noInterrupts();
ch1v = pulseIn(ch1, HIGH, PPMtout);//Throttle
if(ch1v > 0)
{
ch2v = pulseIn(ch2, HIGH, PPMtout);//Imax
}
else//Fail safe
{
ch1v = 1000;
ch2v = 1000;
}
interrupts();
//ALLOW INTERRUPTS BEFORE UPDATE SERVOS
delayMicroseconds(2000);
//Calculate motor amps
long Motor_mA = ((long)(AnIn[1] - 512) * 11.0f);
int Tmax = (int)ch2v;
//Set max throttle
Throttle = (long)map((int)ch1v, 1000, 2000, 1400, Tmax);
//Calc amps
long Amps = (long)map((int)Motor_mA, 0, 36000, 0, 36);
//Calculate cooling temp RTC on AnIn[0]
int cerr = ((int)600 - (int)AnIn[0]);
//Integrate temparature
Cooling += cerr;
if(Cooling < 1000) Cooling = 1000;
else if(Cooling > 2000) Cooling = 2000;
//Use the temperature integrator plus the motor current
//36 Amps gives us 360 bits
PumpSpeed = (long)Cooling + (Amps * 10);
//Update the outputs
Servo1.writeMicroseconds((int)Throttle);
Servo2.writeMicroseconds((int)PumpSpeed);
long Cyc_mS = (micros() - mS);
//ALLOW SERVOS TO UPDATE BEFORE INTERRUPTS OFF
delayMicroseconds(18000 - Cyc_mS);
Cyc_mS = (micros() - mS);
sprintf(buf, "ch1v_Tmax:%d,ch2v_Imax:%d,Throttle:%d,AnIn[0]:%d,AnIn[1]:%d,CoolingError:%d,Cooling:%d,Imax:%d,MotorAmps:%d,Cyc_mS:%d", (int)ch1v, (int)ch2v, (int)Throttle, AnIn[0], AnIn[1], cerr, (int)Cooling, (int)Tmax, (int)Amps, (int)Cyc_mS );
Serial.println(buf);
/*
char incomingByte = 0;
// send data only when you receive data:
while (Serial3.available() > 0) {
// read the incoming byte:
incomingByte = Serial3.read();
Serial.print((char)incomingByte);
delayMicroseconds(1000);
if(incomingByte == 13) break;
}
Serial.println( );
*/
}