/********************************************************************** Copyright (C) 2013 SARVESH KULKARNI Associate Professor, ECE Department Villanova University, PA, USA. LEGAL NOTICE: This library is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . ------------------------------------------------------------------------- Header file for the library of routines for controlling analog and digital servomotors using Adafruit's PCA9685 16-channel PWM breakout board. You may use *any* PCA9685 based as long as the correct I2C device address is used. Version 0.3, Released August 2013. You will need the C++ library for PCA9685; get the following file pca9685.o OR Compile the source files pca9685_pwm.h & pca9685_pwm.cc to pca9685.o -------------------------------------------------------------------------- Class for controlling Servomotors Typical Wire Connections on Servo motors: (please cross-check!) (+V) : Red (GND) : Black or Brown (PWM) : Orange or White *********************************************************************/ #ifndef _Servo #define _Servo #include #include "pca9685_pwm.h" // ------ Class Specific Constants ------------------------------- #define DEFAULT_FREQ 50 // Most servos need 50 Hz updates #define MAXFREQ 60 // Restrict update freq for servos // ------ Class Specific Error Codes -------------------- #define FREQ_ILLEGAL -20 // Illegal frequency, or any other generic // error in reading the set frequency #define POSITIONING_ERR -21 // Could not position servo shaft #define SLEEP_ERR -22 // Could not turn off the pwm channel class Servo { public: Servo(float range, float pcycle, float minpulse, float maxpulse, PWM_Board& pwm, unsigned int ch_num, float freq = DEFAULT_FREQ); ~Servo(){}; int setPosition(float angle, PWM_Board& pwm); float getPosition(void); int center(PWM_Board& pwm); //centers the servo shaft between its left // extreme and right extreme excursions int sleep(PWM_Board& pwm); // turns off pwm output on channel private: float s_range; // full angular range (deg) float s_angle; // current angle of the shaft (deg) float s_pcycle, s_minpulse, s_maxpulse; // pulse & cycle widths (usecs) unsigned int pwm_channel; // PCA9685's channel driving this servo }; #endif