Shop OBEX P1 Docs P2 Docs Learn Events
Making a servo follow a potentiometer — Parallax Forums

Making a servo follow a potentiometer

AlphawookieAlphawookie Posts: 14
edited 2006-08-23 07:27 in BASIC Stamp
Howdy folks. This is my first attempt so go easy.

I was interested in making a standard hobby servo follow the rotations of a potentiometer, but I ran into a snag. It does find the correct·position, as close as I can tell, but it's real jerky.
I started with the instructions for using photoresistors on the Boe-Bot, replacing the photoresistor with a 0-50k pot. I hooked up a standard, unmodified servo (way old, with layers of Pleocene·crud on it) to the connector on P12.

After a rude introduction to math without decimal points, I came up with the following program:

'Robotics with the Boe Bot - LinkPotToServo.bs2
'Link potentiometer circiut connected to P6
'to unmodified servo on P12
'220 ohm resistor
'#103 cap  (0.01F)
'0-50k Potentiometer
'Airtronics 34631 Servo
'{$stamp BS2}
'{$Pbasic 2.5}
'Full Left on pot  TimeP6= 0.00364
'90 Left on pot    TimeP6= 0.00360
'Center  on pot    TimeP6= 0.00200
'90 Right on pot   TimeP6= 0.00052
'Full right on pot TimeP6= 0.00049
Leftpottime CON 360
cenpottime CON 200
rightpottime CON 52
TimeP6 VAR Word       'Rctime on #103 cap.
PulseLength VAR Word  'Pulse to standard servo
Pulseadj VAR Word     'Pulse adjustment from center
' PULSOUT 12, 1250    'Full left
' PULSOUT 12, 850     'Center
' PULSOUT 12, 450     'Full right
DO
 HIGH 6
 PAUSE 2
 RCTIME 6,1, TimeP6
 Pulseadj = (1+ (ABS(Cenpottime - TimeP6)*120/(Cenpottime- rightpottime)))*32/10
 IF TimeP6 > 350 THEN Pulselength = 1250
 IF Timep6 > 200 AND (Timep6 < 350) THEN Pulselength = (850 + pulseadj)
 IF timeP6 <= 200 THEN Pulselength = (850 - pulseadj)
 IF timeP6 < 52 THEN Pulselength = 450
PULSOUT 12, PulseLength
DEBUG HOME, SDEC5 ? TimeP6
DEBUG SDEC4 ? Pulselength
DEBUG SDEC4 ? pulseadj
LOOP


I was wondering if there was a cleaner method to arrive at the right pulse length, and why the thing is so jerky?

Any comments would be welcome, and heartily appreciated.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Engineering is the art of doing·something well with one dollar, which any bungler can do with two after a fashion.

