PING))) & HB25 code help
wandererrob
Posts: 10
Hi all,
I'm trying to piece together some code in BS1 for my Prop-1 controller using a PING))) sensor for the trigger and an HB25 to control a wiper motor. The idea is that when a person is within a given range the lid of a trunk will open, then when they get closer it'll close again. I may or may not add in some LED eyes that turn on/off in conjunction with this, but for now I'm just trying to get the lid open/close code working.
I've almost got it, but I'm missing something. I don't know what.MIB.bs1
Here's the issue: I've got it reacting based on distance, however I can't seem to make it only open or close once then wait until the distance changes to trigger the next event. That is to say, for example, the motor will "open" then a few seconds later it'll do it again and so on so long as something is within range.
What am I missing to tell it to open then wait until it's time to close again?
I thank you all for your forthcoming wisdom.
Rob
I'm trying to piece together some code in BS1 for my Prop-1 controller using a PING))) sensor for the trigger and an HB25 to control a wiper motor. The idea is that when a person is within a given range the lid of a trunk will open, then when they get closer it'll close again. I may or may not add in some LED eyes that turn on/off in conjunction with this, but for now I'm just trying to get the lid open/close code working.
I've almost got it, but I'm missing something. I don't know what.MIB.bs1
Here's the issue: I've got it reacting based on distance, however I can't seem to make it only open or close once then wait until the distance changes to trigger the next event. That is to say, for example, the motor will "open" then a few seconds later it'll do it again and so on so long as something is within range.
What am I missing to tell it to open then wait until it's time to close again?
I thank you all for your forthcoming wisdom.
Rob
Comments
In your Get_Sonar routine, you added some IF statements, but they just fall through to lid_open if none of the conditions are met. Is that what you want?
You calculate inches in the Main loop, but you've already called Get_Sonar and done the IF tests on the previous value of inches. I suggest you let Get_Sonar just get the distance and put the IF statements in the Main loop after you calculate inches. Remember that, if you do this, these routines need to GOTO Main after they're done rather than RETURN since there's no matching GOSUB.
Fix those issues, then post the corrected program (after you've tried it). You might take out some of the debug statements that you don't need at this point and add some that would be useful. You need to leave in the inches display and maybe have one DEBUG statement in each of your three routines (lid_open, lid_close, and check_for_victim) so you can see what decision is being made with the inches value.
Once, you get your code fixed based on what Mike is talking about and posting it on this thread and are still are having problems, I or someone else will be happy to help you through problem in this thread.
Just FYI the Prop-1 controller was designed and sold by Jonnymac (Jon Williams) and has an support forum site at EFX-TEK.com that is designed around people who are doing Holloween props like yours.
He also will write you a basic program based on what you are trying to do
No, I want the default situation to be that the lid is closed if nobody is within range.
Then have it open when they get inside a certain distance, then close again when they get too close.
I'll try your suggestions and see how it goes. Thanks.
If I can make it work, it will be
Anyway, though I'm still not up and running, here's what I've got now based on my best guesses based on your suggestions (keep in mind I'm a code noob, so I may be am probably making some incorrect assumptions). MIB-mod.bs1
Somehow I seem to have taken a couple of steps in the wrong direction. That is to say, the PING))) seems to be "stuck" flashing the act light with no reporting to the debug window. The HB25 and motor are just hanging out waiting for the rest to figure out what it's doing. Unfortunately, there seems to be a loose nut at the front of the keyboard mucking up the works.
Where am I going astray?
Get_Sonar is a subroutine, called with a GOSUB. At the end of the subroutine, you have to have a RETURN, not a GOTO Main.
Your initialization section (Startup) is still in the wrong place and will never be executed. The Initialization section has to come before the Program Code section. You're never initializing the HB-25. Remember that programs start at the beginning and continue towards the end unless you do something to change that (like a GOTO or GOSUB / RETURN).
Maybe I've been staring at this too long tonight. Where'd I leave a return? I thought I got rid of them all. I'm not seeing it.
I think I'ma got to bed now and start fresh int he morning.
Thanks again for your help.
Next question: Is there a way to more precisely control the motor's movement?
I realize there will always be some small errors that creep in because I'm trying to control a continuous rotation motor like a servo, but is there a way to minimize said error. I've got the timing very close to where I want it. That is to say, I have it moving very close to 180* in each direction. But it occasionally over or under shoots. Can that be tightened up at all? Or is this just a limitation of this setup that I'll have to live with?
And yes, Mike, I will check out the references you've listed. I've got another PING))) and HB25 that I have other plans for later.
MIB revised2.bs1