Pololu AVR Library Command Reference © 2001–2019 Pololu Corporation Pololu AVR Library Command Reference 1. Introduction . . . . . . . . . . . . . . . 2. Orangutan Analog-to-Digital Conversion 3. Orangutan Buzzer: Beeps and Music . 4. Orangutan Digital I/O . . . . . . . . . . 5. Orangutan LCD . . . . . . . . . . . . . 6. Orangutan LEDs . . . . . . . . . . . . 7. Orangutan Motor Control . . . . . . . . 8. Orangutan Pulse/PWM Inputs . . . . . 9. Orangutan Pushbuttons . . . . . . . . 10.
Pololu AVR Library Command Reference © 2001–2019 Pololu Corporation 1. Introduction This document describes the Pololu AVR C/C++ Library, a programming library designed for use with Pololu products. The library is used to create programs that run on Atmel ATmega1284P, ATmega644P, ATmega324PA, ATmega328P, ATmega168 and ATmega48 processors, and it supports the following products: 1.
Pololu AVR Library Command Reference Pololu 3pi robot © 2001–2019 Pololu Corporation [https://www.pololu.com/product/975]: a mega168/328-based programmable robot. The 3pi robot essentially contains an SV-328 and a 5-sensor version of the QTR-8RC, both of which are in the list below. Pololu Orangutan SVP-1284 [https://www.pololu.com/product/1327]: based on the mega1284, the SVP-1284 is our newest Orangutan robot controller.
Pololu AVR Library Command Reference Pololu QTR-1A product/960] © 2001–2019 Pololu Corporation [https://www.pololu.com/product/958] and QTR-8A [https://www.pololu.com/ reflectance sensors (analog): an analog sensor containing IR/ phototransistor pairs that allows a robot to detect the difference between shades of color. The QTR sensors can be used for following lines on the floor, for obstacle or drop-off (stairway) detection, and for various other applications. Pololu QTR-1RC [https://www.pololu.
Pololu AVR Library Command Reference © 2001–2019 Pololu Corporation 2. Orangutan Analog-to-Digital Conversion The OrangutanAnalog class and the C functions in this section make it easy to use to the analog inputs and integrated analog hardware on the Orangutan robot controllers (LV, SV, SVP, X2, and Baby Orangutan) and 3pi robot. These functions take care of configuring and running the analog-to-digital converter.
Pololu AVR Library Command Reference © 2001–2019 Pololu Corporation Channels The tables below give a summary of the analog inputs available on your AVR. Some of these pins are hardwired or jumpered to the battery voltage or sensors or trimpots built in to your device, while other pins are available for you to connect your own sensors to. Please refer to the pin assignment table in the user’s guide for your device for more information.
Pololu AVR Library Command Reference © 2001–2019 Pololu Corporation Single-Ended Analog Channels on the Orangutan SVP Channel Pin Keyword Note 0 PA0/ADC0 1 PA1/ADC1 2 PA2/ADC2 3 PA3/ADC3 4 PA4/ADC4 5 PA5/ADC5 6 PA6/ADC6 7 PA7/ADC7 14 internal 1.
Pololu AVR Library Command Reference © 2001–2019 Pololu Corporation Single-Ended Analog Channels on the Orangutan X2 Channel Pin Keyword Note 0 PA0/ADC0 1 PA1/ADC1 2 PA2/ADC2 3 PA3/ADC3 4 PA4/ADC4 5 PA5/ADC5 6 PA6/ADC6 7 PA7/ADC7 14 internal 1.
Pololu AVR Library Command Reference © 2001–2019 Pololu Corporation Differential Analog Channels on the Orangutan SVP and X2 Channel Positive Differential Input Negative Differential Input Gain 9 PA1/ADC1 PA0/ADC0 10x 11 PA1/ADC1 PA0/ADC0 200x 13 PA3/ADC3 PA2/ADC2 10x 15 PA3/ADC3 PA2/ADC2 200x 16 PA0/ADC0 PA1/ADC1 1x 18 PA2/ADC2 PA1/ADC1 1x 19 PA3/ADC3 PA1/ADC1 1x 20 PA4/ADC4 PA1/ADC1 1x 21 PA5/ADC5 PA1/ADC1 1x 22 PA6/ADC6 PA1/ADC1 1x 23 PA7/ADC7 PA1/ADC1 1x 24
Pololu AVR Library Command Reference © 2001–2019 Pololu Corporation Function Reference C++ and Arduino methods are shown in red. C functions are shown in green. static void OrangutanAnalog::setMode(unsigned char mode) void set_analog_mode(unsigned char mode) Used to set the ADC for either 8-bit or 10-bit conversions. The mode argument should be the either MODE_8_BIT or MODE_10_BIT. When the ADC is in 8-bit mode, conversion results will range from 0 to 255 for voltages ranging from 0 to 5 V.
Pololu AVR Library Command Reference © 2001–2019 Pololu Corporation unsigned int analog_read_average(unsigned char channel, unsigned int numSamples) Performs numSamples analog-to-digital conversions on the specified analog input channel and returns the average value of the readings. In 8-bit mode, the result will range from 0 to 255 for voltages from 0 to 5 . In 10-bit mode, the result will range from 0 to 1023 for voltages from 0 to 5 V.
Pololu AVR Library Command Reference © 2001–2019 Pololu Corporation unsigned int read_trimpot() Performs 20 analog-to-digital conversions on the output of the trimmer potentiometer on the Orangutan (including the SVP) or 3pi robot. In 8-bit mode, the result will range from 0 to 255 for voltages from 0 to 5 . In 10-bit mode, the result will range from 0 to 1023 for voltages from 0 to 5 V. This method is equivalent to readAverage(TRIMPOT, 20) .
Pololu AVR Library Command Reference © 2001–2019 Pololu Corporation Performs ten 10-bit analog-to-digital conversions on the battery voltage sensing circuit (a 5/16 voltage divider of VIN) of the Orangutan X2 and returns the average measured battery voltage in millivolts. A result of 9153 would mean a battery voltage of 9.153 V. This function will only return the correct result when there is a short across the “ADC6=BATLEV” SMT jumper on the bottom side of the PCB.
Pololu AVR Library Command Reference © 2001–2019 Pololu Corporation static unsigned int conversionResult() unsigned int analog_conversion_result() Returns the result of the previous analog-to-digital conversion. In 8-bit mode, the result will range from 0 to 255 for voltages from 0 to 5 V. In 10-bit mode, the result will range from 0 to 1023 for voltages from 0 to 5 V.
Pololu AVR Library Command Reference © 2001–2019 Pololu Corporation 3. Orangutan Buzzer: Beeps and Music The OrangutanBuzzer class and the C functions in this section allow various sounds to be played on the buzzer of the Orangutan LV, SV, SVP, X2, and 3pi robot, from simple beeps to complex tunes. The buzzer is controlled using one of the Timer 1 PWM outputs, so it will conflict with any other uses of Timer 1.
Pololu AVR Library Command Reference © 2001–2019 Pololu Corporation Reference C++ and Arduino methods are shown in red. C functions are shown in green. static void OrangutanBuzzer::playFrequency(unsigned int frequency, unsigned int duration, unsigned char volume) void play_frequency(unsigned int freq, unsigned int duration, unsigned char volume) This method will play the specified frequency (in Hz or 0.1 Hz) for the specified duration (in ms). The frequency argument must be between 40 Hz and 10 kHz.
Pololu AVR Library Command Reference © 2001–2019 Pololu Corporation Caution: frequency × duration/1000 must be no greater than 0xFFFF (65535). This means you can’t use a max duration of 65535 ms for frequencies greater than 1 kHz. For example, the maximum duration you can use for a frequency of 10 kHz is 6553 ms. If you use a duration longer than this, you will produce an integer overflow that can result in unexpected behavior.
Pololu AVR Library Command Reference 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 // x will determine the #define C( x ) ( #define C_SHARP( x ) ( #define D_FLAT( x ) ( #define D( x ) ( #define D_SHARP( x ) ( #define E_FLAT( x ) ( #define E( x ) ( #define F( x ) ( #define F_SHARP( x ) ( #define G_FLAT( x ) ( #define G( x ) ( #define G_SHARP( x ) ( #define A_FLAT( x ) ( #define A( x ) ( #define A_SHARP( x ) ( #define B_FLAT( x ) ( #define B( x ) ( octave of 0 + x*12 1 + x*12 1 + x*12 2
Pololu AVR Library Command Reference © 2001–2019 Pololu Corporation • ‘-’ after a note lowers any note one half-step • ‘.’ after a note “dots” it, increasing the length by 50%. Each additional dot adds half as much as the previous dot, so that “A..” is 1.75 times the length of “A”. • ‘O’ followed by a number sets the octave (default: O4). • ‘T’ followed by a number sets the tempo in beats/min (default: T120).
Pololu AVR Library Command Reference © 2001–2019 Pololu Corporation A version of play() that takes a pointer to program space instead of RAM. This is desirable since RAM is limited and the string must be stored in program space anyway. Example: 1 2 3 4 5 6 7 #include const char melody[] PROGMEM = "!L16 V8 cdefgab>cbagfedc"; 1 2 3 4 5 6 7 #include
Pololu AVR Library Command Reference © 2001–2019 Pololu Corporation when it’s time to play the next note in a sequence, or you can use it as the argument to a delay loop to wait while the buzzer is busy. static void OrangutanBuzzer::stopPlaying() void stop_playing() This method will immediately silence the buzzer and terminate any note/frequency/melody that is currently playing. 3.
Pololu AVR Library Command Reference © 2001–2019 Pololu Corporation 4. Orangutan Digital I/O This section of the library provides commands for using the AVR’s pins as generic digital inputs and outputs. The code is all inline, which lets it compile to very small, fast, efficient assembly code if you use constants as your arguments.
Pololu AVR Library Command Reference © 2001–2019 Pololu Corporation Reference C++ and Arduino methods are shown in red. C functions are shown in green. static void OrangutanDigital::setOutput(unsigned char pin, unsigned char outputState); void set_digital_output(unsigned char pin, unsigned char output_state); Sets the specified pin as an output. The pin argument should be one of the IO_* keywords (e.g. IO_D1 for pin PD1).
Pololu AVR Library Command Reference © 2001–2019 Pololu Corporation 5. Orangutan LCD The OrangutanLCD class and the C functions in this section provide a variety of ways of displaying data to the LCD screen of an Orangutan robot controller (LV, SV, SVP, and X2) and 3pi robot, providing an essential tool for user interfaces and debugging.
Pololu AVR Library Command Reference © 2001–2019 Pololu Corporation Reference C++ and Arduino methods are shown in red. C functions are shown in green. static void OrangutanLCD::clear() void clear() Clears the display and returns the cursor to the upper-left corner (0, 0). static void OrangutanLCD::initPrintf() void lcd_init_printf() Initializes the display for use with the standard C function printf(). This is not available in the Arduino environment. See the avr-libc manual [http://www.nongnu.
Pololu AVR Library Command Reference © 2001–2019 Pololu Corporation Example 1 2 3 4 5 6 7 8 #include void someFunction(int x) { // initialize printf() for a 20x4 character LCD lcd_init_printf_with_dimensions(20, 4); // in C++: OrangutanLCD::initPrintf(20, 4); printf("x=%5d", x); } ? static void OrangutanLCD::print(unsigned char character) Prints a single ASCII character to the display at the current cursor position.
Pololu AVR Library Command Reference © 2001–2019 Pololu Corporation Example: 1 2 3 4 5 6 7 8 9 10 #include
Pololu AVR Library Command Reference © 2001–2019 Pololu Corporation void print_binary(unsigned char value) Prints the specified byte in binary to the display at the current cursor position. The value will not wrap or otherwise span lines. static void OrangutanLCD::gotoXY(unsigned char x, unsigned char y) void lcd_goto_xy(int col, int row) Moves the cursor to the specified (x, y) location on the LCD.
Pololu AVR Library Command Reference © 2001–2019 Pololu Corporation pixel. The example below demonstrates how to construct this kind of array. Example: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 #include // the PROGMEM macro comes from the pgmspace.
Pololu AVR Library Command Reference © 2001–2019 Pololu Corporation 6. Orangutan LEDs The OrangutanLEDs class and the C functions in this section are a very simple interface to the user LEDs included on Orangutan controllers and 3pi. The Orangutan X2 has five user LEDs (two red, two green, and one yellow), the Orangutan LV, SV, SVP, and 3pi have two user LEDs (one red and one green), and the Baby Orangutan has one user LED (red).
Pololu AVR Library Command Reference © 2001–2019 Pololu Corporation Reference C++ and Arduino methods are shown in red. C functions are shown in green. static void OrangutanLEDs::red(unsigned char state) void red_led(unsigned char state) This method will turn the red user LED off if state is zero, it will toggle the LED state if state is 255, else it will turn the red user LED on.
Pololu AVR Library Command Reference © 2001–2019 Pololu Corporation This method controls the Orangutan X2’s second red user LED and is only defined for the Orangutan X2 version of the library. You can use the keyword HIGH as an argument to turn the LED on, and you can use the keyword LOW as an argument to turn the LED off. You can use the keyword TOGGLE to toggle the LED state.
Pololu AVR Library Command Reference © 2001–2019 Pololu Corporation 7. Orangutan Motor Control The OrangutanMotors class and the C functions in this section provide PWM-based speed (and direction) control of the two motor channels on the Orangutan controllers and 3pi.
Pololu AVR Library Command Reference © 2001–2019 Pololu Corporation Reference C++ and Arduino methods are shown in red. C functions are shown in green. static void OrangutanMotors::setM1Speed(int speed) void set_m1_speed(int speed) This method will set the speed and direction of motor 1. Speed is a value between -255 and +255. The sign of speed determines the direction of the motor and the magnitude determines the speed.
Pololu AVR Library Command Reference © 2001–2019 Pololu Corporation 8. Orangutan Pulse/PWM Inputs This section of the library makes it easy to measure pulse inputs such as hobby servo RC pulses, PWM frequency and duty cycle, discharge time of a capacitor (measured digitally), etc. For example, with these functions, it becomes simple to program your Orangutan to respond to multiple channels from an RC receiver or to read data from the multitude of sensors that use pulse outputs.
Pololu AVR Library Command Reference © 2001–2019 Pololu Corporation they are referenced. If a variable is not declared “volatile”, the compiler will eliminate what it decides are superfluous reads of a variable from RAM and instead work with that variable in local registers, which saves time and code space, but this can cause situations where you fail to detect when an ISR has changed that variable’s value. • pinRegister & bitmask : Used by the pin-change ISR to determine the input state of the channel.
Pololu AVR Library Command Reference © 2001–2019 Pololu Corporation Reference C++ methods are shown in red. C/C++ functions are shown in green. static unsigned char OrangutanPulseIn::start(const unsigned char pulse_pins[], unsigned char num_pins) unsigned char pulse_in_start(const unsigned char pulse_pins[], unsigned char num_pins) Configures the AVR’s pin-change interrupts to measure pulses on the specified pins. The num_pins parameter should be the length of the pulse_pins array.
Pololu AVR Library Command Reference © 2001–2019 Pololu Corporation for a single channel came from the same instant in time, since pin-change interrupts are disabled while the ISR-maintained PulseInputStruct is being copied to pulse_info. The argument channel should be a number from 0 to one less than the total number of channels used (num_pins-1); the channel acts as an index to the pulse_pins array supplied to the pulse_in_start() function.
Pololu AVR Library Command Reference 1 2 3 4 5 6 © 2001–2019 Pololu Corporation // check for new pulses on pulse input channel 0: unsigned char newPulse = OrangutanPulseIn::newPulse(0); if (newPulse) // if there has been a new pulse of any kind doSomething(); if (newPulse & HIGH_PULSE) // if there has been a new high pulse doSomethingElse(); ? static unsigned char OrangutanPulseIn::newHighPulse(unsigned char channel) unsigned char new_high_pulse(unsigned char channel) This function returns the newPulse
Pololu AVR Library Command Reference © 2001–2019 Pololu Corporation incorrect. You should disregard the first low pulse after the pulse input line has been in a steady-low state for more than 28. minutes.
Pololu AVR Library Command Reference © 2001–2019 Pololu Corporation Example ? 1 2 3 // if last high pulse was longer than 1500 microseconds if (pulse_to_microseconds(get_last_high_pulse(0)) > 1500) doSomething(); 1 2 3 ? // if last high pulse was longer than 1500 microseconds if (OrangutanPulseIn::toMicroseconds(OrangutanPulseIn::getLastHighPulse(0)) > 1500) doSomething(); 8.
Pololu AVR Library Command Reference © 2001–2019 Pololu Corporation 9. Orangutan Pushbuttons The OrangutanPushbuttons class and the C functions in this section make it easy to use to the three pushbuttons on the Orangutan LV, SV, SVP, X2, and 3pi robot as user-interface control inputs to your program. For a higher level overview of this library and programs that show how this library can be used, please see Section 3.g of the Pololu AVR C/C++ Library User’s Guide [https://www.pololu.com/docs/0J20]. 9.
Pololu AVR Library Command Reference © 2001–2019 Pololu Corporation Reference C++ and Arduino methods are shown in red. C functions are shown in green. static unsigned char OrangutanPushbuttons::getSingleDebouncedPress(unsigned char buttons) unsigned char get_single_debounced_button_press(unsigned char buttons) This is a non-blocking function that makes it very easy to perform button-triggered activities from within your main loop.
Pololu AVR Library Command Reference © 2001–2019 Pololu Corporation unsigned char get_single_debounced_button_release(unsigned char buttons) This is a non-blocking function that makes it very easy to perform button-triggered activities from within your main loop. It uses a four-step finite-state machine to detect the transition of a button release and returns the value of the released button once such a transition is detected.
Pololu AVR Library Command Reference © 2001–2019 Pololu Corporation Example 1 2 3 unsigned char button = wait_for_button_press(ANY_BUTTON); someFunction(); // do something as soon as button is pressed wait_for_button_release(button); // wait for pressed button to be released ? 1 2 3 unsigned char button = OrangutanPushbuttons::waitForPress(ANY_BUTTON); someFunction(); // do something as soon as button is pressed OrangutanPushbuttons::waitForRelease(button); // wait for pressed button to be released ?
Pololu AVR Library Command Reference © 2001–2019 Pololu Corporation 10. Orangutan Serial Port Communication The OrangutanSerial class and the C functions in this section provide access to the serial port(s) on the Orangutan controllers and 3pi robot., enabling two-way TTL-level communication with another microcontroller, a serial device, or (through a USB-serial adapter or RS-232 level converter) a personal computer.
Pololu AVR Library Command Reference © 2001–2019 Pololu Corporation Reference C++ methods are shown in red. C functions are shown in green. static void OrangutanSerial::setBaudRate([unsigned char port,] unsigned long baud) unsigned char serial_set_baud_rate([unsigned char port,] unsigned long baud) Sets the baud rate on the serial port. Standard values up to 115200 should work fine; for higher speeds, please consult the AVR documentation.
Pololu AVR Library Command Reference © 2001–2019 Pololu Corporation char serial_receive_buffer_full([unsigned char port ]) Returns 1 (true) when the receive buffer has been filled with received bytes, so that serial reception is halted. Returns 0 (false) otherwise. This function should not be called when receiving data into a ring buffer.
Pololu AVR Library Command Reference © 2001–2019 Pololu Corporation (SERIAL_CHECK). If SERIAL_CHECK is selected, your code must call serial_check() often to ensure reliable reception and timely transmission of data. The default mode for all UART-based ports is SERIAL_AUTOMATIC. The default and only allowed mode for the Orangutan SVP’s and Orangutan X2’s USB_COMM port is SERIAL_CHECK.
Pololu AVR Library Command Reference © 2001–2019 Pololu Corporation 11. Orangutan Servos This section of the library provides the ability to control up to 16 servos by generating digital pulses directly from your Orangutan without the need for a separate servo controller. These servo control functions are non-blocking; pulses are generated in the background by an interrupt while the rest of your code executes.
Pololu AVR Library Command Reference © 2001–2019 Pololu Corporation Reference C++ and Arduino methods are shown in red. C functions are shown in green. static unsigned char OrangutanServos::start(const unsigned char servo_pins[], unsigned char num_pins) unsigned char servos_start(const unsigned char servo_pins[], unsigned char num_pins) Configures the AVR’s Timer 1 module to generate pulses for up to 8 servos. The num_pins parameter should be the length of the servo_pins array.
Pololu AVR Library Command Reference © 2001–2019 Pololu Corporation of an array of AVR pin numbers defined using the IO_* keywords provided by the library (e.g. IO_D1 for servo pulses on pin PD1). The pins should be connected to the signal pins on your servos. If you don’t want this second set of servos, use a num_pins_b value of 0 (and a servo_pins_b value of 0) or use the servos_start() function above.
Pololu AVR Library Command Reference © 2001–2019 Pololu Corporation unsigned int get_servo_speed_b(unsigned char servo_num) These functions set and get a servo’s speed limit in units of tenths of a microsecond per 20 ms. A speed value of 0 means there is no speed limit. A non-zero speed value means that each time the library sends a servo pulse, that pulse’s width will be within speed/10 µs of the previous pulse width sent to that servo.
Pololu AVR Library Command Reference © 2001–2019 Pololu Corporation 12. Orangutan SPI Master Functions This section of the library provides commands for using the AVR’s Serial Peripheral Interface (SPI) module in master mode to communicate with slave SPI devices.
Pololu AVR Library Command Reference © 2001–2019 Pololu Corporation Reference C++ and Arduino methods are shown in red. C functions are shown in green. static void OrangutanSPIMaster::init(unsigned char speed_divider, unsigned char options) void spi_master_init(unsigned char speed_divider, unsigned char options) Initializes the AVR’s hardware SPI module in master mode. This command makes the MOSI and SCK pins outputs so that the AVR can send data to the slave device.
Pololu AVR Library Command Reference © 2001–2019 Pololu Corporation • SPI_LSB_FIRST: Bytes will be transmitted/received starting with the least-significant bit first. • SPI_EDGE_LEADING (default): The AVR will sample data on MISO on the leading edge of SCK. • SPI_EDGE_TRAILING: The AVR will sample data on MISO on the trailing edge of SCK. Example 1 2 3 4 // Initialize the SPI module in master mode at 20/2 = 10 MHz, sample on the trailing edge, ? // LSB first, SCK idle state low.
Pololu AVR Library Command Reference © 2001–2019 Pololu Corporation 13. Orangutan SVP Functions This section of the library provides commands that are only available on the Orangutan SVP [https://www.pololu.com/product/1325]. For a higher level overview of how the library works on the Orangutan SVP, please see Section 3.j of the Pololu AVR C/C++ Library User’s Guide [https://www.pololu.com/docs/0J20]. 13.
Pololu AVR Library Command Reference © 2001–2019 Pololu Corporation Reference C++ and Arduino methods are shown in red. C functions are shown in green. static void OrangutanSVP::setMode(unsigned char mode) void svp_set_mode(unsigned char mode) This command sets the mode of the Orangutan SVP’s auxiliary processor. The mode parameter determines the functions of the auxiliary lines A, B, C, and D.
Pololu AVR Library Command Reference © 2001–2019 Pololu Corporation Returns 1 if the voltage on the power line of the USB connector is high. This indicates that the device is plugged in to a computer or USB power supply. Returns 0 otherwise. This function is useful if you want your Orangutan to behave differently when it is plugged in to USB (for example, by not running its motors).
Pololu AVR Library Command Reference © 2001–2019 Pololu Corporation × 3 mm or about 100 m. For longer distances, you will need to occasionally reset the counts using the functions below. The counts will be increase if A/C changes before B/D, and decrease if B/D changes before A/C.
Pololu AVR Library Command Reference © 2001–2019 Pololu Corporation 14. Orangutan System Resources This section of the library is intended offers general AVR resources. Currently, it only provides information about the amount of free RAM on the AVR. static unsigned char OrangutanResources::getFreeRAM() unsigned char get_free_ram() Returns an estimate of the available free RAM on the AVR, in bytes.
Pololu AVR Library Command Reference © 2001–2019 Pololu Corporation 15. Orangutan X2 Functions These functions are all commented in the library source code libpololu-avr/src/OrangutanX2/ OrangutanX2.cpp [https://github.com/pololu/libpololu-avr/blob/master/src/OrangutanX2/OrangutanX2.cpp] . 15.
Pololu AVR Library Command Reference © 2001–2019 Pololu Corporation 16. QTR Reflectance Sensors The PololuQTRSensors class and the C functions in this section provide an interface for using Pololu’s QTR reflectance sensors [https://www.pololu.com/product/961] together with the Orangutan. The library provides access to the raw sensors values as well as to high level functions including calibration and line-tracking. We recommend not using this part of the library directly on the 3pi.
Pololu AVR Library Command Reference © 2001–2019 Pololu Corporation For a higher level overview of this library and example programs that show how this library can be used, please see Section 3.k of the Pololu AVR C/C++ Library User’s Guide [https://www.pololu.com/ docs/0J20]. 16.
Pololu AVR Library Command Reference © 2001–2019 Pololu Corporation Reference C++ and methods are shown in red. C functions are shown in green. void PololuQTRSensors::read(unsigned int *sensorValues, unsigned char readMode = QTR_EMITTERS_ON) void qtr_read(unsigned int *sensorValues, unsigned char readMode) Reads the raw sensor values into an array. There MUST be space for as many values as there were sensors specified in the constructor.
Pololu AVR Library Command Reference © 2001–2019 Pololu Corporation or after the reading the sensors will have no effect on the readings, but you may wish to use these for testing purposes. void PololuQTRSensors::calibrate(unsigned char readMode = QTR_EMITTERS_ON) void qtr_calibrate(unsigned char readMode) Reads the sensors for calibration. The sensor values are not returned; instead, the maximum and minimum values found over time are stored internally and used for the readCalibrated() method.
Pololu AVR Library Command Reference © 2001–2019 Pololu Corporation line is light on black, set the optional second argument whiteLine to true. In this case, each sensor value will be replaced by the maximum possible value minus its actual value before the averaging. unsigned int* PololuQTRSensors::calibratedMinimumOn unsigned int* qtr_calibrated_minimum_on() The calibrated minumum values measured for each sensor, with emitters on.
Pololu AVR Library Command Reference © 2001–2019 Pololu Corporation provided by the library. For example, if pins is {IO_D3, IO_D6, IO_C1}, sensor 0 is on PD3, sensor 1 is on PD6, and sensor 2 is on PC1. For ATmegaxx8-based controllers, the pin numbers are Arduino-compatible so you can define the pins array using Arduino pin numbers.
Pololu AVR Library Command Reference © 2001–2019 Pololu Corporation sensor 1 is on analog input 0, sensor 2 is on analog input 1, and sensor 3 is on analog input 7. The ATmegaxx8 has 8 total analog input channels (ADC0 – ADC7) that correspond to port C pins PC0 – PC5 and dedicated analog inputs ADC6 and ADC7. The Orangutan SVP and X2 also have 8 analog input channels (ADC0 – ADC7) but they correspond to port A pins PA0 – PA7.
Pololu AVR Library Command Reference © 2001–2019 Pololu Corporation 17. Timing and Delays The following timing and delay functions are designed for the Orangutans and 3pi robot, which run at 20 MHz. They will give different results at other processor frequencies. These functions are not available within the Arduino environment, which has its own delay functions.
Pololu AVR Library Command Reference © 2001–2019 Pololu Corporation Reference C++ methods are shown in red. C/C++ functions are shown in green. static void OrangutanTime::delayMilliseconds(unsigned int milliseconds) void delay_ms(unsigned int milliseconds) void delay(unsigned int milliseconds) Delays for the specified number of milliseconds.
Pololu AVR Library Command Reference © 2001–2019 Pololu Corporation Returns the number of elapsed ticks (in units of 0.4 µs) since the first time an OrangutanTime function was called. The tick counter is not reset by time_reset(). get_ticks() can be used as a highresolution system timer that will overflow back to zero after approximately 28.6 minutes of counting.
Pololu AVR Library Command Reference © 2001–2019 Pololu Corporation 18. Wheel Encoders The PololuWheelEncoders class and the associated C functions provide an easy interface for using the Pololu Wheel Encoders [https://www.pololu.com/product/1217], which allow a robot to know exactly how far its motors have turned at any point in time. This section of the library makes uses of pin-change interrupts to quickly detect and record each transition on the encoder.
Pololu AVR Library Command Reference © 2001–2019 Pololu Corporation Reference C++ and Arduino methods are shown in red. C functions are shown in green. static void PololuWheelEncoders::init(unsigned char m1a, unsigned char m1b, unsigned char m2a, unsigned char m2b) void encoders_init(unsigned char m1a, unsigned char m1b, unsigned char m2a, unsigned char m2b) Initializes the wheel encoders. The four arguments are the four pins that the wheel encoders are connected to.
Pololu AVR Library Command Reference © 2001–2019 Pololu Corporation 19. 3pi Robot Functions This section of the library provides convenient access for 3pi-specific hardware. Currently, it only provides access for the 5 QTR-based line sensors that are included in the 3pi. That is, the QTR functions described in Section 16 do not need to be used for the 3pi. The functions described below are enabled by including one of the 3pi files: 1 2 #include #include
Pololu AVR Library Command Reference © 2001–2019 Pololu Corporation reading represents ambient light levels near the sensor; IR_EMITTERS_ON specifies that the emitters should be turned on for the reading, which results in a measure of reflectance; and IR_EMITTERS_ON_AND_OFF specifies that a reading should be made in both the on and off states.
Pololu AVR Library Command Reference © 2001–2019 Pololu Corporation unsigned int read_line_white(unsigned int *sensorValues, unsigned char readMode) Operates the same as read calibrated, but with a feature designed for line following: this function returns an estimated position of the line.