'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' TAB Electronics Build Your Own Robot Kit BX24 Behavior Tools ' by Dr. J (Juliano@csuChico.edu) ' and Matt Bauer (MBauer1@csuChico.edu) ' California State University, Chico ' Intelligent Systems Laboratory ' Chico, CA 95929-0410 ' http://isl.ecst.csuchico.edu ' October 2004 ' ' BX24 code to support Myke Predko's BYORK Behaviors in PBasic. This version ' requires the BX24_byork Interface Module distributed by Chico State's ISL. ' '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Attribute VB_Name = "BehaviorTools" Option Explicit Public Const Delay As Single = 0.1 Public Const NumChoices As Single = 4.0 '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Public Sub BlinkLED( _ ByVal Count As Byte ) Dim I As Byte For I = 1 To Count Call RobotSend( RobotLEDOn ) Call Sleep( Delay ) Call RobotSend( RobotLEDOff ) Call Sleep( Delay ) Next End Sub 'BlinkLED '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Public Sub ReadCurrentLightLevels( _ ByRef Lcds As Byte, _ ByRef Rcds As Byte ) Lcds = RobotCDSL Call RobotSendReceive( Lcds ) Rcds = RobotCDSR Call RobotSendReceive( Rcds ) End Sub 'ReadCurrentLightLevels() '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Public Sub Navigate( _ ByVal Direction As Byte, _ ByVal PwrNotch As Byte ) Call RobotSend( PwrNotch ) Call Sleep( Delay ) Call RobotSend( Direction ) Call Sleep( Delay ) ' Call RobotSend( RobotStop ) ' Call Sleep( Delay ) End Sub 'Navigate() '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Random() returns a random number between 0 through X-1 Public Function Random( _ ByVal X As Single ) As Byte Random = Cbyte(Rnd * X) End Function 'Random() '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Public Sub ReadCurrentIRvalues( _ ByRef Bump As Byte ) Bump = RobotWhiskers Call RobotSendReceive(Bump) Call Sleep( Delay ) End Sub 'ReadCurrentIRvalues() '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Public Sub GoForward( _ ByVal WithWhiskers As Boolean , _ ByRef Bump As Byte ) Call ReadCurrentIRvalues( Bump ) ' to read value of IR module If( ((Not WithWhiskers) Or (Bump = 0)) ) Then Call RobotSend( RobotForward ) Call Sleep( Delay ) Call RobotSend( RobotStop ) Call Sleep( Delay ) End If End Sub 'GoForward() '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Public Sub IRdetect() Dim DataByte As Byte Do DataByte = RobotWhiskers Call RobotSendReceive(DataByte) Call Sleep( Delay ) Call Whichway( DataByte ) Call Sleep( Delay ) Loop End Sub 'IRdetect() '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Public Sub WhichWay( _ ByVal DataByte As Byte ) Select Case (DataByte) Case 0,6 Call Navigate( RobotForward , RobotPWM2 ) Case 2 Call Navigate( RobotLeft , RobotPWM2 ) Case 4 Call Navigate( RobotRight , RobotPWM2 ) Case Else Call Navigate( RobotStop , RobotPWM0 ) End Select End Sub 'WhichWay() '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Public Sub Hugger( _ ByVal Direction As Byte ) Dim i As Byte Dim Opposite As Byte Dim Bump As Byte If( Direction=RobotRight ) Then ' CCW direction Opposite =RobotLeft Else ' CW direction Opposite =RobotRight End If For i = 1 to 3 Call Navigate( Direction , RobotPWM2 ) Call Navigate( RobotForward , RobotPWM2 ) Call Sleep( Delay ) Next Call ReadCurrentIRvalues( Bump ) ' read value of IR module If(( (Bump=2) And (Direction=RobotRight) ) Or ( (Bump=4) And (Direction=RobotLeft) )) Then Call Navigate( Direction , RobotPWM2 ) Else Call Navigate( Opposite , RobotPWM2 ) End If Call Sleep( Delay ) End Sub 'Hugger() ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''