Starter Pack Page:

Packs

Wham pack      PicOne pack 1      PicOne pack 2      Wham Drag race     

Downloads

see Downloads page

Symbols

these are names for commonly used pins, data items, and numbers.

Choose the set suitable for your robot, and copy and paste the symbols into your program

ToyOta, Harvey and Alice


symbol leftsw    = pinc.0
symbol rightsw   = pinc.1
symbol leftLED   = b.2
symbol rightLED  = b.1
symbol piezo     = b.0
symbol TVremote  = c.7

symbol LMotorFWD  = b.4
symbol LMotorBACK = b.5
symbol RMotorFWD  = b.6
symbol RMotorBACK = b.7

symbol sensor      = c.2     ; readadc line sensor

BOT115

symbol sensor = C.2
symbol LeftMotorFwd = B.4
symbol LeftMotorBack = B.5

WHAM 2

  Top
symbol bswitch = pina.0 	; back switch
symbol fswitch = pinc.3 	; front switch
symbol rmotor = c.2		; right motor
symbol lmotor = c.1 		; left motor
symbol LED1 = a.1		; left LED
symbol LED2 = a.2		; middle LED
symbol LED3 = a.3		; right LED
symbol Fsensor = 12		; Front sensor (ADC) B.0
symbol Lsensor = 19		; Left sensor (ADC)  C.7
symbol Rsensor = 18		; Right sensor (ADC) C.6
symbol tvremote = C.5 

Wham starter Pack 2

Copy and paste the program below to start you off on line following. It includes code for Derivative to be added to the sensor reading.
It also includes code forTV Remote setting of EEPROM data.
- or Download here
This should give extra stability.
'StarterStarter Pack FOR WHAM 2 
'=========================================================
' 26/1/2020
'PORTS
'a.0 = Back pushbutton
'a.1 = Left LED
'a.2 = middle LED
'a.3 = right LED 3
'
'b.0 = Front sensor
'
'c.0 = Odometry input
'c.1 = Left motor PWM output
'c.2 = Right motor PWM output
'c.3 = Front pushbutton 
'c.4 = No connection
'c.5 = TV remote receiver
'c.6 = Right sensor
'c.7 = Left sensor
'
'DIRECTIVES
#picaxe 28X2
#no_table        'No data download
'
'SYMBOLS FOR INPUTS/OUTPUTS 
symbol bswitch = pina.0  'back switch
symbol fswitch = pinc.3  'front switch
symbol rmotor = c.2
symbol lmotor = c.1
symbol LED1 = a.1
symbol LED2 = a.2
symbol LED3 = a.3
symbol TVR = C.5

; symbols must use Channel numbers for readadc
symbol Fsensor = 12  ; B.0 
symbol Lsensor = 19  ; C.7
symbol Rsensor = 18  ; C.6

'SYMBOLS FOR Useful numbers
symbol stopspeed = 490   ; PWM output to stop the motors
symbol centre = 128      ; Line sensor centre reading 
symbol Kp =10      ; amount of Derivative. 

'DECLARE SYMBOLS FOR VARIABLES
symbol leftspeed  = W1
symbol rightspeed = W2
symbol value      = W3
symbol oldvalue   = W4
symbol correction = W5
symbol corrected  = W6		; Sensor reading after Derivative applied


'************************************************************************
'                        INITIALISATION
'************************************************************************
    gosub setup



; loop to await front button, displaying sensor
do
   readadc Fsensor,value   ; line sensor value
   
   if value > centre then
   	high LED2    ; middle
   else
   	low LED2
   endif
   debug			; debug takes about 500 ms!
loop  while fswitch = 1    ; loop while button not pressed

gosub ronan
low LED1,LED2,LED3

; loop controlling motor speeds from sensor
top:

do
   oldvalue = value
   readadc Fsensor,value        ; line sensor
   correction = value - oldvalue * Kp    ; extra to add because of rate of change
   corrected = value + correction

   ; check for underflow 
   if corrected > 32000 then
      corrected = 0
   endif
; *******************Your program****************************
; use "corrected" as your sensor reading,
; use "centre" as the line sensor reading for straight
; use "rightspeed" and "leftspeed" as your motorspeeds

	; this just stops the motors...
	
   ;rightspeed = stopspeed 
   ;leftspeed  = stopspeed 
   
   read  0,word leftspeed
   read  2,word rightspeed
   
   
; ***********************************************
   gosub checkspeeds  ; check speed values
   gosub setmotors       ; output speeds to motors

loop


