Main MRPT website > C++ reference for MRPT 1.4.0
CServoeNeck.h
Go to the documentation of this file.
1/* +---------------------------------------------------------------------------+
2 | Mobile Robot Programming Toolkit (MRPT) |
3 | http://www.mrpt.org/ |
4 | |
5 | Copyright (c) 2005-2016, Individual contributors, see AUTHORS file |
6 | See: http://www.mrpt.org/Authors - All rights reserved. |
7 | Released under BSD License. See details in http://www.mrpt.org/License |
8 +---------------------------------------------------------------------------+ */
9
10#ifndef CServoeNeck_H
11#define CServoeNeck_H
12
16
17namespace mrpt
18{
19 namespace hwdrivers
20 {
21
22 /** A USB-interface for a custom "robotic neck" designed at MAPIR lab.
23 * \ingroup mrpt_hwdrivers_grp */
25 {
26 public:
29
30 /** Gets the firmware version of the eNeck board.
31 * \param out_firmwareVersion: [OUTPUT] A string containing the firmware version.
32 * \return Whether or not the procedure succeded.
33 */
34 bool queryFirmwareVersion( std::string &out_firmwareVersion );
35
36 /** Gets the current angle of the servo (in radians within (-pi,pi))
37 * \param Angle: [OUT] The current angle.
38 * \param Servo: [IN] The id of the servo (in our ATMEGA16, from 0 to 2).
39 * \return Whether or not the procedure succeded.
40 */
41 bool getCurrentAngle( double &angle, const uint8_t servo = 0 );
42
43 /** 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)
44 * \param Angle: the desired angle to turn.
45 * \param Servo: the id of the servo to move (in our ATMEGA16, from 0 to 2).
46 * \param Fast: indicates if the servo must reach the angle at maximum speed
47 * \return Whether or not the procedure succeded.
48 */
49 bool setAngle( double angle, const uint8_t servo = 0, bool fast = false );
50
51 /** 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)
52 * \param Angle: the desired angle to turn.
53 * \param Servo: the id of the servo to move (in our ATMEGA16, from 0 to 2).
54 * \param Speed: indicates the speed of the servo
55 * \return Whether or not the procedure succeded.
56 */
57 bool setAngleAndSpeed( double angle, const uint8_t servo, const uint8_t speed );
58
59 /** Turns the servo up to the specified angle (in radians in the range -pi,pi) filtered by average with the last N specified angles.
60 * \param Angle: the new desired angle to turn.
61 * \param Servo: the id of the servo to move (in our ATMEGA16, from 0 to 2).
62 * \param Fast: indicates if the servo must reach the angle at maximum speed
63 * \return Whether or not the procedure succeded.
64 */
65 bool setAngleWithFilter( double angle, const uint8_t servo = 0, bool fast = false );
66
67 /** Disables the servo so the neck will be loose.
68 * \param Servo: the id of the servo to move (in our ATMEGA16, from 0 to 2).
69 * \return Whether or not the procedure succeded.
70 */
71 bool disableServo( const uint8_t servo = 0 );
72
73 /** Enables the servo so the neck will be tight.
74 * \param Servo: the id of the servo to move (in our ATMEGA16, from 0 to 2).
75 * \return Whether or not the procedure succeded.
76 */
77 bool enableServo( const uint8_t servo = 0 );
78
79 /** Centers the servo at zero position
80 */
81 bool center( const uint8_t servo = 0 );
82
83 /** Gets the truncate factor of the turn
84 */
85 double getTruncateFactor(){ return m_TruncateFactor; }
86
87 /** Gets the truncate factor of the turn
88 */
89 void setTruncateFactor( const double factor ){ ASSERT_( factor > 0 && factor < 1 ); m_TruncateFactor = factor; }
90
91 /** Gets the truncate factor of the turn
92 */
93 void setNumberOfPreviousAngles( const unsigned int number ){ m_NumPrevAngles = number; }
94
95 /** Gets the truncate factor of the turn
96 */
97 unsigned int getNumberOfPreviousAngles(){ return m_NumPrevAngles; }
98
99 /**Load the Offset values for each servo
100 */
101 void setOffsets(float offset0, float offset1, float offset2);
102
103 protected:
104 std::string m_usbSerialNumber; //!< A copy of the device serial number (to open the USB FTDI chip).
105 double m_MaxValue; //!< The value set in the ICR register within the ATMEGA16 controller.
106 double m_TruncateFactor; //!< The range of turn of the servo will be truncated to "+-m_truncate_factor*(pi/2)".
107 std::deque<double> m_PrevAngles; //!< A vector containing the last N angles which where passed to the servo (for averaging)
108 unsigned int m_NumPrevAngles; //!< Number of previous angles to store for averaging
109 std::vector<float> m_offsets; //!< The offset used for each servo
110
111 bool setRegisterValue( const uint16_t value, const uint8_t servo = 0, bool fast = false );
112 bool setRegisterValueAndSpeed( const uint16_t value, const uint8_t servo, const uint16_t speed );
113 bool getRegisterValue( uint16_t &value, const uint8_t servo = 0 );
114
115 private:
116 /** Converts from a decimal angle (in radians) to the corresponding register value for the ATMEGA16 controller (for inner use only).
117 * \param The angle to convert.
118 * \return The value of the register to send.
119 */
120 unsigned int angle2RegValue( const double angle ); // Angle in rad
121
122 /** Converts from a certain value of the ATMEGA16 PWM register to the corresponding decimal angle (for inner use only).
123 * \param The value to convert.
124 * \return The corresponding angle.
125 */
126 double regValue2angle( const uint16_t value );
127
128 /** Tries to connect to the USB device (if disconnected).
129 * \return True on connection OK, false on error.
130 */
132
133 }; // End of class
134
135 } // End of namespace
136
137} // End of namespace
138
139#endif
A definition of a CStream actually representing a USB connection to a FTDI chip.
A USB-interface for a custom "robotic neck" designed at MAPIR lab.
Definition: CServoeNeck.h:25
bool queryFirmwareVersion(std::string &out_firmwareVersion)
Gets the firmware version of the eNeck board.
std::vector< float > m_offsets
The offset used for each servo.
Definition: CServoeNeck.h:109
std::string m_usbSerialNumber
A copy of the device serial number (to open the USB FTDI chip).
Definition: CServoeNeck.h:104
double regValue2angle(const uint16_t value)
Converts from a certain value of the ATMEGA16 PWM register to the corresponding decimal angle (for in...
bool setRegisterValue(const uint16_t value, const uint8_t servo=0, bool fast=false)
bool enableServo(const uint8_t servo=0)
Enables the servo so the neck will be tight.
bool disableServo(const uint8_t servo=0)
Disables the servo so the neck will be loose.
bool setAngle(double angle, const uint8_t servo=0, bool fast=false)
Turns the servo up to the specified angle (in radians in the range -pi,pi, other values will be satur...
double m_MaxValue
The value set in the ICR register within the ATMEGA16 controller.
Definition: CServoeNeck.h:105
unsigned int getNumberOfPreviousAngles()
Gets the truncate factor of the turn.
Definition: CServoeNeck.h:97
bool getCurrentAngle(double &angle, const uint8_t servo=0)
Gets the current angle of the servo (in radians within (-pi,pi))
void setOffsets(float offset0, float offset1, float offset2)
Load the Offset values for each servo.
std::deque< double > m_PrevAngles
A vector containing the last N angles which where passed to the servo (for averaging)
Definition: CServoeNeck.h:107
double getTruncateFactor()
Gets the truncate factor of the turn.
Definition: CServoeNeck.h:85
bool checkConnectionAndConnect()
Tries to connect to the USB device (if disconnected).
void setNumberOfPreviousAngles(const unsigned int number)
Gets the truncate factor of the turn.
Definition: CServoeNeck.h:93
bool center(const uint8_t servo=0)
Centers the servo at zero position.
unsigned int angle2RegValue(const double angle)
Converts from a decimal angle (in radians) to the corresponding register value for the ATMEGA16 contr...
bool setRegisterValueAndSpeed(const uint16_t value, const uint8_t servo, const uint16_t speed)
bool getRegisterValue(uint16_t &value, const uint8_t servo=0)
unsigned int m_NumPrevAngles
Number of previous angles to store for averaging.
Definition: CServoeNeck.h:108
void setTruncateFactor(const double factor)
Gets the truncate factor of the turn.
Definition: CServoeNeck.h:89
double m_TruncateFactor
The range of turn of the servo will be truncated to "+-m_truncate_factor*(pi/2)".
Definition: CServoeNeck.h:106
bool setAngleAndSpeed(double angle, const uint8_t servo, const uint8_t speed)
Turns the servo up to the specified angle (in radians in the range -pi,pi, other values will be satur...
bool setAngleWithFilter(double angle, const uint8_t servo=0, bool fast=false)
Turns the servo up to the specified angle (in radians in the range -pi,pi) filtered by average with t...
#define HWDRIVERS_IMPEXP
#define ASSERT_(f)
Definition: mrpt_macros.h:261
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
unsigned int uint16_t
Definition: pstdint.h:170
unsigned char uint8_t
Definition: pstdint.h:143



Page generated by Doxygen 1.9.6 for MRPT 1.4.0 SVN: at Thu Mar 23 03:22:58 UTC 2023