0
Offline
Sr. Member
Karma: 0
Posts: 340
Arduino rocks
|
 |
« Reply #15 on: December 04, 2012, 09:17:43 am » |
For a motor (with h-bridge/motor shield of course!). You read the pot with ADC and then values above (say ) 700 are forward, values below 300 are backward and values in between are stop. But you still need one pot per motor.
Mark
That looks to be correct. Do you have a link to a recommended h-bridge/motor shield? Remember, I'm simply using a analog, 2-axis joystick (with 2 pots total) to control a pair open-loop motors for use in a pan tilt system. For example, if the joystick is half-way tilted to the right, the pan/tilt system will go half-speed in that direction. I've done this plenty of times with servos but now the components need to be basic, dc motors.
|
|
|
|
|
Logged
|
|
|
|
|
Queens, New York
Offline
Edison Member
Karma: 31
Posts: 1730
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
|
 |
« Reply #16 on: December 04, 2012, 09:46:28 am » |
I've done this plenty of times with servos but now the components need to be basic, dc motors. Then my solution is the one you want to use. It gets data from the 2 pots and tells the motors how to move.If you dont like my second way, then just repeat my first way for both motors. This controls the forward and backwards movement of ONE motor, repeat for second motor. // say the lowest is 350 and the highest is 650, the difference is 300 // so divide 300 by 2, you get 150. // then 350 + 150= 500 (center) //offset, you decide how much dead zone you want, for the center. // +-10 should be enough. If( POT1< 490) { // offset(10) - center(500) ...go forward... } Else if (POT1 > 510) { ... Go backwards... } Else { ... Full stop... }
|
|
|
|
« Last Edit: December 04, 2012, 10:00:06 am by HazardsMind »
|
Logged
|
UNO, MEGA, NANO, 4x4 keypad, micro servos, RF transceivers, bluetooth, ultrasonic sensor, 20x4 I2C LCD, 3.2 TFT touch screen, L298N Dual motor driver, Voice Recognition 15W
"If your doing nothing, it does not mean your lazy, it just means your open for anything that suits you" - Unknown
|
|
|
|
Poole, Dorset, UK
Offline
God Member
Karma: 12
Posts: 776
|
 |
« Reply #17 on: December 04, 2012, 10:35:41 am » |
Which motor shield depends on how much current the motors would require. Take a look and the Arduino one in the hardware section of the main site as a starter. This runs two motors each with speed and direction (4 digital pins in all).
As for the pots one end to earth one to the 5v and the center wiper to the analog pin.
Mark
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
UK
Offline
Brattain Member
Karma: 143
Posts: 19368
I don't think you connected the grounds, Dave.
|
 |
« Reply #18 on: December 04, 2012, 10:38:46 am » |
This runs two motors each with speed and direction (4 digital pins in all). You may also want to add another couple of pins for the brakes.
|
|
|
|
|
Logged
|
Pete, it's a fool looks for logic in the chambers of the human heart.
|
|
|
|
Poole, Dorset, UK
Offline
God Member
Karma: 12
Posts: 776
|
 |
« Reply #19 on: December 04, 2012, 10:56:11 am » |
And two for current sensing?
Mark
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Tesla Member
Karma: 58
Posts: 6774
Arduino rocks
|
 |
« Reply #20 on: December 04, 2012, 06:49:25 pm » |
The quick fix would be to get two of the below (one for each joystick pot) motor controllers, and connect the joystick pots in place of the pots on the controllers. http://www.electronickits.com/kit/complete/motor/k166.htm
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Sr. Member
Karma: 0
Posts: 340
Arduino rocks
|
 |
« Reply #21 on: December 04, 2012, 08:57:47 pm » |
That looks to be perfect. So to summarize, you would use one of these:  and wire each one to one of these in place of the pots that they come with:  is that correct? If so, where else can I get these? They are expensive http://www.electronickits.com/kit/complete/motor/k166.htmAlso, don't I also have to make sure the pots on the joystick are the same resistance as the pots that were originally on the speed controller?
|
|
|
|
« Last Edit: December 04, 2012, 09:04:42 pm by David82 »
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 46
|
 |
« Reply #22 on: December 05, 2012, 02:20:54 am » |
Also, don't I also have to make sure the pots on the joystick are the same resistance as the pots that were originally on the speed controller?
It's a 100k pot. Looking at the schematics it's not simply connected to V+ and ground. There is a 100k resistor on the high side and a 10k connecting it to ground. So yeah it won't act the same unless the joystick pots are 100k. Or you change the resistors to compensate.
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Sr. Member
Karma: 0
Posts: 340
Arduino rocks
|
 |
« Reply #23 on: December 05, 2012, 06:42:45 pm » |
Good point. Now, knowing that, what would I have to change those two resistors to to be able to use the 5k pots that are on the joystick instead?
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Tesla Member
Karma: 58
Posts: 6774
Arduino rocks
|
 |
« Reply #24 on: December 05, 2012, 06:56:27 pm » |
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 46
|
 |
« Reply #25 on: December 05, 2012, 07:56:22 pm » |
Replacing the pots might be a better idea. But if you want to change the resistors you just need to reduce them by the same factor. ie, your 5k pots are 1/20 of the original pot's value. So the top 100k resistor will become 5k, and the bottom 10k will become 500R. That's going to increase the current through that leg but it's still only 1.1mA or so.
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Sr. Member
Karma: 0
Posts: 340
Arduino rocks
|
 |
« Reply #26 on: December 05, 2012, 09:36:33 pm » |
Yep. The pots that came with the motor driver will either fit in the joystick or they won't. If they don't, then I'll have to wither find 100k pots that fit correctly in the joystick or replace the resistors and use the 5k pots. I'll report back after the parts get here.
|
|
|
|
|
Logged
|
|
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 46
|
 |
« Reply #28 on: December 06, 2012, 02:47:48 am » |
If you do decide to make this with Arduino and H-Bridge shields, I wrote this code the other day as a learning experience (I'm new to Arduino) until I realized you wanted a non-MCU solution. Don't have an H-Bridge to test but seems to give proportional bi-directional control. This is just for the "horizontal" motor. int deadZone = 50; // joystick deadzone rangec int maxPWMValue = 255; // maximum PWM value. 255 for built-in PWM int horizPotPin = A0; // Analog pin for horizontal pot sense
int horizPWMPin = 9; // Horiz motor speed control connected to this pinr int horizDirPin = 2; // directional control connected here. HIGH = forward, LOW = reverse
void setup() { pinMode(horizPWMPin, OUTPUT); pinMode(horizDirPin, OUTPUT);
// for debugging Serial.begin(38400); }
void loop() { int horizPWM = 0; // holds the pwm output for 'horizontal' motor boolean forwardDir = true; // direction for 'horizontal' motor. true = forward, false = reverse
// read horizontal pot value int horizPot = analogRead(horizPotPin);
// map the analog value of 0..1023 to -255..+255 // If the direction and speed go in the wrong direction compared to joystick movement, // just switch the sign of the last two parameters int h = map(horizPot, 0, 1023, -maxPWMValue, maxPWMValue);
// check if joy in reverse position if (h < 0) { forwardDir = false; h *= -1; }
// only set final PWM output if joy is outside of deadzone range if (h > deadZone) horizPWM = h;
// set pwm and direction digitalWrite(horizDirPin, forwardDir); analogWrite(horizPWMPin, horizPWM);
//debug crap Serial.print(horizPWM ); Serial.print(", "); Serial.println(forwardDir); delay(50);
}
|
|
|
|
« Last Edit: December 06, 2012, 03:16:05 am by jabbado »
|
Logged
|
|
|
|
|
|