'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' TAB Electronics Build Your Own Robot Kit BX24 Behavior 4 (Object Hugger) ' 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 version of Myke Predko's Behavior4 (Object Hugger) in PBasic. This ' requires the BX24_byork Interface Module distributed by Chico State's ISL. ' '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Attribute VB_Name = "ObjectHugger" Option Explicit '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' The following code creates a behavior based on following the edge profile ' of an object. The robot moves forward until it detects on object, randomly ' picks the direction of the turn and follows the detected object's profile ' in a clockwise or counterclockwise rotation. Public Sub ObjectHugger() Dim RandByte As Byte Dim Bump As Byte Dim i As Byte ' Flash LED four times Call BlinkLED( 4 ) Do Call ReadCurrentIRvalues( Bump ) ' to read value of IRPD module If( Bump <= 1 ) Then Call Navigate( RobotForward , RobotPWM1 ) Else RandByte = Random(2.0) If( RandByte=0 ) Then Call Hugger( RobotRight ) ' Setup for CCW direction Else Call Hugger( RobotLeft ) ' Setup for CW direction End If End If Loop End Sub 'ObjectHugger() ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''