Category: Cruiser Micromouse

Cruiser Micromouse

I made this project a few years ago with some classmates in school.

The school bought the chassis and the pcbs of the cruiser micromouse. Our assignment was to write the code ourselves. The function of this robot is to run through a maze.

 

To test the cars we made a circuit. This is made so 1 side is a maze and the other side is a line for a line following robot.

 

Video of the cruiser in action:

 

Code (Bascom):

'*************************************************
'* Cruiser micromouse                            *
'* Stijn Coenen, Rob Thomas, Stijn van Roy       *
'* 3ELO2                                         *
'*************************************************
$regfile = "m8def.dat"
'Aangeven dat het intern kristal 
'op 8MHz is ingesteld
$crystal = 8000000
'**********************************
'In en uitgangen instellen
Config Portd.0 = Output
Config Portd.1 = Output
Config Portd.2 = Output
Config Portd.3 = Input
Config Portd.4 = Input
Config Portd.5 = Output
Config Portd.6 = Output
Config Portd.7 = Output
Config Portc.6 = Input
Config PORTB = Output
'**********************************
'In en uitgangen declareren
Led0 Alias Portd.0
Led1 Alias Portd.1
Led2 Alias Portd.2
Selectt Alias Portd.3
Modee Alias Portd.4
Sensor0 Alias Portd.5
Sensor1 Alias Portd.6
Sensor2 Alias Portd.7
Resett Alias Portc.6
Motor_en Alias PORTB.0
L_motor Alias PORTB.1
R_motor Alias PORTB.2
Led3 Alias PORTB.3
Led4 Alias PORTB.4
Led5 Alias PORTB.5
Buzzer Alias PORTB.6
'**********************************
'Byte's declareren
Dim Temp_register As Long
Dim Rechts_achter As Bit
Dim Rechts As Bit
Dim Rechts_voor As Bit
Dim Links_voor As Bit
Dim Links As Bit
Dim Links_achter As Bit
Dim I As Byte
Dim Led_bit As Bit
Dim Vanvoor As Bit
Dim Motorwaarde As Byte
Dim Muurbit As Bit
Dim Teller As Byte
'***********************************
'Analoge ingang instellen
Config Adc = Single , Prescaler = Auto
Start Adc
'***********************************
'Timer0 instellen (Voor de IR leds aan te sturen)
Config Timer0 = Timer , Prescale = 64 , Reference = External
'Prescaled kloksnelheid: 8000000 / 64 = 125 Khz
  'Waarde die in timer0 wordt gezet bij een     
  overflow
  Const Preload = 248
  '************************************
  'Interrupt's aanzetten
  Enable Interrupts
  Enable Timer0
  On Timer0 Interupt_label
  '************************************
  'Subroutines
    'Subroutines skippen bij opstarten programma
     GoTo Overint
     Interupt_label:
      'IR leds van de sensoren aansturen
      If Led_bit = 0 Then
         Sensor0 = 1
         Sensor1 = 1
         Sensor2 = 1
         Led_bit = 1
      Else
         Sensor0 = 0
         Sensor1 = 0
         Sensor2 = 0
         Led_bit = 0
      End If
      'De preload waarde terug in Timer0 zetten
      Timer0 = Preload
      'Motor PWM
      Incr Motorwaarde
      If Motorwaarde < 32 Then
         Motor_en = 1
      Else
         Motor_en = 0
         If Motorwaarde = 64 Then
            Motorwaarde = 0
         End If
      End If
   Return
   '*******************************************
   Buzzer_aanst:
      For I = 0 To 100
         Buzzer = 1
         Waitus 100
         Buzzer = 0
         Waitms 1
      Next
   Return
   '**********************************************
   'Analoge ingangen inlezen en omzetten naar bits
   Analoog_in:
      Start Adc
      Temp_register = Getadc(5)
      If Temp_register > 40 Then
         Rechts_achter = 1
         Led5 = 0
      Else
         Rechts_achter = 0
         Led5 = 1
      End If
      Temp_register = Getadc(4)
         If Temp_register > 60 Then
         Rechts = 1
         Led4 =  
      Else
         Rechts = 0
         Led4 = 1
      End If
      Temp_register = Getadc(3)
      If Temp_register > 60 Then
         Rechts_voor = 1
         Led3 = 0
      Else
         Rechts_voor = 0
         Led3 = 1
      End If
      Temp_register = Getadc(2)
      If Temp_register > 60 Then
         Links_voor = 1
         Led2 = 0
      Else
         Links_voor = 0
         Led2 = 1
      End If
      Temp_register = Getadc(1)
      If Temp_register > 40 Then
         Links = 1
         Led1 = 0
      Else
         Links = 0
         Led1 = 1
      End If
      Temp_register = Getadc(0)
      If Temp_register > 40 Then
         Links_achter = 1
         Led0 = 0
      Else
         Links_achter = 0
         Led0 = 1
      End If
   Return
'**************************************
Overint:
'Motors opzetten
L_motor = 1
R_motor = 1
Do
     GoSub Analoog_in
     If Links = 1 Then
         R_motor = 0
         L_motor = 1
         'Rechts draaien tot dat links niks 
 'meer gedetecteerd wordt
         Do
            GoSub Analoog_in
         Loop Until Links = 0
         L_motor = 1
         R_motor = 1
         Teller = 0
     ElseIf Rechts = 1 Then
         R_motor = 1
         L_motor = 0
         'Links draaien tot dat rechts niks 
 'meer gedetecteerd wordt
         Do
            GoSub Analoog_in
         Loop Until Rechts = 0
         L_motor = 1
         R_motor = 1
         Teller = 0
      ElseIf Links_voor = 1 Then
         R_motor = 0
         L_motor = 1
         Waitms 260
         'Links draaien tot dat vanvoor niks 
 'meer gedetecteerd wordt
         Do
            GoSub Analoog_in
         Loop Until Links_voor = 0
         L_motor = 1
         R_motor = 1
         Teller = 0
      End If
      'Als het programma 30 keer doorlopen is 
      'zonder dat er iets gedetecteerd is
      'dan kort naar links draaien
      Incr Teller
      If Teller = 30 Then
         Waitms 20
         R_motor = 1
         L_motor = 0
         Waitms 30
         L_motor = 1
         R_motor = 1
         Waitms 10
         Teller = 0
      End If
Loop
'******************************************
End

Files

Code: Download