Shop OBEX P1 Docs P2 Docs Learn Events
Program looks right but doesnt work right — Parallax Forums

Program looks right but doesnt work right

ewhiting17ewhiting17 Posts: 3
edited 2011-12-12 14:08 in General Discussion
Im trying to make my robot follow a line when it has a golf ball in the back (in12) and transfer it when it runs into another robot (in10) it does everything fine but after the golf ball is dropped instead of waiting like the program says it should it just continues to drive off. I am new and do not understand why it is doing this.

here is my program. any help would be appreciated.

'
[ Brothers robot ]

' {$STAMP BS2} ' Stamp directive.
' {$PBASIC 2.5} ' PBASIC directive.
DEBUG "Program Running!"
'
[ Variables ]
counter VAR Word
pulseCount VAR Byte
'
[ Main Routine ]
FREQOUT 4,2000,3000

DO
IF (IN12 = 0) AND (IN10 = 1) THEN ' Main DO...LOOP
GOSUB Drive
ELSEIF (IN10 = 0) THEN
GOSUB Arm_Lift
ELSE
PAUSE 5
ENDIF
LOOP





'
Subroutines


Drive:

qtis VAR Nib ' qti black/white states

OUTB = 11
GOSUB Check_Qtis

SELECT qtis ' Control servo speeds/directions
CASE 00 ' Rotate right
PULSOUT 13, 650
PULSOUT 12, 650
CASE 00 ' Pivot right
PULSOUT 13, 770
PULSOUT 12, 650
CASE 00 ' Curve right
PULSOUT 13, 800
PULSOUT 12, 650
CASE 10 ' Straight ahead
PULSOUT 13, 900
PULSOUT 12, 600
CASE 10 ' Curve left
PULSOUT 13, 850
PULSOUT 12, 700
CASE 11 ' Pivot left
PULSOUT 13, 850
PULSOUT 12, 770
CASE 01 ' Rotate left
PULSOUT 13, 850
PULSOUT 12, 850
CASE 11
PULSOUT 13, 900
PULSOUT 12, 600
ENDSELECT

RETURN

Arm_Lift:
servoPin CON 14 ' Set I/O pin for servo signal


FOR counter = 1 TO 150
PULSOUT servoPin, 900
PAUSE 10
NEXT
FOR counter = 1 TO 220

PULSOUT servoPin, 1150
PAUSE 20

NEXT
RETURN

Check_Qtis:

' Result -> qtis variable. 0 means white surface, 1 means black surface.

DIRB = 11 ' P7..P4 -> output
PAUSE 0 ' Delay = 230 us
DIRB = 00 ' P7..P4 -> input
PAUSE 0 ' Delay = 230 us
' PULSOUT UnusedPin, 0 ' Delays = 208 + (Duration*2) us
qtis = INB ' Store QTI outputs in INB

RETURN

Comments

  • tobdectobdec Posts: 267
    edited 2011-12-12 12:35
    What are the states of pins 10 and 12 defined by?
  • ewhiting17ewhiting17 Posts: 3
    edited 2011-12-12 13:58
    both are activated when they = 0 and inactive when they = 1
  • ewhiting17ewhiting17 Posts: 3
    edited 2011-12-12 14:08
    they are whiskers and i checked to make sure they were reading right using an example program from the book and they work fine
Sign In or Register to comment.