Arduino Robot Abstraction Libraries
We will be releasing our Arduino Robot Abstraction libraries under a Creative Commons Attribution-Noncommercial 3.0 Unported license.
The libraries will be divided into Sensor, Actuator, Device and Control classes.
These classes are made available to you in the Arduino 0018 environment by adding Encoder, Motor, Camera, and Robot packages to the arduino-0018/hardware/libraries folder. Below Sensor, Actuator, and Device examples are shown.
Sensor
Encoder
There are four encoders on the robot. Two per each side gives a quadrature output such as above. These sensors are connected to the A0-A4 (14-17) pins on the microcontroller. Quadrature encoding allows for determination of speed and direction of each motor. Encoder.revolutions(int) operates using a polling technique at the moment and does not make use of interrupts. class Encoder { public: Encoder(); Encoder(int pin); void count(int num); void revolutions(int num); private: int _pin; int getValue(); };
Actuator
Motor The Motor class is pretty straight forward, it will allow you to change the rate or speed of each motor. One PWM signal makes use of the analogWrite(pin) and the other signal is kept low with a digitalWrite(pin) both functions provided in the Arduino Environment. Pins 5 and 6 are used for the right side while 9 and 10 are used for the left. These are all analogWrite outputs (PWM capable). class Motor { public: Motor(); Motor(int pwm1, int pwm2); Motor(int pwm1, int pwm2, int rate); void rate(int val); void drive(boolean _direction); void stop(); private: int _pwm1; int _pwm2; int _rate; };
Device
Camera This class is designed to control a pan-tilt camera. Servo max and min values must be determined to not force the motors into a degree in which the motors jam. The move functions take a percentage and convert that to the proper servo value between Min and Max. #define HORIZMAX 170 #define HORIZMIN 10 class Camera { public: Camera(); Camera(int vertPin, int horizPin); void move(int vertPercent, int horizPercent); void moveVert(int percent); int moveHoriz(int percent); int getVert(); int getHoriz(); private: int vertPercent; int horizPercent; int vertPin; int horizPin; MegaServo servo[2]; }; Robot
The robot class allows you to make use of differential steering. Currently a turn function is not implemented which would allow you to steer the robot at a specified degree from 0 - 180. Currently the constructor requires an encoder sensor to allow each forward, reverse, spinRight, spinLeft function to operate until a certain revolutions count is met. class Robot { public: Robot(); Robot(int pwm1, int pwm2, int pwm3, int pwm4, int encoderPin); void rate(int val); void forward(int length); void reverse(int length); void stop(); void spinRight(int val); void spinLeft(int val); private: Motor _left; Motor _right; Encoder _sensor; int _rate; }; We hope to provide more advanced control functions not only in these libraries for the base processor but for different add-on processors as well. Please let us know if you have any issues or suggestions on how to make these libraries better.