;====================SUBROUTINES===============
checkspeeds:
if leftspeed > 32767 then 		; check for underflow
  leftspeed = 0
endif
leftspeed = leftspeed max 1023  ; limit max positive number

if rightspeed > 32767 then 		; check for underflow
  rightspeed = 0
endif
rightspeed = rightspeed max 1023  ; limit max positive number
return
;================
setmotors:
    pwmduty lmotor,leftspeed
    pwmduty rmotor,rightspeed
return
;================
setup:
    setfreq em64                'run faster
    'Configure ports B and C
    let dirsB = %11111110
    let dirsC = %00000110     '1=output, 0=input

    ' stop motors
    pwmout pwmdiv4, rmotor, 255,stopspeed   'stop right motor
    pwmout pwmdiv4, lmotor, 255,stopspeed   'stop left motor

   sertxd("Wham_starter_pack 2.bas 26/1/2020",13,10)  ' send message to Terminal window
return
;================
'************************************************************************

symbol lastbutton = B55
symbol thisbutton = B54

ronan:
  if pinc.5=0 then
    return	           	'return if TV receiver powered down
  end if
  high LED1

; fswitch - 0 on entry
  pause 2000     ; check for long press
  if  fswitch = 1  then  ; if button released in time
     return              ; then return
  endif
  high LED2
  w1 = 0
do
  irin TVR, thisbutton ' Wham!
  high LED3
  pause 1000
  low LED3
  
  select thisbutton
  case <= 9 
      if lastbutton > 9 then
        w1 = 0
      endif
      if thisbutton = 9 then
        thisbutton=0
      else
	  thisbutton = thisbutton+1 'on simulation, remove this line. on remote, include this line.
	endif
	w1 = w1 * 10  + thisbutton 'multiplies by 10 first

  case = 21 'if power button is pressed
	return   ; from ronan

  case = 16 'CHA+
	write 0,word w1
	read 0, word w2
	
  case = 17 'CHA-
	write 2,word w1
	read 2, word w3
	
  case = 18 'VOL+
	write 4,word w1
	read 4, word w4
	
  case = 19 'VOL-
	write 6,word w1
	read 6, word w5
	
  case = 20 'MUTE
	write 8,word w1
	read 8, word w6
  
   
  case = 101 '  OK , reads all values and debugs.
	read 0, word w0
	read 2, word w1
	read 4, word w2
	read 6, word w3
	read 8, word w4
	debug
	thisbutton = 101
  endselect
  
  lastbutton = thisbutton
loop



; end of program

PicOne starter Pack 1

  Top
Copy and paste the program below to start you off on very slow line following.
- or Download here
It includes code for Line following.

;PicOne Starter Pack.bas.txt
'=========================================================
' 12/1/2020
; updated for Pic One 



#rem
LEDs
====
High 4   ; Right LED on
Low  4   ; Right LED off

High 6   ; centre LED on
Low  6   ; centre LED off

High 7   ; Left LED on
Low  7   ; Left LED off

Wall sensors
============
Readadc   0,b0   ; left wall sensor
Readadc   1,b1   ; front wall sensor
Readadc   2,b2   ; right sensor
*sensor gets number between 0 and 255 depending on its distance from object sensed.

Line sensor
===========
Readadc   3,b3   ; line (...) sensor

Reverse right motor
==============
high 1     ; reverses right motor relay. 
It can only reverse the right motor meaning you can only spin right. 
If you do high 1 then the right motor will go backwards at the speed you programmed. 
If you do low 1 then it puts the right wheel back to going forward.

Read wall Sensors:
==================
high portc 5    ; turns on Infra red illumination
readadc 0,b0 
readadc 1,b1 
readadc 2,b2 
low portc 5  ; turns off Infra red illumination

Motors:
=======
low  portc 1	;right motor off
high portc 2 	;left motor on

pwmout 1,255,1023 ; right_motor full speed
pwmout 1,255,512  ; right_motor half speed
pwmout 1,255,0    ; right_motor stop

pwmout 2,255,1023 ; left full speed
pwmout 2,255,512  ; left half speed
pwmout 2,255,0    ; left stop


pwmout 2,255,left_motor



Push buttons:
=============
if pin6=0 then    ; if start button pressed
do while pin6 =1  : loop  ; wait for start button

Wheel Sensors:
do while pin0 =1  : loop    ; wait for left wheel counter 
  
do while pin3 =1  : loop    ; wait for right wheel counter 
 


; TV remote

irin c.7,b0   ; wait for TV remote key


#endrem


