Programs

A. Motion Analysis

'{\$STAMP BS2}

'{\$PBASIC 2.0}

'MOTION ANALYSIS PROGRAM

'DECLARATIONS

Detect1 VAR Bit

Detect2 VAR Bit

Detect3 VAR Bit

detect4 VAR Bit

b VAR Byte

tb1 VAR Byte

tb2 VAR Byte

c VAR Byte

c1 VAR Byte

c2 VAR Byte

a VAR Byte

a1 VAR Byte

a2 VAR Byte

r7 VAR Byte

Detect1 = IN1

x1 VAR Byte

x2 VAR Byte

r1 VAR Byte

r2 VAR Byte

r3 VAR Byte

r4 VAR Byte

r5 VAR Byte

r6 VAR Byte

y VAR Byte

vel VAR Byte

v2 VAR Byte

vel2 VAR Byte

v22 VAR Byte

vel3 VAR Byte

v32 VAR Byte

'MAIN PROGRAM

Start: ' Check Gate 1 for car

LOOP :

Gate1:

Detect1 = IN5

IF Detect1 = 0 THEN Count1 'WAITS FOR CAR TO ENTER GATE 1

PAUSE 20

GOTO LOOP

'Timing loop

COUNT1: ' TIME BETWEEN GATES 1 AND 2

FOR y = 1 TO 65000 ' COUNTS TIME BETWEEN GATES

Detect2 = IN8

IF Detect2 = 0 THEN Count2

PAUSE 10

y= y+1

NEXT

Count2: ' TIME BETWEEN GATES 2 AND 3

FOR b = 1 TO 65000

Detect3 = IN15

IF Detect3 = 0 THEN Count3

PAUSE 10

b= b+1

NEXT

Count3: ' TIME BETWEEN GATES 3 AND 4

FOR c = 1 TO 65000

Detect4 = IN1

IF Detect4 = 0 THEN CalcTime

PAUSE 10

c= c+1

NEXT

CalcTime: ' CALCULATES THREE TIMES; USING MODULUS TO GET THREE DIGITS

x1=y/145

r1=y//145

x2=100*r1/145

tb1=b/145

r2=b//145

tb2=100*r2/145

c1=y/145

r3=y//145

c2=100*r3/145

CalcSpeed: ' CALCULATES THREE VELOCITIES; USING MODULUS TO GET THREE DIGITS

vel = 19*145/y

r4 = 19*145//y

v2 = 10*r3/y

vel2 = 19*145/b

r5 = 19*145//b

v22 = 10*r5/b

vel3 = 16*145/c

r6 = 16*145//c

v32 = 10*r6/c

CalcAcc:

a = ((232*y)-(277*c))/b*c*y

r7 = ((232*y)-(277*c))//b*c*y

a1 = 10*r7/b*c*y

a2 = 10*a

'DISPLAYS VALUES FOR EACH TIME AROUND ROADWAY

DEBUG "Counts1= ", DEC y, " counts2 = ", DEC b," Counts3=", DEC c,CR

DEBUG "D1 = 19 cm", " T1 = ", DEC x1,".", DEC x2, "sec", CR

DEBUG "D2 = 19 cm", " T2 = ", DEC tb1,".", DEC tb2, "sec", CR

DEBUG "D3 = 16 cm", " T3 = ", DEC c1,".", DEC c2, "sec", CR

DEBUG "V1 = ", DEC vel, ".", DEC v2, "cm/s" ,CR

DEBUG "v2 = ",DEC vel2, ".", DEC v22, "cm/s", CR

DEBUG "v3 = ",DEC vel3, ".", DEC v32, "cm/s", CR,CR

DEBUG "acc = ", DEC a2, ".", DEC a1, "cm/s/s",CR,CR

'PAUSE 2000

GOTO LOOP

END

B. Smart Road - speed control program

'{\$STAMP BS2}

'{\$PBASIC 2.5}

'DECLARATIONS

Detect1 VAR Bit

Detect2 VAR Bit

Detect1 = IN1

x1 VAR Word

x2 VAR Word

r1 VAR Byte

r2 VAR Byte

r3 VAR Byte

x3 VAR Word

y VAR Word

vel VAR Word

v2 VAR Word

w VAR Nib

z VAR Word

speed VAR Word

w = 0

z = 0

Start:

iter VAR Byte

DEBUGIN DEC speed

DEBUG ? speed

PULSOUT 12, speed

LOOP1 :

Gate1:

Detect1 = IN8

IF Detect1 = 0 THEN Count1 ' Check Gate 1 for car

PAUSE 20

GOTO LOOP1

'Timing loop

COUNT1:

FOR y = 1 TO 65000 'TIME FOR CAR TO GO FROM GATE 1 TO 2

Detect2 = IN1

IF Detect2 = 0 THEN CalcTime

PAUSE 10

y= y+1

NEXT

CalcTime: ' CALCULATES TIME BETWEEN GATES 1 AND 2

x1=y/145

r1=y//145

x2=100*r1/145

x3=100*r1//145

CalcSpeed: ' CALCULATES VELOCITY BETWEEN GATES 1 AND 2

vel = 35*145/y

r3 = 5075//y

v2 = 10*r3/y

'DISPLAYS VALUES

DEBUG "Counts = ", DEC y, CR

DEBUG "Distance = 35 cm", " Time = ", DEC x1,".", DEC x2, "sec", CR

DEBUG "Velocity = ", DEC vel, ".", DEC v2, "cm/s" ,CR,CR

IF y < 38 THEN decrease 'CHECKS TO SEE IF SPEED IS ABOVE LIMIT

z = z + 1

IF z = 10 THEN Start

GOTO LOOP1

decrease: 'LOWERS SPEED

w = w + 1

PULSOUT 12, speed - (w*20) ' PULSES SERVO MOTOR TO REDUCE SPEED

PAUSE 1000

GOTO LOOP1

END

C. Photogate Tester

'{\$STAMP BS2}
'{\$PBASIC 2.0}

'Declarations

IR_detect1 VAR Bit
IR_detect2 VAR Bit
IR_detect3 VAR Bit
IR_detect4 VAR Bit
x1 VAR Byte

LOOP:
PAUSE 50

Gate1:
IR_detect1 = IN1 'check status of gate 1
PAUSE 20

Gate2:
IR_detect2 = IN2 'check status of gate 2
PAUSE 20

Gate3:
IR_detect3 = IN3 'check status of gate 3
PAUSE 20

Gate4:
IR_detect4 = IN4 'check status of gate 4

DEBUG HOME, "Gate1 ", BIN IR_Detect1, " Gate2 ", BIN IR_Detect2, " Gate3 ", BIN IR_Detect3," Gate4 ", BIN IR_Detect4
GOTO LOOP

D. Set Speed

'{\$STAMP BS2}
'{\$PBASIC 2.5}
'Declarations
x VAR Word
OUTPUT 0 'sets pin 0 low

FOR x = 1 TO 100
PULSOUT 0, 800 'pulses servomotor

PAUSE 10
NEXT
END