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
leftcount VAR Word rightcount VAR Word pulsecount VAR Word leftcount = 750 'Initial value for stationary servo rightcount = 750 'Initial value for stationary servo DO 'Main Routine contained within this DO-LOOP IF (leftcount = 829) AND (rightcount = 650) THEN 'If Bot already moving at max speed THEN GOSUB forwardpulse 'forwardpulse to maintain speed ELSE 'If not yet at max speed then pulse each PULSOUT 13, leftcount 'servo adding 3 to the pulse count of each PULSOUT 12, rightcount 'servo. PAUSE 20 'This results in a ramped up speed for smooth leftcount = leftcount + 3 MAX 829 'acceleration. rightcount = rightcount - 3 MIN 650 'MAX and MIN values are those which maintain ENDIF 'a straight course ON a tiled surface. 'Start of sensing routine. Feeler states checked each time through the loop. IF (IN5 = 0) AND (IN7 = 0) THEN 'Both feelers contacting obstacle. HIGH 10 'HIGH outputs light LED's to visually indicate feeler contact HIGH 1 GOSUB backup 'BOT hits obstacle head on so reverses and executes a U-turn GOSUB uturn ELSEIF (IN5 = 0) THEN 'Left feeler contacted HIGH 10 'Left LED lights GOSUB backup 'Bot reverses and turns 90 degrees right to move away GOSUB turnright 'from the left hand obstacle. ELSEIF (IN7 = 0) THEN 'Right feeler contacted HIGH 1 'Right LED lights GOSUB backup 'Bot reverses and turns 90 degrees left to move away GOSUB turnleft 'from the right hand obstacle. ELSE LOW 10 'If Bot is in motion and no feelers are contacted it will LOW 1 'carry ON forward untill an obstacle is detected. ENDIF 'In the meantime no LED's are lit. LOOP 'End of main loop forwardpulse: 'Single pulse forward before returning to 'feeler state' loop PULSOUT 13, 829 PULSOUT 12, 650 PAUSE 20 RETURN turnleft: '90 degree turn left. PAUSE 200 'Pause is added before and after for accurate turn FOR pulsecount = 1 TO 65 STEP 2 'Turn is ramped to prolong servo life PULSOUT 13, 750 - pulsecount MIN 672 PULSOUT 12, 750 - pulsecount MIN 650 PAUSE 20 NEXT leftcount = 750 'Servo speed returned to zero. rightcount = 750 'Bot will ramp up forwards again PAUSE 50 RETURN '90 degree turn right. turnright: 'Pause is added before and after the manouevre to PAUSE 200 'ensure that an accurate turn is executed. FOR pulsecount = 1 TO 65 STEP 2 'Turn is ramped to prolong servo life PULSOUT 13, 750 + pulsecount MAX 829 PULSOUT 12, 750 + pulsecount MAX 850 PAUSE 20 NEXT leftcount = 750 'Servo speed returned to zero. rightcount = 750 'Bot will ramp up forwards again. PAUSE 50 RETURN 'Pause before reversing to ensure servos have stopped 'rotating. Approx 1cm to come to a standstill so BOT backup: 'still has room left before fully coming into contact PAUSE 200 'with any obstacles. FOR pulsecount = 1 TO 120 STEP 4 'Reverse is ramped to prolong servo life. PULSOUT 13, 750 - pulsecount MIN 672 PULSOUT 12, 750 + pulsecount MAX 850 PAUSE 20 NEXT leftcount = 750 'Servo speed returned to zero. rightcount = 750 'Bot will ramp up forwards again. RETURN uturn: 'Bot pauses before executing a U-Turn PAUSE 200 '(180 degrees spin) FOR pulsecount = 1 TO 100 STEP 2 'Turn is ramped to prolong servo life. PULSOUT 13, 750 - pulsecount MIN 672 PULSOUT 12, 750 - pulsecount MIN 650 PAUSE 20 NEXT leftcount = 750 'Servo speed is returned to zero. rightcount = 750 'Bot will ramp up forwards again. PAUSE 50 RETURNAlso, 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