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
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
unsigned __int16 uint16_t
Definition: rptypes.h:44
bool setRegisterValueAndSpeed(const uint16_t value, const uint8_t servo, const uint16_t speed)
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...
bool checkConnectionAndConnect()
Tries to connect to the USB device (if disconnected).
bool queryFirmwareVersion(std::string &out_firmwareVersion)
Gets the firmware version of the eNeck board.
Definition: CServoeNeck.cpp:46
unsigned int m_NumPrevAngles
Number of previous angles to store for averaging.
Definition: CServoeNeck.h:131
void setNumberOfPreviousAngles(const unsigned int number)
Gets the truncate factor of the turn.
Definition: CServoeNeck.h:107
A USB-interface for a custom "robotic neck" designed at MAPIR lab.
Definition: CServoeNeck.h:22
bool center(const uint8_t servo=0)
Centers the servo at zero position.
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...
std::vector< float > m_offsets
The offset used for each servo.
Definition: CServoeNeck.h:133
unsigned char uint8_t
Definition: rptypes.h:41
#define ASSERT_(f)
Defines an assertion mechanism.
Definition: exceptions.h:113
bool getCurrentAngle(double &angle, const uint8_t servo=0)
Gets the current angle of the servo (in radians within (-pi,pi))
bool disableServo(const uint8_t servo=0)
Disables the servo so the neck will be loose.
bool enableServo(const uint8_t servo=0)
Enables the servo so the neck will be tight.
GLsizei const GLchar ** string
Definition: glext.h:4101
unsigned int getNumberOfPreviousAngles()
Gets the truncate factor of the turn.
Definition: CServoeNeck.h:114
void setOffsets(float offset0, float offset1, float offset2)
Load the Offset values for each servo.
double getTruncateFactor()
Gets the truncate factor of the turn.
Definition: CServoeNeck.h:96
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
void setTruncateFactor(const double factor)
Gets the truncate factor of the turn.
Definition: CServoeNeck.h:99
A definition of a CStream actually representing a USB connection to a FTDI chip.
std::string m_usbSerialNumber
A copy of the device serial number (to open the USB FTDI chip).
Definition: CServoeNeck.h:121
bool getRegisterValue(uint16_t &value, const uint8_t servo=0)
double m_TruncateFactor
The range of turn of the servo will be truncated to "+-m_truncate_factor*(pi/2)". ...
Definition: CServoeNeck.h:126
GLsizei const GLfloat * value
Definition: glext.h:4117
double m_MaxValue
The value set in the ICR register within the ATMEGA16 controller.
Definition: CServoeNeck.h:123
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...
std::deque< double > m_PrevAngles
A vector containing the last N angles which where passed to the servo (for averaging) ...
Definition: CServoeNeck.h:129
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
bool setRegisterValue(const uint16_t value, const uint8_t servo=0, bool fast=false)



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at lun oct 28 00:14:14 CET 2019