Shop OBEX P1 Docs P2 Docs Learn Events
Why doesn't the STEP command work? Why can't I take larger steps? — Parallax Forums

Why doesn't the STEP command work? Why can't I take larger steps?

wperkowperko Posts: 66
edited 2013-08-06 21:59 in BASIC Stamp
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

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2013-08-06 12:43
    FOR/STEP/NEXT does work properly. Do you want to write "PULSOUT waist, i"?
  • wperkowperko Posts: 66
    edited 2013-08-06 13:03
    Hi,

    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
  • Mike GreenMike Green Posts: 23,101
    edited 2013-08-06 13:20
    Again I say ...don't you want to put "PULSOUT waist, i" like this?
    WaistMotor:
    FOR i = waistmove TO waistlimit STEP waiststep
    PULSOUT waist, i
    PAUSE 20
    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.
    WaistMotor:
    FOR waistmove = waistmove TO waistlimit STEP waiststep
    PULSOUT wait, waistmove
    PAUSE 20
    NEXT
    RETURN
    
  • wperkowperko Posts: 66
    edited 2013-08-06 13:29
    Hi,

    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!
  • NWCCTVNWCCTV Posts: 3,629
    edited 2013-08-06 21:59
    Next I need an end-user to create a Microsoft Robot Studio program for the D.A.I.R.
    So will you be using the Stamp in conjunction with MSRS?
Sign In or Register to comment.