Arduino with ps2 for 2-motor control

KeithWalker

Joined Jul 10, 2017
3,098
If you are using the two motors as left and right drive, use the analog joytick values to change the PWM to the motors. Y axis will control the speed of both motors together and the X axis will mix with the Y axis to increase the speed of one and decrease the other to cause a turn.
 

Thread Starter

beatsal

Joined Jan 21, 2018
401
If you are using the two motors as left and right drive, use the analog joytick values to change the PWM to the motors. Y axis will control the speed of both motors together and the X axis will mix with the Y axis to increase the speed of one and decrease the other to cause a turn.
Thanks, will try it.
 

KeithWalker

Joined Jul 10, 2017
3,098
This is a short program I wrote to control a tracked vehicle with two inputs from a radio control receiver:

// R/C Tracked Vehicle Mixer
//This program mixes channel one and two from an RC receiver and drives two track motors.
int pin1 = 7; //Channel 1 input
int pin2 = 8; //Channel 2 input
int motor1 = 9;
int motor2 = 10;
int length1;
int length2;
int chanA;
int chanB;

void setup() {

pinMode(pin1, INPUT);
pinMode(pin2, INPUT);
pinMode(motor1, OUTPUT);
pinMode(motor2, OUTPUT);
digitalWrite (motor1, LOW);
digitalWrite (motor2, LOW);

}

void loop() {

//Read length the incoming R/C signals and scale them
length1 = pulseIn(pin1, HIGH);
length1 = map (length1, 900, 1800, 1000, 2000);
length2 = pulseIn(pin2, HIGH);
length2 = map (length2, 900, 1800, 1000, 2000);

//Mix for left track
chanA = (length2 + (length1 - 1500));
//Check left signal limits
if (chanA > 2000)
{chanA = 2000;}
if (chanA < 1000)
{chanA = 1000;}

//Mix for right track
chanB = (length2 - (length1 - 1500));
//Check right signal limits
if (chanB > 2000)
{chanB = 2000;}
if (chanB < 1000)
{chanB = 1000;}

//Output PWM signal for left track
digitalWrite (motor1, HIGH); //Output PWM signal for left track
delayMicroseconds (chanA);
digitalWrite (motor1, LOW);

//Output PWM signal for right track
digitalWrite (motor2, HIGH);
delayMicroseconds (chanB);
digitalWrite (motor2, LOW);

delay (10);
}
 

Thread Starter

beatsal

Joined Jan 21, 2018
401
Thanks. Will try to understand it and try it out. I am trying to do a snow shovel (Canada), so this will be a real help.
 
Top