Shop OBEX P1 Docs P2 Docs Learn Events
GP2D02 IR and Stuttering forward — Parallax Forums

GP2D02 IR and Stuttering forward

Special_KSpecial_K Posts: 162
edited 2006-03-25 23:16 in BASIC Stamp
Hey Folks, I have a Boe-Bot that is connected to two GP2D02 IR sensors (right and left). The program takes a reading and depending on the values returned applies a forward (or turning) pulse (if..then code taken from fast IR roaming). The problem is that the Boe-Bot does not have continuous forward motion. It kind of stutters forward. Any way to correct this.
«1

Comments

  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-03-07 20:07
    A big part of your problem is all those DEBUG statements...They slow the loop execution down dramatically.· You could also reduce or take out the PAUSE 5 you have at the end of the loop if your servos are getting pulses at least every 20 ms.


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • Special_KSpecial_K Posts: 162
    edited 2006-03-08 03:45
    I removed the DEBUG statements. I am still getting the stuttering.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-03-09 02:47
    Next step is to reduce or take out the PAUSE commands in the servo routines.· It would help if you had a scope or a BASIC Stamp Logic Analyzer to see what your pulses look like.· I am going on the assumption that the servos are not getting refreshed quick enough.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • Special_KSpecial_K Posts: 162
    edited 2006-03-09 04:07
    still no luck. has anyone used the GP2D02 IR sensors without a stutter to forward motion. I really need the help.
  • LarryLarry Posts: 212
    edited 2006-03-09 08:09
    It may not be your program at all that is the problem.

    If your Sharp sensors are like the other ones in the series that I have used. (GP2D12 and GP2D15), they daw a lot of power (around 60 mA each when they fire)
    It could be that your stamp is resetting because of that. It would be especially so if you were runing the servos off the same battery, or if the batteries were low.

    Rig up an LED to a pin on your BOEbot (with proper resistor, of course). Add some code to your program that lights the LED for a half second when the program starts, but NOT in the main loop.

    It should light only once each time you start the robot. If it keeps lighting up, you know you have a power issue.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
  • Special_KSpecial_K Posts: 162
    edited 2006-03-10 01:34
    still it jutters.
    there is no restart in the Basic stamp, I rigged the pizzo buzzer to sound (same thing right) and the stamp is not restarting, but it still the wheel servo stutters . If I take out the IR read subroutine·I get no jitter. If I take out the line
    SHIFTIN DLLFT, CLLFT, MSBPOST, [noparse][[/noparse]IRLFT]······
    there is no jitter is there something up with this code.skull.gif
  • LarryLarry Posts: 212
    edited 2006-03-10 04:43
    Well, at least youy eliminated the resetting. Is the servo power directly from the batteries, or does power go therough the voltage regulator?

    I popped your latest code into the editor and got an error on the Backward Label in your decision tree. Where's the subroutine?

    Since I assume the robot will mostly go forward, I'd reverse the order of your decision tree. Then the code would drop trough the decision loops faster most of the time.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
  • Special_KSpecial_K Posts: 162
    edited 2006-03-11 00:36
    I took out the backward and all other code that was not really being used. I was trying to go as lean as possible. I thought the code might just be bloated, but nope, I still need help. Has anyone... ANYONE gotten the Sharp GP2D02 to work with the Basic Stamp 2?
    Hey, Chris Savage have you made this work? Do I need to go out and get a different Sharp IR sensor? Is the Sharp GP2D12 Analog Distance Sensor that Parallax sells the only sensor that works well with the Basic Stamp 2? If so, shouldn't Parallax post that on the Website somewhere?
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-03-11 02:20
    The Sharp GP2D12 is not the only Sharp sensor that works with the BASIC Stamp.· We have had others in the past.· It could be other factors, but without having one I cannot test your code.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • Special_KSpecial_K Posts: 162
    edited 2006-03-11 06:16
    I changed the IF THE statement... still stutters. I got·4 of these IR detectors. I would hate to loose the $100 I spent. How can I help you fix this issue. smhair.gif
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2006-03-11 06:35
    Special_K -

    See if there is anything here that is helpful:
    http://www.acroname.com/robotics/info/examples/GP2D02-4/GP2D02-4.html

    Are you using an interfacing diode, as appears needs to be used?

    Regards,

    Bruce Bates

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    <!--StartFragment -->
  • Special_KSpecial_K Posts: 162
    edited 2006-03-11 17:58
    That is the code I used. I just changed the variable names so they are a little more understandable.
    the code
    read02:
    LOW cl ' turn on detector for reading
    rl:
    IF IN15 = 0 THEN rl ' wait for input high
    SHIFTIN dt, cl, MSBPOST, [noparse][[/noparse]val02]
    HIGH cl ' turn detector off
    PAUSE 1 ' let detector reset
    RETURN

    is just the same as

    READ_IRLFT:
    LOW CLLFT ' turn on detector for reading
    rl:
    IF IN11 = 0 THEN rl ' wait for input high
    SHIFTIN DLLFT, CLLFT, MSBPOST, [noparse][[/noparse]IRLFT]
    HIGH CLLFT ' turn detector off
    PAUSE 1 ' let detector reset
    RETURN
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2006-03-11 18:05
    Special_K -

    I didn't look close enough to note its purpose, but you didn't mention if you had the required diode in place?

    Regards,

    Bruce Bates

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    <!--StartFragment -->
  • Special_KSpecial_K Posts: 162
    edited 2006-03-11 22:56
    Yep,
    I used this post to get that right.
    http://forums.parallax.com/forums/default.aspx?f=5&m=108889&g=109225#m109225
    so the setup is the same as the diagram here.
    http://www.acroname.com/robotics/info/examples/GP2D02-4/GP2D02-4.html
    I just used pins 9 and 11
  • Special_KSpecial_K Posts: 162
    edited 2006-03-16 04:33
    Is there any help. Has anyone...ANYONE gotten the GP2D02 to work with BS2 and servos???
  • LarryLarry Posts: 212
    edited 2006-03-16 05:24
    I think I see your problem. Previous hints were aimed at making your loops execute faster (eliminate debug statements and pauses, etc) in order to make your program comply with the 20ms refresh rate required by your servos. This comes out to 50 times per second.
    It may not be possible with this sensor. I downloaded the datasheet from this Google link below, and it takes too long for the sensor to fire and return data. Actually, the timing data is right in the google link itself (line 3 at the end)

    [noparse][[/noparse]PDF] OPTOELECTRONIC/POWER DEVICES
    File Format: PDF/Adobe Acrobat
    GP2D02. Compact, High Sensitive Distance. Measuring Sensor. (Unit : mm). Features. Applications ... GP2D02. 70ms. 0.1ms. 0.1ms. 1.6ms. 2ms. (Ta=25C,Vcc=5V) ...
    info.hobbyengineering.com/specs/SHARP-GP2D02.pdf - Similar pages

    Note that it takes around 74 microseconds for the sensor to cycle once. If you read both sensors in one loop, and try to execute other code, you will be able to command the servos only every 160 microseconds or so---too slow.

    Thats what is causing the stuttering, the servos aren't getting refreshed often enough, only 1/7to 1/9 as often as they should be.


    Here are some things to try
    1) get a servo controller to refresh the servos --the only drawback is the cost of the controller.

    2) try rewiting your program so servos get refreshed after reading each sensor. the timing will be too slow, but that might be good enough. you will need a variable that remembers what the servo you DIDN'T read said during the previous time it was read.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔


    Post Edited (Larry) : 3/16/2006 6:22:36 AM GMT
  • Special_KSpecial_K Posts: 162
    edited 2006-03-18 01:33
    Ok, that is that. I guess I have to give it up there is no way to get a faster response out of the IR unit. I will just buy new IR sensors and eat the $100. I really wish there was information from Parallax that could have informed me about this. This is a very expensive lesson.
  • LarryLarry Posts: 212
    edited 2006-03-18 02:22
    I don't think you can blame Parallax for a third party product. But it's still cheaper to get a servo controller.Parallaxes is a fine unit and only costs $30 or so.

    There are cheaper units that would also work, though they lack some features. Just Google "Servo Controller"

    Larry

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
  • Special_KSpecial_K Posts: 162
    edited 2006-03-18 04:21
    I'm just a little salty. I thought it would be ok since parallax sells Sharp GP2D12 Analog Distance Sensor. I have the servo controller on the way. Do you really think it will work. I do not know much about the servo controller.
  • PARPAR Posts: 285
    edited 2006-03-18 04:27
    Special_K said...
    Ok, that is that. I guess I have to give it up there is no way to get a faster response out of the IR unit. I will just buy new IR sensors and eat the $100. I really wish there was information from Parallax that could have informed me about this. This is a very expensive lesson.
    What prompted you to select the GP2D02 unit in the first place?

    Parallax has abundantly documented the matter of servos requiring a certain period (pause) between signals (not too short, not too long a period). Parallax has also has on many occasions needed to alert the reader to "timing" issues of all sorts.

    But, it isn't reasonable to expect Parallax to provide information on every combination of products that exists or that could be combined by a customer·--especially so for products (specific models) that it does not even sell/support, and/or for applications which it has not specifically suggested that the specific product is suitable for.

    Parallax has brought affordable·electronics learning, entertainment and even practical applications within the grasp of many by providing very well conceived·products and documentation. But, if you choose to step beyond that perimeter, things can·get messy in a hurry and the lessons can become expensive (or, valuable?).

    PAR
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-03-18 05:59
    Special_K said...
    Ok, that is that. I guess I have to give it up there is no way to get a faster response out of the IR unit. I will just buy new IR sensors and eat the $100. I really wish there was information from Parallax that could have informed me about this. This is a very expensive lesson.
    I was under the impression that you were using a different sensor than the one we carry.· If that is the case I am not sure what other information we could've provided.· As I said above a scope or logic analyzer would've been able to narrow down the delays, but without it I could only guess.· As it was I found it hard to believe that in whittling down your PAUSE statements until you had none that you didn't see a noticable improvement in performance.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • Special_KSpecial_K Posts: 162
    edited 2006-03-24 16:27
    I did get an improvement from removing the debug statements, but it was minimal. I have the Parallax Servo Controller but I thought the documentation that came with it would show code on how to use it. No example code comes in the included documentation. I guess the code for the serial one is the same.

    Post Edited (Special_K) : 3/24/2006 4:39:32 PM GMT
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-03-24 17:48
    There is code for the PSC.· Or are you talking about the Sharp Sensor?· The Sharp Sensor you mentioned we don't carry so we wouldn't have code examples for it.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • Special_KSpecial_K Posts: 162
    edited 2006-03-24 18:05
    Code for the PSC.
    do you have a link to code like that of the
    Ping)) BASIC Stamp Example Code (.zip).

    the docs that come with the PSC
    http://www.parallax.com/dl/docs/prod/motors/PSCusbManBv3_3.pdf
    Do not have code.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-03-24 18:10
    There is example code for the PSC.· Not application specific code for the PSC.· You must write that.· The code you refer to doesn't even support the Sharp Sensor you mentioned so I don't see the relation.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • Special_KSpecial_K Posts: 162
    edited 2006-03-24 18:39
    Sorry I am lost. I thought that if I got the PSC that I would no long need to give the refresh commands to the continues rotation servos every 20 MS.
    From Larry
    Note that it takes around 74 microseconds for the sensor to cycle once. If you read both sensors in one loop, and try to execute other code, you will be able to command the servos only every 160 microseconds or so---too slow.

    By the way thanks again Larry

    I got the PSC so that I could have it provide the refresh statements to the servos in an acceptable time frame. I just did not know why the PSC USB documentation did not come with code or code snippet on how to have your Basic Stamp 2 control it. It just tells you how to control it via the computer and how do download the frames made into the Basic Stamp. I was hoping/looking for code kind of like that of the Ping)) documentation or at least a equivalent chart that said: You control a servo via the basic stamp like this.

    PULSOUT 13, 650
    PULSOUT 12,850
    PAUSE 20

    and like this with the basic stamp sending controls to the PSC.
    ????

    I did not want code for controlling GP2D02
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-03-24 18:42
    You are correct.· If you use the PSC you don't need to refresh the servos.· What I said was that there is no example code for the PSC for your specific application.· You would need to write it.· It could certainly be done.· That is the intention of the PSC though, to alleviate refreshing issues with the servos.· On each iteration of the loop you could send a command to the PSC with the proper values, but it would make more sense to setup code to only send changes to it.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • PARPAR Posts: 285
    edited 2006-03-25 01:09
    Special_K said...
    Code for the PSC.
    do you have a link to code like that of the
    Ping)) BASIC Stamp Example Code (.zip).

    the docs that come with the PSC
    http://www.parallax.com/dl/docs/prod/motors/PSCusbManBv3_3.pdf
    Do not have code.
    There is some example bs2 code operating the PSC·(for the "crawlers") at

    http://www.crustcrawler.com/code/index.php?prod=20

    PAR
  • Special_KSpecial_K Posts: 162
    edited 2006-03-25 22:46
    THe BOE-Bot is really fast now. a little too fast am I going to burn out the servos??
    I have the PSC connected to a standard 9V battery.
  • LarryLarry Posts: 212
    edited 2006-03-25 23:06
    Glad to see you working through the issues involved. That's what the hobby is all about.

    Most servos are made to work in the 4.8-6.0 volt range. As with any motor, overvoltage will create heat, wear out the brushes sooner, and shorten the life of the motors.I'd cut the motor power back to the suggested levels unless you are willing to live with frequent servo replacement. (sometimes people in robot competitions will do anything to get an edge)

    It's more economical, too. 9v batteries don't have many amp/hrs in them for the money. Take one apart, and you'll find teeney little battry cells in series. They just don't hold much energy in them.

    I'd scale back on voltage and gain run time.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Sign In or Register to comment.