class for communicating with the firmware on a Byte Sized Encoder Decoder board
More...
#include <byte-sized-encoder-decoder.h>
|
| | ByteSizedEncoderDecoder (TwoWire *_wire, uint8_t _address=14, int16_t _encoderSlowestInterval=0, int16_t _encoderEnoughCounts=0) |
| | Constructor for the Byte Sized Encoder Decoder class.
|
| |
| void | setEncoderSlowestInterval (uint8_t n, int16_t interval) |
| | set the value of encoderSlowestInterval
|
| |
| void | setEncoderEnoughCounts (uint8_t n, int16_t counts) |
| | set the value of encoderEnoughCounts
|
| |
| boolean | isVelNew (uint8_t n) |
| | whether the velocity was just calculated
|
| |
| void | begin (boolean resetEncoders=true) |
| | sets up the Byte Sized Encoder Decoder board all it really does is tell the board to read from all encoders
|
| |
| void | run () |
| | reads the encoder positions from the board
|
| |
| int32_t | getEncoderPosition (uint8_t n, boolean read=false) |
| | gets the position of an encoder as a 32 bit signed integer (it counts how many times the 16 bit number has overflowed)
|
| |
| int16_t | getEncoderPositionWithoutOverflows (uint8_t n, boolean read=false) |
| | gets the position of an encoder as the 16 bit number that the board returns (it loops around and overflows at 32767 and underflows at -32768)
|
| |
| int16_t | getEncoderVelocity (uint8_t n, boolean read=false) |
| | gets the velocity of an encoder
|
| |
| void | resetEncoderPositions (boolean resetVariables=true) |
| | resets all encoder positions to 0
|
| |
| void | setWhichEncoders (uint8_t mask) |
| | set which encoders you want to receive data from
|
| |
| boolean | isEncoderActive (uint8_t n) |
| | whether you have set to read data from a specific encoder
|
| |
|
| void | write (uint8_t data) |
| | helper function to write a byte to the board
|
| |
|
| uint8_t | address |
| | I2C address of the Byte Sized Encoder Decoder board (as selected by the jumpers)
|
| |
| int16_t | encoderCount [8] |
| | array of 8 numbers representing the number of steps each encoder has taken
|
| |
| int16_t | encoderOverflows [8] |
| | array of 8 numbers representing the number of times each encoder's counter variable has overflowed
|
| |
| int16_t | lastEncoderCount [8] |
| | array of 8 numbers representing the last encoder count read from the board
|
| |
| int16_t | lastVelocityEncoderCount [8] |
| | array of 8 numbers representing the last encoder count read from the board for velocity calculation
|
| |
| TwoWire * | wire |
| | I2C bus to communicate over.
|
| |
| uint8_t | whichEncodersMask |
| | bit mask of which encoders to read from
|
| |
| unsigned long | lastReadMicros [8] |
| | the last time the encoders were read (microseconds)
|
| |
| int16_t | encoderVelocity [8] |
| | array of 8 numbers representing the velocity of each encoder (steps per second)
|
| |
| int16_t | encoderSlowestInterval [8] |
| | after this many milliseconds without an encoder tick velocity is set to zero.
|
| |
| int16_t | encoderEnoughCounts [8] |
| | enough counts to calculate velocity from
|
| |
| boolean | isVelNewVal [8] |
| | array of 8 booleans representing whether the velocity was just calculated
|
| |
class for communicating with the firmware on a Byte Sized Encoder Decoder board
◆ ByteSizedEncoderDecoder()
| ByteSizedEncoderDecoder::ByteSizedEncoderDecoder |
( |
TwoWire * | _wire, |
|
|
uint8_t | _address = 14, |
|
|
int16_t | _encoderSlowestInterval = 0, |
|
|
int16_t | _encoderEnoughCounts = 0 ) |
|
inline |
Constructor for the Byte Sized Encoder Decoder class.
- Parameters
-
| _wire | I2C bus to communicate over. &Wire or &Wire1 |
| _address | I2C address of the Byte Sized Encoder Decoder board (as selected by the jumpers), default is 14, (14-17 are options) |
| _encoderSlowestInterval | after this many milliseconds without a calculation, velocity is recalculated |
| _encoderEnoughCounts | enough counts to calculate velocity |
◆ begin()
| void ByteSizedEncoderDecoder::begin |
( |
boolean | resetEncoders = true | ) |
|
|
inline |
sets up the Byte Sized Encoder Decoder board all it really does is tell the board to read from all encoders
- Parameters
-
| resetEncoders | whether to reset the encoder positions to 0, default is true |
- Note
- call this after Wire.begin() has been called
◆ getEncoderPosition()
| int32_t ByteSizedEncoderDecoder::getEncoderPosition |
( |
uint8_t | n, |
|
|
boolean | read = false ) |
|
inline |
gets the position of an encoder as a 32 bit signed integer (it counts how many times the 16 bit number has overflowed)
- Parameters
-
| n | encoder number (1-8), other values will return 0 |
| read | whether to read the encoder positions from the board before returning the value, default is false |
- Return values
-
| int32_t | the number of steps the encoder has taken |
◆ getEncoderPositionWithoutOverflows()
| int16_t ByteSizedEncoderDecoder::getEncoderPositionWithoutOverflows |
( |
uint8_t | n, |
|
|
boolean | read = false ) |
|
inline |
gets the position of an encoder as the 16 bit number that the board returns (it loops around and overflows at 32767 and underflows at -32768)
- Note
- use getEncoderPosition if you want a 32 bit number that includes how many times the number from the board has overflowed
- Parameters
-
| n | encoder number (1-8), other values will return 0 |
| read | whether to read the encoder positions from the board before returning the value, default is false |
- Return values
-
| int16_t | the number of steps the encoder has taken (though it loops around and overflows at 32767 and underflows at -32768) |
◆ getEncoderVelocity()
| int16_t ByteSizedEncoderDecoder::getEncoderVelocity |
( |
uint8_t | n, |
|
|
boolean | read = false ) |
|
inline |
gets the velocity of an encoder
- Parameters
-
| n | encoder number (1-8), other values will return 0 |
| read | whether to read the encoder positions from the board before returning the value, default is false |
- Return values
-
| int16_t | the velocity of the encoder (steps per second) |
◆ isEncoderActive()
| boolean ByteSizedEncoderDecoder::isEncoderActive |
( |
uint8_t | n | ) |
|
|
inline |
whether you have set to read data from a specific encoder
- Parameters
-
- Return values
-
| boolean | whether you have set to read data from a specific encoder |
◆ isVelNew()
| boolean ByteSizedEncoderDecoder::isVelNew |
( |
uint8_t | n | ) |
|
|
inline |
whether the velocity was just calculated
- Note
- this function resets the value to false, so call it just once
- Parameters
-
- Return values
-
| boolean | whether the velocity was just calculated |
◆ resetEncoderPositions()
| void ByteSizedEncoderDecoder::resetEncoderPositions |
( |
boolean | resetVariables = true | ) |
|
|
inline |
resets all encoder positions to 0
- Parameters
-
| resetVariables | whether to reset the encoderCount and encoderOverflows variables, default is true |
◆ run()
| void ByteSizedEncoderDecoder::run |
( |
| ) |
|
|
inline |
reads the encoder positions from the board
- Note
- call this in your loop to update the encoder positions
◆ setEncoderEnoughCounts()
| void ByteSizedEncoderDecoder::setEncoderEnoughCounts |
( |
uint8_t | n, |
|
|
int16_t | counts ) |
|
inline |
set the value of encoderEnoughCounts
- Parameters
-
| n | encoder number (1-8), or 0 to set all at once |
| counts | enough counts to calculate velocity |
◆ setEncoderSlowestInterval()
| void ByteSizedEncoderDecoder::setEncoderSlowestInterval |
( |
uint8_t | n, |
|
|
int16_t | interval ) |
|
inline |
set the value of encoderSlowestInterval
- Parameters
-
| n | encoder number (1-8), or 0 to set all at once |
| interval | after this many milliseconds without a calculation, velocity is recalculated |
◆ setWhichEncoders()
| void ByteSizedEncoderDecoder::setWhichEncoders |
( |
uint8_t | mask | ) |
|
|
inline |
set which encoders you want to receive data from
- Parameters
-
| mask | 8 bit mask of which encoders to read from 0b00000101 would read from encoders 6 and 8 (aligns with the labels on the board) |
◆ write()
| void ByteSizedEncoderDecoder::write |
( |
uint8_t | data | ) |
|
|
inlineprotected |
helper function to write a byte to the board
◆ address
| uint8_t ByteSizedEncoderDecoder::address |
|
protected |
I2C address of the Byte Sized Encoder Decoder board (as selected by the jumpers)
◆ encoderCount
| int16_t ByteSizedEncoderDecoder::encoderCount[8] |
|
protected |
array of 8 numbers representing the number of steps each encoder has taken
◆ encoderEnoughCounts
| int16_t ByteSizedEncoderDecoder::encoderEnoughCounts[8] |
|
protected |
enough counts to calculate velocity from
◆ encoderOverflows
| int16_t ByteSizedEncoderDecoder::encoderOverflows[8] |
|
protected |
array of 8 numbers representing the number of times each encoder's counter variable has overflowed
◆ encoderSlowestInterval
| int16_t ByteSizedEncoderDecoder::encoderSlowestInterval[8] |
|
protected |
after this many milliseconds without an encoder tick velocity is set to zero.
◆ encoderVelocity
| int16_t ByteSizedEncoderDecoder::encoderVelocity[8] |
|
protected |
array of 8 numbers representing the velocity of each encoder (steps per second)
◆ isVelNewVal
| boolean ByteSizedEncoderDecoder::isVelNewVal[8] |
|
protected |
array of 8 booleans representing whether the velocity was just calculated
◆ lastEncoderCount
| int16_t ByteSizedEncoderDecoder::lastEncoderCount[8] |
|
protected |
array of 8 numbers representing the last encoder count read from the board
◆ lastReadMicros
| unsigned long ByteSizedEncoderDecoder::lastReadMicros[8] |
|
protected |
the last time the encoders were read (microseconds)
◆ lastVelocityEncoderCount
| int16_t ByteSizedEncoderDecoder::lastVelocityEncoderCount[8] |
|
protected |
array of 8 numbers representing the last encoder count read from the board for velocity calculation
◆ whichEncodersMask
| uint8_t ByteSizedEncoderDecoder::whichEncodersMask |
|
protected |
bit mask of which encoders to read from
◆ wire
| TwoWire* ByteSizedEncoderDecoder::wire |
|
protected |
I2C bus to communicate over.
The documentation for this class was generated from the following file: