Re: PS2 Control of Brushless Motor and ESC via Arduino
Posted: Oct 6th, 2012, 4:11 pm
For mine I simply used "x" for forward and "o" for reverse. Without using the stick both right and left thrusters move forward (RTF / LTF) or reverse (RTR / LTR). Throw in the analog stick for steering and you'll see the math function below for how this works. On the extremes, for a full throttle (forward or reverse) with hard rudder in one direction; Use get one thruster to move at full speed and the other not moving at all. With no throttle and hard rudder to one direction you get one thruster to move forward at full speed and the other moving in reverse at full speed.
I hope this helps
if(ps2x.Button(PSB_BLUE)){
TF = ps2x.Analog(PSAB_BLUE);
RTF = TF;
LTF = TF;
RTR = 0;
LTR = 0;
}
else{
RTF = 0;
LTF = 0;
TF = 0;
}
if(ps2x.Button(PSB_CIRCLE)){
TR = ps2x.Analog(PSAB_CIRCLE);
RTF = 0;
LTF = 0;
RTR = TR;
LTR = TR;
}
else{
RTR = 0;
LTR = 0;
TR = 0;
}
if(ps2x.Analog(PSS_LX) <= 100){
LT = map(ps2x.Analog(PSS_LX), 100, 0, 0, 255);
if(TF == 0 && TR == 0){
LTR = LT;
RTF = LT;
}
else if(TF >= 1){
LTF = TF - LT;
if (LTF < 0){
LTR = map(LTF, -1, -255, 1, 255);
LTF = 0;
}
RTF = TF + LT;
if (RTF > 255){
RTF = 255;
}
}
else if (TR >= 1){
LTR = TR - LT;
if (LTR < 0){
LTF = map(LTR, -1, -255, 1, 255);
LTR = 0;
}
RTR = TR + LT;
if (RTR > 255){
RTR = 255;
}
}
}
if(ps2x.Analog(PSS_LX) >= 155){
RT = map(ps2x.Analog(PSS_LX), 155, 255, 0, 255);
if(TF == 0 && TR == 0){
LTF = RT;
RTR = RT;
}
else if(TF >= 1){
LTF = TF + RT;
if (LTF > 255){
LTF = 255;
}
RTF = TF - RT;
if (RTF < 0){
RTR = map(RTF, -1, -255, 1, 255);
RTF = 0;
}
}
else if (TR >= 1){
LTR = TR + RT;
if (LTR > 255){
LTR = 255;
}
RTR = TR - RT;
if (RTR < 0){
RTF = map(RTR, -1, -255, 1, 255);
RTR = 0;
}
}
I hope this helps
if(ps2x.Button(PSB_BLUE)){
TF = ps2x.Analog(PSAB_BLUE);
RTF = TF;
LTF = TF;
RTR = 0;
LTR = 0;
}
else{
RTF = 0;
LTF = 0;
TF = 0;
}
if(ps2x.Button(PSB_CIRCLE)){
TR = ps2x.Analog(PSAB_CIRCLE);
RTF = 0;
LTF = 0;
RTR = TR;
LTR = TR;
}
else{
RTR = 0;
LTR = 0;
TR = 0;
}
if(ps2x.Analog(PSS_LX) <= 100){
LT = map(ps2x.Analog(PSS_LX), 100, 0, 0, 255);
if(TF == 0 && TR == 0){
LTR = LT;
RTF = LT;
}
else if(TF >= 1){
LTF = TF - LT;
if (LTF < 0){
LTR = map(LTF, -1, -255, 1, 255);
LTF = 0;
}
RTF = TF + LT;
if (RTF > 255){
RTF = 255;
}
}
else if (TR >= 1){
LTR = TR - LT;
if (LTR < 0){
LTF = map(LTR, -1, -255, 1, 255);
LTR = 0;
}
RTR = TR + LT;
if (RTR > 255){
RTR = 255;
}
}
}
if(ps2x.Analog(PSS_LX) >= 155){
RT = map(ps2x.Analog(PSS_LX), 155, 255, 0, 255);
if(TF == 0 && TR == 0){
LTF = RT;
RTR = RT;
}
else if(TF >= 1){
LTF = TF + RT;
if (LTF > 255){
LTF = 255;
}
RTF = TF - RT;
if (RTF < 0){
RTR = map(RTF, -1, -255, 1, 255);
RTF = 0;
}
}
else if (TR >= 1){
LTR = TR + RT;
if (LTR > 255){
LTR = 255;
}
RTR = TR - RT;
if (RTR < 0){
RTF = map(RTR, -1, -255, 1, 255);
RTR = 0;
}
}