The-Nevik - Software
November 1997
Stamp1 programs
Simple program to go forward while avoiding obstacles.
' {$STAMP BS1}
'Nevik1.BAS robot pgm DLB November 1997
'BasicStamp1
' D7 D6 D5 D4 D3 D2 D1 D0
' feelL_ feelR_ eyeL eyeR LMF LMB RMF RMB
' Lmotor Rmotor
SYMBOL feelL_ =PIN7 'if bumped then PIN=0
SYMBOL feelR_ =PIN6 'if bumped then PIN=0
SYMBOL eyeL =5 'Left Eye Pin
SYMBOL eyeR =4 'Right Eye Pin
SYMBOL FD =%1010 'both motors set to Forward
SYMBOL BK =%0101 'both motors set to Backward
SYMBOL RT =%1001 'Left-motor Forward, Right-motor Backward =Right Turn
SYMBOL LT =%0110 'Right-motor Forward, Left-motor Backward =Left Turn
SYMBOL FR =%1000 'Left-motor Forwards =Forwards to the Right
SYMBOL FL =%0010 'Right-motor Forwards =Forwards to the Left
SYMBOL BR =%0100 'Left-motor Backwards =Backwards to the Right
SYMBOL BL =%0001 'Right-motor Backwards =Backwards to the Left
start:
DIRS =%00001111 '15 - motor pins output, sensors input
IF FeelR_=0 THEN AvoidR
IF FeelL_=0 THEN AvoidL
PINS=FD 'nothing else to do so FD
GOTO start
AvoidR:
PINS=BK
PAUSE 100
PINS=BR
PAUSE 300
GOTO start
AvoidL:
PINS=BK
PAUSE 100
PINS=BL
PAUSE 300
GOTO start
Program to go forwards while avoiding the dark and obstacles,
' {$STAMP BS1}
DEBUG "Nevik2.BS1" ' robot pgm DLB November 1997
'BasicStamp1
'History
'-------
'26Feb08 added Yawns, bored, wiggle and wiggle2
'---------------------------------------------------------------
' D7 D6 D5 D4 D3 D2 D1 D0
' feelL_ feelR_ eyeL eyeR LMF LMB RMF RMB
' Lmotor Rmotor
SYMBOL feelL_ =PIN7 'if bumped then PIN=0
SYMBOL feelR_ =PIN6 'if bumped then PIN=0
SYMBOL eyeL =5 'Left Eye Pin
SYMBOL eyeR =4 'Right Eye Pin
'high=go '2025-12-22
'L R
'3 1 F
'2 0 B
SYMBOL stop =0 'both motors stopped
SYMBOL FD =%1010 'both motors set to Forward
SYMBOL BK =%0101 'both motors set to Backward
SYMBOL RT =%1001 'Left-motor Forward, Right-motor Backward =Right Turn
SYMBOL LT =%0110 'Right-motor Forward, Left-motor Backward =Left Turn
SYMBOL FR =%1000 'Left-motor Forwards =Forwards to the Right
SYMBOL FL =%0010 'Right-motor Forwards =Forwards to the Left
SYMBOL BR =%0100 'Left-motor Backwards =Backwards to the Right
SYMBOL BL =%0001 'Right-motor Backwards =Backwards to the Left
SYMBOL eyescale =100 'with two 0u1F in series, adjust for best range
SYMBOL eyeMinDiff =10 'minimum difference between eyes before turning,
' adjust for best performance
'
'W0 too LOW AND Nevik is very sensitive TO shadows
'B0
SYMBOL eyeRval =B1
'W1
SYMBOL eyeLval =B2
SYMBOL temp =B3
'W2
SYMBOL bored =B4 'stops Nevik getting stuck
SYMBOL Yawns =B5
'W3
'B6
'B7
'W4
'B8
'B9
'W5
SYMBOL rnd =W5
'B10
'B11
rnd =256
bored =20
start:
DIRS =%00001111 '15 - motor pins output, sensors input
Yawns =Yawns +1
IF yawns>bored THEN wiggle
IF FeelR_=0 THEN AvoidR
IF FeelL_=0 THEN AvoidL
' GOTO readeyes 'decomment to adjust eyescale
GOSUB readeyes
'find which eye is darker and turn away from shadows
temp =eyeLval
eyeLval =eyeLval +eyeMinDiff MAX 255
IF eyeLvaleyeRval THEN gRT
goFD:
PINS=FD 'nothing else to do so FD
GOTO start
AvoidR:
PINS=BK
PAUSE 200
PINS=BR
PAUSE 400
GOTO start
AvoidL:
PINS=BK
PAUSE 100
PINS=BL
PAUSE 300
GOTO start
gRT:
PINS =RT
GOTO start
gLT:
PINS =LT
GOTO start
wiggle:
DEBUG bored
RANDOM rnd
bored =B10 '/2 'random 0 - 127
yawns =0
PINS=RT
PAUSE 300
PINS=LT
PAUSE 200
IF B11<200 THEN start
wiggle2:
DEBUG "wig2 "
PINS=BK
PAUSE 300
PINS=RT
PAUSE 400
PINS=BL
PAUSE 400
PINS=LT
PAUSE 600
GOTO start
'------------------------------------------------------------------------
ReadEyes: '255=>dark, 0=>light
POT eyeR,eyescale,eyeRval
POT eyeL,eyescale,eyeLval
'decomment following lines to adjust eyescale
'DEBUG CLS,"Left ",#eyeLval," Right ",#eyeRval
'GOTO readeyes
RETURN
'------------------------------------------------------------------------
The speed of each motor is governed by the light level, the more light the faster the motors turn.
So The-Nevik moves towards bright lights and slows to a stop in the dark.
To help getting away from obstacles the distance The-Nevik moves each time round the program loop is dependent on obstacles, the more obstacles encountered the less The-Nevik travels. As well The-Nevik gets bored [SYMBOL bored =16] with just going forward towards light and every so often does a wiggle. Similarly after a while of being stuck on obstacles it does a wiggle.
' {$STAMP BS1}
'>IMPDRONE DLB 15-5-98 free 16 2025-12-22 free 24
DEBUG"ImpDrone" 'takes 2 bytes
'Controls Imperial-Drone class robot
'READ 255,B0 :DEBUG B0 '=2 255 is how much space is left - needed for old Editor
'new editor 2.2 allows check before download
'OOps!!!! Works better with motor diodes, L293E doesn't have any itself! 20-9-00
'[can't use PWM because motor-chip crashes, PWM too fast]
'[in fact motor chip really poor - don't use it again! ]
'motor control loop should be a maximum of 10ms, 20ms is a bit jerky
'History
'-------
'2025-12-22 corrected Fl,Fr,Bl,Br
'4Sep06 MotorDir and Read 255,b0 ... commented out: saves 14 bytes
'21-9-00 Avoid renamed Wriggle, avoidscale renamed wrigglescale
' in Wriggle, MAX wrigglescale, changed to & wrigglescale
' mspeed =randlo & %01110111, otherwise goes at full speed?
'20-9-00 pause 100 taken out of MoterDir
'20-9-00 Motor diodes added to mother board, error L293E not got any!
'29-11-99 sums altered again and darklevel now a named constant
'4-4-99 reading of eyes and motor speed sums altered
'-------
' D7 D6 D5 D4 D3 D2 D1 D0
' /Lbump /Rbump Leye Reye LMF LMB RMF RMB
' Lmotor Rmotor
SYMBOL eyescale =50 'with two 0u1F in series, scale 60 is OK
SYMBOL darklevel =150 'controls minimum motor speed
SYMBOL Lbump =PIN7
SYMBOL Rbump =PIN6
SYMBOL Leyepin =5 'Leye Pin
SYMBOL Reyepin =4 'Reye Pin
SYMBOL mspeed =B1 'composite of left and right speeds L*16+R
SYMBOL maxspeed =8 'speeds are 0 - 8, 0/8 - 8/8, ie off - full
SYMBOL speedscale=2'8 'indoor lighting
SYMBOL movetype =B2 'motor directions 3=Bk 2=Rt 1=Lt 0=Fd
SYMBOL Atries =B3 'AvoidTries
SYMBOL i =B4 'DoMove
SYMBOL moves =B5 'count of moves
SYMBOL Reyeval =B6
SYMBOL Leyeval =B7
SYMBOL randlo =B6
SYMBOL randhi =B7
SYMBOL randwork =W3 'B6 and B7 in W3
randwork =randwork -1 '<>0 to get it going
SYMBOL Rspeed =B8
SYMBOL Lspeed =B9
SYMBOL bumps =B10 'count number of bumps
SYMBOL somedist =B11
'movetypes
SYMBOL Fd =0
SYMBOL Rt =1
SYMBOL Lt =2
SYMBOL Bk =3
SYMBOL Fl =4
SYMBOL Fr =5
SYMBOL Bl =6
SYMBOL Br =7
SYMBOL wrigglescale =%11111 '10 without diodes
SYMBOL exploredist =20 'for somedist
SYMBOL ithurts =5 'threshold of current pain
SYMBOL bored =16 '8 without diodes, <7 locks up after a while until bumpers hit!
'count of moves after which a random move is made
'overcomes getting stuck against something with
'nothing registering on bump sensors
DIRS =%00001111
'Notes
'-----
'somedist =exploredist MIN bumps -bumps
'MIN is to prevent somedist being less than zero
'which since somedist is a byte means nearly 255
'ie 3-4 =-1 and -1 is 255-1 =254
'x MIN 3 -3 is always >=0 even if x is <3
Init:
bumps =0
moves =0
Start:
movetype =Fd
somedist =exploredist MIN bumps -bumps 'reset somedist
moves =moves +1
GOSUB ReadEyes
Lspeed =Reyeval/speedscale MAX maxspeed *16 'shift into high nibble
Rspeed =Leyeval/speedscale MAX maxspeed 'low nibble
mspeed =Lspeed +Rspeed
DEBUG CR,#$mspeed
'-- Case -------
IF bumps > ithurts OR moves > bored THEN Wriggle
IF Lbump=0 THEN AvoidL
IF Rbump=0 THEN AvoidR
'-- EndCase ----
Move:
GOSUB DoMove
GOTO Start
AvoidL:
bumps =bumps +1
movetype =Bk
GOSUB DoMove
movetype =Rt
GOTO Move
AvoidR:
bumps =bumps +1
movetype =Bk
GOSUB DoMove
movetype =Lt
GOTO Move
Wriggle:
bumps =0
RANDOM randwork
Atries =randlo & %111
'debug Atries,moves
FOR moves =0 TO Atries 're-initialises moves
somedist =randhi & wrigglescale
RANDOM randwork
mspeed =randlo & %01110111 'restrict motor speeds to 7
movetype =randhi &%111
'DEBUG cr,"avoidmove" ,#movetype
GOSUB DoMove
NEXT
GOTO Start
'------------------------------------------------------------------------
DoMove:
'GOSUB MotorDir 'not needed with motor diodes added
FOR i=0 TO somedist
GOSUB DoMotor
NEXT
RETURN
'------------------------------------------------------------------------
ReadEyes:
PINS =0
POT Reyepin,eyescale,Reyeval
POT Leyepin,eyescale,Leyeval
Reyeval =255-Reyeval MIN darklevel -darklevel
Leyeval =255-Leyeval MIN darklevel -darklevel
'DEBUG CLS,"Left ",#Leyeval," Right ",#Reyeval
'goto readeyes
RETURN
'------------------------------------------------------------------------
'MotorDir:
' PINS =PINS & %11110000 'turn off motors
' PAUSE 100 '>=40 delay otherwise driver chip crashes
' RETURN
'------------------------------------------------------------------------
DoMotor: 'D7-D4 left accum. D3-D0 right accum.
B0 =B0 & %01110111
B0 =B0 +mspeed
BRANCH movetype,(mFd,mRt,mLt,mBk,mFl,mFr,mBl,mBr)
'high=go '2025-12-22
'L R
'3 1 F
'2 0 B
mFd:
PIN1 =BIT3
PIN3 =BIT7
RETURN
mRt:
PIN0 =BIT3
PIN3 =BIT7
RETURN
mLt:
PIN1 =BIT3
PIN2 =BIT7
RETURN
mBk:
PIN0 =BIT3
PIN2 =BIT7
RETURN
mFl:
PIN1 =BIT3
RETURN
mFr:
PIN3 =BIT7
RETURN
mBl:
PIN0 =BIT3
RETURN
mBr:
PIN2 =BIT7
RETURN
'---------------- End ----------------------------------------------------