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::hwdrivers
17 {
18 /** A USB-interface for a custom "robotic neck" designed at MAPIR lab.
19  * \ingroup mrpt_hwdrivers_grp */
21 {
22  public:
23  CServoeNeck();
24  ~CServoeNeck();
25 
26  /** Gets the firmware version of the eNeck board.
27  * \param out_firmwareVersion: [OUTPUT] A string containing the firmware
28  * version.
29  * \return Whether or not the procedure succeded.
30  */
31  bool queryFirmwareVersion(std::string& out_firmwareVersion);
32 
33  /** Gets the current angle of the servo (in radians within (-pi,pi))
34  * \param Angle: [OUT] The current angle.
35  * \param Servo: [IN] The id of the servo (in our ATMEGA16, from 0 to 2).
36  * \return Whether or not the procedure succeded.
37  */
38  bool getCurrentAngle(double& angle, const uint8_t servo = 0);
39 
40  /** Turns the servo up to the specified angle (in radians in the range
41  * -pi,pi, other values will be saturated to the maximum or the mininum)
42  * \param Angle: the desired angle to turn.
43  * \param Servo: the id of the servo to move (in our ATMEGA16, from 0 to
44  * 2).
45  * \param Fast: indicates if the servo must reach the angle at maximum
46  * 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
52  * -pi,pi, other values will be saturated to the maximum or the mininum)
53  * \param Angle: the desired angle to turn.
54  * \param Servo: the id of the servo to move (in our ATMEGA16, from 0 to
55  * 2).
56  * \param Speed: indicates the speed of the servo
57  * \return Whether or not the procedure succeded.
58  */
59  bool setAngleAndSpeed(
60  double angle, const uint8_t servo, const uint8_t speed);
61 
62  /** Turns the servo up to the specified angle (in radians in the range
63  * -pi,pi) filtered by average with the last N specified angles.
64  * \param Angle: the new desired angle to turn.
65  * \param Servo: the id of the servo to move (in our ATMEGA16, from 0 to
66  * 2).
67  * \param Fast: indicates if the servo must reach the angle at maximum
68  * speed
69  * \return Whether or not the procedure succeded.
70  */
71  bool setAngleWithFilter(
72  double angle, const uint8_t servo = 0, bool fast = false);
73 
74  /** Disables the servo so the neck will be loose.
75  * \param Servo: the id of the servo to move (in our ATMEGA16, from 0 to
76  * 2).
77  * \return Whether or not the procedure succeded.
78  */
79  bool disableServo(const uint8_t servo = 0);
80 
81  /** Enables the servo so the neck will be tight.
82  * \param Servo: the id of the servo to move (in our ATMEGA16, from 0 to
83  * 2).
84  * \return Whether or not the procedure succeded.
85  */
86  bool enableServo(const uint8_t servo = 0);
87 
88  /** Centers the servo at zero position
89  */
90  bool center(const uint8_t servo = 0);
91 
92  /** Gets the truncate factor of the turn
93  */
94  double getTruncateFactor() { return m_TruncateFactor; }
95  /** Gets the truncate factor of the turn
96  */
97  void setTruncateFactor(const double factor)
98  {
99  ASSERT_(factor > 0 && factor < 1);
100  m_TruncateFactor = factor;
101  }
102 
103  /** Gets the truncate factor of the turn
104  */
105  void setNumberOfPreviousAngles(const unsigned int number)
106  {
107  m_NumPrevAngles = number;
108  }
109 
110  /** Gets the truncate factor of the turn
111  */
112  unsigned int getNumberOfPreviousAngles() { return m_NumPrevAngles; }
113  /**Load the Offset values for each servo
114  */
115  void setOffsets(float offset0, float offset1, float offset2);
116 
117  protected:
118  /** A copy of the device serial number (to open the USB FTDI chip). */
120  /** The value set in the ICR register within the ATMEGA16 controller. */
121  double m_MaxValue;
122  /** The range of turn of the servo will be truncated to
123  * "+-m_truncate_factor*(pi/2)". */
125  /** A vector containing the last N angles which where passed to the servo
126  * (for averaging) */
127  std::deque<double> m_PrevAngles;
128  /** Number of previous angles to store for averaging */
129  unsigned int m_NumPrevAngles;
130  /** The offset used for each servo */
131  std::vector<float> m_offsets;
132 
133  bool setRegisterValue(
134  const uint16_t value, const uint8_t servo = 0, bool fast = false);
136  const uint16_t value, const uint8_t servo, const uint16_t speed);
137  bool getRegisterValue(uint16_t& value, const uint8_t servo = 0);
138 
139  private:
140  /** Converts from a decimal angle (in radians) to the corresponding register
141  * value for the ATMEGA16 controller (for inner use only).
142  * \param The angle to convert.
143  * \return The value of the register to send.
144  */
145  unsigned int angle2RegValue(const double angle); // Angle in rad
146 
147  /** Converts from a certain value of the ATMEGA16 PWM register to the
148  * corresponding decimal angle (for inner use only).
149  * \param The value to convert.
150  * \return The corresponding angle.
151  */
152  double regValue2angle(const uint16_t value);
153 
154  /** Tries to connect to the USB device (if disconnected).
155  * \return True on connection OK, false on error.
156  */
158 
159 }; // End of class
160 
161 }
162 #endif
163 
164 
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
Contains classes for various device interfaces.
unsigned int m_NumPrevAngles
Number of previous angles to store for averaging.
Definition: CServoeNeck.h:129
void setNumberOfPreviousAngles(const unsigned int number)
Gets the truncate factor of the turn.
Definition: CServoeNeck.h:105
A USB-interface for a custom "robotic neck" designed at MAPIR lab.
Definition: CServoeNeck.h:20
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:131
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:112
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:94
void setTruncateFactor(const double factor)
Gets the truncate factor of the turn.
Definition: CServoeNeck.h:97
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:119
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:124
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:121
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:127
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: 7d5e6d718 Fri Aug 24 01:51:28 2018 +0200 at lun nov 2 08:35:50 CET 2020