Main MRPT website > C++ reference
MRPT logo
CServoeNeck.h
Go to the documentation of this file.
1 /* +---------------------------------------------------------------------------+
2  | The Mobile Robot Programming Toolkit (MRPT) C++ library |
3  | |
4  | http://www.mrpt.org/ |
5  | |
6  | Copyright (C) 2005-2012 University of Malaga |
7  | |
8  | This software was written by the Machine Perception and Intelligent |
9  | Robotics Lab, University of Malaga (Spain). |
10  | Contact: Jose-Luis Blanco <jlblanco@ctima.uma.es> |
11  | |
12  | This file is part of the MRPT project. |
13  | |
14  | MRPT is free software: you can redistribute it and/or modify |
15  | it under the terms of the GNU General Public License as published by |
16  | the Free Software Foundation, either version 3 of the License, or |
17  | (at your option) any later version. |
18  | |
19  | MRPT is distributed in the hope that it will be useful, |
20  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
21  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
22  | GNU General Public License for more details. |
23  | |
24  | You should have received a copy of the GNU General Public License |
25  | along with MRPT. If not, see <http://www.gnu.org/licenses/>. |
26  | |
27  +---------------------------------------------------------------------------+ */
28 
29 #ifndef CServoeNeck_H
30 #define CServoeNeck_H
31 
32 #include <mrpt/utils/utils_defs.h>
35 
36 namespace mrpt
37 {
38  namespace hwdrivers
39  {
40 
41  /** A USB-interface for a custom "robotic neck" designed at MAPIR lab.
42  * \ingroup mrpt_hwdrivers_grp */
44  {
45  public:
46  CServoeNeck();
47  ~CServoeNeck();
48 
49  /** Gets the firmware version of the eNeck board.
50  * \param out_firmwareVersion: [OUTPUT] A string containing the firmware version.
51  * \return Whether or not the procedure succeded.
52  */
53  bool queryFirmwareVersion( std::string &out_firmwareVersion );
54 
55  /** Gets the current angle of the servo (in radians within (-pi,pi))
56  * \param Angle: [OUT] The current angle.
57  * \param Servo: [IN] The id of the servo (in our ATMEGA16, from 0 to 2).
58  * \return Whether or not the procedure succeded.
59  */
60  bool getCurrentAngle( double &angle, const uint8_t servo = 0 );
61 
62  /** 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)
63  * \param Angle: the desired angle to turn.
64  * \param Servo: the id of the servo to move (in our ATMEGA16, from 0 to 2).
65  * \param Fast: indicates if the servo must reach the angle at maximum speed
66  * \return Whether or not the procedure succeded.
67  */
68  bool setAngle( double angle, const uint8_t servo = 0, bool fast = false );
69 
70  /** Turns the servo up to the specified angle (in radians in the range -pi,pi) filtered by average with the last N specified angles.
71  * \param Angle: the new desired angle to turn.
72  * \param Servo: the id of the servo to move (in our ATMEGA16, from 0 to 2).
73  * \param Fast: indicates if the servo must reach the angle at maximum speed
74  * \return Whether or not the procedure succeded.
75  */
76  bool setAngleWithFilter( double angle, const uint8_t servo = 0, bool fast = false );
77 
78  /** Disables the servo so the neck will be loose.
79  * \param Servo: the id of the servo to move (in our ATMEGA16, from 0 to 2).
80  * \return Whether or not the procedure succeded.
81  */
82  bool disableServo( const uint8_t servo = 0 );
83 
84  /** Enables the servo so the neck will be tight.
85  * \param Servo: the id of the servo to move (in our ATMEGA16, from 0 to 2).
86  * \return Whether or not the procedure succeded.
87  */
88  bool enableServo( const uint8_t servo = 0 );
89 
90  /** Centers the servo at zero position
91  */
92  bool center( const uint8_t servo = 0 );
93 
94  /** Gets the truncate factor of the turn
95  */
96  double getTruncateFactor(){ return m_TruncateFactor; }
97 
98  /** Gets the truncate factor of the turn
99  */
100  void setTruncateFactor( const double factor ){ ASSERT_( factor > 0 && factor < 1 ); m_TruncateFactor = factor; }
101 
102  /** Gets the truncate factor of the turn
103  */
104  void setNumberOfPreviousAngles( const unsigned int number ){ m_NumPrevAngles = number; }
105 
106  /** Gets the truncate factor of the turn
107  */
108  unsigned int getNumberOfPreviousAngles(){ return m_NumPrevAngles; }
109 
110  protected:
111  std::string m_usbSerialNumber; //!< A copy of the device serial number (to open the USB FTDI chip).
112  double m_MaxValue; //!< The value set in the ICR register within the ATMEGA16 controller.
113  double m_TruncateFactor; //!< The range of turn of the servo will be truncated to "+-m_truncate_factor*(pi/2)".
114  std::deque<double> m_PrevAngles; //!< A vector containing the last N angles which where passed to the servo (for averaging)
115  unsigned int m_NumPrevAngles; //!< Number of previous angles to store for averaging
116 
117  bool setRegisterValue( const uint16_t value, const uint8_t servo = 0, bool fast = false );
118  bool getRegisterValue( uint16_t &value, const uint8_t servo = 0 );
119 
120  private:
121  /** Converts from a decimal angle (in radians) to the corresponding register value for the ATMEGA16 controller (for inner use only).
122  * \param The angle to convert.
123  * \return The value of the register to send.
124  */
125  unsigned int angle2RegValue( const double angle ); // Angle in rad
126 
127  /** Converts from a certain value of the ATMEGA16 PWM register to the corresponding decimal angle (for inner use only).
128  * \param The value to convert.
129  * \return The corresponding angle.
130  */
131  double regValue2angle( const uint16_t value );
132 
133  /** Tries to connect to the USB device (if disconnected).
134  * \return True on connection OK, false on error.
135  */
136  bool checkConnectionAndConnect();
137 
138  }; // End of class
139 
140  } // End of namespace
141 
142 } // End of namespace
143 
144 #endif



Page generated by Doxygen 1.8.3 for MRPT 0.9.6 SVN: at Fri Feb 15 22:05:02 EST 2013