Why doesn't the STEP command work? Why can't I take larger steps?
wperko
Posts: 66
Hi,
I'm trying to setup some smarter routines for the D.A.I.R. Kit ()
But I'm having some problems ... Using PBASIC v2.2.5 I can't seem to get the FOR/NEXT STEP command to work ...
I can add as in the commented alternate method of stepping a FOR/NEXT statement but can't seem to use the STEP itself.
Another problem is even using the additive line it won't let me step more than 1 and I want the step to be variable too.
' DAIR-ServoTests.BS2
'Test the servo at three different position signals.
'{$STAMP BS2}
'{$PBASIC 2.5}
' Declare Variables
i VAR Word
waist CON 0
waistmove VAR Word
waistlimit VAR Word
waiststep VAR Byte
' Initialize Variables
i = 0
waistmove = 200 ' HX12K 375 = Full Right 900 = Center 1100 = Full Left
' Futaba Std 200 = Full Right 850 = Center 1150 = Full Left
waistlimit = 1150 ' Goto Position
waiststep = 1 ' Determines Speed of Motion
' Main Body
GOSUB init
GOSUB WaistMotor
END
init:
FOR i = 0 TO 20
PULSOUT waist, waistmove
PAUSE 20
NEXT
RETURN
WaistMotor:
FOR i = waistmove TO waistlimit STEP waiststep
'waistmove = waistmove + waiststep
PULSOUT waist, waistmove
PAUSE 20
NEXT
RETURN
END
Here is the smooth programming I'm using now ... but I want to make it easier for end users to program the robot for their own functions;
http://www.youtube.com/watch?v=8WDjUoqKQaE
Print yourself a D.A.I.R.: http://www.brainless.org/DAIR-Kit.html
I'm trying to setup some smarter routines for the D.A.I.R. Kit ()
But I'm having some problems ... Using PBASIC v2.2.5 I can't seem to get the FOR/NEXT STEP command to work ...
I can add as in the commented alternate method of stepping a FOR/NEXT statement but can't seem to use the STEP itself.
Another problem is even using the additive line it won't let me step more than 1 and I want the step to be variable too.
' DAIR-ServoTests.BS2
'Test the servo at three different position signals.
'{$STAMP BS2}
'{$PBASIC 2.5}
' Declare Variables
i VAR Word
waist CON 0
waistmove VAR Word
waistlimit VAR Word
waiststep VAR Byte
' Initialize Variables
i = 0
waistmove = 200 ' HX12K 375 = Full Right 900 = Center 1100 = Full Left
' Futaba Std 200 = Full Right 850 = Center 1150 = Full Left
waistlimit = 1150 ' Goto Position
waiststep = 1 ' Determines Speed of Motion
' Main Body
GOSUB init
GOSUB WaistMotor
END
init:
FOR i = 0 TO 20
PULSOUT waist, waistmove
PAUSE 20
NEXT
RETURN
WaistMotor:
FOR i = waistmove TO waistlimit STEP waiststep
'waistmove = waistmove + waiststep
PULSOUT waist, waistmove
PAUSE 20
NEXT
RETURN
END
Here is the smooth programming I'm using now ... but I want to make it easier for end users to program the robot for their own functions;
http://www.youtube.com/watch?v=8WDjUoqKQaE
Print yourself a D.A.I.R.: http://www.brainless.org/DAIR-Kit.html
Comments
Okay, if the FOR/NEXT/STEP doesn't work ... why can't I increment greater than 1 with the statement; waistmove = waistmove + waiststep
I've tried it at different locations around the FOR/NEXT statement ... If I initialize waiststep = 2 or greater the servo only moves to the starting location and doesn't move again.
WaistMotor:
FOR i = waistmove TO waistlimit 'STEP waiststep
PULSOUT waist, waistmove
PAUSE 20
waistmove = waistmove + waiststep
NEXT
RETURN
You could do the following if you want, but it can be a bit confusing since the behavior of the FOR statement depends on how it's implemented. Some compilers grab all the values first and save them away (the initial value, limit value, and step value), then figure out what to do with them. Other compilers re-evaluate everything each time through the loop. By using the loop variable in the other expressions, you can get different behavior with different compilers. In the case of the Stamps, there's only one compiler and it re-evaluates it all for each loop.
Thanks ... I guess I didn't look close enough the first time ... one of the hazards of aged eyes ... and brain farts ...
Next I need an end-user to create a Microsoft Robot Studio program for the D.A.I.R. ... that might be the best final solution for end-users ... and even my own demos.
So much stuff to do and so little time ...
Thanks again for the help!