Ramp coding problem
Hi guys!
I'm working my way through the BoeBot projects and have completed the whisker project.· I'm trying to modify the coding in the book to ramp up into motion and turns.· I can get all the subroutines sorted apart from the forward subroutine as it is designed to only pulse forward once before going off to check the whisker states.· I've tried adding FOR-NEXT and DO-LOOP routines but can't get it right.
Ideally I need something like:
FOR pulsecount = 1 to (somehow I'm thinking inifite here)
PULSOUT 13, 750 + pulsecount MAX 829·· '829 for max speed without arcing
PULSOUT 12, 750 - pulsecount MIN 650
PAUSE 20
NEXT
Any ideas on what I could use that would have the same effect as the rampup routine above, whilst being able to check whisker states regularly?
Any help much appreciated
Thanks!
I'm working my way through the BoeBot projects and have completed the whisker project.· I'm trying to modify the coding in the book to ramp up into motion and turns.· I can get all the subroutines sorted apart from the forward subroutine as it is designed to only pulse forward once before going off to check the whisker states.· I've tried adding FOR-NEXT and DO-LOOP routines but can't get it right.
Ideally I need something like:
FOR pulsecount = 1 to (somehow I'm thinking inifite here)
PULSOUT 13, 750 + pulsecount MAX 829·· '829 for max speed without arcing
PULSOUT 12, 750 - pulsecount MIN 650
PAUSE 20
NEXT
Any ideas on what I could use that would have the same effect as the rampup routine above, whilst being able to check whisker states regularly?
Any help much appreciated
Thanks!
Comments
Would that work?
Rich H
http://forums.parallax.com/showthread.php?p=741023
DO
IF (leftcount = 829) AND (rightcount = 650) THEN
GOSUB forwardpulse
ELSE
PULSOUT 13, leftcount
PULSOUT 12, rightcount
PAUSE 20
leftcount·= leftcount + 3 MAX 829
rightcount = rightcount - 3 MIN 650
ENDIF
Then loop then carries on to check the whiskers·
Of course, these are just suggestions (not hard and fast rules) but they help others understand your code, and you to understand it in a month.
I do comment my code alot, especially as I'm very forgetful!
Here is the code I used.· I can't find the files when I use the attachment manager, they don't show up even though I know they're there so sorry if the big post bugs you I havn't fine tuned my pause statements or ramping speeds yet either.
Also, white space in reasonable amounts is your friend. You can also add comments aligned left, instead of feeling limited to comments stuck on the right. A good program probably has both. As a personal preference, I like to put in a big multiline comment that is simply a big line, with the word SUBROUTINE, to indicate that everything afterwards is subroutines.
I'd like to compliment you on your well commented code. I work with beginning programmers every day, and they have the bad habit of choosing "a,b,c,x,y,z" for their variable names, and not commenting at all! And, they've been programming for 6 weeks now...
Now that I understand how to label the pins, it should be much easier work through coding with simplifying tricks like that.· I see what you mean about white space now, I didn't bother looking at the code once I'd pasted it in here but now that I do look I notice it's taken out a whole bunch of unused lines.· I had compressed it all down to fit 2 pages of A4 also so I could print it and hand it in as part of an assessment.
Thanks for your tips, I'll keep pottering my way through this Boe-bot book and see if I can improve on the given coding .· Gotta say I'm enjoying this stuff more than I thought I would.