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