WAM Ch. 4 Exercise 1/2
kf4mat
Posts: 21
I'm having problems with this one and now I have to ask for help. For background I'll post the problem from the book in whole....
·······
······ FOR counter = 700 TO 800 STEP 4
···········PULSOUT 14,·counter
·· ······· PAUSE 20
·········· DEBUG DEC4 counter, CR, CRSRUP········'This line is my addition
······ NEXT
······ FOR counter = 700 TO 800 STEP 4
·········· FOR counter = 800 TO 7000
···········PULSOUT 14,·counter
·········· PAUSE 20
·········· DEBUG DEC4 counter, CR, CRSRUP········ 'This line is my addition
······ NEXT
··········
Now I have no problem with this and if I add a counter declaration it runs with no problems. However, moving on to question·two, I seem to be missing the solution. The answer provided in the manual will not work as written.·Here is the book code block for question #2:
········· FOR counter = 700 TO 800 STEP 4
··············· FOR·pulses = 1 TO 10
················· PULSOUT 14,·counter
················· PAUSE 20
················· DEBUG DEC4 counter, CR, CRSRUP········ ' mine
··············· NEXT
··········NEXT
········· FOR counter = 800 TO 700 STEP 4
················FOR pulses = 1 TO 10
················· PULSOUT 14,·pulses
········ ········ PAUSE 20
················· DEBUG DEC4 counter, CR, CRSRUP········· ' mine
················NEXT
·········· NEXT
No matter how I try to rewrite this it will not work properly. attached is my lastest try. Anyone want to give me a hint so that I can figure this one out.
Thanks, Tom
Here is the code block for 1b:Ch 4 Controlling Motion pg 135 said...
·1. Write a code block that sweeps the value of Pulsout controlling a servo from a duration of 700 to 800, in increments of (a) 1, (b) 4.
2. Add a nested FOR...NEXT loop to your answer to exerxise 1b so that it delivers ten pulses before incrementing the pulsout duration argument by 4.
·······
······ FOR counter = 700 TO 800 STEP 4
···········PULSOUT 14,·counter
·· ······· PAUSE 20
·········· DEBUG DEC4 counter, CR, CRSRUP········'This line is my addition
······ NEXT
······ FOR counter = 700 TO 800 STEP 4
·········· FOR counter = 800 TO 7000
···········PULSOUT 14,·counter
·········· PAUSE 20
·········· DEBUG DEC4 counter, CR, CRSRUP········ 'This line is my addition
······ NEXT
··········
Now I have no problem with this and if I add a counter declaration it runs with no problems. However, moving on to question·two, I seem to be missing the solution. The answer provided in the manual will not work as written.·Here is the book code block for question #2:
········· FOR counter = 700 TO 800 STEP 4
··············· FOR·pulses = 1 TO 10
················· PULSOUT 14,·counter
················· PAUSE 20
················· DEBUG DEC4 counter, CR, CRSRUP········ ' mine
··············· NEXT
··········NEXT
········· FOR counter = 800 TO 700 STEP 4
················FOR pulses = 1 TO 10
················· PULSOUT 14,·pulses
········ ········ PAUSE 20
················· DEBUG DEC4 counter, CR, CRSRUP········· ' mine
················NEXT
·········· NEXT
No matter how I try to rewrite this it will not work properly. attached is my lastest try. Anyone want to give me a hint so that I can figure this one out.
Thanks, Tom
bs2
482B
Comments
Tom
Working straight from the questions as they are posted, this is what I think the answers should be:
They are not tested.· Please try them out and let me know if they work.
Regards, Andy
Post Edited (Andy Lindsay (Parallax)) : 10/24/2005 1:03:40 AM GMT
······· DEBUG DEC3 counter, CR, CRSRUP
When you run it the debug terminal counts in steps of 4 starting from 700. So then I changed it to read the value of pulses, when you run it then the debug terminal counts from 1 to 10 over and over until the value of counter gets to 800.
The only way I could get it to work the way the question is worded was to add a nested IF...THEN statement· See the attachment on my second post. That way the value of counter as displayed on the debug terminal counts from 700 to 710 by 1's and then counts the rest of the way by 4's. It works but I don't know if nesting a IF...THEN inside a FOR...NEXT is considered good pratice.
Tom
I think you will see it better if you use
· DEBUG ? counter
instead.··Here, try this one:
' Chapter 4, Exercise 2
·
FOR counter = 700 TO 800 STEP 4
· FOR pulses = 1 TO 10
··· PULSOUT 14, counter
··· ' PAUSE 20
··· DEBUG ? counter
· NEXT
NEXT
The result in the Debug Terminal should display counter = 700 ten times, followed by counter = 704 ten times, and so on up to counter = 800 ten times.· Keep in mind that the counter variable is the PULSOUT command's duration argument in the solution.
These nested loops are important.· The net effect is that it causes the servo to hold the 700 position for about 1/10 second, followed by the 710 <edit>, no, it's actually 704 </edit> position for about 1/10 of a second, and so on.·
The results will probably be more visible on the servo with this kind of subroutine (without the DEBUG command):
' Another example - 9 positions, 3/4 seconds each
·
FOR counter =·350 TO·1150 STEP 100
· FOR pulses = 1 TO 32
··· PULSOUT 14, counter
··· PAUSE 20
· NEXT
NEXT
Lots of machines are programmed with that kind of loop.· The other day on the news, I saw one of those biomedical machines that puts a drop of solution on hundreds of different test slides.· While the motors and the microcontroller's programming language are likely different, it·almost certainly still uses nested loops to advance the plate of slides to one position, stay there for a while the eye dropper does its thing, then advance to the next position, etc.
Regards, Andy
Post Edited (Andy Lindsay (Parallax)) : 10/24/2005 10:16:30 PM GMT
I've been reading it as you want the servo to advance by steps of·1, from 700 to 710 and then starting at 711 start advancing by steps of 4. Not sure I would have understood that without your help.
Thanks alot,
Tom