Let's Make Robots!

2 motor, parallax board, BS2 code, Ping rangefinder on Servo... code isn't working, please help.

Here's the equipment being used:

Basic Stamp Editor

Parallax "Board Of Education" microcontroller (college project)

Ping((( Ultra Sonic Rangefinder

Servo

For some reason the code does not fully upload to the board, it gets about 25% of the way and then stops with an error.  Something about hardware communication failure.

Here is the code, perhaps you can pin point an error that we are missing.

 

' {$STAMP BS2}

' {$PBASIC 2.5}

'Controlls a two motored rover with a ping sensor mounted to a servo

 

 

Trigger CON    5

Scale   CON    $200

 

RawToIn CON 889

RawToCm CON 2257

 

IsHigh  CON 1

IsLow   CON 0

 

rawDist  VAR Word

inches   VAR Word

counter VAR Word

leftvalue VAR Word

rightvalue VAR Word

 

Ping PIN 5

 

PAUSE 4000                             '3 seconds to activate

SEROUT 14, 84, [$80, 2,2]              'sets controller in two motor mode

LOW 15                                 'reset motor controller

HIGH 15

PAUSE 100                              'motor controller startup time

FOR counter = 1 TO 10                  'Servo center

PULSOUT 1, 720

PAUSE 20

NEXT

 

'----------MAIN---------------------------------------------------------------------------------------------------------------

 

DO

 

GOSUB Get_Sonar

 

IF (inches < 8) THEN                     'when obstacle is less then 8 inches away:

SEROUT 14, 84, [$80, 0, 4, 0]            'motors stop

SEROUT 14, 84, [$80, 0, 6, 0]

PAUSE 500

GOSUB Servo_Look

 

  IF (leftvalue < rightvalue) THEN

GOSUB Turn_Right

  ELSEIF (leftvalue > rightvalue) THEN

GOSUB Turn_Left

  ELSEIF (leftvalue + rightvalue < 5) THEN

GOSUB Turn_Around

  ELSE

GOSUB Turn_Around

  ENDIF

 

ELSE

SEROUT 14, 84, [$80, 0, 4, 100]         'right motor strait

SEROUT 14, 84, [$80, 0, 6, 100]         'left motor strait

ENDIF

 

LOOP

 

'---------SUBROUTINES------------------------------------------------------------------------------------------------------

 

Get_Sonar:                             'gets sonar from strait ahead

Ping = IsLow

PULSOUT Ping, Trigger

PULSIN  Ping, IsHigh, rawDist

rawDist = rawDist */ Scale

rawDist = rawDist / 2

inches = rawDist ** RawToIn

RETURN

 

Get_Sonar_Left:                        'gets sonar from left

Ping = IsLow

PULSOUT Ping, Trigger

PULSIN  Ping, IsHigh, rawDist

rawDist = rawDist */ Scale

rawDist = rawDist / 2

leftvalue = rawDist ** RawToIn

RETURN

 

Get_Sonar_Right:                       'gets sonar from right

Ping = IsLow

PULSOUT Ping, Trigger

PULSIN  Ping, IsHigh, rawDist

rawDist = rawDist */ Scale

rawDist = rawDist / 2

rightvalue = rawDist ** RawToIn

RETURN

 

 

Servo_Look:

FOR counter = 1 TO 50                  'Servo left

PULSOUT 1, 1250

PAUSE 20

NEXT

GOSUB Get_Sonar_Left                   'get left distance

FOR counter = 1 TO 50                  'Servo right

PULSOUT 1, 300

PAUSE 20

NEXT

GOSUB Get_Sonar_Right                  'get right distance

FOR counter = 1 TO 50                  'Servo center

PULSOUT 1, 720

PAUSE 20

NEXT

RETURN

 

 

Turn_Left:

SEROUT 14, 84, [$80, 0, 4, 100]       'right motor forward

SEROUT 14, 84, [$80, 0, 7, 100]       'left motor reverse

PAUSE 2000

RETURN

 

Turn_Right:

SEROUT 14, 84, [$80, 0, 5, 100]       'right motor reverse

SEROUT 14, 84, [$80, 0, 6, 100]       'left motor forward

PAUSE 2000

RETURN

 

Turn_Around:

SEROUT 14, 84, [$80, 0, 5, 100]       'right motor reverse

SEROUT 14, 84, [$80, 0, 7, 100]       'left motor reverse

PAUSE 1000

SEROUT 14, 84, [$80, 0, 5, 100]       'right motor reverse

SEROUT 14, 84, [$80, 0, 6, 100]       'left motor forward

PAUSE 2000

RETURN

 

 

.

 

Thanks for your help!!!!!!!!!

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

The exact error code could be very helpful in determining the problem.

You might even try googling the error text if you haven't already.