sc8000.H

Go to the documentation of this file.
00001 /*!@file sc8000.H Interface to a serial-servo-controller
00002  derived from ssc
00003  */
00004 
00005 // //////////////////////////////////////////////////////////////////// //
00006 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2001 by the //
00007 // University of Southern California (USC) and the iLab at USC.         //
00008 // See http://iLab.usc.edu for information about this project.          //
00009 // //////////////////////////////////////////////////////////////////// //
00010 // Major portions of the iLab Neuromorphic Vision Toolkit are protected //
00011 // under the U.S. patent ``Computation of Intrinsic Perceptual Saliency //
00012 // in Visual Environments, and Applications'' by Christof Koch and      //
00013 // Laurent Itti, California Institute of Technology, 2001 (patent       //
00014 // pending; application number 09/912,225 filed July 23, 2001; see      //
00015 // http://pair.uspto.gov/cgi-bin/final/home.pl for current status).     //
00016 // //////////////////////////////////////////////////////////////////// //
00017 // This file is part of the iLab Neuromorphic Vision C++ Toolkit.       //
00018 //                                                                      //
00019 // The iLab Neuromorphic Vision C++ Toolkit is free software; you can   //
00020 // redistribute it and/or modify it under the terms of the GNU General  //
00021 // Public License as published by the Free Software Foundation; either  //
00022 // version 2 of the License, or (at your option) any later version.     //
00023 //                                                                      //
00024 // The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope  //
00025 // that it will be useful, but WITHOUT ANY WARRANTY; without even the   //
00026 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      //
00027 // PURPOSE.  See the GNU General Public License for more details.       //
00028 //                                                                      //
00029 // You should have received a copy of the GNU General Public License    //
00030 // along with the iLab Neuromorphic Vision C++ Toolkit; if not, write   //
00031 // to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,   //
00032 // Boston, MA 02111-1307 USA.                                           //
00033 // //////////////////////////////////////////////////////////////////// //
00034 //
00035 // Primary maintainer for this file: Lior Elazary <elazary@usc.edu>
00036 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Devices/sc8000.H $
00037 // $Id: sc8000.H 6990 2006-08-11 18:13:51Z rjpeters $
00038 //
00039 
00040 #ifndef SC8000_H_DEFINED
00041 #define SC8000_H_DEFINED
00042 
00043 #include "Component/ModelComponent.H"
00044 #include "Component/ModelParam.H"
00045 
00046 class Serial;
00047 
00048 #define SSCNUMSERVOS 8
00049 
00050 //! Interface to a serial-servo-controller
00051 /*! The sc8000.C and sc8000.H files has the sc-8000 controller code that
00052   help control the servos via the controller.  The class is SC8000
00053   class. Its functions include moving a servo to a specified position,
00054   using a serial port. There are two ways to move the servos and thet
00055   their current positions: either using calibrated values in
00056   [-1.0..1.0], or using raw positions in [0..65535]. Calibrated
00057   positions are converted to raw using two linear ramps (one for each
00058   side of the neutral position) that can be set using the calibrate()
00059   function. EXAMPLE: if you do a calibrate(servo, 100, 20, 150), then,
00060   subsequently, move(servo, 0.0F) will be equivalent to moveRaw(servo,
00061   100), move(servo, -1.0F) will be equivalent to moveRaw(servo, 20)
00062   and move(servo, 1.0F) will be equivalent to moveRaw(servo, 150). */
00063 class SC8000 : public ModelComponent
00064 {
00065 public:
00066   //! Default constructor; see ModelComponent.H
00067   SC8000(OptionManager& mgr,
00068       const std::string& descrName = "SC8000 Servo Driver",
00069       const std::string& tagName = "SC8000driver",
00070       const char *defdev = "/dev/ttyUSB0");
00071 
00072   //! Destructor
00073   ~SC8000();
00074 
00075   //! Moves servo # to given position in [-1.0 .. 1.0]
00076   /*! Returns true on success, false if some serial error occurred. */
00077   bool move(const int servo, const float position);
00078 
00079   //! Gets the current position of given servo
00080   float getPosition(const int servo) const;
00081 
00082   //! Calibrate a servo
00083   /*! Calibration will be made so that move(servo, 0.0F) will send the
00084     value 'neutralval' to the servo, move(servo, -1.0F) will send
00085     minval and move(servo, 1.0F) will send maxval. */
00086   void calibrate(const int servo, const short neutralval, const short minval,
00087                  const short maxval);
00088 
00089   //! Moves servo # to given RAW (uncalibrated) position in [0..65535]
00090   /*! Returns true on success, false if some serial error occurred. */
00091   bool moveRaw(const int servo, const short rawpos);
00092 
00093   //! Gets the current RAW (uncalibrated) position [0..65535] of given servo
00094   short getPositionRaw(const int servo) const;
00095 
00096 protected:
00097   nub::soft_ref<Serial> itsPort;   //!< Serial port to use
00098   rutz::shared_ptr<NModelParam<float> > *zero;     //!< zero calibration values
00099   rutz::shared_ptr<NModelParam<float> > *posmult;  //!< positive multiplier calib
00100   rutz::shared_ptr<NModelParam<float> > *negmult;  //!< negative multiplier calib
00101   short *pos;                   //!< raw servo positions [0..65535]
00102 
00103   //! Convert from raw (0..65535) to calibrated (-1.0..1.0) position
00104   float rawToCalib(const int servo, const short rawpos) const;
00105 
00106   //! Convert from calibrated (-1.0..1.0) to raw (0..65535) position
00107   short calibToRaw(const int servo, const float position) const;
00108 };
00109 
00110 #endif
00111 
00112 // ######################################################################
00113 /* So things look consistent in everyone's emacs... */
00114 /* Local Variables: */
00115 /* indent-tabs-mode: nil */
00116 /* End: */
Generated on Sun May 8 08:04:45 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3