Robot Control Library

Description

Functions for reading the PRU-accelerated quadrature encoder counter.

<rc/encoder_pru.h>

This can be used for reading encoder channel 4 on the Robotics Cape and BeagleBone Blue. Channels 1-3 are instead counted with the eQEP hardware encoder counters, see <rc/encoder_eqep.h> to use channels 1-3.

Author
James Strawson
Date
1/31/2018

Functions

int rc_encoder_pru_init (void)
 Initializes the pru encoder counter for channel 4. More...
 
void rc_encoder_pru_cleanup (void)
 Stops the PRU encoder counter and closes file descriptors. This is not strictly necessary but is recommended that the user calls this function at the end of their program. More...
 
int rc_encoder_pru_read (void)
 Reads the current position of encoder channel 4. More...
 
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 arbitrary position if desired. More...
 

Function Documentation

◆ rc_encoder_pru_init()

int rc_encoder_pru_init ( void  )

Initializes the pru encoder counter for channel 4.

This also resets the encoder position to 0 so the first position read is consistent. Note this does NOT initialize the eqep-accelerated encoder counters on channels 1-3. To use channels 1-3 you must use <rc/encoder_eqep.h>

Returns
0 on success or -1 on failure
Examples:
rc_test_encoders_pru.c.

◆ rc_encoder_pru_cleanup()

void rc_encoder_pru_cleanup ( void  )

Stops the PRU encoder counter and closes file descriptors. This is not strictly necessary but is recommended that the user calls this function at the end of their program.

Examples:
rc_test_encoders_pru.c.

◆ rc_encoder_pru_read()

int rc_encoder_pru_read ( void  )

Reads the current position of encoder channel 4.

This is a signed 32-bit integer that wraps around if the position is allowed to read +- 2^31

Returns
The current position (signed 32-bit integer) or -1 and prints an error message is there is a problem.
Examples:
rc_test_encoders_pru.c.

◆ rc_encoder_pru_write()

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 arbitrary position if desired.

Parameters
[in]posThe new position
Returns
0 on success, -1 on failure