This repository was archived by the owner on Sep 27, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathservo_ex_cpp.h
63 lines (52 loc) · 1.56 KB
/
servo_ex_cpp.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/**
* @file
* @author John Doe
*
* @defgroup Servo
* @brief Control and communication with smart servos. Provides interfaces for
* setting and getting data, and implements the low-level protocols.
* @ingroup Peripherals
* @{
*/
#ifndef SERVO_EX_CPP_H
#define SERVO_EX_CPP_H
/********************************* Includes **********************************/
#include <stdint.h>
namespace peripherals{
// Constant Declarations
// ----------------------------------------------------------------------------
extern const float MAX_POS;
extern const float MIN_POS;
// Classes and structs
// ----------------------------------------------------------------------------
/**
* @brief Interface for communication with a smart servo
*/
class servo{
public:
/**
* @brief Servo constructor
* @param id Unique identifier for motor, used to address it in commands
*/
servo(uint8_t id) : m_id(id) {}
~servo(){}
/**
* @brief Moves the servo to the specified position
* @param angle The desired angle in degrees (min: MIN_POS, max: MAX_POS)
* @return true if successful, otherwise false
*/
bool set_position(float angle);
/**
* @brief Reads the current position from the servo
* @note The position read is stored in the `last_position` member
*/
void read_position();
float last_position; /**< Last-read position; updated by `read_position` */
private:
const uint8_t m_id; /**< Unique identifier for motor, used to address it */
}
} // end namespace peripherals
/**
* @}
*/
#endif /* SERVO_EX_CPP_H */