Public Member Functions | Private Attributes
EncoderDriver Class Reference

Driver to use a motor encoder on a supported serial device. More...

#include <encoder_driver.h>

Inheritance diagram for EncoderDriver:
Inheritance graph
[legend]

List of all members.

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_

Detailed Description

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.


Constructor & Destructor Documentation

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.

Note:
the maximum number of encoder objects is limited to 16 even after destruction of objects
Parameters:
hwdefines where the serial device is mounted like /dev/ttyACM0
encoder1_pinfirst encoder pin on the serial device. This should be a pin supporting external interrupts
encoder2_pinsecond 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.

Parameters:
hwdefines 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.


Member Function Documentation

uint8_t EncoderDriver::getDeviceAddress ( void  ) [virtual]

Implements bosch_drivers_common::sensor_driver.

Definition at line 118 of file encoder_driver.cpp.

Getter method to get the encoder id of the object on the connected serial device.

Returns:
encoder id on the serial device [0..15]

Definition at line 145 of file encoder_driver.cpp.

Gets the current motor encoder position from the connected hardware device.

Note:
Make sure to call getPosition at least every 1 billion encoder ticks for the connected hardware works with a int32_t. An overflow is handles by this function
Returns:
latest encoder position in encoder ticks

Definition at line 150 of file encoder_driver.cpp.

Initializes the driver and the connected hardware.

Returns:
a boolean indicating success

Definition at line 124 of file encoder_driver.cpp.

Inverts the encoder output.

Todo:
this should not be neccessary and should be possible by changing the encoder pins, but it does not work :(

Definition at line 225 of file encoder_driver.cpp.

bool EncoderDriver::setPosition ( int32_t  position)

Sets the current motor encoder position to position.

Parameters:
positionthe position to set the encoder count to
Returns:
true if encoder write was successful or false if not

Definition at line 195 of file encoder_driver.cpp.


Member Data Documentation

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.


The documentation for this class was generated from the following files:


encoder_driver
Author(s): Kai Franke
autogenerated on Mon Oct 6 2014 10:10:43