'
'DIRECTIVES
#picaxe 28X1
#no_table        'No data download
'
'SYMBOLS FOR INPUTS/OUTPUTS 
symbol startbutton = pin6  'start button
symbol rmotor = 1
symbol lmotor = 2
symbol LED1 = 7   ; left LED
symbol LED2 = 6   ; centre LED
symbol LED3 = 4   ; right LED

; symbols must use Channel numbers for readadc
symbol Fsensor = 3  ; A.3 

'SYMBOLS FOR Useful numbers
symbol stopspeed = 0   ; PWM output to stop the motors
symbol centre = 128    ; Line sensor centre reading 
symbol Kp =10          ; amount of Derivative. 

'DECLARE SYMBOLS FOR VARIABLES
symbol leftspeed  = W1
symbol rightspeed = W2
symbol value      = W3
symbol oldvalue   = W4
symbol correction = W5
symbol corrected  = W6		; Sensor reading after Derivative applied


symbol leftish = 80
symbol rightish = 160


'************************************************************************
'                        INITIALISATION
'************************************************************************
    gosub setup



; loop to await front button, displaying sensor
do
   readadc Fsensor,value   ; line sensor value
   
   if value > centre then
   	high LED2    ; middle
   else
   	low LED2
   endif
   debug			; debug takes about 500 ms!
loop  while startbutton = 1    ; loop while button not pressed



; loop controlling motor speeds from sensor
top:

do
   oldvalue = value
   readadc Fsensor,value        ; line sensor
   correction = value - oldvalue * Kp    ; extra to add because of rate of change
   corrected = value + correction

   ; check for underflow 
   if corrected > 32000 then
      corrected = 0
   endif
; *******************Your program****************************
; use "corrected" as your sensor reading,
; use "centre" as the line sensor reading for straight
; use "rightspeed" and "leftspeed" as your motorspeeds

   if corrected > rightish then
       high LED3
       low LED1,LED2
       rightspeed = stopspeed +500
       leftspeed  = stopspeed 
   else 
       if  corrected > leftish then
           high LED2
           low LED1,LED3
           rightspeed = stopspeed +500
           leftspeed  = stopspeed +500
       else
           high LED1
           low LED2,LED3
           rightspeed = stopspeed 
           leftspeed  = stopspeed +500 
        endif
    endif

	; this just stops the motors...
  ; rightspeed = stopspeed 
  ; leftspeed  = stopspeed 
; ***********************************************
   gosub checkspeeds  ; check speed values
   gosub setmotors       ; output speeds to motors

loop


;====================SUBROUTINES===============
checkspeeds:
if leftspeed > 32767 then 		; check for underflow
  leftspeed = 0
endif
leftspeed = leftspeed max 1023  ; limit max positive number

if rightspeed > 32767 then 		; check for underflow
  rightspeed = 0
endif
rightspeed = rightspeed max 1023  ; limit max positive number
return

setmotors:
Pwmout 1 ,255,rightspeed 
Pwmout 2 ,255,leftspeed

return

setup:
    setfreq m8                'run faster
   
    ' stop motors
    Pwmout 1 ,255,0 
    Pwmout 2 ,255,0

    sertxd("PicOne Starter Pack.bas.txt",13,10)  ' send message to Terminal window
return



; end of program

PicOne starter Pack 2

  Top
Copy and paste the program below to start you off on maze solving. It includes code for sensing walls and wheel counting.
It also includes code for TV Remote setting of EEPROM data.
- or Download here
This lets you test motor speeds and wheel counters and wall sensors.
;PicOne Starter Pack 2.bas
'=========================
' 27/1/2020
; updated for Pic One 
; wheel counters


#rem
EXAMPLES OF CODE
LEDs
====
High 4   ; Right LED on
Low  4   ; Right LED off

High 6   ; centre LED on
Low  6   ; centre LED off

High 7   ; Left LED on
Low  7   ; Left LED off

Wall sensors
============
Readadc   0,b0   ; left wall sensor
Readadc   1,b1   ; front wall sensor
Readadc   2,b2   ; right sensor
*sensor gets number between 0 and 255 depending on its distance from object sensed.

Line sensor
===========
Readadc   3,b3   ; line (...) sensor

Reverse right motor
==============
high 1     ; reverses right motor relay. 
It can only reverse the right motor meaning you can only spin right. 
If you do high 1 then the right motor will go backwards at the speed you programmed. 
If you do low 1 then it puts the right wheel back to going forward.

Read wall Sensors:
==================
high portc 5    ; turns on Infra red illumination
readadc 0,b0 
readadc 1,b1 
readadc 2,b2 
low portc 5  ; turns off Infra red illumination

