1 /* 2 Pololu3pi.h - Library for using the 3pi robot. 3 */ 4 5 /* 6 * Written by Paul Grayson, 2008. 7 * Copyright (c) 2008-2012 Pololu Corporation. For more information, see 8 * 9 * http://www.pololu.com 10 * http://forum.pololu.com 11 * http://www.pololu.com/docs/0J18 12 * 13 * You may freely modify and share this code, as long as you keep this 14 * notice intact (including the two links above). Licensed under the 15 * Creative Commons BY-SA 3.0 license: 16 * 17 * http://creativecommons.org/licenses/by-sa/3.0/ 18 * 19 * Disclaimer: To the extent permitted by law, Pololu provides this work 20 * without any warranty. It might be defective, in which case you agree 21 * to be responsible for all resulting costs and damages. 22 */ 23 24 #ifndef Pololu3pi_h 25 #define Pololu3pi_h 26 27 #ifndef LIB_POLOLU 28 #ifndef ARDUINO 29 30 #include "../OrangutanAnalog/OrangutanAnalog.h" 31 #include "../OrangutanBuzzer/OrangutanBuzzer.h" 32 #include "../OrangutanMotors/OrangutanMotors.h" 33 #include "../OrangutanLCD/OrangutanLCD.h" 34 #include "../OrangutanLEDs/OrangutanLEDs.h" 35 #include "../OrangutanPushbuttons/OrangutanPushbuttons.h" 36 #include "../OrangutanTime/OrangutanTime.h" 37 #include "../OrangutanSerial/OrangutanSerial.h" 38 #include "../OrangutanServos/OrangutanServos.h" 39 #include "../PololuWheelEncoders/PololuWheelEncoders.h" 40 #include "../OrangutanResources/OrangutanResources.h" 41 #include "../OrangutanDigital/OrangutanDigital.h" 42 #include "../OrangutanPulseIn/OrangutanPulseIn.h" 43 #include "../OrangutanSPIMaster/OrangutanSPIMaster.h" 44 45 #endif 46 #endif 47 48 #define IR_EMITTERS_OFF 0 49 #define IR_EMITTERS_ON 1 50 #define IR_EMITTERS_ON_AND_OFF 2 51 52 #ifdef __cplusplus 53 54 class Pololu3pi 55 { 56 public: 57 58 // Constructor: does nothing. Pololu3pi()59 Pololu3pi() { } 60 61 // Initializes 3pi. Currently all that this does is set up the 62 // line sensors pins, turn off the line sensor emitter LEDs to 63 // conserve power, and reset the system timer. Note: the system 64 // timer is not used in the Arduino environment. 65 // 66 // You may choose a timeout for the line sensors, specified here 67 // in microseconds. 68 // 69 // Setting disable_emitter_pin = 1 causes PC5 not to be used to 70 // control the emitters, so that you can use it for other things. 71 static void init(unsigned int line_sensor_timeout = 1000, unsigned char disable_emitter_pin = 0); 72 73 // Reads values into the array sensor_values. This must have 74 // space for five unsigned int values and be called AFTER init. 75 static void readLineSensors(unsigned int *sensor_values, unsigned char readMode = IR_EMITTERS_ON); 76 77 void emittersOn(); 78 void emittersOff(); 79 void calibrateLineSensors(unsigned char readMode = IR_EMITTERS_ON); 80 void readLineSensorsCalibrated(unsigned int *sensor_values, unsigned char readMode = IR_EMITTERS_ON); 81 void lineSensorsResetCalibration(); 82 unsigned int readLine(unsigned int *sensor_values, unsigned char readMode = IR_EMITTERS_ON, unsigned char white_line = 0); 83 84 unsigned int *getLineSensorsCalibratedMinimumOn(); 85 unsigned int *getLineSensorsCalibratedMaximumOn(); 86 unsigned int *getLineSensorsCalibratedMinimumOff(); 87 unsigned int *getLineSensorsCalibratedMaximumOff(); 88 }; 89 90 extern "C" { 91 #endif // __cplusplus 92 93 void pololu_3pi_init(unsigned int line_sensor_timeout); 94 void pololu_3pi_init_disable_emitter_pin(unsigned int line_sensor_timeout); 95 void read_line_sensors(unsigned int *sensor_values, unsigned char readMode); 96 void emitters_on(void); 97 void emitters_off(void); 98 void calibrate_line_sensors(unsigned char readMode); 99 void line_sensors_reset_calibration(void); 100 void read_line_sensors_calibrated(unsigned int *sensor_values, unsigned char readMode); 101 unsigned int read_line(unsigned int *sensor_values, unsigned char readMode); 102 unsigned int read_line_white(unsigned int *sensor_values, unsigned char readMode); 103 104 unsigned int *get_line_sensors_calibrated_minimum_on(void); 105 unsigned int *get_line_sensors_calibrated_maximum_on(void); 106 unsigned int *get_line_sensors_calibrated_minimum_off(void); 107 unsigned int *get_line_sensors_calibrated_maximum_off(void); 108 109 #ifdef __cplusplus 110 } 111 #endif 112 113 114 #endif 115 116 // Local Variables: ** 117 // mode: C++ ** 118 // c-basic-offset: 4 ** 119 // tab-width: 4 ** 120 // indent-tabs-mode: t ** 121 // end: ** 122