Pages: [1] 2   Go Down
Author Topic: Looking for code to turn motor into servo  (Read 3100 times)
0 Members and 1 Guest are viewing this topic.
Northern California (by San Francisco)
Offline Offline
Sr. Member
****
Karma: 3
Posts: 258
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I have a 12 Volt windshield wiper motor with a Pololu simple motor controller that I want to run like a servo. That is, I want to give the motor controller an angle and have the motor shaft turn until it reaches that angle. I have a potentiometer hooked up to the motor shaft to tell me what angle the shaft is currently at.

Can anyone steer me to any code that does that?
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 524
Posts: 26442
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Seems simple enough - wire up your pot to +5 & ground, wiper to an analog pin.
Map the end to end voltages into the ~270 degrees that the pot will turn.
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Northern California (by San Francisco)
Offline Offline
Sr. Member
****
Karma: 3
Posts: 258
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm looking for something that uses variable speed and PID logic to get the right angle. I think that servos use something a little more sophisticated like that. But maybe not.
Logged

Phoenix, Arizona USA
Offline Offline
Faraday Member
**
Karma: 39
Posts: 5557
Where's the beer?
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm looking for something that uses variable speed and PID logic to get the right angle. I think that servos use something a little more sophisticated like that. But maybe not.

Industrial servos probably do (and maybe serial-bus digital servos), but standard r/c servos convert the PPM signal into a voltage reference, then use a comparator (with a small voltage window to prevent "hunting") comparing the voltage from the conversion and the voltage from the internal potentiometer until they are "equal" (ie, within the window).

You can do the same thing with code; compare the analog value from your potentiometer with that of the value you want to seek to - if there is a difference (+/- a window percentage), move the motor in the direction to decrease this distance, until there is no difference. The size of the window will depend on how fast your motor rotates, the accuracy of your potentiometer, and how much mass is being moved by the motor (plus a few other variables).

Get this working first (it's not as difficult as it sounds); later you can work on the PID version (which is a whole 'nother ball of wax)...

smiley
Logged

I will not respond to Arduino help PM's from random forum users; if you have such a question, start a new topic thread.

Northern California (by San Francisco)
Offline Offline
Sr. Member
****
Karma: 3
Posts: 258
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Get this working first (it's not as difficult as it sounds); later you can work on the PID version (which is a whole 'nother ball of wax)...

That sounds like the way to go. I thought I needed to do something more complex. But I'll get it working and see.
Logged

0
Offline Offline
Tesla Member
***
Karma: 141
Posts: 9470
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

With a little creative wiring, you should be able to use the internals of an inexpensive servo to control an h-bridge driving the wiper motor. Below is my "to-do" big servo project (still need to get the h-bridge).

Logged

Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   smiley-cool

Boston Suburbs
Offline Offline
God Member
*****
Karma: 16
Posts: 955
I am above your silly so-called "Laws", Mister Ohm.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

!

Loving the Winch Servo idea....
Logged

When the testing is complete there will be... cake.

Phoenix, Arizona USA
Offline Offline
Faraday Member
**
Karma: 39
Posts: 5557
Where's the beer?
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

With a little creative wiring, you should be able to use the internals of an inexpensive servo to control an h-bridge driving the wiper motor. Below is my "to-do" big servo project (still need to get the h-bridge).



Yeah - I've seen this done with a windshield wiper motor (for use as a large servo for steering control) - but now I am curious what you intend to control with -that- motor/gearbox (just what do you plan to move or incorporate it into)...?
Logged

I will not respond to Arduino help PM's from random forum users; if you have such a question, start a new topic thread.

Northern California (by San Francisco)
Offline Offline
Sr. Member
****
Karma: 3
Posts: 258
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yeah - I've seen this done with a windshield wiper motor (for use as a large servo for steering control) - but now I am curious what you intend to control with -that- motor/gearbox (just what do you plan to move or incorporate it into)...?

I know you are asking zoomkat what he plans to do. But I was interested to see you mention using a windshield wiper motor for use as a large servo for steering control. That's exactly what I plan to do!
Logged

Phoenix, Arizona USA
Offline Offline
Faraday Member
**
Karma: 39
Posts: 5557
Where's the beer?
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Yeah - I've seen this done with a windshield wiper motor (for use as a large servo for steering control) - but now I am curious what you intend to control with -that- motor/gearbox (just what do you plan to move or incorporate it into)...?

I know you are asking zoomkat what he plans to do. But I was interested to see you mention using a windshield wiper motor for use as a large servo for steering control. That's exactly what I plan to do!

Check out these links:

http://www.fieroaddiction.com/servo.html
http://forum.kansascityrobotics.org/showthread.php?t=580
http://130.94.182.150/mowers.htm

On the last link, scroll down and read about "Monster Servos" - all basically follow the same plan; the h-bridge output of the servo is used to actuate a larger h-bridge, then the larger motor being controlled by that h-bridge is connected (mechanically) to the potentiometer on the output shaft of the servo (the servo's motor is disconnected; the output shaft on a servo is connected mechanically to the internal potentiometer).

Note that this kind of a setup will work, but should the mechanical linkage between the motor and the servo's potentiometer fail in any manner, your larger motor may continue to turn, and possibly cause damage to the mechanicals of your system (the only suggestion I could give here is to implement limit switches - perhaps also a second potentiometer monitored by the Arduino - or hack into the servo's pot to read it).

smiley
Logged

