1
1
/* *
2
2
* @file EncoderClass.h
3
3
* @author Leonardo Cavagnis
4
- * @brief Header file for the EncoderClass of the Portenta Machine Control.
4
+ * @brief Header file for the encoder module of the Portenta Machine Control.
5
5
*
6
6
* This library provides a class to manage the Quadrature Encoder Interface devices
7
7
* of the Portenta Machine Control. It allows interfacing with two encoders through
22
22
/* *
23
23
* @class EncoderClass
24
24
* @brief Class for managing Quadrature Encoder Interface devices of the Portenta Machine Control.
25
+ *
26
+ * This class provides methods to interact with two quadrature encoders. Each encoder
27
+ * has two channels (A and B) for quadrature signals and an index channel. The class
28
+ * allows reading the current state, pulses, and revolutions of each encoder.
25
29
*/
26
30
class EncoderClass {
27
31
public:
@@ -31,12 +35,12 @@ class EncoderClass {
31
35
* This constructor initializes the two QEI objects for encoder 0 and encoder 1
32
36
* with the specified pin assignments.
33
37
*
34
- * @param enc0_A_pin Pin assignment for encoder 0 channel A (default: PA_0 ).
35
- * @param enc0_B_pin Pin assignment for encoder 0 channel B (default: PB_0 ).
36
- * @param enc0_I_pin Pin assignment for encoder 0 Index channel (default: PC_0 ).
37
- * @param enc1_A_pin Pin assignment for encoder 1 channel A (default: PD_0 ).
38
- * @param enc1_B_pin Pin assignment for encoder 1 channel B (default: PE_0 ).
39
- * @param enc1_I_pin Pin assignment for encoder 1 Index channel (default: PF_0 ).
38
+ * @param enc0_A_pin Pin assignment for encoder 0 channel A (default: PJ_8 ).
39
+ * @param enc0_B_pin Pin assignment for encoder 0 channel B (default: PH_12 ).
40
+ * @param enc0_I_pin Pin assignment for encoder 0 Index channel (default: PH_11 ).
41
+ * @param enc1_A_pin Pin assignment for encoder 1 channel A (default: PC_13 ).
42
+ * @param enc1_B_pin Pin assignment for encoder 1 channel B (default: PI_7 ).
43
+ * @param enc1_I_pin Pin assignment for encoder 1 Index channel (default: PJ_10 ).
40
44
*/
41
45
EncoderClass (PinName enc0_A_pin = PJ_8, PinName enc0_B_pin = PH_12, PinName enc0_I_pin = PH_11,
42
46
PinName enc1_A_pin = PC_13, PinName enc1_B_pin = PI_7, PinName enc1_I_pin = PJ_10);
@@ -49,14 +53,45 @@ class EncoderClass {
49
53
~EncoderClass ();
50
54
51
55
/* *
52
- * @brief Get the QEI object for the specified encoder index.
53
- *
54
- * This method returns a reference to the QEI object for the specified encoder index.
55
- *
56
- * @param index The index for selecting the encoder (0 or 1).
57
- * @return A reference to the corresponding QEI object.
56
+ * @brief Reset the encoder counter for the specified channel.
57
+ *
58
+ * @param channel The encoder channel (0 or 1) to reset.
59
+ */
60
+ void reset (int channel);
61
+
62
+ /* *
63
+ * @brief Get the current state of the specified encoder channel.
64
+ *
65
+ * The current state is the value of the encoder counter.
66
+ *
67
+ * @param channel The encoder channel (0 or 1) to read the state from.
68
+ * @return The current state of the encoder channel as a 2-bit number, where:
69
+ * bit 0 = The reading from channel B
70
+ * bit 1 = The reading from channel A
71
+ */
72
+ int getCurrentState (int channel);
73
+
74
+ /* *
75
+ * @brief Get the number of pulses counted by the specified encoder channel.
76
+ *
77
+ * This method returns the number of pulses counted by the encoder. Each pulse
78
+ * corresponds to a change in the encoder's quadrature signal.
79
+ *
80
+ * @param channel The encoder channel (0 or 1) to read the pulses from.
81
+ * @return The number of pulses counted by the encoder channel.
82
+ */
83
+ int getPulses (int channel);
84
+
85
+ /* *
86
+ * @brief Get the number of revolutions counted by the specified encoder channel.
87
+ *
88
+ * This method returns the number of full revolutions counted by the encoder.
89
+ * It utilizes the index channel to track revolutions.
90
+ *
91
+ * @param channel The encoder channel (0 or 1) to read the revolutions from.
92
+ * @return The number of revolutions counted by the encoder channel.
58
93
*/
59
- QEI& operator [] (int index );
94
+ int getRevolutions (int channel );
60
95
61
96
private:
62
97
QEI _enc0; // QEI object for encoder 0
0 commit comments