Main MRPT website > C++ reference for MRPT 1.9.9
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-2018, 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 
14 #include <mrpt/core/exceptions.h>
15 
16 namespace mrpt
17 {
18 namespace hwdrivers
19 {
20 /** A USB-interface for a custom "robotic neck" designed at MAPIR lab.
21  * \ingroup mrpt_hwdrivers_grp */
23 {
24  public:
25  CServoeNeck();
26  ~CServoeNeck();
27 
28  /** Gets the firmware version of the eNeck board.
29  * \param out_firmwareVersion: [OUTPUT] A string containing the firmware
30  * version.
31  * \return Whether or not the procedure succeded.
32  */
33  bool queryFirmwareVersion(std::string& out_firmwareVersion);
34 
35  /** Gets the current angle of the servo (in radians within (-pi,pi))
36  * \param Angle: [OUT] The current angle.
37  * \param Servo: [IN] The id of the servo (in our ATMEGA16, from 0 to 2).
38  * \return Whether or not the procedure succeded.
39  */
40  bool getCurrentAngle(double& angle, const uint8_t servo = 0);
41 
42  /** Turns the servo up to the specified angle (in radians in the range
43  * -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
46  * 2).
47  * \param Fast: indicates if the servo must reach the angle at maximum
48  * speed
49  * \return Whether or not the procedure succeded.
50  */
51  bool setAngle(double angle, const uint8_t servo = 0, bool fast = false);
52 
53  /** Turns the servo up to the specified angle (in radians in the range
54  * -pi,pi, other values will be saturated to the maximum or the mininum)
55  * \param Angle: the desired angle to turn.
56  * \param Servo: the id of the servo to move (in our ATMEGA16, from 0 to
57  * 2).
58  * \param Speed: indicates the speed of the servo
59  * \return Whether or not the procedure succeded.
60  */
61  bool setAngleAndSpeed(
62  double angle, const uint8_t servo, const uint8_t speed);
63 
64  /** Turns the servo up to the specified angle (in radians in the range
65  * -pi,pi) filtered by average with the last N specified angles.
66  * \param Angle: the new desired angle to turn.
67  * \param Servo: the id of the servo to move (in our ATMEGA16, from 0 to
68  * 2).
69  * \param Fast: indicates if the servo must reach the angle at maximum
70  * speed
71  * \return Whether or not the procedure succeded.
72  */
73  bool setAngleWithFilter(
74  double angle, const uint8_t servo = 0, bool fast = false);
75 
76  /** Disables the servo so the neck will be loose.
77  * \param Servo: the id of the servo to move (in our ATMEGA16, from 0 to
78  * 2).
79  * \return Whether or not the procedure succeded.
80  */
81  bool disableServo(const uint8_t servo = 0);
82 
83  /** Enables the servo so the neck will be tight.
84  * \param Servo: the id of the servo to move (in our ATMEGA16, from 0 to
85  * 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  /** Gets the truncate factor of the turn
98  */
99  void setTruncateFactor(const double factor)
100  {
101  ASSERT_(factor > 0 && factor < 1);
102  m_TruncateFactor = factor;
103  }
104 
105  /** Gets the truncate factor of the turn
106  */
107  void setNumberOfPreviousAngles(const unsigned int number)
108  {
109  m_NumPrevAngles = number;
110  }
111 
112  /** Gets the truncate factor of the turn
113  */
114  unsigned int getNumberOfPreviousAngles() { return m_NumPrevAngles; }
115  /**Load the Offset values for each servo
116  */
117  void setOffsets(float offset0, float offset1, float offset2);
118 
119  protected:
120  /** A copy of the device serial number (to open the USB FTDI chip). */
122  /** The value set in the ICR register within the ATMEGA16 controller. */
123  double m_MaxValue;
124  /** The range of turn of the servo will be truncated to
125  * "+-m_truncate_factor*(pi/2)". */
127  /** A vector containing the last N angles which where passed to the servo
128  * (for averaging) */
129  std::deque<double> m_PrevAngles;
130  /** Number of previous angles to store for averaging */
131  unsigned int m_NumPrevAngles;
132  /** The offset used for each servo */
133  std::vector<float> m_offsets;
134 
135  bool setRegisterValue(
136  const uint16_t value, const uint8_t servo = 0, bool fast = false);
138  const uint16_t value, const uint8_t servo, const uint16_t speed);
139  bool getRegisterValue(uint16_t& value, const uint8_t servo = 0);
140 
141  private:
142  /** Converts from a decimal angle (in radians) to the corresponding register
143  * value for the ATMEGA16 controller (for inner use only).
144  * \param The angle to convert.
145  * \return The value of the register to send.
146  */
147  unsigned int angle2RegValue(const double angle); // Angle in rad
148 
149  /** Converts from a certain value of the ATMEGA16 PWM register to the
150  * corresponding decimal angle (for inner use only).
151  * \param The value to convert.
152  * \return The corresponding angle.
153  */
154  double regValue2angle(const uint16_t value);
155 
156  /** Tries to connect to the USB device (if disconnected).
157  * \return True on connection OK, false on error.
158  */
160 
161 }; // End of class
162 
163 } // namespace hwdrivers
164 
165 } // namespace mrpt
166 
167 #endif
mrpt::hwdrivers::CServoeNeck::checkConnectionAndConnect
bool checkConnectionAndConnect()
Tries to connect to the USB device (if disconnected).
Definition: CServoeNeck.cpp:402
exceptions.h
mrpt::hwdrivers::CServoeNeck
A USB-interface for a custom "robotic neck" designed at MAPIR lab.
Definition: CServoeNeck.h:22
uint16_t
unsigned __int16 uint16_t
Definition: rptypes.h:44
mrpt::hwdrivers::CServoeNeck::m_NumPrevAngles
unsigned int m_NumPrevAngles
Number of previous angles to store for averaging.
Definition: CServoeNeck.h:131
mrpt::hwdrivers::CServoeNeck::queryFirmwareVersion
bool queryFirmwareVersion(std::string &out_firmwareVersion)
Gets the firmware version of the eNeck board.
Definition: CServoeNeck.cpp:46
mrpt::hwdrivers::CServoeNeck::setRegisterValueAndSpeed
bool setRegisterValueAndSpeed(const uint16_t value, const uint8_t servo, const uint16_t speed)
Definition: CServoeNeck.cpp:163
mrpt::hwdrivers::CServoeNeck::angle2RegValue
unsigned int angle2RegValue(const double angle)
Converts from a decimal angle (in radians) to the corresponding register value for the ATMEGA16 contr...
Definition: CServoeNeck.cpp:77
mrpt::hwdrivers::CServoeNeck::center
bool center(const uint8_t servo=0)
Centers the servo at zero position.
Definition: CServoeNeck.cpp:393
mrpt::hwdrivers::CServoeNeck::setAngleWithFilter
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...
Definition: CServoeNeck.cpp:308
mrpt
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Definition: CKalmanFilterCapable.h:30
mrpt::hwdrivers::CServoeNeck::setAngle
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...
Definition: CServoeNeck.cpp:255
uint8_t
unsigned char uint8_t
Definition: rptypes.h:41
ASSERT_
#define ASSERT_(f)
Defines an assertion mechanism.
Definition: exceptions.h:113
mrpt::hwdrivers::CServoeNeck::m_offsets
std::vector< float > m_offsets
The offset used for each servo.
Definition: CServoeNeck.h:133
mrpt::hwdrivers::CServoeNeck::setNumberOfPreviousAngles
void setNumberOfPreviousAngles(const unsigned int number)
Gets the truncate factor of the turn.
Definition: CServoeNeck.h:107
mrpt::hwdrivers::CServoeNeck::disableServo
bool disableServo(const uint8_t servo=0)
Disables the servo so the neck will be loose.
Definition: CServoeNeck.cpp:331
mrpt::comms::CInterfaceFTDI
A definition of a CStream actually representing a USB connection to a FTDI chip.
Definition: CInterfaceFTDI.h:75
mrpt::hwdrivers::CServoeNeck::getCurrentAngle
bool getCurrentAngle(double &angle, const uint8_t servo=0)
Gets the current angle of the servo (in radians within (-pi,pi))
Definition: CServoeNeck.cpp:240
mrpt::hwdrivers::CServoeNeck::setOffsets
void setOffsets(float offset0, float offset1, float offset2)
Load the Offset values for each servo.
Definition: CServoeNeck.cpp:427
CInterfaceFTDI.h
mrpt::hwdrivers::CServoeNeck::m_usbSerialNumber
std::string m_usbSerialNumber
A copy of the device serial number (to open the USB FTDI chip).
Definition: CServoeNeck.h:121
mrpt::hwdrivers::CServoeNeck::getTruncateFactor
double getTruncateFactor()
Gets the truncate factor of the turn.
Definition: CServoeNeck.h:96
mrpt::hwdrivers::CServoeNeck::getNumberOfPreviousAngles
unsigned int getNumberOfPreviousAngles()
Gets the truncate factor of the turn.
Definition: CServoeNeck.h:114
mrpt::hwdrivers::CServoeNeck::setTruncateFactor
void setTruncateFactor(const double factor)
Gets the truncate factor of the turn.
Definition: CServoeNeck.h:99
mrpt::hwdrivers::CServoeNeck::getRegisterValue
bool getRegisterValue(uint16_t &value, const uint8_t servo=0)
Definition: CServoeNeck.cpp:201
mrpt::hwdrivers::CServoeNeck::m_TruncateFactor
double m_TruncateFactor
The range of turn of the servo will be truncated to "+-m_truncate_factor*(pi/2)".
Definition: CServoeNeck.h:126
mrpt::hwdrivers::CServoeNeck::m_MaxValue
double m_MaxValue
The value set in the ICR register within the ATMEGA16 controller.
Definition: CServoeNeck.h:123
mrpt::hwdrivers::CServoeNeck::CServoeNeck
CServoeNeck()
Definition: CServoeNeck.cpp:30
mrpt::hwdrivers::CServoeNeck::enableServo
bool enableServo(const uint8_t servo=0)
Enables the servo so the neck will be tight.
Definition: CServoeNeck.cpp:362
mrpt::hwdrivers::CServoeNeck::~CServoeNeck
~CServoeNeck()
Definition: CServoeNeck.cpp:42
value
GLsizei const GLfloat * value
Definition: glext.h:4117
mrpt::hwdrivers::CServoeNeck::m_PrevAngles
std::deque< double > m_PrevAngles
A vector containing the last N angles which where passed to the servo (for averaging)
Definition: CServoeNeck.h:129
mrpt::hwdrivers::CServoeNeck::setAngleAndSpeed
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...
Definition: CServoeNeck.cpp:285
mrpt::hwdrivers::CServoeNeck::setRegisterValue
bool setRegisterValue(const uint16_t value, const uint8_t servo=0, bool fast=false)
Definition: CServoeNeck.cpp:125
string
GLsizei const GLchar ** string
Definition: glext.h:4101
mrpt::hwdrivers::CServoeNeck::regValue2angle
double regValue2angle(const uint16_t value)
Converts from a certain value of the ATMEGA16 PWM register to the corresponding decimal angle (for in...
Definition: CServoeNeck.cpp:99



Page generated by Doxygen 1.8.17 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at miƩ 12 jul 2023 10:03:34 CEST