Encoder driver class. More...
Public Member Functions | |
| def | __init__ (self, pin1, pin2, timer) |
| def | update (self) |
| Updates the position of the encoder. More... | |
| def | get_position (self) |
| Returns the current position of the encoder. | |
| def | set_position (self, pos) |
| Resets the position of the encoder to the specified value "pos". More... | |
| def | get_delta (self) |
| Returns the "good" deltas. | |
Public Attributes | |
| position | |
| old_count | |
| period | |
| tim | |
| new_count | |
| raw_delta | |
| delta | |
Encoder driver class.
| pin1 | Object creating the first pin of the encoder |
| pin2 | Object creating the second pin of the encoder |
| tim | A user input which initializes the timer object. |
| def enc.EncoderDriver.set_position | ( | self, | |
| pos | |||
| ) |
Resets the position of the encoder to the specified value "pos".
| pos | A user input whose value is used to reset the position of the encoder |
| def enc.EncoderDriver.update | ( | self | ) |
Updates the position of the encoder.
This function updates the position of the encoder whenever it is called. This is done by taking the differnce of the last two positions (represented by "delta" variables) and checking for the validity of the deltas. A "bad" delta, is defined when the two positions being referenced in the delta span across the encoder period (going from 0 to 0XFFFF or 0XFFFF to 0). The code then adjusts the "bad" delta by adding the period to the delta.
The position is then updated, by continuously adding "good" deltas.