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