Greetings!
I am working on a bot with a parallax bs2 homework board, a sabertooth 2x5, and a tritrack chassis. The problem that I am having, is that when I send a pulsout command of 750 to my controller for each motor it does not stop. I have my dip switches set for a micro according to the printout. It will turn just fine using pivot steering, but when I need the bot to stop to take some measurements, it does not.
Here is the code for reference.
'{$stamp BS2}
'{$Pbasic 2.5}
'Lynxmotion Bot
'Written by Jason Smith 25Feb09
’
’
'------Variables----------------------------------------------------------------------------------------------------------
Right PIN 14 'Variable for right motor controller
Left PIN 15 'Variable for left motor controller
Hturret PIN 01 'Variable for Horizontle Turret movement
Vturret PIN 12 'Variable for verticle turret movement
Ping PIN 00 'Variable for Ping sensor
counter VAR Byte 'Variable for counter
Time VAR Word 'Variable for time
Time1 VAR Byte 'Variable for time1
Time2 VAR Byte 'Variable for time2
'------Initialize---------------------------------------------------------------------------------------------------------
PAUSE 5000 'Wait 5 sec before starting
'------Main Program-------------------------------------------------------------------------------------------------------
Main:
GOSUB radar 'check distance
IF time > 1000 THEN GOSUB Forward 'if distance is clear go Foward
IF time <= 1000 THEN GOSUB turret_scan 'if object is detected then scan for clear path
IF time1 > time2 THEN GOSUB turn_left 'if time1 is greater than time2 then turn left
IF time2 > time1 THEN GOSUB turn_right 'if time2 is greater than time1 then turn right
GOTO Main
'------Sub-Routines-------------------------------------------------------------------------------------------------------
Forward:
DO WHILE Time > 1000 'keep moving until Ping senses something in the way
GOSUB radar 'run radar subroutine
IF Time <= 1000 THEN GOTO Main 'keep checking distance while moving foward
PULSOUT right, 400
PULSOUT left, 400 'Go forward
LOOP
Back_Up:
FOR counter = 1 TO 20
GOSUB radar
IF time > 700 THEN GOTO Main 'return to main if time is right
PULSOUT right, 800
PULSOUT left, 500 'Back up
PAUSE 18
NEXT
RETURN
Turn_Right:
DO UNTIL time > 1000 'keep moving for 130 pulses
GOSUB radar
IF Time > 1000 THEN GOTO Main 'keep checking distance while turning
PULSOUT right, 740
PULSOUT left, 800 'Turn right
PAUSE 18
LOOP
RETURN
Turn_Left:
FOR counter = 1 TO 130 'keep moving for 130 pulses
GOSUB radar
IF Time > 1000 THEN GOTO Main 'keep checking distance while turning
PULSOUT right, 800
PULSOUT left, 740 'Turn left
PAUSE 18
NEXT
RETURN
Turret_Scan:
PULSOUT right, 750
PULSOUT left, 750
FOR counter = 1 TO 120
PULSOUT hturret, 800
NEXT
GOSUB time_1
PAUSE 1500
FOR counter = 1 TO 230
PULSOUT hturret, 450
NEXT
GOSUB time_2
PAUSE 1500
FOR counter = 1 TO 51
PULSOUT hturret, 825
NEXT
RETURN
Radar:
PULSOUT ping, 5
PULSIN ping, 1, time
RETURN
Time_1:
PULSOUT ping, 5
PULSIN ping, 1, time1
RETURN
Time_2:
PULSOUT ping, 5
PULSIN ping, 1, time2
RETURN [/list]