Shop OBEX P1 Docs P2 Docs Learn Events
literally first code ever written — Parallax Forums

literally first code ever written

tyler utmantyler utman Posts: 2
edited 2009-03-22 15:23 in Robotics
So yeah the name basically says it all.· Mainly I'm just looking at basic movement, without the robot. AM i going in the right direction·atleast for starters.
'----[noparse][[/noparse] Title ]
' Basic commands of said bot, hopefully it works
' {$STAMP BS2p}
' {$PBASIC 2.0}
'
[noparse][[/noparse] I/O Definitions ]
'
ServoLeft·· PIN 13······· ' Left Servo connected to P13
ServoRight· PIN 12······· ' Right Servo connected to p12
'
[noparse][[/noparse] Constants ]
'
LowTime CON 20
'
'
[noparse][[/noparse] Variables ]
'
counter VAR Byte
'
[noparse][[/noparse] EEPROM Data ]
'
RunStatus DATA 0
'
[noparse][[/noparse] Initialization ]
'
DEBUG CLS
READ Runstatus, temp
temp = ~temp
WRITE Runstatus, temp
IF· (temp > 0) THEN
· DEBUG "Press/release Reset..."
·· END
·· ENDIF
DEBUG "Main Program running...", CR
'
[noparse][[/noparse] Main Code ]
'
FOR counter = 1 TO 100
· PULSOUT ServoLeft,· 850
· PULSOUT servoRight, 650
· PAUSE 20
Next
· PULSOUT ServoLeft, 715
FOR counter = 1 TO 100
· PULSOUT ServoLeft,· 850
· PULSOUT servoRight, 650
· PAUSE 5
NEXT
· PULSOUT ServoRight, 650
' move forward turn left move forward, turn right

'

Comments

  • P!-RoP!-Ro Posts: 1,189
    edited 2009-03-19 01:41
    I feel that either you are missing part of your code, or you copied a ton of it unnecessarily, confusing me. If you could tell me what is going on this would help.

    Is this program just supposed to go forward then turn, or is it reading sensor data too?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    PG
  • P!-RoP!-Ro Posts: 1,189
    edited 2009-03-19 01:45
    Also, I just noticed you are using a BS2p, which means the regular values 850 and 650 won't work like they do on the BS2.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    PG
  • tyler utmantyler utman Posts: 2
    edited 2009-03-19 01:45
    Well For now yes just the turning and moving part, reading sensor data should be learned within the next couple days. Pretty much what im asking is the script looking correct?
  • P!-RoP!-Ro Posts: 1,189
    edited 2009-03-19 02:05
    Your pulse values are wrong for the BS2p and one of your pauses is 5 instead of 20. To help you out a little I found some code on the Parallax website for you.

    Temp VAR Word 'Work space for FOR NEXT
    Servo_pin CON 0 'I/O pin that is connected to servo
    for temp = 0 to 200
    pulsout Servo_pin,1875
    pause 20
    next
    for temp = 0 to 200
    pulsout Servo_pin,2250
    pause 20
    next
    for temp = 0 to 200
    pulsout Servo_pin,1500
    pause 20
    next
    STOP

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    PG
  • SRLMSRLM Posts: 5,045
    edited 2009-03-19 03:45
    From a code cleanliness standpoint, whitespace is a nice addition to most projects. Also, you never use the LowTime constant, so you don't need it.
  • JDJD Posts: 570
    edited 2009-03-20 16:32
    tyler utman

    In addition to Pi Guy's help, here is the range that you would use for the servo control on the BS2p24.

    1.0·ms = 1250 = Full Speed Clockwise Rotation

    1.5·ms = 1875 = Stopped

    2.0 ms = 2500 = Full Speed Counter Clockwise Rotation

    There is a full explaination of·how these values are calculated·in the BASIC Stamp Syntax & Reference Manual under PULSOUT, available at the links below. Anyone will tell you, this book is a must have when programming the BASIC Stamp.

    ______________________________________________________________________________

    BASIC Stamp Syntax & Reference Manual [noparse][[/noparse] hard copy ]:
    http://www.parallax.com/Store/Books/BASICStamp/tabid/168/CategoryID/42/List/0/Level/a/ProductID/143/Default.aspx?SortField=ProductName%2cProductName

    BASIC Stamp Syntax & Reference Manual [noparse][[/noparse] soft copy ]:
    http://www.parallax.com/Portals/0/Downloads/docs/prod/stamps/web-BSM-v2.2.pdf

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Respectfully,


    Joshua Donelson
    www.parallax.com
  • GWJaxGWJax Posts: 267
    edited 2009-03-22 15:23
    I've noticed that you are using a BS2P and trying to run it under Version 2.0 this will not work you need Version 2.5 also you did not make a Variable out of the temp and a syntax code will appear when you try to run your program. Listed below is a small mod to your code that you provided. Hope this helps you out a bit.

    '----[noparse][[/noparse] Title ]
    ' Basic commands of said bot, hopefully it works
    ' {$STAMP BS2p}
    ' {$PBASIC 2.5}
    '
    [noparse][[/noparse] I/O Definitions ]

    ServoLeft PIN 13 ' Left Servo connected to P13
    ServoRight PIN 12 ' Right Servo connected to p12

    '
    [noparse][[/noparse] Constants ]
    CW CON 1250
    CCW CON 2500
    MotorStop CON 1875
    '
    [noparse][[/noparse] Variables ]

    temp VAR Word
    counter VAR Byte
    '
    [noparse][[/noparse] EEPROM Data ]
    '
    RunStatus DATA 0
    '
    [noparse][[/noparse] Initialization ]
    '
    DEBUG CLS

    READ Runstatus, temp
    temp = ~temp
    WRITE Runstatus, temp
    IF (temp > 0) THEN
    DEBUG "Press/release Reset..."
    END
    ENDIF

    DEBUG "Main Program running...", CR

    '
    [noparse][[/noparse] Main Code ]

    Main:
    ' Enter your main routine here
    ' ENTER YOUR GOSUB ROUTINES HERE TO ACCESS THE SUBROUTINES

    GOTO Main ' return to the start of the routine

    TurnLeft:
    ' Enter your Left Turn routine here

    TurnRight:
    ' Enter your Right Turn routine here

    Forward:
    ' Enter your Forward routine here

    FOR counter = 1 TO 100 'Move forward 100 pulses
    PULSOUT ServoLeft, CCW
    PULSOUT servoRight, CW
    PAUSE 5
    NEXT

    RETURN


    ' move forward turn left move forward, turn right
    ' THIS ROUTINE CAN BE ADDED IN THE MAIN ROUTINE OR ADDED AS A SUBROUTINE CALLED
    ' BY THE MAIN ROUTINE IF CONDITIONS ARE RIGHT!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    If a robot has a screw then it must be romoved and hacked into..
Sign In or Register to comment.