code update - guys - I am rusty on my coding - any comments welcome. I could really use some help on the throttle mapping -or the logic that decides which motor(s) to throttle and how much. you can see how I have it now - works -but I can see some situations - like going right in buffer speed zone (say 25mph) then just tapping the gas pedal - likely cause big motor breaking. any other comments on how to improve the throttle decisions welcome!
code------------------------------
//proto code for hybrid gas/elec drive by wire system. the servos control each motor, and based on drive wheel rpms, tell which thottle what position is best.
//using an Arduino UNO board.
//observed results - seems to work. throttle mapping suspect.
#include <Servo.h>
Servo myservoG; // create servo object to control a servo - gas motor throttle actuator
Servo myservoE; //elec motor throttle actuator
int GasPedalPin = 0; //input pin for gas pedal pot
int WheelRpmPin = 2; //for now, input for pot, but place hall sensor here later.
float WC = 4.18; //static value for measured wheel circumference, used in MPH calc. unit in feet.
int MRE = 3000; //static value, measured maximum RPM possible by elec motor
int MRG = 9000; //static value, measured maximum RPM possible by gas motor
float GRE = 5; //static value for gear ratio on elec drive - in this case 12T and 60T sprockets.
float GRG = 5.625; //static value for gear ratio on gas drive - in this case 8T and 45T sprockets
int GTP; //used to write to servo gas motor throttle position
int ETP; //used to write to servo elec motor throttle position
// *************************************************
void setup() {
myservoG.attach(9); // attaches the servo on pin 9 to the servo object - gas drive servo
myservoE.attach(11); // attaches the servo on pin 12 to the servo object - elec drive servo
GTP = 0; //return both throttles to zero.
ETP = 0;
pinMode(2, INPUT); //for push button turbo
Serial.begin(9600); //serial monitor so I can track the vars
}
// *************************************************
void loop() {
int Throttle = GasPedal();
int WheelRpm = WheelSensor();
int mph = mphCalc(WheelRpm);
ThrottleMap(Throttle,mph);
ThrottleSet();
turbo(mph);
TestMonitor(Throttle,WheelRpm,mph,GTP,ETP);
} //end of loop
// *************************************************
int mphCalc(int x)
{
x = (x* WC)/88; //a lot of simplification here, but this works.
return x;
}
// *************************************************
void turbo(int x) //results - the servo follows gas pedal position until button is pushed. on release of button, returns to current pot value.
{
int switchstate = 0; //for the turbo button 
switchstate = digitalRead(2);
while (switchstate == HIGH) { //protection for elec motor - dont engage after its max rpms..
switchstate = digitalRead(2);
if (x<25) { //bad coding - using mph, knowing elec motor will not drive over 28 mph.
ETP = 150;
GTP = 150;
}
else {
ETP = 0;
GTP = 150;
}
TestMonitor(0,x,0,GTP,ETP);
ThrottleSet();
}
}
// *************************************************
int GasPedal()
{
int x = analogRead(GasPedalPin); // for gas pedal input
x = map(x, 0, 1023, 0, 180); // scale it to use it with the servo (value between 0 and 180)
return x;
}
// *************************************************
int WheelSensor()
{
int x = analogRead(WheelRpmPin); //input for fake wheel RPM
x = map(x,0,1023,0,2000); //maps input to 0-2000 rpm range - this is again, rear axle - so post gear ratios.
return x;
}
// *************************************************
void ThrottleMap( int G,int S) //throttle mapping - based on mph - decide best motor or combo to use, then assign throttle positions
{
if (S<20) {
ETP = G; //setting elc and gas throttle positions -poor coding - the 20 is mph, knowing that elec motor max rpms (3000) through ratio (5) yeild max mph of 28.5mph.
GTP = 0;
}
if (S >=20 && S< 27) { //setting throttole positions - buffer range
ETP = G;
GTP = G;
}
if (S >27) { //high range
ETP = 0;
GTP = G;
}
}
// *************************************************
void ThrottleSet()
{
myservoE.write(ETP); //writes the final servo position for elec motor throttle
myservoG.write(GTP);// writes the final servo postion for gas motor throttle
delay(15); // waits for the servo to get there
}
// *************************************************
void TestMonitor(int aa,int bb,int cc,int dd,int ee)
{
char* a = "Gas"; //change these for other labels print format is ("char a, int aa,")
char* b = "RPMs";
char* c = "mph";
char* d = "GTP";
char* e= "ETP";
Serial.print(a);
Serial.print("=");
Serial.print(aa);
Serial.print("\t");
Serial.print(b);
Serial.print("=");
Serial.print(bb);
Serial.print("\t");
Serial.print(c);
Serial.print("=");
Serial.print(cc);
Serial.print("\t");
Serial.print(d);
Serial.print("=");
Serial.print(dd);
Serial.print("\t");
Serial.print(e);
Serial.print("=");
Serial.print(ee);
Serial.print("\n");
}