Go Down

Topic: using arduino leonardo and joystick to control a car (Read 1 time) previous topic - next topic

dhruvin

hello,
i am using arduino leonardo, 2 axis joystick, and H-bridge L298N to control two 6vdc motor . The purpose is to move motors in the same direction forwards when the joystick is forward
when the joystick is at right up --  left motor should go fast forward and right motor should go slowly forward
when the joystick is at right -- left motor should move and right motor should stop
when the joystick is right down-- left motor should go fast in reverse while right motor should go slow in reverse
when the joystick is down-- both the motors should go in reverse direction
when joystick is at left down-- right motor should move fast reverse and left motor should move slowly in reverse
when joystick is at left -- right motor should move and left motor should stop
when joystick is  left up -- right motor should move fast forward and left should move slowly forward.
the magnitude should be consider for the speed of the motor when the joystick is half way only half power should be provided to the motors.
i want to know what can be code for this kind of joystick controlled car.
can anyone help me as i m new to the arduino coding 

PaulS

Quote
i want to know what can be code for this kind of joystick controlled car.

Instead of trying to write all the code at once, break the problem into manageable pieces. Start with reading the joystick. Can you get readings that make sense as you move the joystick around?

Can you determine that the joystick is in each of the states you suggest? That's a series of if/else if statements.

Can you make the motors behave in the way that you suggest?

Quote
i m new to the arduino coding 

Then, why did you jump in the deep end? Frankly, this sounds like a homework problem that you've left to the last minute, and you've mistaken the forum for the homework hotline.
The art of getting good answers lies in asking good questions.

PeterH

What you're describing is usually called differential steering. The algorithm to control is is quite simple. You read the joysticks to get the speed and steering inputs. After reading the raw joystick position, map it to produce a signed number where zero represents the joystick's neutral position, positive values represent movement one way, negative represents movement the other way.

The output for one motor is the speed input plus the steering input. The output for the other is the speed input minus the steering input. You can scale the speed and steering to produce the control sensitivity that you want. You would want to constrain the motor outputs so that they never go beyond the range +/- 255.

Now that you have the speed for each motor as a signed number in the range +/- 255, you take the sign of the number and use that to select the direction, and use the absolute value to set the motor PWM duty cycle.

PeterH

Was there something wrong with the other thread where you posted the identical question?

AWOL

#4
Jun 22, 2014, 03:44 pm Last Edit: Jun 22, 2014, 04:02 pm by AWOL Reason: 1
Posting the same question THREE TIMES is more likely to earn you a ban than win friends.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.
I speak for myself, not Arduino.

AWOL

. . . and reporting my last post to moderation SIX TIMES as "spam" is even more likely to see your exclusion.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.
I speak for myself, not Arduino.

Go Up