GOSUB issue
Shack
Posts: 11
I'm having a little issue with the attached code.· The last "GOSUB right"·doesn't seem to be functioning.· I changed the pin information thinking it was a bad output.· It did not change the issue.· It's probably somehting simple that I'm missing.· Any help would be nice?
Comments
Can you please explain what the program is doing or not doing as expected? That way we can see how it is supposed to operate and offer some suggestions.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Respectfully,
Joshua Donelson
www.parallax.com
In the above, "time" is the same as time(0). Try this:
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When the going gets weird, the weird turn pro. -- HST
1uffakind.com/robots/povBitMapBuilder.php
1uffakind.com/robots/resistorLadder.php
Looking at the code I see you are calling the ping: routine once in the search but then use the time values as though they were called each time at 9, noon, and 3 o'clock servo position.
You would want to call each of the positions the servo needs to go to, and then use the ping: routine to get that measurement, and then have a statement like time = time0, 1, or 2 depending on what position the servo is in. Once you have that, you will have 3 different time measurements all from the different positions you are searching for.
So the flow would look something like the following:
Step1: Move servo to position
Step2: Take measurement
Step3: Assign time measurement to new time(0-3) variable
Step4: Repeat steps 1-3 until all measurements have been taken and assigned to variables
Step5: Run routine to turn on LEDs
I hope this helps,
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Respectfully,
Joshua Donelson
www.parallax.com
Jos - "ping" is being called each time the FOR...NEXT for the servo is being executed.· By using the "ping_num = ping_num +1" and the time(ping_num) indirect addressing, I'm loading the information into time0, time1, and time2 each time the servo moves.· I'll verify the information in time0, time1, and time2 tonight to make sure it is working.· The other two subs, "left" and "straight" are functioning correctly.· Thanks.
Distance = 0021 cm
ping_num = 00
Distance = 0028 cm
ping_num = 01
Distance = 0048 cm
Ping_num = 02
Time0 = 0028 cm
Time1 = 0048 cm
Time 2 = 0000 cm
The initial distances information is correct along with the ping_num value, but the information is· being placed in the wrong variables i.e. time1 into time0, time2 into time1.·This leaves "0000" for time2. I must be missing something in the sequence of the code, but I don't know what it is.
In your implied array:
time0 = time(0) = time
time1 = time(1)
time2 = time(2)
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When the going gets weird, the weird turn pro. -- HST
1uffakind.com/robots/povBitMapBuilder.php
1uffakind.com/robots/resistorLadder.php
When the·first·GOSUB ping is ran, let say·"time"·is calculated at·10.· That means time(ping_num) = 10 ** 2251 = time(0).· That saves the initial value of "time".·When the·next GOSUB·ping is ran, let say·"time"·is calculated at·12.· That means time(ping_num) = 12 ** 2251 = time(1).· That saves the second value in time(1).
I hope that helps to clear it up.
Jos and Zoot - I've got it working now.· I needed to move the indirect address pointer statement, ping_num = ping_num +1, up before the GOSUB ping.· It changes the time variables to time1, time2, and time3 and solves the problem.· Just something in the sequence, I guess.· I didn't change anything else.· Thanks for your help.