Comments

  • willthiswork89willthiswork89 Posts: 359
    edited 2006-07-29 19:45
    in the book Whats a microcontroller they discribe a wonderful way of controller a servo with a 10k pot
  • AlphawookieAlphawookie Posts: 14
    edited 2006-07-29 19:56
    Thanks.
    It's still on the pile to be read. Under "teach yourself electricity and electronics", "robotics with the boe-bot", "robots for dummies", "physics", and a whole passle of other .pdf stuff I printed out at work.
    I'll look it up.

    "The best design is the one with the fewest original ideas"



    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Engineering is the art of doing·something well with one dollar, which any bungler can do with two after a fashion.
  • AlphawookieAlphawookie Posts: 14
    edited 2006-07-29 20:35
    I read it, and I think I grok.
    Using a pot. for position control involves a trade-off : accuracy vs time.
    If you wanted 100 steps, it'd take you 0.2 sec to measure at the high end. It kind of ties up the BS doesn't it?
    Is this why the encoder was invented?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Engineering is the art of doing·something well with one dollar, which any bungler can do with two after a fashion.
  • willthiswork89willthiswork89 Posts: 359
    edited 2006-07-29 21:17
    well im new to alot of it im not positive on that but i know that that was pretty fast at recognizing and positioning the servo, almost instantaniously
  • Danny22Danny22 Posts: 29
    edited 2006-07-30 18:29
    I've been using a 5K ,Dual Axis,center-off,analog Joystick to control a servo pan/tilt mechanism and the following works for me. I'm reading the pot with the RCTIME command so you'll have to adjust the numbers accordingly. This will also work with an ADC0831.
    The code is for one channel:

    DO
    GOSUB Read_Pot
    GOSUB Out-Servo
    LOOP

    Read_Pot:
    HIGH potPin
    PAUSE 1
    RCTIME potPin,pos
    pos = pos ** $C800 'convert to 0-250
    IF pos >140 OR pos <110 THEN
    pos = ((pos*/$0219)+500)MIN 500 MAX 1000 'convert to 500-750-1000
    ELSE
    pos = 750
    ENDIF
    RETURN

    Out_Servo:
    PULSOUT servoPin,pos
    PAUSE 20
    RETURN

    For me the secret was converting the pot data to RC commands. If you use an ADC0831 then just convert the 0-255 to 0-250 and then
    after establishing your dead zone the code becomes: pot = (pot *2)+500. My servo runs real smooth and follows in both speed and position.
  • bennettdanbennettdan Posts: 614
    edited 2006-07-31 01:28
    Danny22
    What cap do you use with the 5K pot on your joystick to be read by RCTIME I am trying to do the same and when I run your code I dont get a full travel I only get about 650-750-850 out of the servo when I debug the value...I want something like 500-750-1000..
  • Danny22Danny22 Posts: 29
    edited 2006-07-31 08:16
    bennettdan:
    I'm using a .1 ufd. What is the range of the raw data coming from your RCTIME ? I think that I got something like 1 - 304 which I scaled to 0-250. You will probably have to play with the " pos */ $0219" expression. You can always make it come out more than 500 on the low end and more than 1000 on the upper end and then limit with MIN 500 MAX 1000. Keep in touch and let me know how you're doing.
  • AlphawookieAlphawookie Posts: 14
    edited 2006-07-31 15:39
    Thanks all. This is giving me fits.

    I tried a couple different resistors to get the results down to a reasonable time frame. I need to calculated the decay time based on the math, ran out of tinker-time.

    Questions:

    Does the stamp stop at the rctime command in the program for the duration of the decay?
    Does the number returned from rctime represent the number of cycles it takes for the decay, or the time it takes. I'm confused because I get a value of 1 for very low settings. 2 milliseconds is (I think) the lowest resolution possible. I could be wrong though. (microeconds?)
    Example: If rctime returns "350" does this represent 0.35 seconds?

    The integer math is still giving me fits too. I've never seen a */ before, and ** used to be how you'd raise a number to a power (3**3 = 27). I'll just have to play with it some more when I get home.
    Interesting code guys. Thanks.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Engineering is the art of doing·something well with one dollar, which any bungler can do with two after a fashion.
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2006-07-31 15:48
    Alphawookie -

    Just one quick question. Have you referred to the PBASIC Reference Manual or the PBASIC Help file? The reason I ask is that nearly all of your questions are answered there, in one form or another, in much more detail than we might offer here.

    Regards,

    Bruce Bates

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    <!--StartFragment -->
  • AlphawookieAlphawookie Posts: 14
    edited 2006-07-31 16:04
    Yes. The problem is that I can't do .pdf here (at work) or at home. Adobe will not reinstall after all exhaustive (regisrty deletion) attempts. It's put a real hitch in my git-along.

    I can never seem to find the info once I've read it in the printed book. I'll try again with the books though, I'm not sure the info I'm looking for is printed somewhere in the 1000+ pages I have on my table. In particular, the units of measurement don't jive with how I percieve the thing to work.

    4000 cycles per second = 0.00025 seconds/ cycle
    How (when I debug the program) does the stamp generate a number like .00001 as a time for the decay?

    I don't have a Pbasic reference, just the Boe-bot and Microcontroller reference. (hard copies)
    I've used the Help (that's where I learned about the integer math), but it is as limited as my experience.
    I may just have to break down and buy something that reads .pdf files. (agony)

    Thanks
    Tom

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Engineering is the art of doing·something well with one dollar, which any bungler can do with two after a fashion.
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2006-07-31 17:18
    Alphawookie -

    I'm HERE for ANY man who know what a hitch in his git-along is! There aren't many of us left!

    What operating system are you using? What kind of computer? Do you have all available Microsoft updates installed? Which version of Adobe Acrobat Reader DID you have, and which version are you now attempting to install?

    What do you mean, specifically, by "Adobe will not reinstall after all exhaustive (regisrty deletion) attempts"?

    Have you used the ordinary Microsoft "ADD/REMOVE PROGRAMS" feature of the Control Panel facility? The results of that attempt?

    What error message or problem(s) do you get/experiene when you attempt a re-install, regardless of any of my previous questions?

    At least in THEORY Adobe Acrobat Reader is so designed, that it can and will install successfully (even) over a prior version!

    Regards,

    Bruce Bates

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    <!--StartFragment -->
  • AlphawookieAlphawookie Posts: 14
    edited 2006-07-31 19:51
    Bruce,
    Just an old dog trying to learn a few new tricks. They're fighting me all the way.

    I'm using XP, and the problem showed up a couple days before I installed all the updates a couple (3-4) weeks ago. The work 'puters a Dell, with that funky memory, and that MAY be the problem. But it doesn't explain why the work and home 'puter's messed up. I may be under attack, but I don't think this is the result of that.
    Home 'puter's a Sony, XP home, recently updated.

    I tried the standard removal first then, reinstalled 6.0 pro. - - Some memory error, it's been a while I forget.
    Then I did another standard "remove", and installed 5.0. no change except "error opening file" now.
    Then, standard uninstall, registry deletion in all users, current user, and my profile. All gone.
    Reinstalled 6.0. Still no go. Another removal, and registry deletion.

    I went back, and put in Adobe 4.0., (reader only) No dice. remove, delete, again.

    Completely puzzled, I did a "system restore" to undo to a time a few weeks before I noticed the problem. (3 months)
    Adobe 6.0 came back as expected, but still will crash just after giving me a glimpse of the document.
    "error opening file" or "error writing file".

    At work, I called the tech support guys in; they did the same procedures with the same result. I gave up at home. I may buy a Pentium (a bit faster than the stamp, but not much) just for adobe, but that'd be a hassle.

    To add insult to injury, last night someone hacked my e-mail, and had it forwarded to another address.
    They then proceeded to change my passwords to ebay, pay-pal, etc. and ordered up thousands of bucks in electronics, all to be shipped to Nigeria. They ruined my "good name".

    I love computers.

    Tom

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Engineering is the art of doing·something well with one dollar, which any bungler can do with two after a fashion.
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2006-07-31 22:53
    Tom -

    It sounds to me like a good virus cleaning is in order, before you do anything else!

    Regards,

    Bruce Bates

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    <!--StartFragment -->
  • robot makerrobot maker Posts: 17
    edited 2006-08-23 07:27
    Danny22 said...
    I've been using a 5K ,Dual Axis,center-off,analog Joystick to control a servo pan/tilt mechanism and the following works for me. I'm reading the pot with the RCTIME command so you'll have to adjust the numbers accordingly. This will also work with an ADC0831.
    The code is for one channel:

    DO
    GOSUB Read_Pot
    GOSUB Out-Servo
    LOOP

    Read_Pot:
    HIGH potPin
    PAUSE 1
    RCTIME potPin,pos
    pos = pos ** $C800 'convert to 0-250
    IF pos >140 OR pos <110 THEN
    pos = ((pos*/$0219)+500)MIN 500 MAX 1000 'convert to 500-750-1000
    ELSE
    pos = 750
    ENDIF
    RETURN

    Out_Servo:
    PULSOUT servoPin,pos
    PAUSE 20
    RETURN

    For me the secret was converting the pot data to RC commands. If you use an ADC0831 then just convert the 0-255 to 0-250 and then
    after establishing your dead zone the code becomes: pot = (pot *2)+500. My servo runs real smooth and follows in both speed and position.
    danny do have circuit for hooking up 2 bs2 stamps one for aid using joystick and and one for scc-2 controller from scott edwards,want to have it remote control fopr stamp for 433 transmitter and servo stamp on reciever,also looking for 6 pot up/down contol for 6 axis robot arm control
Sign In or Register to comment.