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://mrpt.sourceforge.net/                            |
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                 class HWDRIVERS_IMPEXP CServoeNeck : public hwdrivers::CInterfaceFTDIMessages
00041                 {
00042                 public:
00043                         CServoeNeck();
00044                         ~CServoeNeck();
00045 
00046                         /** Gets the firmware version of the eNeck board.
00047                           * \param out_firmwareVersion: [OUTPUT] A string containing the firmware version.
00048                           * \return Whether or not the procedure succeded.
00049                           */
00050                         bool queryFirmwareVersion( std::string &out_firmwareVersion );                  
00051 
00052                         /** Gets the current angle of the servo (in radians within (-pi,pi))
00053                           * \param Angle: [OUT] The current angle.
00054                           * \param Servo: [IN] The id of the servo (in our ATMEGA16, from 0 to 2).
00055                           * \return Whether or not the procedure succeded.
00056                           */
00057                         bool getCurrentAngle( double &angle, const uint8_t servo = 0 );
00058 
00059                         /** 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)
00060                           * \param Angle: the desired angle to turn.
00061                           * \param Servo: the id of the servo to move (in our ATMEGA16, from 0 to 2).
00062                           * \param Fast: indicates if the servo must reach the angle at maximum speed
00063                           * \return Whether or not the procedure succeded.
00064                           */
00065                         bool setAngle( double angle, const uint8_t servo = 0, bool fast = false );
00066 
00067                         /** Turns the servo up to the specified angle (in radians in the range -pi,pi) filtered by average with the last N specified angles.
00068                           * \param Angle: the new desired angle to turn.
00069                           * \param Servo: the id of the servo to move (in our ATMEGA16, from 0 to 2).
00070                           * \param Fast: indicates if the servo must reach the angle at maximum speed
00071                           * \return Whether or not the procedure succeded.
00072                           */
00073                         bool setAngleWithFilter( double angle, const uint8_t servo = 0, bool fast = false );
00074 
00075                         /** Disables the servo so the neck will be loose.
00076                           * \param Servo: the id of the servo to move (in our ATMEGA16, from 0 to 2).
00077                           * \return Whether or not the procedure succeded.
00078                           */
00079                         bool disableServo( const uint8_t servo = 0 );
00080 
00081                         /** Enables the servo so the neck will be tight.
00082                           * \param Servo: the id of the servo to move (in our ATMEGA16, from 0 to 2).
00083                           * \return Whether or not the procedure succeded.
00084                           */
00085                         bool enableServo( const uint8_t servo = 0 );
00086 
00087                         /** Centers the servo at zero position
00088                           */
00089                         bool center( const uint8_t servo = 0 );
00090 
00091                         /** Gets the truncate factor of the turn
00092                           */
00093                         double getTruncateFactor(){ return m_TruncateFactor; }
00094 
00095                         /** Gets the truncate factor of the turn
00096                           */
00097                         void setTruncateFactor( const double factor ){ ASSERT_( factor > 0 && factor < 1 ); m_TruncateFactor = factor; }
00098 
00099                         /** Gets the truncate factor of the turn
00100                           */
00101                         void setNumberOfPreviousAngles( const unsigned int number ){ m_NumPrevAngles = number; }
00102 
00103                         /** Gets the truncate factor of the turn
00104                           */
00105                         unsigned int getNumberOfPreviousAngles(){ return m_NumPrevAngles; }
00106 
00107                 protected:
00108                         std::string     m_usbSerialNumber;                              //!< A copy of the device serial number (to open the USB FTDI chip).
00109                         double m_MaxValue;                                                      //!< The value set in the ICR register within the ATMEGA16 controller.
00110                         double m_TruncateFactor;                                        //!< The range of turn of the servo will be truncated to "+-m_truncate_factor*(pi/2)".
00111                         std::deque<double> m_PrevAngles;                        //!< A vector containing the last N angles which where passed to the servo (for averaging)
00112                         unsigned int m_NumPrevAngles;                           //!< Number of previous angles to store for averaging
00113 
00114                         bool setRegisterValue( const uint16_t value, const uint8_t servo = 0, bool fast = false );
00115                         bool getRegisterValue( uint16_t &value, const uint8_t servo = 0 );
00116 
00117                 private:
00118                         /** Converts from a decimal angle (in radians) to the corresponding register value for the ATMEGA16 controller (for inner use only).
00119                           * \param The angle to convert.
00120                           * \return The value of the register to send.
00121                           */
00122                         unsigned int angle2RegValue( const double angle );                                              // Angle in rad
00123 
00124                         /** Converts from a certain value of the ATMEGA16 PWM register to the corresponding decimal angle (for inner use only).
00125                           * \param The value to convert.
00126                           * \return The corresponding angle.
00127                           */
00128                         double regValue2angle( const uint16_t value );
00129 
00130                         /** Tries to connect to the USB device (if disconnected).
00131                           * \return True on connection OK, false on error.
00132                           */
00133                         bool checkConnectionAndConnect();
00134 
00135                 };      // End of class
00136 
00137         } // End of namespace
00138 
00139 } // End of namespace
00140 
00141 #endif



Page generated by Doxygen 1.7.3 for MRPT 0.9.4 SVN: at Sat Mar 26 06:40:17 UTC 2011