Robot Control Library
encoder_pru.h
Go to the documentation of this file.
1 /**
2  * <rc/encoder_pru.h>
3  *
4  * @brief Functions for reading the PRU-accelerated quadrature encoder
5  * counter.
6  *
7  * This can be used for reading encoder channel 4 on the Robotics Cape and
8  * BeagleBone Blue. Channels 1-3 are instead counted with the eQEP hardware
9  * encoder counters, see <rc/encoder_eqep.h> to use channels 1-3.
10  *
11  *
12  * @author James Strawson
13  * @date 1/31/2018
14  *
15  * @addtogroup Encoder_PRU
16  * @ingroup Quadrature_Encoder
17  * @{
18  */
19 
20 #ifndef RC_ENCODER_PRU_H
21 #define RC_ENCODER_PRU_H
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
27 
28 /**
29  * @brief Initializes the pru encoder counter for channel 4
30  *
31  * This also resets the encoder position to 0 so the first position read is
32  * consistent. Note this does NOT initialize the eqep-accelerated encoder
33  * counters on channels 1-3. To use channels 1-3 you must use
34  * <rc/encoder_eqep.h>
35  *
36  * @return 0 on success or -1 on failure
37  */
38 int rc_encoder_pru_init(void);
39 
40 /**
41  * @brief Stops the PRU encoder counter and closes file descriptors. This
42  * is not strictly necessary but is recommended that the user calls this
43  * function at the end of their program.
44  */
45 void rc_encoder_pru_cleanup(void);
46 
47 /**
48  * @brief Reads the current position of encoder channel 4.
49  *
50  * This is a signed 32-bit integer that wraps around if the position is allowed
51  * to read +- 2^31
52  *
53  * @return The current position (signed 32-bit integer) or -1 and prints an
54  * error message is there is a problem.
55  */
56 int rc_encoder_pru_read(void);
57 
58 /**
59  * @brief Sets the current position of encoder channel 4. Usually for
60  * resetting a counter to 0 but can set an arbitrary position if desired.
61  *
62  * @param[in] pos The new position
63  *
64  * @return 0 on success, -1 on failure
65  */
66 int rc_encoder_pru_write(int pos);
67 
68 
69 #ifdef __cplusplus
70 }
71 #endif
72 
73 #endif // RC_ENCODER_PRU_H
74 
75 /** @} end group Encoder_PRU*/
int rc_encoder_pru_write(int pos)
Sets the current position of encoder channel 4. Usually for resetting a counter to 0 but can set an a...
int rc_encoder_pru_init(void)
Initializes the pru encoder counter for channel 4.
int rc_encoder_pru_read(void)
Reads the current position of encoder channel 4.
void rc_encoder_pru_cleanup(void)
Stops the PRU encoder counter and closes file descriptors. This is not strictly necessary but is reco...