I will not respond to Arduino help PM's from random forum users; if you have such a question, start a new topic thread.

Northern California (by San Francisco)
Offline Offline
Sr. Member
****
Karma: 3
Posts: 258
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for the links and other information, cr0sh. That's very interesting and helpful.

With my application, I'm a little hesitant to use the servo internal potentiometer and control signals. I'd rather reproduce what the servo is doing, and do it in my Arduino and using my own potentiometer. (And I think I'll use a rotary encoder rather than a potentiometer.) But the best thing to do seems to be to get started and try a variety of ways. The links you have help me do that.
Logged

0
Offline Offline
Tesla Member
***
Karma: 141
Posts: 9470
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
but now I am curious what you intend to control with -that- motor/gearbox (just what do you plan to move or incorporate it into)...?

My interest is to find an easy and inexpensive way to control the winch like a servo. It might work better in an on/off mode as opposed to fast PPM due to the internal brake setup. Would be interesting to use in a very large three servo type hexapod, one that could carry a passenger. Brackets would have to be welded to the spool and such, but for only $40 at one of the big harbor freight sales, I couldn't pass it by.
Logged

Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   smiley-cool

Phoenix, Arizona USA
Offline Offline
Faraday Member
**
Karma: 39
Posts: 5557
Where's the beer?
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
but now I am curious what you intend to control with -that- motor/gearbox (just what do you plan to move or incorporate it into)...?

My interest is to find an easy and inexpensive way to control the winch like a servo. It might work better in an on/off mode as opposed to fast PPM due to the internal brake setup. Would be interesting to use in a very large three servo type hexapod, one that could carry a passenger. Brackets would have to be welded to the spool and such, but for only $40 at one of the big harbor freight sales, I couldn't pass it by.

If you're interested in building a giant hexapod - you might just do a google search for "Jamie's Robot Spider"...
Logged

I will not respond to Arduino help PM's from random forum users; if you have such a question, start a new topic thread.

0
Offline Offline
Tesla Member
***
Karma: 141
Posts: 9470
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
If you're interested in building a giant hexapod - you might just do a google search for "Jamie's Robot Spider"...

I hope you are not refering to the person below.I could only stand to watch about the first half of the video.  smiley-wink

Logged

Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   smiley-cool

Phoenix, Arizona USA
Offline Offline
Faraday Member
**
Karma: 39
Posts: 5557
Where's the beer?
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
If you're interested in building a giant hexapod - you might just do a google search for "Jamie's Robot Spider"...

I hope you are not refering to the person below.I could only stand to watch about the first half of the video.  smiley-wink


Yeah - that's the guy; he's got tons of videos about his project. He started out with a small plastic working model (radio-controlled) he built; it uses two motors, and is fairly ingenious in the mechanism (he might've been smarter to patent and sell it as a toy). He ended up then moving to a plot of land out in the middle of nowhere, which could only be hiked to, then carving out a patch of land and setting up this stange three story "home" in the wilderness (totally off the grid - collects rainwater for drinking and such). Occasionally he builds strange alt-energy contraptions (wind generators and such) - those are documented too.

Other times, he seems to travel back "home" (to his parents and such?) - he seems very "nomadic" or something; I can't explain it, but it certainly is fascinating to watch him build this thing over time. Somehow he has managed all this, but I have yet to find out how or where he gets the money to do any of it. A lot of the materials he uses are "scrounged", but then again that land - while cheap - still had to cost -something-. Maybe he has a trust fund - or maybe he begs off his parents - or maybe he has "disability" and uses our tax dollars - I dunno.

I'm also trying to figure out - should he get the machine fully working and walking - how he plans to get it "off the mountain"; he has to hike a good distance from where his car is to where his house (hovel?) in the trees is, thru somewhat dense forest. So - unless he plans to cut all the trees in his way down (I wouldn't put it past him), he's going to have to take it apart and move it (with the help of friends - which he seems to have a lot of) - but I think he built it to be taken apart, so he may already have it all figured out.

Yes - his videos are hard to watch; he has a very "twitchy" personality, and it comes thru on the videos (ADD/ADHD? Something else? All of the above? Who knows!); apparently, though, he has it together enough to build this machine, and a place in the woods from junk/scrap, and still get gas, food, water, etc - and stay alive in the woods with little or nothing else - other than some friends.

In a way - he's living a very free and comfortable (for himself, if nobody else) life - without having the "rat race", thinking about a "career", etc - and still has access to the internet.

I envy his lifestyle a bit; my wife and I talk about "moving to 40 acres in the middle of nowhere and living off the grid" (in a steel building, or something made from shipping container, or a manufactured home - I dunno) - but I keep thinking "how will we pay for property taxes" and "what about the internet" - because all I know is software development - and at the minimum (ie, contract coding from home) you need some kind of internet for that. I also fantasize about having an "off the grid robot shop" - or some other weird thing to pay the bills; I'll have to come up with something if I want this to be a reality.

At any rate, its fun to see what Jamie is up to - I have a friend who's a little bit like him (the guy who was helping with my UGV project) - I just don't know how they do it (part of my problem is I "collect" things - I have a lot of "things" - and in a way, that holds me back in certain ways from doing something like this - I also have a house that I am paying on - but can't sell because of the current market - etc)...

smiley

/still smiling!
Logged

I will not respond to Arduino help PM's from random forum users; if you have such a question, start a new topic thread.

Pages: [1] 2   Go Up
Jump to: