Main MRPT website > C++ reference
MRPT logo
CServoeNeck.h
Go to the documentation of this file.
00001 /* +---------------------------------------------------------------------------+
00002    |          The Mobile Robot Programming Toolkit (MRPT) C++ library          |
00003    |                                                                           |
00004    |                       http://www.mrpt.org/                                |
00005    |                                                                           |
00006    |   Copyright (C) 2005-2011  University of Malaga                           |
00007    |                                                                           |
00008    |    This software was written by the Machine Perception and Intelligent    |
00009    |      Robotics Lab, University of Malaga (Spain).                          |
00010    |    Contact: Jose-Luis Blanco  <jlblanco@ctima.uma.es>                     |
00011    |                                                                           |
00012    |  This file is part of the MRPT project.                                   |
00013    |                                                                           |
00014    |     MRPT is free software: you can redistribute it and/or modify          |
00015    |     it under the terms of the GNU General Public License as published by  |
00016    |     the Free Software Foundation, either version 3 of the License, or     |
00017    |     (at your option) any later version.                                   |
00018    |                                                                           |
00019    |   MRPT is distributed in the hope that it will be useful,                 |
00020    |     but WITHOUT ANY WARRANTY; without even the implied warranty of        |
00021    |     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         |
00022    |     GNU General Public License for more details.                          |
00023    |                                                                           |
00024    |     You should have received a copy of the GNU General Public License     |
00025    |     along with MRPT.  If not, see <http://www.gnu.org/licenses/>.         |
00026    |                                                                           |
00027    +---------------------------------------------------------------------------+ */
00028 
00029 #ifndef CServoeNeck_H
00030 #define CServoeNeck_H
00031 
00032 #include <mrpt/utils/utils_defs.h>
00033 #include <mrpt/hwdrivers/link_pragmas.h>
00034 #include <mrpt/hwdrivers/CInterfaceFTDIMessages.h>
00035 
00036 namespace mrpt
00037 {
00038         namespace hwdrivers
00039         {
00040 
00041                 /** A USB-interface for a custom "robotic neck" designed at MAPIR lab.
00042                   * \ingroup mrpt_hwdrivers_grp */
00043                 class HWDRIVERS_IMPEXP CServoeNeck : public hwdrivers::CInterfaceFTDIMessages
00044                 {
00045                 public:
00046                         CServoeNeck();
00047                         ~CServoeNeck();
00048 
00049                         /** Gets the firmware version of the eNeck board.
00050                           * \param out_firmwareVersion: [OUTPUT] A string containing the firmware version.
00051                           * \return Whether or not the procedure succeded.
00052                           */
00053                         bool queryFirmwareVersion( std::string &out_firmwareVersion );                  
00054 
00055                         /** Gets the current angle of the servo (in radians within (-pi,pi))
00056                           * \param Angle: [OUT] The current angle.
00057                           * \param Servo: [IN] The id of the servo (in our ATMEGA16, from 0 to 2).
00058                           * \return Whether or not the procedure succeded.
00059                           */
00060                         bool getCurrentAngle( double &angle, const uint8_t servo = 0 );
00061 
00062                         /** Turns the servo up to the specified angle (in radians in the range -pi,pi, other values will be saturated to the maximum or the mininum)
00063                           * \param Angle: the desired angle to turn.
00064                           * \param Servo: the id of the servo to move (in our ATMEGA16, from 0 to 2).
00065                           * \param Fast: indicates if the servo must reach the angle at maximum speed
00066                           * \return Whether or not the procedure succeded.
00067                           */
00068                         bool setAngle( double angle, const uint8_t servo = 0, bool fast = false );
00069 
00070                         /** Turns the servo up to the specified angle (in radians in the range -pi,pi) filtered by average with the last N specified angles.
00071                           * \param Angle: the new desired angle to turn.
00072                           * \param Servo: the id of the servo to move (in our ATMEGA16, from 0 to 2).
00073                           * \param Fast: indicates if the servo must reach the angle at maximum speed
00074                           * \return Whether or not the procedure succeded.
00075                           */
00076                         bool setAngleWithFilter( double angle, const uint8_t servo = 0, bool fast = false );
00077 
00078                         /** Disables the servo so the neck will be loose.
00079                           * \param Servo: the id of the servo to move (in our ATMEGA16, from 0 to 2).
00080                           * \return Whether or not the procedure succeded.
00081                           */
00082                         bool disableServo( const uint8_t servo = 0 );
00083 
00084                         /** Enables the servo so the neck will be tight.
00085                           * \param Servo: the id of the servo to move (in our ATMEGA16, from 0 to 2).
00086                           * \return Whether or not the procedure succeded.
00087                           */
00088                         bool enableServo( const uint8_t servo = 0 );
00089 
00090                         /** Centers the servo at zero position
00091                           */
00092                         bool center( const uint8_t servo = 0 );
00093 
00094                         /** Gets the truncate factor of the turn
00095                           */
00096                         double getTruncateFactor(){ return m_TruncateFactor; }
00097 
00098                         /** Gets the truncate factor of the turn
00099                           */
00100                         void setTruncateFactor( const double factor ){ ASSERT_( factor > 0 && factor < 1 ); m_TruncateFactor = factor; }
00101 
00102                         /** Gets the truncate factor of the turn
00103                           */
00104                         void setNumberOfPreviousAngles( const unsigned int number ){ m_NumPrevAngles = number; }
00105 
00106                         /** Gets the truncate factor of the turn
00107                           */
00108                         unsigned int getNumberOfPreviousAngles(){ return m_NumPrevAngles; }
00109 
00110                 protected:
00111                         std::string     m_usbSerialNumber;                              //!< A copy of the device serial number (to open the USB FTDI chip).
00112                         double m_MaxValue;                                                      //!< The value set in the ICR register within the ATMEGA16 controller.
00113                         double m_TruncateFactor;                                        //!< The range of turn of the servo will be truncated to "+-m_truncate_factor*(pi/2)".
00114                         std::deque<double> m_PrevAngles;                        //!< A vector containing the last N angles which where passed to the servo (for averaging)
00115                         unsigned int m_NumPrevAngles;                           //!< Number of previous angles to store for averaging
00116 
00117                         bool setRegisterValue( const uint16_t value, const uint8_t servo = 0, bool fast = false );
00118                         bool getRegisterValue( uint16_t &value, const uint8_t servo = 0 );
00119 
00120                 private:
00121                         /** Converts from a decimal angle (in radians) to the corresponding register value for the ATMEGA16 controller (for inner use only).
00122                           * \param The angle to convert.
00123                           * \return The value of the register to send.
00124                           */
00125                         unsigned int angle2RegValue( const double angle );                                              // Angle in rad
00126 
00127                         /** Converts from a certain value of the ATMEGA16 PWM register to the corresponding decimal angle (for inner use only).
00128                           * \param The value to convert.
00129                           * \return The corresponding angle.
00130                           */
00131                         double regValue2angle( const uint16_t value );
00132 
00133                         /** Tries to connect to the USB device (if disconnected).
00134                           * \return True on connection OK, false on error.
00135                           */
00136                         bool checkConnectionAndConnect();
00137 
00138                 };      // End of class
00139 
00140         } // End of namespace
00141 
00142 } // End of namespace
00143 
00144 #endif



Page generated by Doxygen 1.7.5 for MRPT 0.9.5 SVN: at Thu Oct 13 21:25:36 UTC 2011