Go Down

Topic: I need help to control 2 dc motors with a ps2 analog joystick (Read 12048 times) previous topic - next topic

JimboZA

Quote
i need the code for two motors,i tried to double the code but it not works,what do I do now?


I think you post the code to show what you tried, and explain what didn't work.
Johannesburg hams call me: ZS6JMB on Highveld rep 145.7875 (-600 & 88.5 tone)
Dr Perry Cox: "Help me to help you, help me to help you...."
Your answer may already be here: https://forum.arduino.cc/index.php?topic=384198.0

roter45

Hi


Really when moving a robot, you have two motors (L motor and R motor)
So you have 4 possible combinations (could be more).

going straight (L forward ,R forward)
Back (L backward, R backward)
Right(L forward, R backward)
Left(L backward, R Forward)

you use a switch case with the four positions using the previous code.

How to obtain the case be need. There are different forms, for my robot I use this:
Code: [Select]

x= analogRead(0);// values
y = analogRead(1);//

if(x > 700){
go straight}
if(x <400){
back}
if ( 400< x < 700){
      if(y > 700){
        left}
      if(y <400){
         right}
      if(400< y < 700){
      stop}
}


I recomend you to use this limit values, because I obtain it after trying hours through  you should try and discover yours.

Also It's important to put the stop mode, you don't want your robot going ahead and falling from the table  :smiley-eek-blue: :smiley-red:

Try it and post your code


Roger_bb

thanks for the code, but i think i not explain what i'm doing with the joystick thing.
http://www.youtube.com/watch?v=PLHYmyXcQWY
my robot is much like this one in the video , however i want only to drill the PCB.I want to control it manually too,this is the joystick service.
does your code  work for this purpose?

roter45

#18
Feb 24, 2014, 12:08 pm Last Edit: Feb 24, 2014, 03:29 pm by roter45 Reason: 1
In this case, duplicate the code but changing the variables.

If you use the same variables (Just copy and paste) it won't work.

Roger_bb

Quote
In this case, duplicated the code but changing the variables.

i duplicated the code, changed the variables and it working now. But one motor is not working properly, its not going backward,i think the problem is on the driver output. I'll  make some tests and when my robot is working, i  will post a video.
Thanks for the help.

Go Up