Driver to use a motor encoder on a supported serial device. More...
#include <encoder_driver.h>
Public Member Functions | |
EncoderDriver (bosch_hardware_interface *hw, uint8_t encoder1_pin, uint8_t encoder2_pin) | |
Constructor: also constructs an encoder object on the serial device itself. | |
EncoderDriver (bosch_hardware_interface *hw, uint8_t encoder_id) | |
Constructor: does not construct a new object on the serial device but uses the one defined by encoder_id. | |
uint8_t | getDeviceAddress (void) |
uint8_t | getEncoderID () |
Getter method to get the encoder id of the object on the connected serial device. | |
int64_t | getPosition () |
Gets the current motor encoder position from the connected hardware device. | |
bool | initialize () |
Initializes the driver and the connected hardware. | |
void | invertOutput () |
Inverts the encoder output. | |
bool | setPosition (int32_t position) |
Sets the current motor encoder position to position. | |
~EncoderDriver () | |
Private Attributes | |
uint8_t | _encoder1_pin |
uint8_t | _encoder2_pin |
uint8_t | _encoder_id |
int32_t | _last_position |
int64_t | _overflow |
int | invert_ |
Driver to use a motor encoder on a supported serial device.
This class enables the user to create an instance of an encoder on the connected serial device itself. The device will keep track of the encoder value using external interrupts if available on the selected pin. To contruct the encoder object the user needs to define two pins to be used by the device. These pins will automatically enable the internal pullup resistor and expect the connected encoder to pull the input to ground or drive in both directions. It is highly recommended to use a pin with external interrupt support at least for encoder1_pin. If not, the encoder object will need to be polled frequently to detect any changes. See http://www.pjrc.com/teensy/td_libs_Encoder.html for more information
Definition at line 64 of file encoder_driver.h.
EncoderDriver::EncoderDriver | ( | bosch_hardware_interface * | hw, |
uint8_t | encoder1_pin, | ||
uint8_t | encoder2_pin | ||
) |
Constructor: also constructs an encoder object on the serial device itself.
hw | defines where the serial device is mounted like /dev/ttyACM0 |
encoder1_pin | first encoder pin on the serial device. This should be a pin supporting external interrupts |
encoder2_pin | second encoder pin on the serial device. |
Definition at line 41 of file encoder_driver.cpp.
EncoderDriver::EncoderDriver | ( | bosch_hardware_interface * | hw, |
uint8_t | encoder_id | ||
) |
Constructor: does not construct a new object on the serial device but uses the one defined by encoder_id.
hw | defines where the serial device is mounted like /dev/ttyACM0 |
Definition at line 81 of file encoder_driver.cpp.
Definition at line 99 of file encoder_driver.cpp.
uint8_t EncoderDriver::getDeviceAddress | ( | void | ) | [virtual] |
Implements bosch_drivers_common::sensor_driver.
Definition at line 118 of file encoder_driver.cpp.
uint8_t EncoderDriver::getEncoderID | ( | ) |
Getter method to get the encoder id of the object on the connected serial device.
Definition at line 145 of file encoder_driver.cpp.
int64_t EncoderDriver::getPosition | ( | ) |
Gets the current motor encoder position from the connected hardware device.
Definition at line 150 of file encoder_driver.cpp.
bool EncoderDriver::initialize | ( | ) |
Initializes the driver and the connected hardware.
Definition at line 124 of file encoder_driver.cpp.
void EncoderDriver::invertOutput | ( | ) |
Inverts the encoder output.
Definition at line 225 of file encoder_driver.cpp.
bool EncoderDriver::setPosition | ( | int32_t | position | ) |
Sets the current motor encoder position to position.
position | the position to set the encoder count to |
Definition at line 195 of file encoder_driver.cpp.
uint8_t EncoderDriver::_encoder1_pin [private] |
Definition at line 126 of file encoder_driver.h.
uint8_t EncoderDriver::_encoder2_pin [private] |
Definition at line 127 of file encoder_driver.h.
uint8_t EncoderDriver::_encoder_id [private] |
Definition at line 128 of file encoder_driver.h.
int32_t EncoderDriver::_last_position [private] |
Definition at line 130 of file encoder_driver.h.
int64_t EncoderDriver::_overflow [private] |
Definition at line 129 of file encoder_driver.h.
int EncoderDriver::invert_ [private] |
Definition at line 131 of file encoder_driver.h.