1
+ /* *
2
+ * @file EncoderClass.h
3
+ * @author Leonardo Cavagnis
4
+ * @brief Header file for the EncoderClass of the Portenta Machine Control.
5
+ *
6
+ * This library provides a class to manage the Quadrature Encoder Interface devices
7
+ * of the Portenta Machine Control. It allows interfacing with two encoders through
8
+ * the QEI (Quadrature Encoder Interface) library and provides methods to access
9
+ * and control each encoder individually.
10
+ */
11
+
12
+ #ifndef __ENCODER_CLASS_H
13
+ #define __ENCODER_CLASS_H
14
+
15
+ /* Includes -------------------------------------------------------------------*/
16
+ #include " utility/QEI/QEI.h"
17
+ #include < Arduino.h>
18
+ #include < mbed.h>
19
+
20
+ /* Class ----------------------------------------------------------------------*/
21
+
22
+ /* *
23
+ * @class EncoderClass
24
+ * @brief Class for managing Quadrature Encoder Interface devices of the Portenta Machine Control.
25
+ */
26
+ class EncoderClass {
27
+ public:
28
+ /* *
29
+ * @brief Construct an EncoderClass object.
30
+ *
31
+ * This constructor initializes the two QEI objects for encoder 0 and encoder 1
32
+ * with the specified pin assignments.
33
+ *
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).
40
+ */
41
+ EncoderClass (PinName enc0_A_pin = PJ_8, PinName enc0_B_pin = PH_12, PinName enc0_I_pin = PH_11,
42
+ PinName enc1_A_pin = PC_13, PinName enc1_B_pin = PI_7, PinName enc1_I_pin = PJ_10);
43
+
44
+ /* *
45
+ * @brief Destruct the EncoderClass object.
46
+ *
47
+ * This destructor releases any resources used by the EncoderClass object.
48
+ */
49
+ ~EncoderClass ();
50
+
51
+ /* *
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.
58
+ */
59
+ QEI& operator [](int index);
60
+
61
+ private:
62
+ QEI enc_0; // QEI object for encoder 0
63
+ QEI enc_1; // QEI object for encoder 1
64
+ };
65
+
66
+ extern EncoderClass MachineControl_Encoders;
67
+
68
+ #endif /* __ENCODER_CLASS_H */
0 commit comments