literally first code ever written
tyler utman
Posts: 2
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
'
'----[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
Is this program just supposed to go forward then turn, or is it reading sensor data too?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
PG
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
PG
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
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
'----[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..