Category: HexAvoider

HexAvoider

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

The plastic parts and the pcbs (kit) where bought by the school. Our assignment was to solder the pcb’s and write the program.

Normally the hexavoider goes forward. This happens by lifting the left side, the right side is then put forward and left back to the rear. Then the other side is lifted and the left side goes to the front. This is how it steps forwards.

The hexavoider has 2 types of sensors: the whiskers and the IR sensors. If the whiskers feel something then it goes backwards, turns to the other side as from where it detected and walks on. If the IR sensors detect something it will reverse and then turn. This is in always in the same direction because there is only 1 IR sensor.

 

Video of the HexAvoider in action:

Please accept YouTube cookies to play this video. By accepting you will be accessing content from YouTube, a service provided by an external third party.

YouTube privacy policy

If you accept this notice, your choice will be saved and the page will refresh.

 

Code (Bascom):

'*************************************************
'* HexAvoider                                    *
'* Stijn Coenen, Rob Thomas, Stijn van Roy       *
'* 3ELO2                                         *
'*************************************************
$regfile = "89C51RC.dat"

'Kristal = 11Mhz
$crystal = 11059200
'*************************************************
'In en uitgangen aanduiden
Config Servos = 3 , Servo1 = P1.5 , Servo2 = P1.6 , Servo3 = P1.7 , Reload = 100

Led1 Alias P0.0
Led2 Alias P0.1
Led3 Alias P0.2
Led4 Alias P0.3
Buzzer Alias P0.5
Switch1 Alias P0.4
Switch2 Alias P0.5
Links_antenne Alias P3.2
Recht_antenne Alias P3.3
Led_antenne Alias T0
Irled_left Alias P1.0
Irled_right Alias P1.1
Irin Alias P1.2
Led_left Alias P1.3
Led_right Alias P1.4

Dim index As Byte
'*************************************************
'Subroutines
  'Subroutines skippen bij opstarten programma
  GoTo Oversub
  '*************************************************
  'Ir leds laten knipperen
  Ir_led_sturen:
     For index = 0 To 100
      Irled_left = 1
      Irled_right = 1
      delay
      Irled_left = 0
      Irled_right = 0
      Delay
     Next
  Return
  '*************************************************
  'Als er links gedetecteerd is
  Links_detect:
     Led1 = 0
     GoSub Servo_mid
     GoSub Achteruit
     GoSub Achteruit
     Waitms 2000
     GoSub Servo_mid
     GoSub Rechts_draai
     GoSub Rechts_draai
     Led1 = 1
  Return
  '*************************************************
  'Als er rechts gedetecteerd is
  Rechts_detect:
     Led2 = 0
     GoSub Servo_mid
     GoSub Achteruit
     GoSub Achteruit
     Waitms 2000
     GoSub Servo_mid
     GoSub Links_draai
     GoSub Links_draai
     Led2 = 1
  Return
  '*************************************************
  'Alle servo's in de middenstand zetten
  Servo_mid:
     Servo1 = 12
     Servo2 = 12
     Servo3 = 12
  Return
  '*************************************************  'Achteruit lopen
  Achteruit:
     'links omhoog
     Servo2 = 16
     Waitms 350
     'links naar achter
     Servo3 = 8
     Waitms 350
     'links naar voor
     Servo1 = 8
     Waitms 350
     ' rechts omhoog
     Servo2 = 8
     Waitms 350
     'rechts naar achter
     Servo1 = 16
     Waitms 350
     'links naar voor
     Servo3 = 16
     Waitms 350
  Return
  '*************************************************
  'Naar rechts draaien
  Rechts_draai:
     'links omhoog
     Servo2 = 16
     Waitms 350
     'links naar voor
     Servo3 = 14
     Waitms 350
     'rechts naar voor
     Servo1 = 8
     Waitms 350
     'rechts omhoog
     Servo2 = 8
     Waitms 350
     'rechts naar achter
     Servo1 = 14
     Waitms 350
     'links naar achter
     Servo3 = 8
     Waitms 350
  Return
  '*************************************************
  'Naar links draaien
  Links_draai:
     'links omhoog
     Servo2 = 16
     Waitms 350
     'links naar achter
     Servo3 = 8
     Waitms 350
     'rechts naar voor
     Servo1 = 14
     Waitms 350
      'rechts omhoog
     Servo2 = 8
     Waitms 350
     'rechts naar voor
     Servo1 = 8
     Waitms 350
     'links naar voor
     Servo3 = 14
     Waitms 350
  Return
  '*************************************************
  'Sensoren checken
  Sensor_check:
      'Linkse antenne
      If Links_antenne = 0 Then
         GoSub Links_detect
      End If
      'Rechtse antenne
      If Recht_antenne = 0 Then
         GoSub Rechts_detect
      End If
      'IR-Leds
      GoSub Ir_led_sturen
      If Irin = 0 Then
         GoSub Rechts_detect
      End If
  Return
Oversub:
'*************************************************
   'Servo's in de middenstand zetten
   GoSub Servo_mid
Do
   'rechts omhoog
   Servo2 = 8
      Waitms 350
      If Links_antenne = 0 Then
         GoSub Links_detect
      End If
      If Recht_antenne = 0 Then
         GoSub Rechts_detect
      End If
      GoSub Ir_led_sturen
      If Irin = 0 Then
         GoSub Rechts_detect
      End If
   'Links naar achter
   Servo3 = 10
     Waitms 350
     If Links_antenne = 0 Then
        GoSub Links_detect
     End If
     If Recht_antenne = 0 Then
        GoSub Rechts_detect
     End If
      GoSub Ir_led_sturen
     If Irin = 0 Then
        GoSub Rechts_detect
     End If
   'Rechts voor
   Servo1 = 8
      Waitms 350
      If Links_antenne = 0 Then
         GoSub Links_detect
      End If
      If Recht_antenne = 0 Then
         GoSub Rechts_detect
      End If
      GoSub Ir_led_sturen
      If Irin = 0 Then
         GoSub Rechts_detect
      End If
   'links omhoog
   Servo2 = 16
      Waitms 350
      If Links_antenne = 0 Then
         GoSub Links_detect
      End If
      If Recht_antenne = 0 Then
         GoSub Rechts_detect
      End If
      GoSub Ir_led_sturen
      If Irin = 0 Then
         GoSub Rechts_detect
      End If
   'rechts naar achter
   Servo1 = 15
      Waitms 350
      If Links_antenne = 0 Then
         GoSub Links_detect
      End If
      If Recht_antenne = 0 Then
         GoSub Rechts_detect
      End If
      GoSub Ir_led_sturen
      If Irin = 0 Then
         GoSub Rechts_detect
      End If
   'Links Naar Voor
   Servo3 = 14
      Waitms 350
      If Links_antenne = 0 Then
         GoSub Links_detect
      End If
      If Recht_antenne = 0 Then
         GoSub Rechts_detect
      End If
      GoSub Ir_led_sturen
      If Irin = 0 Then
         GoSub Rechts_detect
      End If
Loop
'*************************************************
End

Top

Files

Code: Download