//----------------------------------------------------------------- // Program: PBot_BOB-A_VC6.osc // Function: Lesson B. Proximity Sensor Test // Designer: Phil Malone, phil@philbot.com www.philbot.com // Details: http://www.philbot.com // // Device: Bot On a Board (BOB) V1.1 // Compiler: OOPic 6.x // Motor Drive: SN75410 With Tamiya Gearbox // Quad encoder:OPB610 // // // Version Date Comment // ------- --------- ------- // 1.00 8/8/2005 Original //----------------------------------------------------------------- //------------------------------------------------------- // BOB I/O Port definitions //------------------------------------------------------- Const IO_LINE_LEFT = 3; // Left Fairchild Analog Reflective sensor Const IO_LINE_MID = 2; // Middle Fairchild Analog Reflective sensor Const IO_LINE_RIGHT = 1; // Right Fairchild Analog Reflective sensor Const IO_PROXIMITY_LEFT = 8; // Left Sharp Digital Prox sensor Const IO_PROXIMITY_RIGHT = 9; // Right Sharp Digital Prox sensor Const IO_PROXIMITY_REAR = 10; // Rear Sharp Digital Prox sensor Const IO_LED1 = 12; // General Purpose LED 1 Const IO_LED2 = 13; // General Purpose LED 2 Const IO_LED3 = 14; // General Purpose LED 3 Const IO_LED4 = 15; // General Purpose LED 4 Const IO_LED_GROUP = 1; // LED I/O Group 1 (Lines 8-15) Const IO_LED_NIBBLE = 1; // LED I/O High Nible (Lines 12-15) Const IO_MOTOR_LEFT_FWD = 24; // Left Motor H-Bridge High Const IO_MOTOR_LEFT_REV = 25; // Left Motor H-Bridge Low Const IO_MOTOR_LEFT_PWM = 18; // Left Motor PWM control Const IO_MOTOR_RIGHT_FWD = 26; // Right Motor H-Bridge High Const IO_MOTOR_RIGHT_REV = 27; // Right Motor H-Bridge Low Const IO_MOTOR_RIGHT_PWM = 17; // Right Motor PWM control Const IO_ENCODER_LEFT_FRONT = 31; // Left A I/R optical interruptor Const IO_ENCODER_LEFT_BACK = 30; // Left B I/R optical interruptor Const IO_ENCODER_RIGHT_FRONT = 29; // Right A I/R optical interruptor Const IO_ENCODER_RIGHT_BACK = 28; // Right B I/R optical interruptor //----------------------------------------------------------------- // Constants, used for default values //----------------------------------------------------------------- Const CLOCK_PRESCALE = 5; // Divide Clock by 6 Const FIVE_SECONDS = 50; // 50 tenths Const SLOW_PWM = 2; // Maximum PWM divide for 312KHz Const PWM_PERIOD = 100; // Maximum PWM +/- range Const OBSTACLE = cvLow; // Eye Sees Obstacle Const CLEAR = cvHigh; // Eye Does Not see Obstacle //----------------------------------------------------------------- // User Objects. Use these to access BOB hardware. //----------------------------------------------------------------- oCountDownO ActionTimer = New oCountDownO; // User Timer // LED Object (accessed as individual bits) oDIO1 LED1 = New oDIO1; // Driver for LED1 oDIO1 LED2 = New oDIO1; // Driver for LED2 oDIO1 LED3 = New oDIO1; // Driver for LED3 // Digital Proximity sensors oDIO1 LeftEye = New oDIO1; // Left Prox Sensor oDIO1 RightEye = New oDIO1; // Right Prox Sensor oDIO1 RearEye = New oDIO1; // Rear Prox Sensor //----------------------------------------------------------------- // General Variables //----------------------------------------------------------------- //----------------------------------------------------------------- // BOB Main Program //----------------------------------------------------------------- Void Main(Void) { // Always set up the required IO first. SetupIO(); // Wait for 5 second "Start Up" to elapse While(ActionTimer.NonZero); // Display Prox state on LEDs While(cvTrue) { LED1.Value = ~LeftEye.Value; // Set LED1 based on Left Eye LED2.Value = ~RearEye.Value; // Set LED2 based on Rear Eye LED3.Value = ~RightEye.Value; // Set LED3 based on Right Eye } } //################################################################# // These are the standard functions that All lessons have //################################################################# //----------------------------------------------------------------- // SetupIO() // Configure all the IO Objects here //----------------------------------------------------------------- Void SetupIO( Void ) { // -------------------------------- // setup the ActionTimer Timer for 1/10th Second ticks // Preload counter with 5 second delay // -------------------------------- ActionTimer.PreScale = CLOCK_PRESCALE; ActionTimer.ClockIn.Link(ooPIC.Hz60); ActionTimer = FIVE_SECONDS; ActionTimer.Operate = cvTrue; // -------------------------------- // setup the LED Drivers // -------------------------------- LED1.IOLine = IO_LED1; LED1.Direction = cvOutput ; LED2.IOLine = IO_LED2; LED2.Direction = cvOutput ; LED3.IOLine = IO_LED3; LED3.Direction = cvOutput ; // -------------------------------- // setup the Eye proximity sensors // -------------------------------- LeftEye.IOLine = IO_PROXIMITY_LEFT; LeftEye.Direction = cvInput; RightEye.IOLine = IO_PROXIMITY_RIGHT; RightEye.Direction = cvInput; RearEye.IOLine = IO_PROXIMITY_REAR; RearEye.Direction = cvInput; } //----------------------------------------------------------------- // WaitTenths(Byte Tenths) // This function uses the Action timer to wait for a number // of "tenths" of a second. // This method is more accurate than the OOPic.Delay function //----------------------------------------------------------------- Void WaitTenths(Byte Tenths) { // Set timer ActionTimer = Tenths; While(ActionTimer.NonZero); } //################################################################# // Lesson specific functions //#################################################################