My favorites | Sign in
Project Home Downloads Issues
Search
for
LibraryDocumentation  
How do I use this?
Updated Oct 15, 2010 by MFergs7@gmail.com

These libraries were developed for the ArbotiX and MINI robocontrollers, but can be used on most Arduinos.

Commander

Documentation for the Commander library is in the Commander product manual.

EncodersAB

The EncodersAB library will decode 2 pairs of quadrature signals using a set of interrupts. The library works with either the ArbotiX or the MINI. There is no need to create an instance of the library, it is automatically created by the system, named Encoders. The left & right count are long integers, but they could overrun if not read and cleared often enough.

/* This sketch will print encoder values every 5s, showing how 
far the wheel has moved in the 5s interval -- the motors are 
not running though, just move it with your hand. */
#include <EncodersAB.h>

void setup(){
    Encoders.begin();
    Serial.begin(38400);
    Serial.println("Encoder Test!");
}

void loop(){
    delay(5000);
    Serial.print("L:");
    Serial.print(Encoders.left);     // get the left side value
    Serial.print(" R:");
    Serial.println(Encoders.right);  // and right side
    Encoders.reset();                // set left & right both to 0
}

Note that on the ArbotiX, the interrupt handlers are on a multiplexed channel, and thus are somewhat long -- maximum count frequency is therefore limited.

EncodersCD

The EncodersCD library will count 2 pairs of clock and direction signals using a set of interrupts. The library works with either the ArbotiX or the MINI. This library is preferred over the EncodersAB if you have external hardware quadrature decoding (such as found on the Nubotics encoders), as it runs much faster.

There is no need to create an instance of the library, it is automatically created by the system, named Encoders. The left & right count are long integers, but they could overrun if not read and cleared often enough.

Coming Soon

HServo

The HServo library is basically a repackaged version of the old hardware-only Servo library. If your ArbotiX/MINI is heavily loaded, you may find that the new software-extended Serial library causes glitches. This library will allow you to control servos without glitches -- however it is limited to only 2 servos, instead of the 12 that the new Servo library can do. The interface is the same as the Servo library.

Motors, Motors2, BigMotors

These libraries all implement various forms of dual motor control. Motors can be used to control the onboard motor driver on the MINI, Motors2 is for the ArbotiX, and BigMotors is for attached a larger 30A motor driver to the ArbotiX. All have the same set of functions:

void left(int pwm) - set the left motor speed.
void right(int pwm) - set the right motor speed.
void set(int lpwm, int rpwm) - set the left and right motor speeds at the same time.

Motor speeds are between -255 and 255. -255 is full reverse, 0 is stopped, and 255 is full speed forward. In addition to the above, BigMotors also implements braking:

void brakeLeft(int pwm);
void brakeRight(int pwm);

Here, pwm is between 0 and 255, and represents the amount of braking to be applied. The following short example shows how to use the libraries:

#include <Motors.h>

Motors drive = Motors();

void setup(){
    drive.set(-255,-255); // drive backwards at full speed 
    delay(1000);

    drive.set(0,0); // stop
    delay(1000);

    drive.set(100,100); // drive forward at half speed
    delay(1000);

    drive.left(0); // stop the left motor, turn in place
    delay(500);    
    drive.right(50); // cut right motor speed in half
    delay(500)
    drive.right(0); // and stop
}

void loop(){
    
}

SharpIR

This library allows easy usage of a number of Sharp IR ranging sensors. Each IR ranger uses on analog pin. The library function getData() converts the analog voltage into a distance in centimeters. The library function getSmoothData() takes multiple readings from the analog port and may yield better results when the sensor power supply is noisy.

When creating a our SharpIR object, we need to pass both the type of sensor connected, and which analog pin it is connected to. The analog pins are numbered 0-5 (or 0-7 on the arbotiX). The valid types are:

  • GP2D12 - The original analog IR ranger in the Sharp family of sensors. Mid range sensor, 4"-32" range. Use this for sensors marked as GP2D12 or GP2Y0A21YK (which is a newer ROHS version).
  • GP2D120 - Short range sensor, 1.5"-12" range.
  • GP2Y0A02YK - Long range sensor, 8"-60" range.

It is important to select the correct sensors type, or the conversion will be incorrect and you will receive incorrect and useless range data.

#include <SharpIR.h>

// To create an object, we need to pass both the type, and the analog pin being used
SharpIR myIR = SharpIR(GP2D120,0);

void setup(){
    Serial.begin(38400);
}

// print distance in CM, every second
void loop(){		
    Serial.println(myIR.getData());
    delay(1000);	
}

Srf05

This library allows easy usage of an SRF-05 sonar ranger, in single-pin mode. The SRF-05 does no on-board conversion of the pulse width to length, that is the primary purpose of this library. getData() sends out a ping, reads the return pulse, and then returns the distance in centimeters to the nearest object. Note: getData() should not be called faster than ~20-30Hz, to allow for ring-down time on the sonar.

#include <Srf05.h>

// attach an SRF-05 to digital pin 5. Be sure that it is setup for single pin mode.
Srf05 mySonar = Srf05(5);  

void setup(){
    Serial.begin(38400);
}

// print distance in CM, every second. 
void loop(){  
    Serial.println(mySonar.getData());
    delay(1000);
}

Srf02/08

This library allows the use of Srf-02 and Srf-08 I2C-based sonar ranging sensors. The constructor to create an Srf08 object is: Srf08(deviceID), where deviceID is the the offset for the particular sonar ranger you want to connect to, the default is 0. To take a reading, call ping(), and then call getData() after a sufficient amount of time (50-65ms).

// This is a simple example of how to use the Srf08 library
#include <Wire.h>
#include <Srf08.h>

// Create an instance of Srf08, constructor is Srf08(deviceID)
Srf08 sonar = Srf08(0);

void setup(){	  // this is called once
    Wire.begin(); // this is needed to start the I2C bus
    Serial.begin(38400);
    sonar.ping();
}

void loop(){      // this will print the sensor distance in CM, every 2sec.
    sonar.ping();
    delay(50);    
    Serial.print(sonar.getData());
	delay(1950);
}

Tpa81

This library will take readings from a Devantech Tpa-81 Thermopile, an advanced I2C sensor. To get a reading, call getData(char8 pixels) on your Tpa81 object. This will return an integer value for the ambient temperature, and will fill pixels with the 8 individual readings.

// This is a simple example of how to use the TPA81 library
#include <Wire.h>
#include <Tpa81.h>

// Create an instance of Tpa81, constructor is Tpa81(deviceID)
Tpa81 thermo = Tpa81(0);

void setup(){     // this is called once
  Wire.begin();   // this must be called to start the I2C bus
  Serial.begin(38400);
}

void loop(){      // print a reading every 2 seconds
  int i;
  unsigned char reading[8];

  // query the sensor
  i = thermo.getData(reading);
    
  // send up data to PC like "AMBIENT: p1, p2.... p8.\n"
  Serial.print(i);    // print the ambient temperature;
  Serial.print(": ");
  Serial.print((int)reading[0]);
  for(i=1;i<8;i++){
    Serial.print(",");
    Serial.print((int)reading[i]);
  }
  Serial.println(".");
  delay(2000);	
}

Sign in to add a comment
Powered by Google Project Hosting