Shop OBEX P1 Docs P2 Docs Learn Events
Counting servo pulses, and back tracking them (can it be done?). — Parallax Forums

Counting servo pulses, and back tracking them (can it be done?).

SciTech02SciTech02 Posts: 154
edited 2006-04-01 21:52 in BASIC Stamp
I know that you can count servo pulses, but can you back track them?· For example; If my robot goes forward for 24 pulses, and 1 left pulse.· Then if I make it turn around, can I make it back track them?· For example; can I make it do·1 right pulse, and go forward 24 pulses?· It sounds like you can do it, can I?······ -SciTech02.

Comments

  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-03-24 19:02
    The Digital Wheel Encoder Kit might help with this.· You could track that information to some degree...Without feedback though you would probably not be able to accurately follow your path.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • SciTech02SciTech02 Posts: 154
    edited 2006-03-25 03:59
    Yeah that's what my problem is.· I was looking for a way so it could count pulses without getting the Encoders.· I know you can count servo pulses.· Can I do somthing like this; I have a counter that counts left pulses, right pulses, and forward pulses.· It stores them and when the time is right, it will execute a U-turn and go back, except if it does a left pulse it would turn right and vice-versa.· There's got to be a loophole in PBASIC that lets you do this.· One more thing, not accurately is fine by me, just if it does it is what I'm asking.···· -SciTech02.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-03-25 04:14
    Without extremely good calibration values for your wheels the counts would be useless.· But it could be done.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • SciTech02SciTech02 Posts: 154
    edited 2006-03-25 17:03
    I see.· My question now is, how would you program it to·log counts in order?· I don't know a command that logs counts in order, if one even exists.· My weels are calibrated pretty good, I can make them beter.··If it can be done, how?··· -SciTech02.
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2006-03-25 17:31
    · I think you'd need to make a "map" in an EEPROM.· Keep a running count of each step so that you'd be writing DATA (which would be a direction code) for each step in your sequence.· You'd have to decide beforehand, I think, how many steps you'll want to have record of, but not necessarily (?).
    · So, each servo actuation is a step (an address in memory) and each step records a direction code (e.g. 01 = FWD, 02 = LT, 03 = RT, 04 = REV.)· Then, when you want to backtrack, you'll READ that address and deal accordingly.
    · Does that make sense?
  • SciTech02SciTech02 Posts: 154
    edited 2006-03-27 03:56
    Sort of, half of it I do.· I don't know anything about DATA command or stuff like that.· I understand about having a fixed amount of pulses to log.· What·if I had it count up to 1000 pulses but it did only 900.· Would it still back track them, or would it not work?·

    Here's what I'm working on, it's part of it.··What it does is it goes until the two ir sensers detect somthing, and it back tracks what it did.· What I'm asking is; Is there a type of "LOG" command or any command that's does the same thing?· Then, how would I program it to do it?· I·really want this program to work, so if you can help, I would be very happy.· NOTE.· In my program, I put it so when it makes a right turn, it logs it as a left.· I did that because when it turns around, it will turn the right direction.· And I had problems with the ENTER Key.

    IF (irDetectLeft = 0) AND (irDetectRight = 0) THEN

    GOSUB Back_Track

    ELSEIF (irDetectLeft = 0) THEN
    · LOG(?)·leftPulse
    · PULSOUT 13, 850
    · PULSOUT 12, 650
    · PAUSE 20

    ELSEIF (irDetectRight = 0) THEN

    · LOG(?) rightPulse

    · PULSOUT 13, 850·

    · PULSOUT 12, 650

    · PAUSE 20

    ELSE

    · LOG(?) forwardPulse

    · PULSOUT 13, 850

    · PULSOUT 12, 650

    · PAUSE 20

    ENDIF

    Back_Track:

    · FOR counter = 1 TO 40

    ··· PULSOUT 13, 650

    ··· PULSOUT 12, 650

    ··· PAUSE 20

    · NEXT

    · ???·

    Post Edited (SciTech02) : 3/27/2006 5:23:34 AM GMT
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2006-03-27 06:06
    SciTech2 -

    First there is no "LOG" command as you proposed, and second, why do you feel there is a need, or requirement to back-track? If it's your feeling that this is the only way a robot can remove itself from a situation where it has gotten "stuck" (boxed in), let me assure you, it's not.

    I'm not suggesting one couldn't do what you're asking, I just don't see the merit or purpose to doing it. Perhaps I'm missing something.

    When you go into a store, you go in front first. When you come out, you come out front first. You don't back out the opposite way you came in (rear first). Why should the robot be required to do so, and to what end?

    Regards,

    Bruce Bates

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    <!--StartFragment -->

    Post Edited (Bruce Bates) : 3/27/2006 6:20:02 AM GMT
  • SciTech02SciTech02 Posts: 154
    edited 2006-03-27 17:31
    Oh, heh heh.· I know this program pointless, that it's stupid to back track when it get's stuck.··But I'm using·this as a test before I intergrate it into my real progect.· I'm using this as a tool because it's easer to make this work them my whole other·program.· I know it's dumb, but my real progect that uses this is going to be great.
  • allanlane5allanlane5 Posts: 3,815
    edited 2006-03-27 20:37
    I don't think so. The 'pulses' you send out to the Servo are only signals that the Servo electronics use to guage how fast to run the motors (if at all -- in the 'center' position, pulse-width 1.5 mSec or so, the motors don't run at all).

    So this is NOT the same as a stepper motor, which really does move a certain distance per 'step'. Thus the sheer number of pulses sent does not really equal distance traveled. The encoder is really the only reliable way to determine how far your wheel has turned.

    On the other hand, how far your robot has moved IS a factor of how long you've been sending pulses. Not a very exact factor, but there's clearly some relationship there. And the number of pulses you've sent is ALSO related to "how long you've been sending pulses". So perhaps you COULD use this number as a rough 'time' indication to reverse the path of your robot.

    This assumes your robot is not 'blocked' by running in to anything, of course...

    Oh, and you can 'log' up to 65,536 pulses merely by using two 'word' variables...

    LeftCount VAR Word
    RightCount VAR Word

    GoStraight:
    · PULSOUT LeftMotor, 850
    · PULSOUT RightMotor, 650
    · LeftCount·= LeftCount + 1
    · RightCount = RightCount + 1
    · RETURN

    Now, if you want to 'log' a 'path' of these counts, you could write them into an external eeprom.· I wouldn't use the on-BS2 eeprom for this, as you'll be writing LOTS of data in short periods of time, which could wear out the eeprom.· An external eeprom is much more easily replaced.

    Post Edited (allanlane5) : 3/27/2006 8:41:54 PM GMT
  • SciTech02SciTech02 Posts: 154
    edited 2006-03-27 22:16
    Okay!· I entered part of·my program I'm working on.· It uses the GoStrait subroutine that you showed me.· What it does is it goes forward until it detects somthing, then it's supposed to turn around and go forward·the same amount of pulses it counted forward.··Here is part of it:

    IF (irDetectLeft = 1) OR (irDetectRight = 1) THEN
    · GOSUB GoStrait
    ELSEIF (irDetectLeft = 0) OR (irDetectRight = 0) THEN
    · GOSUB Back_Track
    ELSE
    · GOSUB Back_Track
    ENDIF

    Now I don't know how to make it count turning pulses, and how to make it back track them.··confused.gif··

    Post Edited (SciTech02) : 3/27/2006 10:19:46 PM GMT
  • SciTech02SciTech02 Posts: 154
    edited 2006-03-27 23:18
    Wait I developed a program that back tracks forward pulses.· It goes forward and adds once to a 'ForwardCounter'.· Then, when it detects somthing, it executes a U-turn, and·does a 'FOR counter 0 TO ForwardCounter' so it does the same amount of pulses it counted before.· It works fine I guess.·

    But I don't know how to count turning pulses and back track thoses in order.· Could·I still make it back track when it makes turns, and go back in order?


    Post Edited (SciTech02) : 3/28/2006 4:05:33 AM GMT
  • SciTech02SciTech02 Posts: 154
    edited 2006-03-28 21:58
    Well, don't worry about that last question, I got one to work.· It's like a triangle in a way, and like Mr.· Savage said; you need really good calibration for your servos for it to work properly.· What it does is it counts forward pulses, left turn pulses, and right ones.· Then when the time is right (when both sensers detect somthing) it executes a U-turn, and like my other program it does a FOR...NEXT command of the left pulses,·and right pulses.· That, most of the time points it back·to it's starting point, wich it then go's forward the same amount of·forward pulses it counted.· It dosen't follow the exact path it made, but it returns to it's starting point, and I'm sure somebody could develop a program that does that using this as a draft.·

    I would show you the file, but I could not find it on my computer (?).· But if you want to make it, just follow the guidlines I just discussed.· Thank you guys for your help.····· -SciTech02.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-03-28 23:08
    Now that I see exactly what you're trying to do I will say this...I have a similar project in that I wanted to be able to specify way-points in the real workd and have a Robot (Tank) navigate that.· On a large scale a GPS would work almost by itself (Short of obstacle detection).· On a smaller scale I was thinking of measuring distance traveled on a given compass heading.· That makes up for some of the calibration issues becaue you correct you path based on the heading, not the number of pulses which can vary for each direction the servo is rotating.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • SciTech02SciTech02 Posts: 154
    edited 2006-03-29 02:13
    Yeah I know (About the compass).· That is a great little gizmo for your robo's.· The GPS is good to (Having a compass in it and the ability to map).· With ether one you could almost go perfectly strait.··· -SciTech02.
  • SciTech02SciTech02 Posts: 154
    edited 2006-04-01 02:15
    Well, If anyone is interested, here's my program.· It took me awile to find it on my computer, but I found it.· Remeber, your servo pulses must be accurate for it to work properly.
  • Tricky NekroTricky Nekro Posts: 218
    edited 2006-04-01 21:52
    You use 3 servos!!!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    -Rule your Destiny-
    --Be Good. Be Bad. Be Provas--
Sign In or Register to comment.