Hello, I’ve been working on a 1/12 scale tiger II tank, and am wanting to run it on two 12v motors with an FS-T6 (6 channel) rc controller. So far what I have is if switch B is on it allows the motors to run. Channel 3 makes the motors run forwards or backwards depending on the position of Switch D. I need help with the following:
1-Turning, I want channel 4’s input to speed up and slow down the respective motors.
i.e if speed is zero and left stick is hit motor B goes forwards and A goes backwards
also if the tank is going forwards or backwards already, to either add speed to one side and decease the other resulting in a turn.
This should make it look like the double differential that the Tiger II had.
2-Safety feature on switch D, I only want it to activate if channel 3 is less than 1000 (input) so that it won’t switch direction while the motors are running.
I’m new to Arduino and any help would be greatly appreciated. Bellow I have the code and with it I’ve also made a diagram of the setup I have, I hope it is properly formatted and clear to read.
int in1B = 12; //B is right motor
int in2B = 13;
int in1A = 4; //A is Left Motor
int in2A = 7;
int switchB = 2;
int switchD = 8;
//the following are all ~PWM capable ports
int enableB = 11;
int enableA = 10;
int rc_channel4 = 9;
int rc_channel3 = 3;
void setup()
{
pinMode(rc_channel3, INPUT);
pinMode(rc_channel4, INPUT);
pinMode(switchB, INPUT);
pinMode(switchD, INPUT);
pinMode(in1B, OUTPUT);
pinMode(in2B, OUTPUT);
pinMode(in1A, OUTPUT);
pinMode(in2A, OUTPUT);
pinMode(enableB, OUTPUT);
pinMode(enableA, OUTPUT);
Serial.begin(9600);
}
void loop()
{
int pwmA = 0;
int pwmB = 0;
int rc3 = pulseIn(rc_channel3, HIGH, 25000);
int rc4 = pulseIn(rc_channel4, HIGH, 25000);
int swb = pulseIn(switchB, HIGH, 25000);
int swd = pulseIn(switchD, HIGH, 25000);
Serial.println(rc3);
//Ignition Switch
if (swb > 1500) //if switch b is turned on then proceed with the function
{
if(rc3==0)
{
digitalWrite(in1B, LOW);
digitalWrite(in2B, LOW);
digitalWrite(in1A, LOW);
digitalWrite(in2A, LOW);
analogWrite(enableB, 0);
analogWrite(enableA, 0);
}
//Forwards
else if ((rc3 > 1000 && swd < 1500)) //if channal 3 is less than 1000 and if switch d is off go forwards
{
pwmA = map(rc3, 1000, 2000, 0, 255); //map our speed to 0-255 range
pwmB = map(rc3, 1000, 2000, 0, 255); //map our speed to 0-255 range
digitalWrite(in1B, LOW);
digitalWrite(in2B, HIGH);
digitalWrite(in1A, LOW);
digitalWrite(in2A, HIGH);
analogWrite(enableB, pwmB);
analogWrite(enableA, pwmA);
}
//Backwards
else if ((rc3 > 1000 && swd > 1500)) //if channal 3 is less than 1000 and if switch d is on (only other choice from above) go backwards
{
pwmA = map(rc3, 1000, 2000, 0, 155); //map our speed to 0-155 range (155 because it goes slower)
pwmB = map(rc3, 1000, 2000, 0, 155); //map our speed to 0-155 range
digitalWrite(in1B, HIGH);
digitalWrite(in2B, LOW);
digitalWrite(in1A, HIGH);
digitalWrite(in2A, LOW);
analogWrite(enableB, pwmB);
analogWrite(enableA, pwmA);
}
else //anything other than above shut off motors
{
digitalWrite(in1B, LOW);
digitalWrite(in2B, LOW);
digitalWrite(in1A, LOW);
digitalWrite(in2A, LOW);
analogWrite(enableB, 0);
analogWrite(enableA, 0);
}
}
delay(10);
}