Motors:
=======
low  portc 1	;right motor off
high portc 2 	;left motor on

pwmout 1,255,1023 ; right_motor full speed
pwmout 1,255,512  ; right_motor half speed
pwmout 1,255,0    ; right_motor stop

pwmout 2,255,1023 ; left full speed
pwmout 2,255,512  ; left half speed
pwmout 2,255,0    ; left stop


pwmout 2,255,left_motor



Push buttons:
=============
if pin6=0 then    ; if start button pressed
do while pin6 =1  : loop  ; wait for start button

Wheel Sensors:
do while pin0 =1  : loop    ; wait for left wheel counter 
  
do while pin3 =1  : loop    ; wait for right wheel counter 
 


; TV remote

irin c.7,b0   ; wait for TV remote key

END OF EXAMPLES
#endrem


'
'DIRECTIVES
#picaxe 28X1
#no_table        'No data download
'
'SYMBOLS FOR INPUTS/OUTPUTS 
symbol startbutton = pin6  'start button
symbol rmotor = 1
symbol lmotor = 2
symbol LED1 = 7   ; left LED
symbol LED2 = 6   ; centre LED
symbol LED3 = 4   ; right LED
symbol Lwheel = pin0 ' left wheel state
symbol Rwheel = pin3 ' right wheel state
symbol TVR  = 7      ; c.7 TV remote


; symbols must use Channel numbers for readadc
symbol Fsensor = 3  ; A.3 

'SYMBOLS FOR Useful numbers
symbol stopspeed = 0   ; PWM output to stop the motors
symbol centre = 128    ; Line sensor centre reading 
symbol Kp =10          ; amount of Derivative. 

symbol leftish = 80
symbol rightish = 160


'DECLARE SYMBOLS FOR VARIABLES
symbol leftvalue = b0    ; left wall sensor
symbol frontvalue = b1   ; front wall sensor
symbol rightvalue = b2   ; right wall sensor



symbol leftspeed  = W4
symbol rightspeed = W5
symbol value      = W6
symbol oldvalue   = W7
symbol correction = W8
symbol corrected  = W9		; Sensor reading after Derivative applied

symbol left_count  = b24
symbol right_count = b25
symbol Lwheelstate = b26
symbol Rwheelstate = b27

symbol lastbutton = B26
symbol thisbutton = B27

'************************************************************************
'                        INITIALISATION
'************************************************************************
    gosub setup

; loop to await start button, displaying sensor
do
   gosub wallsensors
   
   if leftvalue > 43 then
   	high LED1    ; left
   else
   	low LED1
   endif

   if b1 > 5 then
   	high LED2   ; middle
   else
   	low LED2   endif

   if b2 > 5 then
   	high LED3    ; right
   else
   	low LED3
   endif
   debug			; debug takes about 500 ms!
loop  while startbutton = 1    ; loop while button not pressed

gosub ronan

; loop counting wheel sensors
top:


    Lwheelstate = 0
    Rwheelstate = 0
    read 0,word leftspeed ;  = 200 
    read 2,word rightspeed   ;=  200 
    read 4,word W0
    left_count = W0          ; set with Vol +
    right_count =  0
   
do
 
; *******************Your program****************************

   gosub  Count_Right
   gosub  Count_Left
   
   if left_count >200  then
     rightspeed = 0 
     leftspeed  = 0 
   endif
   
   ; ***********************************************
   gosub checkspeeds  ; check speed values
   gosub setmotors       ; output speeds to motors

loop


;====================SUBROUTINES===============
checkspeeds:
if leftspeed > 32767 then 		; check for underflow
  leftspeed = 0
endif
leftspeed = leftspeed max 1023  ; limit max positive number

if rightspeed > 32767 then 		; check for underflow
  rightspeed = 0
endif
rightspeed = rightspeed max 1023  ; limit max positive number
return

;=================
setmotors:
Pwmout 1 ,255,rightspeed 
Pwmout 2 ,255,leftspeed

return

;=================
setup:
    setfreq m8                'run faster
   
    ' stop motors
    Pwmout 1 ,255,0 
    Pwmout 2 ,255,0

    sertxd("PicOne Starter Pack 2 counts displ.bas.txt",13,10)  ' send message to Terminal window
return

;==============
Count_Left:
    if pin0 = 1 then
      high 7
     if Lwheelstate =1 then
      return
     endif
      Lwheelstate =1
     
    else
      low 7
      if Lwheelstate =0 then
        return
      endif
        Lwheelstate =0
        inc left_count
    endif
