Shop OBEX P1 Docs P2 Docs Learn Events
Help! Having trouble getting my servos to go forward correctly! — Parallax Forums

Help! Having trouble getting my servos to go forward correctly!

omgitsaliv55omgitsaliv55 Posts: 24
edited 2006-10-11 23:06 in BASIC Stamp
Hi. My name is Patrick and I am very interested in robotics and have been for about three months. I've written a lot of PBASIC 2.5 programs, however I have just run into a dilema with my Boe Bot. I recently had to recailibrate my continous rotation servos because one was moving slightly slow that the others. I got it to a point of nearly perfect calibration and reassembled my Boe Bot. I fixed up a few things in the code just to make outputs match up and found that my problem was far from fixed. It had actually worsened. Now, one of the servos made a strange "clicking" noise. But that wasn't the big problem. The big problem was that one of the servos was only going half the speed of the other one now (don't worry. the one that was clicking worked fine. it was the one that sounded normal that was strange). I thought to myself, "Maybe its a defective servo..." and switched the servo ports to see if the same servo would go slow again. Surprisingly, it didn't. The other one was going slow now. This scared me. I was really worried that my servo port had weakened, however when I ran a program that looked like this:

' {$STAMP BS2}
' {$PBASIC 2.5}

DO
PULSOUT 12, 650
PULSOUT 13, 850
LOOP

...It went forward perfectly! I was relieved. I knew then I was most likely having a software problem. So, I played around with my program a bit to try and figure out what was the problem. Eventually, I had it all the way down to the attached program "buggy code!.bs2" (it use to be a complete light seeking and object avoiding program). It still didn't go forward correctly. And strangely, when I held my hand in front of one of the IR detectors, it's left wheel rotated bacdkwards. There is NOTHING in the code to tell it to go backwards! I'm thinking I should get new servos, but what if its my BS2? That's a pretty good chunk of change for replacement parts if it happens to be my BS2, or even worse, my Board of Education. Any help is appreciated. Thanks!

Comments

  • Steph LindsaySteph Lindsay Posts: 767
    edited 2006-10-11 22:24
    Hello Omgitsaliv55

    This may not be the only bug, but I noticed that you are using:

    <snipped other declarations>

    leftir CON 13

    DO
    DEBUG CLS, DEC irright, CR, DEC irleft
    FREQOUT rightir, 1, 37500
    irright = IN0
    FREQOUT leftir, 1, 37500
    irleft = IN14
    IF (irleft = 1) AND (irright = 1) THEN
    PULSOUT 13, leftforward
    PULSOUT 12, rightforward
    ENDIF
    LOOP

    From the code it appears the command FREQOUT leftir·is sending·signals to both the servo and the IR led, and the servo can't interpret it.·Are·you using the·IR circuits directly from the book?

    -Stephanie Lindsay
  • Mike GreenMike Green Posts: 23,101
    edited 2006-10-11 22:30
    I don't see anything in the code that would cause the behavior that you describe. Could you have loaded the wrong program into the BS2? In general, I suggest that you put a PAUSE statement in the DO loop so that the pulses get produced maybe every 10ms to 20ms. A simple PAUSE 10 will do. The servos must see a pulse at least every 20ms for proper operation. Try commenting out all the non-declaration statements except the DO, PULSOUT, LOOP, and PAUSE, make sure it works, then add back the others one or two at a time, each time seeing if the whole program still works properly.

    Oops, Stephanie sure picked up on the probable cause. The FREQOUT output is not something a servo can interpret properly.

    Post Edited (Mike Green) : 10/11/2006 10:34:07 PM GMT
  • omgitsaliv55omgitsaliv55 Posts: 24
    edited 2006-10-11 22:46
    Does this mean that I can't wire anything to ports 13 and 12? I haven't ever wired anything to these ports except for now, so this very well could be the problem (sorry i haven't tested it yet. i have to leave the house in a bit). If it is, I'm mildly disappointed (two less i/o pins, but yet VERY relieved (my problem's fixed!). thankyou!
  • Mike GreenMike Green Posts: 23,101
    edited 2006-10-11 22:50
    It just means that you can't use the same ports for two different functions (IR & Servo). It helps make things clearer if you use CON names for all the I/O pins that you use. In your case, you've got "leftir" meaning one pin and "rightir" meaning another pin, but use the numbers 12 and 13 for the servo pins (rather than naming them).

    Another thing that helps is to use the PIN declaration rather than CON when you're defining I/O pins. The Stamp Basic statements sometimes use numbers for I/O pins and sometimes use special names (like IN1). The PIN declarations allows you to give a specific name to an I/O pin that can be used in either context and the compiler will "put in the right thing".

    Post Edited (Mike Green) : 10/11/2006 10:57:54 PM GMT
  • omgitsaliv55omgitsaliv55 Posts: 24
    edited 2006-10-11 22:51
    I just tested it and it fixed it!!!! Thankyou SOOOOOOOOOO much you guys. I love you people (that just slipped out, but i really feel like I'm floating right now (i've been trying to fix this for days!) ). Again, thank you SOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO much!

    Have a great day!

    Bye wink.gif
  • Steph LindsaySteph Lindsay Posts: 767
    edited 2006-10-11 23:06
    Are you using a Board of Education with servo headers?· Look above them, you can see they are labeled with the BASIC Stamp I/O pin numbers they are connected to, and X4 and X5 below.· Header X5 uses·I/O pins 13 and 12.·

    If you are using Servo Port 13, you are connected to I/O pin P13, and anything you plug into the P13 socket to the left of the breadboard area will receive the same output signals you send to the servo.· If you tried to use the P13 socket as an input, whatever device you are trying to read with·I/O pin·13 will probably also be sending interference to the servo.· So the answer is yes, the P12 and P13 connections next to the breadboard should not be used for other circuits while you are using servos in the X5 header.·The BASIC Stamp still has the same 16 I/O pins it always had, it's just that two of them are busy with the servos. That still leaves 14 I/O pins to play with though!

    Thanks Mike for pointing out the need for PAUSE commands.· I spotted the pin use conflict and didn't dig any further.

    -Stephanie Lindsay
    ·
Sign In or Register to comment.