return
;==============
Count_Right:    
    if pin3 = 1 then
      high 4
     if Rwheelstate =1 then
      return
     endif
      Rwheelstate =1
     
    else
      low 4
      if Rwheelstate =0 then
        return
      endif
        Rwheelstate =0
        inc right_count
    endif
return
;=====================


ronan:
  if pinc.7=0 then
    return	           	'return if TV receiver powered down
  end if
  high LED1

; startbutton - 0 on entry
  pause 1000     ; check for long press
  if  startbutton = 1  then  ; if button released in time
     return              ; then return
  endif
  high LED2
  w1 = 0
do
  irin TVR, thisbutton ' Wham!
  high LED3
  pause 1000
  low LED3
  
  select thisbutton
  case <= 9 
      if lastbutton > 9 then
        w1 = 0
      endif
      if thisbutton = 9 then
        thisbutton=0
      else
	  thisbutton = thisbutton+1 'on simulation, remove this line. on remote, include this line.
	endif
	w1 = w1 * 10  + thisbutton 'multiplies by 10 first

  case = 21 'if power button is pressed
	return   ; from ronan

  case = 16 'CHA+
	write 0,word w1
	read 0, word w2
	
  case = 17 'CHA-
	write 2,word w1
	read 2, word w3
	
  case = 18 'VOL+
	write 4,word w1
	read 4, word w4
	
  case = 19 'VOL-
	write 6,word w1
	read 6, word w5
	
  case = 20 'MUTE
	write 8,word w1
	read 8, word w6
  
   
  case = 101 '  OK , reads all values and debugs.
	read 0, word w0
	read 2, word w1
	read 4, word w2
	read 6, word w3
	read 8, word w4
	debug
	thisbutton = 101
  endselect
  
  lastbutton = thisbutton
loop

wallsensors:
   high portc 5			'IR leds on
   readadc  0,leftvalue		'read left wall sensor
   readadc  1,frontvalue	'read front wall sensor
   readadc  2,rightvalue	'read right wall sensor
   low portc 5			'IR leds off
   
return


; end of program

Wham Drag race starter

  Top
The program below is the program for drag racing.   It uses an "include file" for the complicated stuff.
Wham drag race starter pack Download
Wham drag race include file Download

Note: the downloaded file name must be changed to get it to work with the Picaxe Editor -
You must remove the
".txt" at the end

Wham drag race Student tasks


;Wham Drag race starter pack 8/2/2020.
#include "Drag_race_include_V2.basinc"  ; needed for all the symbols and subroutines

myprog:
#rem
 see the seperate file  "Student Drag Race Tasks.txt" for 
 student tasks to be done using this starter pack.
 This program will need changing for sensor start operation
 Data W0 - W8 are used by the Include file
#endrem

symbol Dist = W10
gosub setup			    ; needed at switch-on switches motors off

high LED1			    ; Left hand LED ON
low  LED2,LED3		    ; other LEDs OFF


; loop to await front button, displaying sensor reading
do
   readadc Fsensor,value   ; line sensor value
   
   if value > 140 then
   	high LED3    ; right
	low LED1,LED2
   else
	if  value > 80 then
   	   high LED2    ; middle
	   low LED1,LED3
      else
   	   high LED1   ; left
	   low LED2,LED3
	endif
   endif

   readadc Rsensor,rvalue  ; paper sensor
   if rvalue >10 then      ; if paper detected
	high LED1,LED2,LED3
      gosub wait4paper	   ; wait till paper goes away
      ;goto race           ; start race when paper goes away
   endif

   W9 = timer              ; display timer in W9
   debug			       ; debug takes about 500 ms!
loop  while fswitch = 1    ; loop while front button is not pressed

gosub ronan  ; input from TV remote on long press
race:

;read tuning variables from EEPROM
read CHPLUS   , word speed  ; read speed from EEPROM 
read CHMINUS  , word Kp     ; read Kp from EEPROM 
read VolPLUS  , word Kd     ; read Kd from EEPROM
read VolMINUS , word Dist   ; read distance from EEPROM
;debug
timer = 0                   ; set distance doen track = 0

do
   pause 10
   readadc Fsensor,value   ; line sensor value
   gosub MotorMaths        ; calculate left and right speeds from sensor value
   ;debug
   gosub setmotors         ; check, then set motor speeds
   
   ; check for end of track....
   if timer > Dist then
	   speed = stopspeed
   endif
   ; check for "start again" on back button
  if  bswitch = 0 then myprog
loop



© Copyright St Albans Robots